Thursday, May 24, 2018

Python API Execution Server Setup


In this post, I'm outling the process i used to setup an execution server used to run API tests using python.

Setup an API automation ready execution server

  1. Confirm Python -version (python --version)
  2. Install pip (yum -y install python-pip)
  3. Install pip environment (https://docs.pipenv.org/) (pip install pipenv)
  4. Upgrade it (pip install --upgrade pip)
  5. Install requests module (pip2.7 install requests)
  6. Install git (Yum install gut -y)
  7. Clone the git repo (git clone git://github.com/requests/requests.git)
  8. Cd requests; pip install.

I also found the below guides very useful to get a fundamental understanding of api testing. 
  1. Beginner's Guide to API Automation with Python - https://www.grossum.com/blog/beginner-s-guide-to-automating-api-tests-using-python
  1. API Tutorials - https://www.dataquest.io/blog/python-api-tutorial/


GET Status codes
  • 200 -- everything went okay, and the result has been returned (if any)
  • 301 -- the server is redirecting you to a different endpoint. This can happen when a company switches domain names, or an endpoint name is changed.
  • 401 -- the server thinks you're not authenticated. This happens when you don't send the right credentials to access an API (we'll talk about authentication in a later post).
  • 400 -- the server thinks you made a bad request. This can happen when you don't send along the right data, among other things.
  • 403 -- the resource you're trying to access is forbidden -- you don't have the right permissions to see it.
  • 404 -- the resource you tried to access wasn't found on the server.

Finding your way in vi (the editor)

While in command mode (case sensitive)
  • move the cursor with arrow keys; if there aren't any arrow keys, use j,k,h,l (Fn + left/right key to navigate to start/end of line)

  • i - change to insert mode (before cursor)
  • a - change to insert mode (after cursor)
  • A - change to insert mode (at end of line)
  • r - replace one character
  • R - overwrite text
  • x - delete one character
  • dd - delete one line
  • yy - yank line (copy)
  • p - paste deleted or yanked text after cursor
  • P - paste deleted or yanked text before cursor
  • G - go to end of the file
  • 1G - go to top of the file
  • J - merge next line with this one
  • / - search, follow / with text to find
  • :wq - write file and quit
  • :q! - quit without saving
  • %s/old/new/g - substitute; replace "old" with "new" on all lines
  • :g/pattern/d - delete all lines that match the pattern
  • 0 - move to the beginning of the current line
  • $ - move to end of line
  • H - move to the top of the current window (high)
  • M - move to the top of the current window (middle)
  • L - move to the top of the current window (low)
  • 1G - move to the first line of the file
  • 20G - move to the bottom line of the file
  • G - move to the last line of the file.
While in insert mode
  • ESC - change to command mode
  • any text typed is entered at the cursor
Typical vi session
  1. Type "vi file.txt" at command prompt
  2. Move cursor to where new text will be added
  3. Type "i" to change to insert mode
  4. Type new text
  5. Type ESC to go back to command mode
  6. type ":wq" and ENTER to write the file and quit

Thursday, May 3, 2018

Jenkins installation as a service using .war files on a Virtual Machine


Steps to bring up a Jenkins instance on a centOS7 instance


1. Bringup a VM and & Install any linux distro of your preference. In this case, I'm using CentOS7.
2. Install supported Jenkins v1.624 wget https://updates.jenkins-ci.org/download/war/1.624/jenkins.war.
3. Install Java 7 yum install java-1.7.0-openjdk (https://www.atlantic.net/cloud-hosting/how-to-install-java-jre-jdk-centos-7/) and configure the OS to use java 1.7 by default
4. Set environment (export $JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64" | sudo tee -a /etc/profile;  echo 'export $JRE_HOME=/usr/lib/jvm/jre/' | tee -a /etc/profile; source /etc/profile)
5. Install Jenkins (cd ~; java -jar jenkins.war)
6. Configure Jenkins as a service ( cd /etc/systemd/system; vi jenkins.service and add below lines to it.

[Unit]
Description=Jenkins Service
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/java -jar /usr/local/bin/jenkins.war
Restart=on-abort

[Install]
WantedBy=multi-user.target

7. Start the Jenkins Service (systemctl daemon-reload; systemctl start jenkins.service)


Establishing trust between Jenkins and other applications

Get the certificate of the application (in this case it's named as 'ccm.cer')
  1. export $JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64" | sudo tee -a /etc/profile
  2. echo 'export $JRE_HOME=/usr/lib/jvm/jre/' | tee -a /etc/profile
  3. source /etc/profile

  1. echo $JRE_HOME
  2. echo $JAVA_HOME

  1. java InstallCert 10.193.180.190
  2. cp jssecacerts $JAVA_HOME/lib/security
  3. cp jssecacerts ~/.keystore
  4. keytool -list -alias 10.193.180.190-1
  5. Cd /usr/lib/jvm/jre-1.8.0-openjdk/lib/security
  6. keytool -importcert -file /root/ccm.cer -keystore cacerts -alias 10.193.180.190-1
  7. keytool -list -alias 10.193.180.190-1
  8. reboot
  9. systemctl status jenkins.service
  10. systemctl start jenkins.service
  11. systemctl status jenkins.service
  12. java SSLPoke 10.193.180.190 443