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