Continuous Integration

The HP Application Automation Tools plugin for the Jenkins continuous integration server provides a mechanism for incorporating virtual services into a build script. This open source plugin enables you to add steps to your Jenkins build job to:

  • deploy and undeploy virtual services
  • start and stop simulation and learning
  • export virtual services

This section describes several testing scenarios that you can automate using Jenkins.

For detailed instructions on using the plugin to complete these tasks, see https://wiki.jenkins-ci.org/display/JENKINS/HP+Application+Automation+Tools

Note: The HP Application Automation Tools Plugin for Jenkins is a java application that can be run on a Jenkins server running on Windows or on any Linux platform.

General prerequisites

Before you begin setting up a job in Jenkins, make sure to:

  • Create a virtual service. In the Service Virtualization Designer, create or open the virtual service that you want to use in your build job.
  • Deploy the virtual service. Try to deploy the virtual service to the target Service Virtualization Server to verify that all required agents are ready.
  • Use source control. It is recommended to commit virtual service files to source control to enable easy distribution to build machines.

Back to top

Configure the connection to your Service Virtualization Server

Configure the Jenkins connection to your Service Virtualization Server, according to the plugin documentation.

Test the connection to verify the setup.

You can configure connections to multiple Service Virtualization Servers in Jenkins. The Servers are then available for selection when you create build steps.

Back to top

Use a virtual service in a Jenkins test

A virtualized service may be very useful when your tests need to use services which are not available in your testing environment.

Create a build job in Jenkins

  1. Create a new free-style project.
  2. Specify source control options to checkout your tests and virtual service files.
  3. Add the SV: Deploy Virtual Service build step to deploy the virtual service on the Service Virtualization Server.

    Specify the Service Virtualization project path relative to the checkout directory. You can optionally choose to specify a specific virtual service from the project, if you do not want to deploy all the virtual services.

  4. Run the build to verify the source control connection, paths, and the connection to the Service Virtualization Server.

    Review the build log to confirm the names and IDs of the deployed virtual services and the simulation models that were used. The names or IDs are also needed for setting up the subsequent steps in the build job.

    Example:

  5. Add the SV: Change Mode of Virtual Service build step to change the virtual service mode to Simulate. Specify the Service Virtualization Server, virtual service, and data and performance models to use.

  6. Add a build step to run your Jenkins tests that are using the virtual service.
  7. At the end of the job, add the SV: Undeploy Virtual Service build step to undeploy the virtual service from the Service Virtualization Server.

Back to top

Automate the update of virtual service models

This section describes how to set up a Jenkins job to automatically update a simulation model (data or performance) in your service. A virtual service with a periodically updated model can be used as a fresh backup of the real service in the event of unexpected failure.

Prerequisite: Prepare the virtual service.

Create or open a virtual service and create a simulation model. The data model can be empty.

Create a build job in Jenkins

  1. Perform steps 1-4 of Use a virtual service in a Jenkins test.
  2. Add the SV: Change Mode of Virtual Service build step to change the virtual service mode to Learn.
  3. Add a build step to run your Jenkins tests that are using the virtual service, in order to record data.
  4. Add the SV: Export Virtual Service build step to export the virtual service. The export step creates a new folder named according to the virtual service name in the target directory that you specify .

    Note: Before export, the virtual service must be switched from Learning to Stand-By mode to stop learning and generate the updated simulation models. Make sure to select the option to switch the service to Stand-By mode before export.

  5. Add the SV: Undeploy Virtual Service build step to undeploy the virtual service from the Service Virtualization Server.
  6. Add a post-build action to select a storage option for the exported service. For example, you can use the built-in Jenkins Archive the artifacts option to download the updated data model files. Alternatively, zip the files using the Compress Artifacts plugin, check the files back in to source control, upload the files via FTP, and so on.

Back to top

Use a virtual service in a LoadRunner scenario

This section describes how to setup a Jenkins job for a LoadRunner scenario that is using a virtual service.

Prerequisite: Prepare the virtual service

  1. Create or open a virtual service in the Designer. Prepare simulation models to use in the LoadRunner scenario.
  2. Try to deploy the virtual service on the Service Virtualization Server to verify the settings.
  3. Commit all virtual service files to your version control system or place them on shared storage so they are accessible by the Jenkins job.

Prerequisite: Prepare the LoadRunner script

  1. In HPE Virtual User Generator, create a LoadRunner script that calls the virtual service.
  2. In HPE LoadRunner Controller, create a LoadRunner scenario that consumes the script from the previous step.
  3. In the Design tab of the LoadRunner scenario, open the Service Virtualization Setup dialog box .
  4. Enter the management endpoint (URL) of the Service Virtualization Server, and related credentials, to view the list of deployed services on your Service Virtualization Server.
  5. Select your virtual service, models, and virtual service mode.
  6. Try to run the LoadRunner scenario from LoadRunner Controller to verify the settings.
  7. Commit all LoadRunner scenario files to your version control system or place them on shared storage so they are accessible by the Jenkins job.

