blob: 13f41eab4471516f2751dc4c01d703630434f52b [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 Zhurba817a8142018-10-08 21:38:15 +03008 * 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 Zhurba817a8142018-10-08 21:38:15 +030017def EXTRA_PARAMS = readYaml(text: env.getProperty('EXTRA_PARAMS')) ?: [:]
18def env_vars = EXTRA_PARAMS.get("envs") ?: []
Ievgeniia Zadorozhnae4fd7292019-11-13 18:32:59 +030019def override_config = env.getProperty('EXTRA_PARAMS') ?: ""
Oleksii Zhurba71e97882018-02-16 20:09:43 -060020
Oleksii Zhurba817a8142018-10-08 21:38:15 +030021def IMAGE = (env.getProperty('IMAGE')) ?: 'docker-prod-local.docker.mirantis.net/mirantis/cvp/cvp-sanity-checks:stable'
22def SLAVE_NODE = (env.getProperty('SLAVE_NODE')) ?: 'docker'
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020023
Oleksii Zhurba817a8142018-10-08 21:38:15 +030024/*
25YAML example
26=====
Oleksii Zhurba817a8142018-10-08 21:38:15 +030027# commands is a map of commands which looks like step_name: shell_command
28commands:
29 001_prepare: rm /var/lib/g.txt
30 002_prepare: git clone http://repo_with_tests.git
31 003_test: cd repo_with_tests && pytest /var/lib/ --collect-only
32 004_collect: cp cvp-spt /var/lib/validation_artifacts/
33# envs is a list of new environment variables
34envs:
35 - SALT_USERNAME=admin
36 - SALT_PASSWORD=password
37 - drivetrain_version=testing
Oleksii Zhurba817a8142018-10-08 21:38:15 +030038*/
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020039
Oleksii Zhurba817a8142018-10-08 21:38:15 +030040node (SLAVE_NODE) {
41 def artifacts_dir = 'validation_artifacts'
Oleksii Zhurbafe27db72019-05-30 18:03:41 -050042 def test_suite_name = "${env.JOB_NAME}"
43 def xml_file = "${test_suite_name}_report.xml"
44
Oleksii Zhurba817a8142018-10-08 21:38:15 +030045 def configRun = [:]
46 try {
47 withEnv(env_vars) {
48 stage('Initialization') {
49 def container_workdir = '/var/lib'
Oleksii Zhurba817a8142018-10-08 21:38:15 +030050 def workdir = "${container_workdir}/${test_suite_name}"
Oleksii Zhurba817a8142018-10-08 21:38:15 +030051 def tests_set = (env.getProperty('tests_set')) ?: ''
Dmitriy Kruglov6749a372019-08-19 12:53:41 +020052 def script = "pytest --junitxml ${container_workdir}/${artifacts_dir}/${xml_file} -vv ${tests_set}"
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020053
Oleksii Zhurba817a8142018-10-08 21:38:15 +030054 sh "mkdir -p ${artifacts_dir}"
55
56 // Enrichment for docker commands
57 def commands = EXTRA_PARAMS.get("commands") ?: ['010_start_tests': "cd ${workdir} && with_venv.sh ${script}"]
58 def commands_list = commands.collectEntries{ [ (it.key) : { sh("${it.value}") } ] }
59
60 // Enrichment for env variables
61 def creds = common.getCredentials(SALT_MASTER_CREDENTIALS)
62 def env_vars_list = [
63 "SALT_USERNAME=${creds.username}",
64 "SALT_PASSWORD=${creds.password}",
Hanna Arhipova16d95af2019-06-04 12:39:30 +030065 "SALT_URL=${SALT_MASTER_URL}",
Ievgeniia Zadorozhnae4fd7292019-11-13 18:32:59 +030066 "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt",
67 "OVERRIDE_CONFIG=${override_config}"
Oleksii Zhurba817a8142018-10-08 21:38:15 +030068 ] + env_vars
Oleksii Zhurbad9034952018-09-03 21:06:06 -050069
Oleksii Zhurba817a8142018-10-08 21:38:15 +030070 // Generating final config
Oleksii Zhurbab7be9ff2019-07-22 11:15:02 -050071 def force_pull = (env.getProperty('force_pull')) ?: false
Oleksii Zhurba817a8142018-10-08 21:38:15 +030072 configRun = [
73 'image': IMAGE,
Oleksii Zhurbab7be9ff2019-07-22 11:15:02 -050074 'dockerPull': force_pull.toBoolean(),
Oleksii Zhurba817a8142018-10-08 21:38:15 +030075 'baseRepoPreConfig': false,
76 'dockerMaxCpus': 2,
77 'dockerExtraOpts' : [
Hanna Arhipova5a380532019-02-07 12:17:37 +020078 "--network=host",
Oleksii Zhurba817a8142018-10-08 21:38:15 +030079 "-v /root/qa_results/:/root/qa_results/",
Hanna Arhipova16d95af2019-06-04 12:39:30 +030080 "-v /etc/ssl/certs/:/etc/ssl/certs/:ro",
Oleksii Zhurba817a8142018-10-08 21:38:15 +030081 "-v ${env.WORKSPACE}/${artifacts_dir}/:${container_workdir}/${artifacts_dir}/",
82 ],
83 'envOpts' : env_vars_list,
84 'runCommands' : commands_list
85 ]
86 }
87
88 stage('Run Tests') {
89 salt_testing.setupDockerAndTest(configRun)
90 }
91
92 stage ('Publish results') {
93 archiveArtifacts artifacts: "${artifacts_dir}/*"
94 junit "${artifacts_dir}/*.xml"
95 if (env.JOB_NAME.contains("cvp-spt")) {
96 plot csvFileName: 'plot-glance.csv',
97 group: 'SPT',
98 style: 'line',
99 title: 'SPT Glance results',
100 xmlSeries: [[
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500101 file: "${artifacts_dir}/${xml_file}",
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300102 nodeType: 'NODESET',
103 url: '',
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500104 xpath: '/testsuite/testcase[@classname="tests.test_glance"]/properties/property']]
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300105 plot csvFileName: 'plot-hw2hw.csv',
106 group: 'SPT',
107 style: 'line',
108 title: 'SPT HW2HW results',
109 xmlSeries: [[
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500110 file: "${artifacts_dir}/${xml_file}",
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300111 nodeType: 'NODESET',
112 url: '',
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500113 xpath: '/testsuite/testcase[@classname="tests.test_hw2hw"]/properties/property']]
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300114 plot csvFileName: 'plot-vm2vm.csv',
115 group: 'SPT',
116 style: 'line',
117 title: 'SPT VM2VM results',
118 xmlSeries: [[
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500119 file: "${artifacts_dir}/${xml_file}",
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300120 nodeType: 'NODESET',
121 url: '',
Oleksii Zhurbafe27db72019-05-30 18:03:41 -0500122 xpath: '/testsuite/testcase[@classname="tests.test_vm2vm"]/properties/property']]
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300123 }
Oleksii Zhurbad9034952018-09-03 21:06:06 -0500124 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600125 }
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300126 }
127 catch (Throwable e) {
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600128 currentBuild.result = "FAILURE"
129 throw e
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300130 }
131 finally {
132 sh "rm -rf ${artifacts_dir}"
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600133 }
134}