Friday, 4 July 2014

Configuring Jenkins Agent to run Robot Framework Tests

This covers the instructions to setup the client machine (the Jenkins Agent) on which the robot framework test cases will run) and the instructions to create a jenkins job to run the robot test cases.

On the Client Machine:
Pre-Conditions:
Install the mandatory softwares (if missing) in the agent machine as shown below:
yum install firefox
yum install vim
yum install dbus
dbus-uuidgen > /var/lib/dbus/machine-id
yum install gcc
yum list installed | grep ssl
yum install openssl openssl-devel
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel


On CentOS, you need the postgres dev packages (in case you are running Postgres related tests):
sudo yum install postgresql-devel

Below are the steps to be done on the client machine (CentOS) which will run the Robot framework test case:
1. Log in to the Agent Machine:
   ssh root@<ip>

2. To run the browser in headless mode execute the below:
           yum install Xvfb - check
which Xvfb (It is be located in /usr/bin)
cd /usr/bin

Create a file called "Xvfb.sh"
vim Xvfb.sh

Add the below script in the ‘Xvfb.sh’ file:

#!/bin/sh
mode=$1
case "$mode" in
'start')
if [ -f /usr/bin/Xvfb ]; then
    echo "***Starting up the Virtual Frame Buffer on Screen 1***"
    /usr/bin/Xvfb :99 -screen 0 1152x900x8 &
fi
;;
*)
echo " Usage: "
echo " $0 start (start XVFB)"
echo " $0 stop (stop XVFB - not supported)"
exit 1
;;
esac
dbus-uuidgen > /var/lib/dbus/machine-id
exit 0

