blob: b0e12e98a9a43d43b70afc22ae681049fb74b6f3 [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
22 * report_prefix Some prefix to put to report name
23 *
24 */
25
26
27common = new com.mirantis.mk.Common()
28salt = new com.mirantis.mk.Salt()
29validate = new com.mirantis.mcp.Validate()
30
31def saltMaster
32extraYamlContext = env.getProperty('EXTRA_PARAMS')
33if (extraYamlContext) {
34 common.mergeEnv(env, extraYamlContext) }
35def SALT_MASTER_CREDENTIALS=(env.SALT_MASTER_CREDENTIALS) ?: 'salt'
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050036def VERBOSE = (env.VERBOSE) ? env.VERBOSE.toBoolean() : true
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050037def DEBUG_MODE = (env.DEBUG_MODE) ?: false
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050038def STOP_ON_ERROR = (env.STOP_ON_ERROR) ? env.STOP_ON_ERROR.toBoolean() : false
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050039def GENERATE_CONFIG = (env.GENERATE_CONFIG) ?: true
40def remote_artifacts_dir = (env.remote_artifacts_dir) ?: '/root/test/'
41def report_prefix = (env.report_prefix) ?: ''
42def args = ''
43node() {
44 try{
45 stage('Initialization') {
46 deleteDir()
47 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -050048 container_name = "${env.JOB_NAME}"
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050049 cluster_name=salt.getPillar(saltMaster, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
50 os_version=salt.getPillar(saltMaster, 'I@salt:master', '_param:openstack_version')['return'][0].values()[0]
51 if (os_version == '') {
52 throw new Exception("Openstack is not found on this env. Exiting")
53 }
54 TEST_IMAGE = (env.TEST_IMAGE) ?: "docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:${os_version}"
55 runtest_node = salt.runSaltProcessStep(saltMaster, 'I@runtest:*', 'test.ping')['return'][0]
56 if (runtest_node.values()[0]) {
57 // Let's use Service node that was defined in reclass. If several nodes are defined
58 // we will use the first from salt output
59 common.infoMsg("Service node ${runtest_node.keySet()[0]} is defined in reclass")
60 SERVICE_NODE = runtest_node.keySet()[0]
61 }
62 else {
Oleksii Zhurba12e7aa42019-05-13 16:22:07 -050063 throw new Exception("Runtest config is not found in reclass. Please create runtest.yml and include it " +
64 "into reclass. Check documentation for more details")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050065 }
66 common.infoMsg('Refreshing pillars on service node')
67 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
68 tempest_node=salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_test_target')['return'][0].values()[0] ?: 'I@gerrit:client'
69 }
70 stage('Preparing resources') {
71 if ( PREPARE_RESOURCES.toBoolean() ) {
72 common.infoMsg('Running salt.minion state on service node')
73 salt.enforceState(saltMaster, SERVICE_NODE, ['salt.minion'], VERBOSE, STOP_ON_ERROR, null, false, 300, 2, true, [], 60)
74 common.infoMsg('Running keystone.client on service node')
75 salt.enforceState(saltMaster, SERVICE_NODE, 'keystone.client', VERBOSE, STOP_ON_ERROR)
76 common.infoMsg('Running glance.client on service node')
77 salt.enforceState(saltMaster, SERVICE_NODE, 'glance.client', VERBOSE, STOP_ON_ERROR)
78 common.infoMsg('Running nova.client on service node')
79 salt.enforceState(saltMaster, SERVICE_NODE, 'nova.client', VERBOSE, STOP_ON_ERROR)
80 }
81 else {
82 common.infoMsg('Skipping resources preparation')
83 }
84 }
85 stage('Generate config') {
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050086 if ( GENERATE_CONFIG.toBoolean() ) {
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050087 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.remove', ["${remote_artifacts_dir}"])
88 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
89 fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0)
90 TARGET_NODE = (env.TARGET_NODE) ?: tempest_node
91 if (TARGET_NODE != tempest_node) {
92 common.infoMsg("TARGET_NODE is defined in Jenkins")
93 def params_to_update = ['tempest_test_target': "${TARGET_NODE}"]
94 common.infoMsg("Overriding default ${tempest_node} value of tempest_test_target parameter")
95 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
96 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${TARGET_NODE}"]])
97 salt.checkResult(result)
98 }
99 common.infoMsg("TARGET_NODE is ${TARGET_NODE}")
100 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.remove', ["${remote_artifacts_dir}"])
101 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
102 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest', VERBOSE, STOP_ON_ERROR)
103 // we need to refresh pillars on target node after runtest state
104 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
105 if (TARGET_NODE != tempest_node) {
106 common.infoMsg("Reverting 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': "${tempest_node}"]])
109 }
110 SKIP_LIST_PATH = (env.SKIP_LIST_PATH) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_skip_list_path')['return'][0].values()[0]
111 runtest_tempest_cfg_dir = salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_dir')['return'][0].values()[0] ?: '/root/test/'
112 if (SKIP_LIST_PATH) {
113 salt.cmdRun(saltMaster, SERVICE_NODE, "salt-cp ${TARGET_NODE} ${SKIP_LIST_PATH} ${runtest_tempest_cfg_dir}/skip.list")
114 args += ' --blacklist-file /root/tempest/skip.list '
115 }
116 }
117 else {
118 common.infoMsg('Skipping Tempest config generation')
119 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_artifacts_dir}/reports")
120 }
121 }
122
123 stage('Run Tempest tests') {
Oleksii Zhurbac5987cb2019-04-23 21:47:57 -0500124 mounts = ['/root/test/tempest_generated.conf': '/etc/tempest/tempest.conf']
125 validate.runContainer(master: saltMaster, target: TARGET_NODE, dockerImageLink: TEST_IMAGE,
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500126 mounts: mounts, name: container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500127 report_prefix += 'tempest_'
128 if (env.concurrency) {
129 args += ' -w ' + env.concurrency
130 }
131 if (TEMPEST_TEST_PATTERN == 'set=smoke') {
132 args += ' -s '
133 report_prefix += 'smoke'
134 }
135 else {
136 if (TEMPEST_TEST_PATTERN != 'set=full') {
137 args += " -r ${TEMPEST_TEST_PATTERN} "
138 report_prefix += 'full'
139 }
140 }
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500141 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec -e ARGS=\'${args}\' ${container_name} /bin/bash -c 'run-tempest'")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500142 }
143 stage('Collect results') {
144 report_prefix += "_report_${env.BUILD_NUMBER}"
145 // will be removed after changing runtest-formula logic
146 salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_artifacts_dir}/reports; mv ${remote_artifacts_dir}/report_* ${remote_artifacts_dir}/reports")
147 validate.addFiles(saltMaster, TARGET_NODE, "${remote_artifacts_dir}/reports", '')
148 sh "mv report_*.xml ${report_prefix}.xml"
149 sh "mv report_*.log ${report_prefix}.log"
150 archiveArtifacts artifacts: "${report_prefix}.*"
151 junit "${report_prefix}.xml"
152 }
153 } catch (Throwable e) {
154 // If there was an error or exception thrown, the build failed
155 currentBuild.result = "FAILURE"
156 throw e
157 } finally {
158 if (DEBUG_MODE == 'false') {
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500159 validate.runCleanup(saltMaster, TARGET_NODE, container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500160 }
161 }
162}