Tuesday 8 August 2023

Jenkins - Build Steps - Execute Windows batch command - pytest

::echo off

echo test_product=%test_product%

echo test_env=%test_env%

echo list_devices=[%list_devices%]

echo total iteration=%ota_iterations%

echo total max attempts=%ota_max_attempt%

set test1=KPI_Scripts\UbiCell\%KPM_Tests%

echo test1=%test1%

echo is_test_result_to_be_uploaded_on_cloud=%is_test_result_to_be_uploaded_on_cloud%

pytest %test1% -n=%NumberOfThreadsForOTAIterations% --junitxml="./Reports/reports.xml" --html="./Reports/reports.html" 

Jenkins Groovy Function To Be Used by Active Choice Parameter - To Have Auto Selected Based On Certain Logic

 

Jenkins Groovy Function To Be Used by Active Choice Parameter - To Have Auto Selected Based On Certain Logic

def get_list(x,delimiter,item_to_be_selected,bool_is_selected=false) {

    list_selected = null

    if(x!=null && x.length() > 0) {

        list = x.split(delimiter)

        list_selected = []

        for(int i=0;i<list.size();i++){

            if(bool_is_selected){

                if(list[i].trim().equals(item_to_be_selected)){

                     list_selected[i] = list[i].trim() + ':selected'

                    

                    }

                else {

                    list_selected[i] = list[i].trim()

                }

            }

            else {

                list_selected[i] = list[i].trim()

            }

            

        }

       

    }

     return list_selected

}


Calling the function - return get_list(list_ota_servers,'-','t:98,d:http://updqa4.ubicquia.com',true)

Tuesday 25 July 2023

Regular Expression For Exclusion

 Regular expression for exclusion

Regular expression can be applied for excluding certain words - 

1. Use (?!<word to be excluded>)

2. (?i) to make cases insensitive

Example - discarded and template to be excluded where (?i) indicates being case insensitive

(?i)(?!.*discarded.*)(?!.*template.*)(.*ubicell.*) 

Saturday 22 July 2023

Regular Expression - How To Create Regular Expression For Case Insensitive

 How To Create Regular Expression For Case Insensitive


  1. Use Simple Regular Expression Syntax - (?i)<Normal Regular Expression>
    • (?i) -> Indicates Case Insensitive Regular Expression
  2. Use Language And Technology To Use Library/Methods/Interface To Pass Additional Parameter As             Flag To Determine If Case Sensitive Or Case InSensitive Comparison Is Required. 
  • FindPattern(<regular expression>, caseSensitiveFlag(True/False))

Tuesday 30 May 2023

MQTT Protocol - IOT Design Approach

Original Source - https://www.javatpoint.com/mqtt-protocol

 MQTT stands for Message Queuing Telemetry Transport. MQTT is a machine to machine internet of things connectivity protocol. It is an extremely lightweight and publish-subscribe messaging transport protocol. This protocol is useful for the connection with the remote location where the bandwidth is a premium. These characteristics make it useful in various situations, including constant environment such as for communication machine to machine and internet of things contexts. It is a publish and subscribe system where we can publish and receive the messages as a client. It makes it easy for communication between multiple devices. It is a simple messaging protocol designed for the constrained devices and with low bandwidth, so it's a perfect solution for the internet of things applications.

Current MQTT Version - MQTT 5.0, developed and managed by OASIS.

Journey - MQTT 3.1 -> MQTT 3.1.1 (Backward Compatible) -> MQTT 5.0 (Not Backward Compatible)

The major functional objectives in version 5.0 are:

  • Enhancement in the scalability and the large-scale system in order to set up with the thousands or the millions of devices.
  • Improvement in the error reporting

Characteristics of MQTT

The MQTT has some unique features which are hardly found in other protocols. Some of the features of an MQTT are given below:

  • It is a machine to machine protocol, i.e., it provides communication between the devices.
  • It is designed as a simple and lightweight messaging protocol that uses a publish/subscribe system to exchange the information between the client and the server.
  • It does not require that both the client and the server establish a connection at the same time.
  • It provides faster data transmission, like how WhatsApp/messenger provides a faster delivery. It's a real-time messaging protocol.
  • It allows the clients to subscribe to the narrow selection of topics so that they can receive the information they are looking for.

