blob: 87c14c8453b30a9dce5a1281dc6da95a8e6b7b91 [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 {
63 common.infoMsg("Service node is not defined in reclass")
64 SERVICE_NODE = (env.SERVICE_NODE) ?: 'I@salt:master'
65 common.infoMsg("${SERVICE_NODE} will be used as Service node")
66 def classes_to_add = ["cluster.${cluster_name}.infra.runtest"]
67 fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0)
68 common.infoMsg("Full service node name ${fullnodename}")
69 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
70 null, null, ['name': fullnodename, 'classes': classes_to_add])
71 salt.checkResult(result)
72 }
73 common.infoMsg('Refreshing pillars on service node')
74 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
75 tempest_node=salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_test_target')['return'][0].values()[0] ?: 'I@gerrit:client'
76 }
77 stage('Preparing resources') {
78 if ( PREPARE_RESOURCES.toBoolean() ) {
79 common.infoMsg('Running salt.minion state on service node')
80 salt.enforceState(saltMaster, SERVICE_NODE, ['salt.minion'], VERBOSE, STOP_ON_ERROR, null, false, 300, 2, true, [], 60)
81 common.infoMsg('Running keystone.client on service node')
82 salt.enforceState(saltMaster, SERVICE_NODE, 'keystone.client', VERBOSE, STOP_ON_ERROR)
83 common.infoMsg('Running glance.client on service node')
84 salt.enforceState(saltMaster, SERVICE_NODE, 'glance.client', VERBOSE, STOP_ON_ERROR)
85 common.infoMsg('Running nova.client on service node')
86 salt.enforceState(saltMaster, SERVICE_NODE, 'nova.client', VERBOSE, STOP_ON_ERROR)
87 }
88 else {
89 common.infoMsg('Skipping resources preparation')
90 }
91 }
92 stage('Generate config') {
Oleksii Zhurbaf66b0e02019-04-15 15:57:42 -050093 if ( GENERATE_CONFIG.toBoolean() ) {
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -050094 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.remove', ["${remote_artifacts_dir}"])
95 salt.runSaltProcessStep(saltMaster, SERVICE_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
96 fullnodename = salt.getMinions(saltMaster, SERVICE_NODE).get(0)
97 TARGET_NODE = (env.TARGET_NODE) ?: tempest_node
98 if (TARGET_NODE != tempest_node) {
99 common.infoMsg("TARGET_NODE is defined in Jenkins")
100 def params_to_update = ['tempest_test_target': "${TARGET_NODE}"]
101 common.infoMsg("Overriding default ${tempest_node} value of tempest_test_target parameter")
102 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
103 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${TARGET_NODE}"]])
104 salt.checkResult(result)
105 }
106 common.infoMsg("TARGET_NODE is ${TARGET_NODE}")
107 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.remove', ["${remote_artifacts_dir}"])
108 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'file.mkdir', ["${remote_artifacts_dir}"])
109 salt.enforceState(saltMaster, SERVICE_NODE, 'runtest', VERBOSE, STOP_ON_ERROR)
110 // we need to refresh pillars on target node after runtest state
111 salt.runSaltProcessStep(saltMaster, TARGET_NODE, 'saltutil.refresh_pillar', [], null, VERBOSE)
112 if (TARGET_NODE != tempest_node) {
113 common.infoMsg("Reverting tempest_test_target parameter")
114 result = salt.runSaltCommand(saltMaster, 'local', ['expression': SERVICE_NODE, 'type': 'compound'], 'reclass.node_update',
115 null, null, ['name': fullnodename, 'parameters': ['tempest_test_target': "${tempest_node}"]])
116 }
117 SKIP_LIST_PATH = (env.SKIP_LIST_PATH) ?: salt.getPillar(saltMaster, SERVICE_NODE, '_param:tempest_skip_list_path')['return'][0].values()[0]
118 runtest_tempest_cfg_dir = salt.getPillar(saltMaster, SERVICE_NODE, '_param:runtest_tempest_cfg_dir')['return'][0].values()[0] ?: '/root/test/'
119 if (SKIP_LIST_PATH) {
120 salt.cmdRun(saltMaster, SERVICE_NODE, "salt-cp ${TARGET_NODE} ${SKIP_LIST_PATH} ${runtest_tempest_cfg_dir}/skip.list")
121 args += ' --blacklist-file /root/tempest/skip.list '
122 }
123 }
124 else {
125 common.infoMsg('Skipping Tempest config generation')
126 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_artifacts_dir}/reports")
127 }
128 }
129
130 stage('Run Tempest tests') {
Oleksii Zhurbac5987cb2019-04-23 21:47:57 -0500131 mounts = ['/root/test/tempest_generated.conf': '/etc/tempest/tempest.conf']
132 validate.runContainer(master: saltMaster, target: TARGET_NODE, dockerImageLink: TEST_IMAGE,
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500133 mounts: mounts, name: container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500134 report_prefix += 'tempest_'
135 if (env.concurrency) {
136 args += ' -w ' + env.concurrency
137 }
138 if (TEMPEST_TEST_PATTERN == 'set=smoke') {
139 args += ' -s '
140 report_prefix += 'smoke'
141 }
142 else {
143 if (TEMPEST_TEST_PATTERN != 'set=full') {
144 args += " -r ${TEMPEST_TEST_PATTERN} "
145 report_prefix += 'full'
146 }
147 }
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500148 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec -e ARGS=\'${args}\' ${container_name} /bin/bash -c 'run-tempest'")
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500149 }
150 stage('Collect results') {
151 report_prefix += "_report_${env.BUILD_NUMBER}"
152 // will be removed after changing runtest-formula logic
153 salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_artifacts_dir}/reports; mv ${remote_artifacts_dir}/report_* ${remote_artifacts_dir}/reports")
154 validate.addFiles(saltMaster, TARGET_NODE, "${remote_artifacts_dir}/reports", '')
155 sh "mv report_*.xml ${report_prefix}.xml"
156 sh "mv report_*.log ${report_prefix}.log"
157 archiveArtifacts artifacts: "${report_prefix}.*"
158 junit "${report_prefix}.xml"
159 }
160 } catch (Throwable e) {
161 // If there was an error or exception thrown, the build failed
162 currentBuild.result = "FAILURE"
163 throw e
164 } finally {
165 if (DEBUG_MODE == 'false') {
Oleksii Zhurbab7593dc2019-05-13 12:29:55 -0500166 validate.runCleanup(saltMaster, TARGET_NODE, container_name)
Oleksii Zhurba90b6fa92019-03-26 13:14:21 -0500167 }
168 }
169}