blob: 5891ed1d35e875c6d6a3606572bb47baa9d9683d [file] [log] [blame]
Oleksii Zhurba57a16422019-03-26 13:14:21 -05001/**
2 *
3 * Launch CVP Tempest verification of the cloud
4 *
5 * Expected parameters:
6
7 * SALT_MASTER_URL URL of Salt master
8 * SALT_MASTER_CREDENTIALS Credentials that are used in this Jenkins for accessing Salt master (usually "salt")
9 * SERVICE_NODE Node, where runtest formula and some other states will be executed
10 * VERBOSE Show salt output in Jenkins console
11 * DEBUG_MODE Remove or keep container after the test
12 * STOP_ON_ERROR Stop pipeline if error during salt run occurs
13 * GENERATE_CONFIG Run runtest formula / generate Tempest config
14 * SKIP_LIST_PATH Path to skip list (not in use right now)
15 * TEST_IMAGE Docker image link to use for running container with testing tools.
16 * TARGET_NODE Node to run container with Tempest/Rally
17 * PREPARE_RESOURCES Prepare Openstack resources before test run
18 * TEMPEST_TEST_PATTERN Tests to run
19 * TEMPEST_ENDPOINT_TYPE Type of OS endpoint to use during test run (not in use right now)
20 * concurrency Number of threads to use for Tempest test run
21 * remote_artifacts_dir Folder to use for artifacts on remote node
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -050022 * runtest_tempest_cfg_dir Folder to use to generate and store tempest.conf
23 * runtest_tempest_cfg_name Tempest config name
Oleksii Zhurba57a16422019-03-26 13:14:21 -050024 * report_prefix Some prefix to put to report name
25 *
26 */
27
28
29common = new com.mirantis.mk.Common()
30salt = new com.mirantis.mk.Salt()
31validate = new com.mirantis.mcp.Validate()
32
33def saltMaster
34extraYamlContext = env.getProperty('EXTRA_PARAMS')
35if (extraYamlContext) {
36 common.mergeEnv(env, extraYamlContext) }
37def SALT_MASTER_CREDENTIALS=(env.SALT_MASTER_CREDENTIALS) ?: 'salt'
38def VERBOSE = (env.VERBOSE) ? env.VERBOSE.toBoolean() : true
39def DEBUG_MODE = (env.DEBUG_MODE) ?: false
40def STOP_ON_ERROR = (env.STOP_ON_ERROR) ? env.STOP_ON_ERROR.toBoolean() : false
41def GENERATE_CONFIG = (env.GENERATE_CONFIG) ?: true
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -050042// do not change unless you know what you're doing
Oleksii Zhurba57a16422019-03-26 13:14:21 -050043def remote_artifacts_dir = (env.remote_artifacts_dir) ?: '/root/test/'
44def report_prefix = (env.report_prefix) ?: ''
45def args = ''
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -050046def mounts = [:]
Oleksii Zhurba57a16422019-03-26 13:14:21 -050047node() {
48 try{
49 stage('Initialization') {
50 deleteDir()
51 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
52 container_name = "${env.JOB_NAME}"
53 cluster_name=salt.getPillar(saltMaster, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
54 os_version=salt.getPillar(saltMaster, 'I@salt:master', '_param:openstack_version')['return'][0].values()[0]
55 if (!os_version) {
56 throw new Exception("Openstack is not found on this env. Exiting")
57 }
58 TEST_IMAGE = (env.TEST_IMAGE) ?: "docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:${os_version}"
59 runtest_node = salt.runSaltProcessStep(saltMaster, 'I@runtest:*', 'test.ping')['return'][0]
60 if (runtest_node.values()[0]) {
61 // Let's use Service node that was defined in reclass. If several nodes are defined
62 // we will use the first from salt output
63 common.infoMsg("Service node ${runtest_node.keySet()[0]} is defined in reclass")
64 SERVICE_NODE = runtest_node.keySet()[0]
65 }
66 else {
67 throw new Exception("Runtest config is not found in reclass. Please create runtest.yml and include it " +
68 "into reclass. Check documentation for more details")
69 }
70 common.infoMsg('Refreshing pillars on service node')
71 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
72 tempest_node=salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_test_target')['return'][0].values()[0] ?: 'I@gerrit:client'
73 }
74 stage('Preparing resources') {
75 if ( PREPARE_RESOURCES.toBoolean() ) {
76 common.infoMsg('Running salt.minion state on service node')
77 salt.enforceState(saltMaster, SERVICE_NODE, ['salt.minion'], VERBOSE, STOP_ON_ERROR, null, false, 300, 2, true, [], 60)
78 common.infoMsg('Running keystone.client on service node')
79 salt.enforceState(saltMaster, SERVICE_NODE, 'keystone.client', VERBOSE, STOP_ON_ERROR)
80 common.infoMsg('Running glance.client on service node')
81 salt.enforceState(saltMaster, SERVICE_NODE, 'glance.client', VERBOSE, STOP_ON_ERROR)
82 common.infoMsg('Running nova.client on service node')
83 salt.enforceState(saltMaster, SERVICE_NODE, 'nova.client', VERBOSE, STOP_ON_ERROR)
84 }
85 else {
86 common.infoMsg('Skipping resources preparation')
87 }
88 }
89 stage('Generate config') {
90 if ( GENERATE_CONFIG.toBoolean() ) {
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -050091 // default is /root/test/
92 runtest_tempest_cfg_dir = (env.runtest_tempest_cfg_dir) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_dir')['return'][0].values()[0]
93 // default is tempest_generated.conf
94 runtest_tempest_cfg_name = (env.runtest_tempest_cfg_name) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_name')['return'][0].values()[0]
95 common.infoMsg("runtest_tempest_cfg is ${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}")
96 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.remove', ["${runtest_tempest_cfg_dir}"])
97 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.mkdir', ["${runtest_tempest_cfg_dir}"])
Oleksii Zhurba57a16422019-03-26 13:14:21 -050098 fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0)
99 TARGET_NODE = (env.TARGET_NODE) ?: tempest_node
100 if (TARGET_NODE != tempest_node) {
101 common.infoMsg("TARGET_NODE is defined in Jenkins")
102 def params_to_update = ['tempest_test_target': "${TARGET_NODE}"]
103 common.infoMsg("Overriding default ${tempest_node} value of tempest_test_target parameter")
104 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
105 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${TARGET_NODE}"]])
106 salt.checkResult(result)
107 }
108 common.infoMsg("TARGET_NODE is ${TARGET_NODE}")
109 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.remove', ["${remote_artifacts_dir}"])
110 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -0500111 // runtest state hangs if tempest_test_target is cfg01*
112 // let's run runtest.generate_tempest_config only for this case
113 if (TARGET_NODE == 'cfg01*') {
114 common.warningMsg("It is not recommended to run Tempest container on cfg node, but.. proceeding")
115 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest.generate_tempest_config', VERBOSE, STOP_ON_ERROR)
116 } else {
117 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest', VERBOSE, STOP_ON_ERROR)
118 }
Oleksii Zhurba57a16422019-03-26 13:14:21 -0500119 // we need to refresh pillars on target node after runtest state
120 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
121 if (TARGET_NODE != tempest_node) {
122 common.infoMsg("Reverting tempest_test_target parameter")
123 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
124 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${tempest_node}"]])
125 }
126 SKIP_LIST_PATH = (env.SKIP_LIST_PATH) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_skip_list_path')['return'][0].values()[0]
Oleksii Zhurba57a16422019-03-26 13:14:21 -0500127 if (SKIP_LIST_PATH) {
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -0500128 mounts = ["${runtest_tempest_cfg_dir}/skip.list": "/root/tempest/skip.list"]
Oleksii Zhurba57a16422019-03-26 13:14:21 -0500129 salt.cmdRun(saltMaster, SERVICE_NODE, "salt-cp ${TARGET_NODE} ${SKIP_LIST_PATH} ${runtest_tempest_cfg_dir}/skip.list")
130 args += ' --blacklist-file /root/tempest/skip.list '
131 }
132 }
133 else {
134 common.infoMsg('Skipping Tempest config generation')
135 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_artifacts_dir}/reports")
136 }
137 }
138
139 stage('Run Tempest tests') {
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -0500140 mounts = mounts + ["${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}": "/etc/tempest/tempest.conf"]
Oleksii Zhurba57a16422019-03-26 13:14:21 -0500141 validate.runContainer(master: saltMaster, target: TARGET_NODE, dockerImageLink: TEST_IMAGE,
142 mounts: mounts, name: container_name)
143 report_prefix += 'tempest_'
144 if (env.concurrency) {
145 args += ' -w ' + env.concurrency
146 }
147 if (TEMPEST_TEST_PATTERN == 'set=smoke') {
148 args += ' -s '
149 report_prefix += 'smoke'
150 }
151 else {
152 if (TEMPEST_TEST_PATTERN != 'set=full') {
153 args += " -r ${TEMPEST_TEST_PATTERN} "
Oleksii Zhurbaeffd26f2019-05-29 16:08:40 -0500154 report_prefix += 'custom'
Oleksii Zhurba57a16422019-03-26 13:14:21 -0500155 }
156 }
157 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec -e ARGS=\'${args}\' ${container_name} /bin/bash -c 'run-tempest'")
158 }
159 stage('Collect results') {
160 report_prefix += "_report_${env.BUILD_NUMBER}"
161 // will be removed after changing runtest-formula logic
162 salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_artifacts_dir}/reports; mv ${remote_artifacts_dir}/report_* ${remote_artifacts_dir}/reports")
163 validate.addFiles(saltMaster, TARGET_NODE, "${remote_artifacts_dir}/reports", '')
164 sh "mv report_*.xml ${report_prefix}.xml"
165 sh "mv report_*.log ${report_prefix}.log"
166 archiveArtifacts artifacts: "${report_prefix}.*"
167 junit "${report_prefix}.xml"
168 }
169 } catch (Throwable e) {
170 // If there was an error or exception thrown, the build failed
171 currentBuild.result = "FAILURE"
172 throw e
173 } finally {
174 if (DEBUG_MODE == 'false') {
175 validate.runCleanup(saltMaster, TARGET_NODE, container_name)
176 }
177 }
178}