blob: c4351b99e12f593595027e27da6ec2b371541e39 [file] [log] [blame]
Oleksii Zhurba90b6fa92019-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 Zhurbabaa42c92019-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 Zhurba90b6fa92019-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'
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050038def VERBOSE = (env.VERBOSE) ? env.VERBOSE.toBoolean() : true
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050039def DEBUG_MODE = (env.DEBUG_MODE) ?: false
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050040def STOP_ON_ERROR = (env.STOP_ON_ERROR) ? env.STOP_ON_ERROR.toBoolean() : false
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050041def GENERATE_CONFIG = (env.GENERATE_CONFIG) ?: true
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050042// do not change unless you know what you're doing
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050043def remote_artifacts_dir = (env.remote_artifacts_dir) ?: '/root/test/'
44def report_prefix = (env.report_prefix) ?: ''
45def args = ''
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050046def mounts = [:]
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050047node() {
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050048 stage('Initialization') {
49 deleteDir()
50 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
51 container_name = "${env.JOB_NAME}"
52 cluster_name=salt.getPillar(saltMaster, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
53 os_version=salt.getPillar(saltMaster, 'I@salt:master', '_param:openstack_version')['return'][0].values()[0]
54 if (!os_version) {
55 throw new Exception("Openstack is not found on this env. Exiting")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050056 }
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050057 TEST_IMAGE = (env.TEST_IMAGE) ?: "docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:${os_version}"
58 runtest_node = salt.runSaltProcessStep(saltMaster, 'I@runtest:*', 'test.ping')['return'][0]
59 if (runtest_node.values()[0]) {
60 // Let's use Service node that was defined in reclass. If several nodes are defined
61 // we will use the first from salt output
62 common.infoMsg("Service node ${runtest_node.keySet()[0]} is defined in reclass")
63 SERVICE_NODE = runtest_node.keySet()[0]
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050064 }
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050065 else {
66 throw new Exception("Runtest config is not found in reclass. Please create runtest.yml and include it " +
67 "into reclass. Check documentation for more details")
68 }
69 common.infoMsg('Refreshing pillars on service node')
70 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
71 // default node is cid01 (preferably) or cfg01
72 default_node=salt.getPillar(saltMaster, 'I@salt:master', '_param:cicd_control_node01_hostname')['return'][0].values()[0] ?: 'cfg01'
73 // fetch tempest_test_target from runtest.yaml, otherwise fallback to default_node
74 tempest_node=salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_test_target')['return'][0].values()[0] ?: default_node+'*'
75 // TARGET_NODE will always override any settings above
76 TARGET_NODE = (env.TARGET_NODE) ?: tempest_node
Oleksii Zhurba712b05a2019-07-17 12:29:49 -050077 // default is /root/test/
78 runtest_tempest_cfg_dir = (env.runtest_tempest_cfg_dir) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_dir')['return'][0].values()[0]
79 // default is tempest_generated.conf
80 runtest_tempest_cfg_name = (env.runtest_tempest_cfg_name) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_name')['return'][0].values()[0]
81 common.infoMsg("runtest_tempest_cfg is ${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}")
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -050082 }
83 stage('Preparing resources') {
84 if ( PREPARE_RESOURCES.toBoolean() ) {
85 common.infoMsg('Running salt.minion state on service node')
86 salt.enforceState(saltMaster, SERVICE_NODE, ['salt.minion'], VERBOSE, STOP_ON_ERROR, null, false, 300, 2, true, [], 60)
87 common.infoMsg('Running keystone.client on service node')
88 salt.enforceState(saltMaster, SERVICE_NODE, 'keystone.client', VERBOSE, STOP_ON_ERROR)
89 common.infoMsg('Running glance.client on service node')
90 salt.enforceState(saltMaster, SERVICE_NODE, 'glance.client', VERBOSE, STOP_ON_ERROR)
91 common.infoMsg('Running nova.client on service node')
92 salt.enforceState(saltMaster, SERVICE_NODE, 'nova.client', VERBOSE, STOP_ON_ERROR)
93 }
94 else {
95 common.infoMsg('Skipping resources preparation')
96 }
97 }
98 stage('Generate config') {
99 if ( GENERATE_CONFIG.toBoolean() ) {
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500100 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.remove', ["${runtest_tempest_cfg_dir}"])
101 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.mkdir', ["${runtest_tempest_cfg_dir}"])
102 fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0)
103 if (TARGET_NODE != tempest_node) {
104 common.infoMsg("TARGET_NODE is defined in Jenkins")
105 def params_to_update = ['tempest_test_target': "${TARGET_NODE}"]
106 common.infoMsg("Overriding default ${tempest_node} value of tempest_test_target parameter")
107 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
108 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${TARGET_NODE}"]])
109 salt.checkResult(result)
110 }
111 common.infoMsg("TARGET_NODE is ${TARGET_NODE}")
112 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.remove', ["${remote_artifacts_dir}"])
113 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
114 // runtest state hangs if tempest_test_target is cfg01*
115 // let's run runtest.generate_tempest_config only for this case
116 if (TARGET_NODE == 'cfg01*') {
117 common.warningMsg("It is not recommended to run Tempest container on cfg node, but.. proceeding")
118 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest.generate_tempest_config', VERBOSE, STOP_ON_ERROR)
119 } else {
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500120 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest', VERBOSE, STOP_ON_ERROR)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500121 }
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500122 // we need to refresh pillars on target node after runtest state
123 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
124 if (TARGET_NODE != tempest_node) {
125 common.infoMsg("Reverting tempest_test_target parameter")
126 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
127 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${tempest_node}"]])
128 }
129 SKIP_LIST_PATH = (env.SKIP_LIST_PATH) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_skip_list_path')['return'][0].values()[0]
130 if (SKIP_LIST_PATH) {
Oleksii Zhurbaf03497f2019-07-17 15:02:44 -0500131 mounts = ["${runtest_tempest_cfg_dir}/skip.list": "/var/lib/tempest/skiplists/skip.list"]
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500132 salt.cmdRun(saltMaster, SERVICE_NODE, "salt-cp ${TARGET_NODE} ${SKIP_LIST_PATH} ${runtest_tempest_cfg_dir}/skip.list")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500133 }
134 }
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500135 else {
136 common.infoMsg('Skipping Tempest config generation')
137 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_artifacts_dir}/reports")
138 }
139 }
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500140
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500141 try{
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500142 stage('Run Tempest tests') {
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500143 mounts = mounts + ["${runtest_tempest_cfg_dir}/${runtest_tempest_cfg_name}": "/etc/tempest/tempest.conf"]
Oleksii Zhurbac5987cb2019-04-23 21:47:57 -0500144 validate.runContainer(master: saltMaster, target: TARGET_NODE, dockerImageLink: TEST_IMAGE,
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500145 mounts: mounts, name: container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500146 report_prefix += 'tempest_'
147 if (env.concurrency) {
148 args += ' -w ' + env.concurrency
149 }
150 if (TEMPEST_TEST_PATTERN == 'set=smoke') {
151 args += ' -s '
152 report_prefix += 'smoke'
153 }
154 else {
155 if (TEMPEST_TEST_PATTERN != 'set=full') {
156 args += " -r ${TEMPEST_TEST_PATTERN} "
Oleksii Zhurbabaa42c92019-05-29 16:08:40 -0500157 report_prefix += 'custom'
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500158 }
159 }
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500160 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec -e ARGS=\'${args}\' ${container_name} /bin/bash -c 'run-tempest'")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500161 }
162 stage('Collect results') {
163 report_prefix += "_report_${env.BUILD_NUMBER}"
164 // will be removed after changing runtest-formula logic
165 salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_artifacts_dir}/reports; mv ${remote_artifacts_dir}/report_* ${remote_artifacts_dir}/reports")
166 validate.addFiles(saltMaster, TARGET_NODE, "${remote_artifacts_dir}/reports", '')
167 sh "mv report_*.xml ${report_prefix}.xml"
168 sh "mv report_*.log ${report_prefix}.log"
169 archiveArtifacts artifacts: "${report_prefix}.*"
170 junit "${report_prefix}.xml"
171 }
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500172 } finally {
Oleksii Zhurba8b23cb32019-07-17 12:19:09 -0500173 if ( ! DEBUG_MODE.toBoolean() ) {
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500174 validate.runCleanup(saltMaster, TARGET_NODE, container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500175 }
176 }
177}