Create a build job in Jenkins

  1. Perform steps 1-4 of Use a virtual service in a Jenkins test.
  1. Add the Execute HP tests from file system build step to execute the LoadRunner scenario, as described in the plugin documentation. This step runs the scenario, and switches your virtual service to Simulate mode, using the simulation models defined in the LoadRunner scenario.
  2. Add the SV: Undeploy Virtual Service build step to undeploy the virtual service from the Service Virtualization Server.
  3. Add a post-build action to publish the LoadRunner test results.

Back to top

Use Service Virtualization build steps in a Jenkins pipeline script

The functionality of the Service Virtualization build steps in the HP Application Automation Tools Plugin is also available for use in Jenkins Pipeline Scripts. For more details, see the plugin documentation.

This example presents a commented script that uses all four of the Service Virtualization build steps from the plugin.

node {	
   // name of Service Virtualization Server configuration defined
   // in Jenkins Configuration section
   def serverName ='localhost'
   def virtualServiceUrl = 'http://localhost:6070/OlympicMedalSummaryService'
			
   stage 'Checkout'
   checkout scm: [$class   : "SubversionSCM",
		locations: [[remote       : 
	'https://svnserver/svn/Demo/OlympicMedalSummaryRestDemo',
		credentialsId: 'SvnCreds', local: 'Demo']]]
   // Try to undeploy service first to be sure that following deployment
   // will not fail
   stage 'Undeploy service from server'
   svUndeployStep continueIfNotDeployed: true, force: true, serverName: serverName,
	serviceSelection: [projectPassword: '', selectionType: 'SERVICE',
		service: 'OlympicMedalSummaryService']
			
   stage 'Deploy service'
   svDeployStep firstAgentFallback: true, force: false, projectPassword: '',
	projectPath: 'Demo\\Simulation\\OlympicMedalSummaryService.vproj',
	serverName: serverName, service: ''
			
   // Switch service to learning mode using empty 'AutoUpdate DM'
   stage 'Switch service to Learning'
   svChangeModeStep force: false, mode: 'LEARNING', serverName: serverName,
	dataModel: [dataModel: 'AutoUpdate DM', selectionType: 'BY_NAME'],
	performanceModel: [selectionType: 'NONE'],
	serviceSelection: [projectPassword: '', selectionType: 'SERVICE',
		service: 'OlympicMedalSummaryService']
			
   // Compile test application
	stage 'Build test client'
	bat 'msbuild Demo\\Application\\OlympicMedalSummaryRestDemo.csproj'
			
   // Run test application against virtual service in learning mode.
   // This application contains client & server in one executable.
   // Output of client thread is prefixed with "c:"
   // and output of server thread is prefixed with "s:".
   // We should see server & client outputs in log because virtual service is in
   // learning mode and forwards real service.
   stage 'Run test client'
   bat 'Demo\\Application\\bin\\Debug\\OlympicMedalSummaryRestDemo.exe ' + virtualServiceUrl
			
   // Switching service from learning to simulation mode updates data model.
   stage 'Switch service to Simulating'
   svChangeModeStep force: false, mode: 'SIMULATING', serverName: serverName,
	dataModel: [dataModel: 'AutoUpdate DM', selectionType: 'BY_NAME'],
	performanceModel: [selectionType: 'NONE'],
	serviceSelection: [projectPassword: '', selectionType: 'SERVICE',
		service: 'OlympicMedalSummaryService']
			
   // Run test application against virtual service in simulation mode
   // We should see only client outputs in log because virtual service 
   // simulates responses without touching real service.  
   stage 'Run test client'
   bat 'Demo\\Application\\bin\\Debug\\OlympicMedalSummaryRestDemo.exe ' + virtualServiceUrl
			
   // Export of updated data model.
   stage 'Export service'
   svExportStep cleanTargetDirectory: true, force: false, serverName: serverName,
	serviceSelection: [projectPassword: '', selectionType: 'SERVICE',
		service: 'OlympicMedalSummaryService'],
	switchToStandByFirst: true, targetDirectory: 'freshModel'
			
   // Undeploy virtual service to release server resources at the end of test.
   stage 'Undeploy service from server'
   svUndeployStep continueIfNotDeployed: true, force: true, serverName: serverName,
	serviceSelection: [projectPassword: '', selectionType: 'SERVICE',
		service: 'OlympicMedalSummaryService']
  }
		

Back to top