blob: d64e057a81dc31c5f03660f59e211092ebc5d36f [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") ?: []
Oleksii Zhurba71e97882018-02-16 20:09:43 -060019
Oleksii Zhurba817a8142018-10-08 21:38:15 +030020def 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 Zhurba817a8142018-10-08 21:38:15 +030023/*
24YAML example
25=====
Oleksii Zhurba71e97882018-02-16 20:09:43 -060026
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
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020038
Oleksii Zhurba817a8142018-10-08 21:38:15 +030039*/
Hanna Arhipova3b4b0652018-12-03 14:06:58 +020040
Oleksii Zhurba817a8142018-10-08 21:38:15 +030041node (SLAVE_NODE) {
42 def artifacts_dir = 'validation_artifacts'
43 def configRun = [:]
44 try {
45 withEnv(env_vars) {
46 stage('Initialization') {
47 def container_workdir = '/var/lib'
48 def test_suite_name = "${env.JOB_NAME}"
49 def workdir = "${container_workdir}/${test_suite_name}"
50 def xml_file = "${test_suite_name}_report.xml"
51 def tests_set = (env.getProperty('tests_set')) ?: ''
Hanna Arhipova2dd42af2019-05-15 17:09:13 +030052 def script = "pytest --junitxml ${container_workdir}/${artifacts_dir}/${xml_file} --tb=short -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}",
66 "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt"
Oleksii Zhurba817a8142018-10-08 21:38:15 +030067 ] + env_vars
Oleksii Zhurbad9034952018-09-03 21:06:06 -050068
Oleksii Zhurba817a8142018-10-08 21:38:15 +030069 // Generating final config
70 configRun = [
71 'image': IMAGE,
72 'baseRepoPreConfig': false,
73 'dockerMaxCpus': 2,
74 'dockerExtraOpts' : [
Hanna Arhipova5a380532019-02-07 12:17:37 +020075 "--network=host",
Oleksii Zhurba817a8142018-10-08 21:38:15 +030076 "-v /root/qa_results/:/root/qa_results/",
Hanna Arhipova16d95af2019-06-04 12:39:30 +030077 "-v /etc/ssl/certs/:/etc/ssl/certs/:ro",
Oleksii Zhurba817a8142018-10-08 21:38:15 +030078 "-v ${env.WORKSPACE}/${artifacts_dir}/:${container_workdir}/${artifacts_dir}/",
79 ],
80 'envOpts' : env_vars_list,
81 'runCommands' : commands_list
82 ]
83 }
84
85 stage('Run Tests') {
86 salt_testing.setupDockerAndTest(configRun)
87 }
88
89 stage ('Publish results') {
90 archiveArtifacts artifacts: "${artifacts_dir}/*"
91 junit "${artifacts_dir}/*.xml"
92 if (env.JOB_NAME.contains("cvp-spt")) {
93 plot csvFileName: 'plot-glance.csv',
94 group: 'SPT',
95 style: 'line',
96 title: 'SPT Glance results',
97 xmlSeries: [[
98 file: "${env.JOB_NAME}_report.xml",
99 nodeType: 'NODESET',
100 url: '',
101 xpath: '/testsuite/testcase[@name="test_speed_glance"]/properties/property']]
102 plot csvFileName: 'plot-hw2hw.csv',
103 group: 'SPT',
104 style: 'line',
105 title: 'SPT HW2HW results',
106 xmlSeries: [[
107 file: "${env.JOB_NAME}_report.xml",
108 nodeType: 'NODESET',
109 url: '',
110 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_hw2hw"]/properties/property']]
111 plot csvFileName: 'plot-vm2vm.csv',
112 group: 'SPT',
113 style: 'line',
114 title: 'SPT VM2VM results',
115 xmlSeries: [[
116 file: "${env.JOB_NAME}_report.xml",
117 nodeType: 'NODESET',
118 url: '',
119 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_vm2vm"]/properties/property']]
120 }
Oleksii Zhurbad9034952018-09-03 21:06:06 -0500121 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600122 }
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300123 }
124 catch (Throwable e) {
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600125 currentBuild.result = "FAILURE"
126 throw e
Oleksii Zhurba817a8142018-10-08 21:38:15 +0300127 }
128 finally {
129 sh "rm -rf ${artifacts_dir}"
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600130 }
131}