blob: b6461309802d0219cf74252f51874b45953bf303 [file] [log] [blame]
Oleksii Zhurba71e97882018-02-16 20:09:43 -06001/**
2 *
3 * Launch pytest frameworks in Jenkins
4 *
5 * Expected parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -05008 * IMAGE Docker image link to use for running container with test framework.
9 * EXTRA_PARAMS Yaml context which contains additional setting for job
Oleksii Zhurba71e97882018-02-16 20:09:43 -060010 *
Oleksii Zhurba71e97882018-02-16 20:09:43 -060011 */
12
Oleksii Zhurbad9034952018-09-03 21:06:06 -050013common = new com.mirantis.mk.Common()
Oleksii Zhurba71e97882018-02-16 20:09:43 -060014validate = new com.mirantis.mcp.Validate()
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020015salt_testing = new com.mirantis.mk.SaltModelTesting()
Hanna Arhipovab451e792018-12-18 15:27:35 +020016
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050017def EXTRA_PARAMS = readYaml(text: env.getProperty('EXTRA_PARAMS')) ?: [:]
18def env_vars = EXTRA_PARAMS.get("envs") ?: []
Oleksii Zhurba71e97882018-02-16 20:09:43 -060019
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050020def IMAGE = (env.getProperty('IMAGE')) ?: 'docker-prod-local.docker.mirantis.net/mirantis/cvp/cvp-sanity-checks:stable'
21def SLAVE_NODE = (env.getProperty('SLAVE_NODE')) ?: 'docker'
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020022
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050023/*
24YAML example
25=====
26# commands is a map of commands which looks like step_name: shell_command
27commands:
28 001_prepare: rm /var/lib/g.txt
29 002_prepare: git clone http://repo_with_tests.git
30 003_test: cd repo_with_tests && pytest /var/lib/ --collect-only
31 004_collect: cp cvp-spt /var/lib/validation_artifacts/
32# envs is a list of new environment variables
33envs:
34 - SALT_USERNAME=admin
35 - SALT_PASSWORD=password
36 - drivetrain_version=testing
37*/
Oleksii Zhurba71e97882018-02-16 20:09:43 -060038
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050039node (SLAVE_NODE) {
40 def artifacts_dir = 'validation_artifacts'
41 def configRun = [:]
42 try {
43 withEnv(env_vars) {
44 stage('Initialization') {
45 def container_workdir = '/var/lib'
46 def test_suite_name = "${env.JOB_NAME}"
47 def workdir = "${container_workdir}/${test_suite_name}"
48 def xml_file = "${test_suite_name}_report.xml"
49 def tests_set = (env.getProperty('tests_set')) ?: ''
50 def script = "pytest --junitxml ${container_workdir}/${artifacts_dir}/${xml_file} --tb=short -vv ${tests_set}"
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020051
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050052 sh "mkdir -p ${artifacts_dir}"
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020053
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050054 // Enrichment for docker commands
55 def commands = EXTRA_PARAMS.get("commands") ?: ['010_start_tests': "cd ${workdir} && with_venv.sh ${script}"]
56 def commands_list = commands.collectEntries{ [ (it.key) : { sh("${it.value}") } ] }
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020057
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050058 // Enrichment for env variables
59 def creds = common.getCredentials(SALT_MASTER_CREDENTIALS)
60 def env_vars_list = [
61 "SALT_USERNAME=${creds.username}",
62 "SALT_PASSWORD=${creds.password}",
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020063 "SALT_URL=${SALT_MASTER_URL}"
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050064 ] + env_vars
Oleksii Zhurbad9034952018-09-03 21:06:06 -050065
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -050066 // Generating final config
67 configRun = [
68 'image': IMAGE,
69 'baseRepoPreConfig': false,
70 'dockerMaxCpus': 2,
71 'dockerExtraOpts' : [
72 "--network=host",
73 "-v /root/qa_results/:/root/qa_results/",
74 "-v ${env.WORKSPACE}/${artifacts_dir}/:${container_workdir}/${artifacts_dir}/",
75 ],
76 'envOpts' : env_vars_list,
77 'runCommands' : commands_list
78 ]
79 }
80
81 stage('Run Tests') {
82 salt_testing.setupDockerAndTest(configRun)
83 }
84
85 stage ('Publish results') {
86 archiveArtifacts artifacts: "${artifacts_dir}/*"
87 junit "${artifacts_dir}/*.xml"
88 if (env.JOB_NAME.contains("cvp-spt")) {
89 plot csvFileName: 'plot-glance.csv',
90 group: 'SPT',
91 style: 'line',
92 title: 'SPT Glance results',
93 xmlSeries: [[
94 file: "${env.JOB_NAME}_report.xml",
95 nodeType: 'NODESET',
96 url: '',
97 xpath: '/testsuite/testcase[@name="test_speed_glance"]/properties/property']]
98 plot csvFileName: 'plot-hw2hw.csv',
99 group: 'SPT',
100 style: 'line',
101 title: 'SPT HW2HW results',
102 xmlSeries: [[
103 file: "${env.JOB_NAME}_report.xml",
104 nodeType: 'NODESET',
105 url: '',
106 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_hw2hw"]/properties/property']]
107 plot csvFileName: 'plot-vm2vm.csv',
108 group: 'SPT',
109 style: 'line',
110 title: 'SPT VM2VM results',
111 xmlSeries: [[
112 file: "${env.JOB_NAME}_report.xml",
113 nodeType: 'NODESET',
114 url: '',
115 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_vm2vm"]/properties/property']]
116 }
Oleksii Zhurbad9034952018-09-03 21:06:06 -0500117 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600118 }
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -0500119 }
120 catch (Throwable e) {
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600121 currentBuild.result = "FAILURE"
122 throw e
Oleksii Zhurbacaa46e12019-04-16 17:38:09 -0500123 }
124 finally {
125 sh "rm -rf ${artifacts_dir}"
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600126 }
127}