Using Jenkins to Validate your Nutanix Calm Deployment

Nutanix , 0 Comments

In most use cases, Jenkins is used for software testing, building, delivering and software deployment, and it’s mostly used by software developers.
In this blog post, I will show you how you can use Jenkins to test and validate you deployed application,

I will be using Nutanix Calm to install a simple web server inside the deployed virtual machine, a more production oriented scenario will be to use this to test an application hosted behind a load balancer.
The test is very basic, I will use a small bash script to test if the deployed VM are up and running our Apache web server.

Let’s start from scratch

Running your Jenkins instance
The easiest and quickest way to run Jenkins for testing purpose is to use Docker container, the following command can be used to run the latest Jenkins version and then extract the admin password.

mkdir /var/jenkins
docker run -d --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins/jenkins:lts
docker exec myjenkins cat /var/jenkins_home/secrets/initialAdminPassword

Let create our Jenkins test

Create a free style project and add a parameterized action with a variable named machine_ip, this variable will be used to inject the deployed virtual machine ip address and will be used inside our testing script.

Then copy and paste the below script inside the script box

#!/bin/bash

echo "machine ip = ${machine_ip}"


url="http://${machine_ip}"
code=`curl -sL --connect-timeout 20 --max-time 30 -w "%{http_code}\\n" "$url" -o /dev/null`

if [ "$code" = "200" ]; then
  echo "Website $url is online."
  exit 0
else
  echo "Website $url seems to be offline."
  exit 1
fi

The script will basically use curl to browse a web server hosted on the deployed virtual machine, if successful, Jenkins job will be marked as SUCCESS, otherwise, we will raise an error.

You can test the job by using Build with Parameters

I will be using Jenkins REST API to launch the test job after deploying the virtual machine and then monitor its status.

  • First script, will simply run the job using an HTTP POST request with the supplied parameter.
  • Second script, will be used to monitor the successful or failed execution of this job, it will make a first request to see if the job is running, if not, it will continue to do so until a timeout of five minutes is reached, of course you can change the timeout value to whatever meet your need.

The tricky part is from where to recover the job id, strangely this is returned as the header value Location.

Nutanix Calm tasks should be ordered like this at Start level

After running your blueprint, you should see your job kicking, you can view the detailed output from console output on Jenkins interface.

I hope this can give you an idea on how to use Jenkins to validate your Calm deployment, all scripts are hosted on my Github repo.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.