(For more details please refer http://sahi.co.in/w/configuring-sahi-with-xvbf )

Run the script using the below command:
sh Xvfb.sh start


3. Install pyenv to switch between Python versions:

mkdir /localdisk
cd /localdisk
git clone git://github.com/yyuu/pyenv.git pyenv

Find the path where pyenv is installed and add the below in ~/.bashrc file
   export PYENV_ROOT=/localdisk/pyenv
   export PATH=$PYENV_ROOT/bin:$PATH

Reload the env variables:
   source ~/.bashrc


4. Installing Python 2.7.5 :
    Install Python 2.7.5 using the below command:   
           pyenv install 2.7.5


(In case of build failure please refer https://github.com/yyuu/pyenv/wiki/Common-build-problems)


5. Installing Virtual Env:
Go upto the bin directory of Python installed via pyenv and install virtualenv:
  cd /localdisk/pyenv/versions/2.7.5/bin
   ./pip install virtualenv



1. Open the Jenkins webpage.
2. Create a new job.
3. Do the mandatory things like adding the gitlab/svn URL (To checkout the Robot framework test cases), agent machine's label (The slave machine should be created)  and Build Parameters (If needed)


4. Add the below shell script which will run the Robot framework test:

echo "Start the UI tests...................."

PYENV_HOME=$WORKSPACE/.pyenv

# Delete previously built virtualenv
if [ -d $PYENV_HOME ]; then
  rm -rf $PYENV_HOME
fi

# Create virtualenv and install necessary packages
/localdisk/pyenv/versions/2.7.5/bin/virtualenv $PYENV_HOME
. $PYENV_HOME/bin/activate

# You could also run "sudo pip install --quiet $WORKSPACE/" where your setup.py file lives

pip install --quiet robotframework
pip install --quiet robotframework-httplibrary
pip install --quiet robotframework-selenium2library
pip install --quiet robotframework-randomlibrary
pip install --quiet robotframework-DatabaseLibrary

#Specify the display here since we're using Xvfb (Xvfb :99 -ac -screen 0 1280x1024x24 +extension RANDR)
export DISPLAY=:99

#Execute our tests!
pybot -L TRACE /my/robot/test/cases

5. In Post-build actions, add ‘Publish Robot Framework Test Report” (The robot Framework plugin should be installed in the Jenkins server)
.
Directory of Robot output = $WORKSPACE
Thresholds for build result = 75 to 90 ( As desired)





Monday, 9 June 2014

Clear QPID Queues and delete them

1. Connect to Qpid:
    # qpid-tool

2.  List the Queues:
   qpid:  list queue
 
     Object Summary:
    ID   Created   Destroyed  Index
    ===============================================================
    154  02:05:42  -          175.ax-q-myqueue2
    155  07:14:00  -          175.ax-q-myqueue1
    156  07:15:36  -          175.ax-q-myqueue1-dl


3. To delete the Queue use the below command:
    qpid: call 154 purge 0 {}
    qpid: OK (0) - {}

    Here, '154' is the ID of the Queue.

4. Press Ctrl + c to come out of QPID terminal.

5. Run the below command to see if the Messages are cleared:
    # qpid-stat -q

Queues
  queue                            dur  autoDel  excl  msg   msgIn  msgOut  bytes  bytesIn  bytesOut  cons  bind
  ================================================================================================================
  ax-q-solar-myqueue1-dl          Y                      0   589    589       0    553k     553k        0     2
  ax-q-solar-myqueue1           Y                      0   589    589       0    553k     553k        0     2
  ax-q-myqueue2                     Y                      0   330    330       0    250k     250k        0     2


6. Delete the Queue using the below command:
   #  qpid-config del queue ax-q-solar-myqueue1

    Here 'ax-q-solar-myqueue1' is the queue name.


Friday, 6 June 2014

No Java Found Issue

Recently, we faced the 'no Java' issue while trying to run a server using the init scripts.

The error we saw was:


which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)

We already has JAVA_HOME configured in the bashrc file. But the init script was looking for it elsewhere.

Below are the steps we can do to fix this issue:

1. Run the echo command to check the JAVA_HOME path
     echo $JAVA_HOME
     /usr/java/jdk1.7.0_51/       ---> This is the JAVA_HOME Path in my machine.

2. Run the which command to locate the program.
    which java
     /usr/java/jdk1.7.0_51/bin/java

3. Create a symlink to this location in '/usr/bin/' for this case as it is one of the location the init script looks for java.
    ln -s /usr/java/jdk1.7.0_51/bin/java /usr/bin/java
  

Try to run the Server again. 

    
    


Tuesday, 3 June 2014

Setting up SSH Keys

There are many blogs about creating keys and SSHing into the machines. I have written this one as i often get confused about the location of keys and the machines on which it should be generated. (Yeah! I know. I am forgetful!)

Machine Names:  Machine1 and Machine2.
Problem Statement: We should be able to log in from Machine1 to Machine2 without using password.

Steps to Enable SSH login between Machine1 and Machine2:

1. Log into Machine1.

2. Go to ~/.ssh folder. If this folder does not exist then create one using the below command in both the machines:
    mkdir ~/.ssh/
    mkdir ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys


3. Go to the ~/.ssh folder and generate the Key pair:
    ssh-keygen -t rsa

4. Once you enter the above command, the next question that will come up is:
    Enter file in which to save the key (/Users/deepti/.ssh/id_rsa):

5. Provide a name for the keys. In my case, the name was 'mykeys'.

6. The next question that will come up is:
     Enter passphrase (empty for no passphrase):
       
        It is your choice whether you want to use a passphrase. In case, you are using automated scripts to SSH between the machines then its better to leave it empty. In order to leave it empty just hit the 'Enter/Return' key.

7. The below lines will be printed once you are done with the above steps:

     Your identification has been saved in mykeys.
Your public key has been saved in mykeys.pub.
The key fingerprint is:
fe:3c:f4:6a:06:c8:3a:17:98:67:b8:1a:01:66:da:28 deepti@Deeptis-MacBook-Pro-5.local
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|.o               |
|++               |
|E o  = .S        |
|.  .+ *.. .      |
|  .  = ..o .     |
|   .+ .  o+ .    |
|  .. o   o+o     |
+-----------------+

8. Here your key generation process has been completed.

9. Open the mykeys.pub file. Replace the machine name with the IP of the Machine1.

Before replacing:  root@Deeptis-MacBook-Pro-5.local
After replacing: root@192.168.1.105

10. Copy the contents of mykeys.pub file to 'authorized_file' of Machine2 using the below command:
cat ~/.ssh/id_rsa.pub | ssh root@192.168.1.115 "cat >> ~/.ssh/authorized_keys"

Here, 192.168.1.115 is the IP of Machine2.

11. Now you are ready to go. Try to login from Machine1 to Machine2 without using password:

ssh root@192.168.1.115    #Machine2's IP

You should not be prompted for a password. However, if you have set a passphrase, then the system will prompt you for it.











Changing the Timezone of PostGreSQL DB

Steps to change the Timezone of PostGres DB are:

1. Log into the Machine which has the PostGres DB.

2. Log into the DB:
    psql -U postgres -d <db_name>

3. Check the time zone of the DB using the below command:
    # show timezone;

4. Log out from the DB.
 
5. Switch to postgres user:
    su - postgres

6. Open the 'postgresql.conf' file in edit mode. This file is usually located inside 'pgdata' folder. Search for the string 'timezone'. Change the value of 'timezone' as desired. The valid timezone values are listed at this link. In this case, we have changed the timezone value to 'Europe/London'.

#intervalstyle = 'postgres'

timezone = 'Europe/London'

7. Save the file.

8. Restart the PG DB. The commands I used are listed below. It depends on the location of the installation.

To Stop:

/usr/pgsql-9.3/bin/pg_ctl -D /ebs/pgdata/ -m fast stop

To Start:
/usr/pgsql-9.3/bin/pg_ctl -D /ebs/pgdata/ -l logfile start

9. Log into the DB again. And check the Timezone:
    #show timezone;

     TimeZone
     ---------------
     Europe/London