MQTT Architecture


To understand the MQTT architecture, we first look at the components of the MQTT.

  • Message
  • Client
  • Server or Broker
  • TOPIC

Message

The message is the data that is carried out by the protocol across the network for the application. When the message is transmitted over the network, then the message contains the following parameters:

  1. Payload data
  2. Quality of Service (QoS)
  3. Collection of Properties
  4. Topic Name

Client

In MQTT, the subscriber and publisher are the two roles of a client. The clients subscribe to the topics to publish and receive messages. In simple words, we can say that if any program or device uses an MQTT, then that device is referred to as a client. A device is a client if it opens the network connection to the server, publishes messages that other clients want to see, subscribes to the messages that it is interested in receiving, unsubscribes to the messages that it is not interested in receiving, and closes the network connection to the server.

In MQTT, the client performs two operations:

In MQTT, the client performs two operations:

Publish: When the client sends the data to the server, then we call this operation as a publish.

Subscribe: When the client receives the data from the server, then we call this operation a subscription.

Server

The device or a program that allows the client to publish the messages and subscribe to the messages. A server accepts the network connection from the client, accepts the messages from the client, processes the subscribe and unsubscribe requests, forwards the application messages to the client, and closes the network connection from the client.

TOPIC

MQTT protocol

The label provided to the message is checked against the subscription known by the server is known as TOPIC.

Now we will look at the architecture of MQTT. To understand it more clearly, we will look at the example. Suppose a device has a temperature sensor and wants to send the rating to the server or the broker. If the phone or desktop application wishes to receive this temperature value on the other side, then there will be two things that happened. The publisher first defines the topic; for example, the temperature then publishes the message, i.e., the temperature's value. After publishing the message, the phone or the desktop application on the other side will subscribe to the topic, i.e., temperature and then receive the published message, i.e., the value of the temperature. The server or the broker's role is to deliver the published message to the phone or the desktop application.

MQTT Message Format

MQTT protocol

The MQTT uses the command and the command acknowledgment format, which means that each command has an associated acknowledgment. As shown in the above figure that the connect command has connect acknowledgment, subscribe command has subscribe acknowledgment, and publish command has publish acknowledgment. This mechanism is similar to the handshaking mechanism as in TCP protocol.

Now we will look at the packet structure or message format of the MQTT.

Sunday 14 May 2023

Problem Statement - Jenkins HTML Pubisher Does Not Display HTML Reports Properly With CSS

By default, Jenkins latest version displays Extent Report or any html report with CSS in normal text, as Extent Report or any html report with CSS contains scripts which pose threat to web security. 

To overcome the problem, we have to override property - hudson.model.DirectoryBrowserSupport.CSP

There are 2 options available - 

1. Pass Parameter While Invoking Jenkins With War File - 

    java -Dhudson.model.DirectoryBrowserSupport.CSP="" -jar jenkins.war

2. Configure Jenkins 

    1.     Go to http://localhost:8080/ using admin credentials

2.     Click on Manage Jenkins link.

3.     Click on Script Console.

4.     Type below Syntax in Script Console and click on Run link.

            System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")


Thursday 9 March 2023

 Confiuring VSCode For Protractor Execution- 

Create launch.json file, this file should be under .vscode folder.

launch.json file should have reference to runner tool in program attribute and args attribute should contain the parameters for program attribute. 

Run command would refer lanunch.json for parameters used for execution

Typically, it should like as below - 

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version""0.2.0",
    "configurations": [
        

        {
            "type""pwa-node",          
            "request""launch",
            "name""Protractor Runner",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program""${env:APPDATA}/npm/node_modules/protractor/bin/protractor",
            "args": ["${workspaceFolder}/conf/conf_Jenkins.js"]
            /*
            "args": [
                "-c", "/Users/xyz/config",
                "-p", "2012"
            */
        }
    ]
}