blob: 65ed46dc670f113795bb21f441df1f4bd4332961 [file] [log] [blame]
Petr Lomakin47fee0a2017-08-01 10:46:05 -07001package com.mirantis.mcp
2
3/**
4 *
5 * Tests providing functions
6 *
7 */
8
9/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060010 * Run docker container with basic (keystone) parameters
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -050011 * For backward compatibility. Deprecated.
12 * Will be removed soon.
Petr Lomakin47fee0a2017-08-01 10:46:05 -070013 *
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060014 * @param target Host to run container
15 * @param dockerImageLink Docker image link. May be custom or default rally image
Petr Lomakin47fee0a2017-08-01 10:46:05 -070016 */
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -050017def runBasicContainer(master, target, dockerImageLink="xrally/xrally-openstack:0.10.1"){
Petr Lomakin47fee0a2017-08-01 10:46:05 -070018 def salt = new com.mirantis.mk.Salt()
19 def common = new com.mirantis.mk.Common()
Sam Stoelinga28bdb722017-09-25 18:29:59 -070020 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
21 def keystone = _pillar['return'][0].values()[0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060022 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
23 salt.cmdRun(master, target, "docker rm -f cvp")
24 }
25 salt.cmdRun(master, target, "docker run -tid --net=host --name=cvp " +
26 "-u root -e OS_USERNAME=${keystone.admin_name} " +
Petr Lomakin47fee0a2017-08-01 10:46:05 -070027 "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " +
28 "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " +
Oleksii Zhurba1bf9be12018-01-17 15:20:00 -060029 "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin --entrypoint /bin/bash ${dockerImageLink}")
Petr Lomakin47fee0a2017-08-01 10:46:05 -070030}
31
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -050032
33/**
34 * Run docker container with parameters
35 *
36 * @param target Host to run container
37 * @param dockerImageLink Docker image link. May be custom or default rally image
38 * @param name Name for container
39 * @param env_var Environment variables to set in container
40 * @param entrypoint Set entrypoint to /bin/bash or leave default
41**/
42
43
44def runContainer(master, target, dockerImageLink, name='cvp', env_var=[], entrypoint=true){
45 def salt = new com.mirantis.mk.Salt()
46 def common = new com.mirantis.mk.Common()
47 def variables = ''
48 def entry_point = ''
Oleksii Zhurbaf4f89332019-03-15 15:47:52 -050049 def cluster_name = salt.getPillar(master, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -050050 if ( salt.cmdRun(master, target, "docker ps -f name=${name} -q", false, null, false)['return'][0].values()[0] ) {
51 salt.cmdRun(master, target, "docker rm -f ${name}")
52 }
53 if (env_var.size() > 0) {
54 variables = ' -e ' + env_var.join(' -e ')
55 }
56 if (entrypoint) {
57 entry_point = '--entrypoint /bin/bash'
58 }
59 salt.cmdRun(master, target, "docker run -tid --net=host --name=${name} " +
Oleksii Zhurba115474a2019-02-13 18:27:31 -060060 "-u root ${entry_point} ${variables} " +
61 "-v /srv/salt/pki/${cluster_name}/:/etc/certs ${dockerImageLink}")
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -050062}
63
64
Petr Lomakin47fee0a2017-08-01 10:46:05 -070065/**
Oleksii Zhurba4bcf07f2018-09-11 15:23:18 -050066 * Get v2 Keystone credentials from pillars
67 *
68 */
69def _get_keystone_creds_v2(master){
70 def salt = new com.mirantis.mk.Salt()
71 def common = new com.mirantis.mk.Common()
72 def keystone = []
73 common.infoMsg("Fetching Keystone v2 credentials")
74 _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')['return'][0].values()[0]
75 keystone.add("OS_USERNAME=${_pillar.admin_name}")
76 keystone.add("OS_PASSWORD=${_pillar.admin_password}")
77 keystone.add("OS_TENANT_NAME=${_pillar.admin_tenant}")
78 keystone.add("OS_AUTH_URL=http://${_pillar.bind.private_address}:${_pillar.bind.private_port}/v2.0")
79 keystone.add("OS_REGION_NAME=${_pillar.region}")
80 keystone.add("OS_ENDPOINT_TYPE=admin")
81 return keystone
82}
83
84/**
85 * Get v3 Keystone credentials from pillars
86 *
87 */
88def _get_keystone_creds_v3(master){
89 def salt = new com.mirantis.mk.Salt()
90 def common = new com.mirantis.mk.Common()
91 pillar_name = 'keystone:client:os_client_config:cfgs:root:content:clouds:admin_identity'
92 common.infoMsg("Fetching Keystone v3 credentials")
93 def _pillar = salt.getPillar(master, 'I@keystone:client', pillar_name)['return'][0].values()[0]
94 def keystone = []
95 if (_pillar) {
96 keystone.add("OS_USERNAME=${_pillar.auth.username}")
97 keystone.add("OS_PASSWORD=${_pillar.auth.password}")
98 keystone.add("OS_TENANT_NAME=${_pillar.auth.project_name}")
99 keystone.add("OS_PROJECT_NAME=${_pillar.auth.project_name}")
100 keystone.add("OS_AUTH_URL=${_pillar.auth.auth_url}/v3")
101 keystone.add("OS_REGION_NAME=${_pillar.region_name}")
102 keystone.add("OS_IDENTITY_API_VERSION=${_pillar.identity_api_version}")
Oleksii Zhurba115474a2019-02-13 18:27:31 -0600103 keystone.add("OS_ENDPOINT_TYPE=internal")
Oleksii Zhurba4bcf07f2018-09-11 15:23:18 -0500104 keystone.add("OS_PROJECT_DOMAIN_NAME=${_pillar.auth.project_domain_name}")
105 keystone.add("OS_USER_DOMAIN_NAME=${_pillar.auth.user_domain_name}")
Oleksii Zhurba115474a2019-02-13 18:27:31 -0600106 // we mount /srv/salt/pki/${cluster_name}/:/etc/certs with certs for cvp container
107 keystone.add("OS_CACERT='/etc/certs/proxy-with-chain.crt'")
Oleksii Zhurba4bcf07f2018-09-11 15:23:18 -0500108 return keystone
109 }
110 else {
111 common.warningMsg("Failed to fetch Keystone v3 credentials")
112 return false
113 }
114}
115
116/**
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700117 * Get file content (encoded). The content encoded by Base64.
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700118 *
119 * @param target Compound target (should target only one host)
120 * @param file File path to read
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700121 * @return The encoded content of the file
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700122 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700123def getFileContentEncoded(master, target, file) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700124 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700125 def file_content = ''
126 def cmd = "base64 -w0 ${file} > ${file}_encoded; " +
127 "split -b 1MB -d ${file}_encoded ${file}__; " +
128 "rm ${file}_encoded"
129 salt.cmdRun(master, target, cmd, false, null, false)
130 def filename = file.tokenize('/').last()
131 def folder = file - filename
132 def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"])
133 for ( part in parts['return'][0].values()[0]) {
134 def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false)
135 file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','')
136 }
137 salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"])
138 return file_content
139}
140
141/**
142 * Copy files from remote to local directory. The content of files will be
143 * decoded by Base64.
144 *
145 * @param target Compound target (should target only one host)
146 * @param folder The path to remote folder.
147 * @param output_dir The path to local folder.
148 */
149def addFiles(master, target, folder, output_dir) {
150 def salt = new com.mirantis.mk.Salt()
151 def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"])
152 def files = _result['return'][0].values()[0]
153 for (file in files) {
154 def file_content = getFileContentEncoded(master, target, "${file}")
155 def fileName = file.tokenize('/').last()
156 writeFile file: "${output_dir}${fileName}_encoded", text: file_content
157 def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " +
158 "rm ${output_dir}${fileName}_encoded"
159 sh(script: cmd)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700160 }
161}
162
163/**
164 * Get reclass value
165 *
166 * @param target The host for which the values will be provided
167 * @param filter Parameters divided by dots
168 * @return The pillar data
169 */
170def getReclassValue(master, target, filter) {
171 def common = new com.mirantis.mk.Common()
172 def salt = new com.mirantis.mk.Salt()
173 def items = filter.tokenize('.')
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700174 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${target}", false, null, false)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700175 _result = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700176 for (int k = 0; k < items.size(); k++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700177 if ( _result ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700178 _result = _result["${items[k]}"]
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700179 }
180 }
181 return _result
182}
183
184/**
185 * Create list of nodes in JSON format.
186 *
187 * @param filter The Salt's matcher
188 * @return JSON list of nodes
189 */
190def getNodeList(master, filter = null) {
191 def salt = new com.mirantis.mk.Salt()
192 def common = new com.mirantis.mk.Common()
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700193 def nodes = []
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700194 def filtered_list = null
195 def controllers = salt.getMinions(master, 'I@nova:controller')
196 def hw_nodes = salt.getMinions(master, 'G@virtual:physical')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700197 if ( filter ) {
198 filtered_list = salt.getMinions(master, filter)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700199 }
200 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false)
201 def reclass_top = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700202 def nodesList = reclass_top['base'].keySet()
203 for (int i = 0; i < nodesList.size(); i++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700204 if ( filtered_list ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700205 if ( ! filtered_list.contains(nodesList[i]) ) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700206 continue
207 }
208 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700209 def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address')
210 def network_data = [ip: ip, name: 'management']
211 def roles = [nodesList[i].tokenize('.')[0]]
212 if ( controllers.contains(nodesList[i]) ) {
213 roles.add('controller')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700214 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700215 if ( hw_nodes.contains(nodesList[i]) ) {
216 roles.add('hw_node')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700217 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700218 nodes.add([id: i+1, ip: ip, roles: roles, network_data: [network_data]])
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700219 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700220 return common.prettify(nodes)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700221}
222
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500223/**
224 * Execute mcp sanity tests
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500225 * Deprecated. Will be removed soon
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500226 *
227 * @param salt_url Salt master url
228 * @param salt_credentials Salt credentials
229 * @param test_set Test set for mcp sanity framework
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600230 * @param env_vars Additional environment variables for cvp-sanity-checks
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500231 * @param output_dir Directory for results
232 */
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600233def runSanityTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500234 def common = new com.mirantis.mk.Common()
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600235 def creds = common.getCredentials(salt_credentials)
236 def username = creds.username
237 def password = creds.password
238 def settings = ""
239 if ( env_vars != "" ) {
240 for (var in env_vars.tokenize(";")) {
241 settings += "export ${var}; "
242 }
243 }
244 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
Oleksii Zhurba5250a9c2018-03-21 15:47:03 -0500245 "pytest --junitxml ${output_dir}cvp_sanity.xml --tb=short -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}"
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500246 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
247 def statusCode = sh script:script, returnStatus:true
248 }
249}
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700250
251/**
Oleksii Zhurba4e366ff2018-02-16 20:06:52 -0600252 * Execute pytest framework tests
253 *
254 * @param salt_url Salt master url
255 * @param salt_credentials Salt credentials
256 * @param test_set Test set to run
257 * @param env_vars Additional environment variables for cvp-sanity-checks
258 * @param output_dir Directory for results
259 */
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500260def runPyTests(salt_url, salt_credentials, test_set="", env_vars="", name='cvp', container_node="", remote_dir='/root/qa_results/', artifacts_dir='validation_artifacts/') {
261 def xml_file = "${name}_report.xml"
262 def common = new com.mirantis.mk.Common()
263 def salt = new com.mirantis.mk.Salt()
264 def creds = common.getCredentials(salt_credentials)
265 def username = creds.username
266 def password = creds.password
267 if (container_node != "") {
268 def saltMaster
269 saltMaster = salt.connection(salt_url, salt_credentials)
270 def script = "pytest --junitxml ${xml_file} --tb=short -sv ${test_set}"
271 env_vars.addAll("SALT_USERNAME=${username}", "SALT_PASSWORD=${password}",
272 "SALT_URL=${salt_url}")
273 variables = ' -e ' + env_vars.join(' -e ')
274 salt.cmdRun(saltMaster, container_node, "docker exec ${variables} ${name} bash -c '${script}'", false)
275 salt.cmdRun(saltMaster, container_node, "docker cp ${name}:/var/lib/${xml_file} ${remote_dir}${xml_file}")
276 addFiles(saltMaster, container_node, remote_dir+xml_file, artifacts_dir)
277 }
278 else {
279 if (env_vars.size() > 0) {
280 variables = 'export ' + env_vars.join(';export ')
281 }
282 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${variables}; " +
283 "pytest --junitxml ${artifacts_dir}${xml_file} --tb=short -sv ${env.WORKSPACE}/${test_set}"
284 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
285 def statusCode = sh script:script, returnStatus:true
286 }
287 }
288}
289
290/**
291 * Execute pytest framework tests
292 * For backward compatibility
293 * Will be removed soon
294 *
295 * @param salt_url Salt master url
296 * @param salt_credentials Salt credentials
297 * @param test_set Test set to run
298 * @param env_vars Additional environment variables for cvp-sanity-checks
299 * @param output_dir Directory for results
300 */
Oleksii Zhurba4e366ff2018-02-16 20:06:52 -0600301def runTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
302 def common = new com.mirantis.mk.Common()
303 def creds = common.getCredentials(salt_credentials)
304 def username = creds.username
305 def password = creds.password
306 def settings = ""
307 if ( env_vars != "" ) {
308 for (var in env_vars.tokenize(";")) {
309 settings += "export ${var}; "
310 }
311 }
312 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
313 "pytest --junitxml ${output_dir}report.xml --tb=short -sv ${env.WORKSPACE}/${test_set}"
314 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
315 def statusCode = sh script:script, returnStatus:true
316 }
317}
318
319/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700320 * Execute tempest tests
321 *
322 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700323 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700324 * @param pattern If not false, will run only tests matched the pattern
325 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800326 * @param confRepository Git repository with configuration files for Tempest
327 * @param confBranch Git branch which will be used during the checkout
328 * @param repository Git repository with Tempest
329 * @param version Version of Tempest (tag, branch or commit)
Sergey Galkind1068e22018-02-13 13:59:32 +0400330 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700331 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400332def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false", results = '/root/qa_results') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700333 def salt = new com.mirantis.mk.Salt()
334 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700335 def dest_folder = '/home/rally/qa_results'
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800336 def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700337 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
338 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
339 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
340 def keystone = _pillar['return'][0].values()[0]
Dmitry Tsapikovb6911922018-07-24 15:21:23 +0000341 def env_vars = ['tempest_version=15.0.0',
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700342 "OS_USERNAME=${keystone.admin_name}",
343 "OS_PASSWORD=${keystone.admin_password}",
344 "OS_TENANT_NAME=${keystone.admin_tenant}",
345 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
346 "OS_REGION_NAME=${keystone.region}",
347 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
348 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800349 if (confRepository != '' ) {
350 cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " +
351 'rally deployment create --fromenv --name=tempest; rally deployment config; ' +
352 'rally verify create-verifier --name tempest_verifier --type tempest ' +
Dmitry Tsapikovb6911922018-07-24 15:21:23 +0000353 "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800354 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; '
355 skip_list = '--skip-list test_config/tempest/skip-list.yaml'
356 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700357 if (pattern == 'false') {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800358 cmd += "rally verify start --pattern set=full ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700359 }
360 else {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800361 cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700362 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700363 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
364 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
mkraynovd49daf52018-07-12 16:11:14 +0400365 salt.cmdRun(master, target, "docker run -w /home/rally -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400366 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
367 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700368 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700369}
370
371/**
Oleg Basov40e502c2018-09-04 20:42:21 +0200372 * Make all-in-one scenario cmd for rally tests
373 *
374 * @param scenarios_path Path to scenarios folder/file
375 * @param skip_scenarios Comma-delimited list of scenarios names to skip
376 * @param bundle_file Bundle name to create
377*/
Oleg Basov06fce2a2018-11-09 21:39:03 +0100378def bundle_up_scenarios(scenarios_path, skip_scenarios, bundle_file = '' ) {
Oleg Basov40e502c2018-09-04 20:42:21 +0200379 def skip_names = ''
380 def skip_dirs = ''
381 def result = ''
382 if (skip_scenarios != ''){
383 for ( scen in skip_scenarios.split(',') ) {
384 if ( scen.contains('yaml')) {
385 skip_names += "! -name ${scen} "
386 }
387 else {
388 skip_dirs += "-path ${scenarios_path}/${scen} -prune -o "
389 }
390 }
391 }
Oleg Basov06fce2a2018-11-09 21:39:03 +0100392 if (bundle_file != '') {
393 result = "if [ -f ${scenarios_path} ]; then cp ${scenarios_path} ${bundle_file}; " +
Oleg Basov40e502c2018-09-04 20:42:21 +0200394 "else " +
395 "find -L ${scenarios_path} " + skip_dirs +
396 " -name '*.yaml' " + skip_names +
397 "-exec cat {} >> ${bundle_file} \\; ; " +
398 "sed -i '/---/d' ${bundle_file}; fi; "
Oleg Basov06fce2a2018-11-09 21:39:03 +0100399 } else {
400 result = "find -L ${scenarios_path} " + skip_dirs +
401 " -name '*.yaml' " + skip_names
402 }
Oleg Basov40e502c2018-09-04 20:42:21 +0200403
404 return result
405}
406
407/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700408 * Execute rally tests
409 *
410 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700411 * @param dockerImageLink Docker image link
Oleg Basov20afb152018-06-10 03:09:25 +0200412 * @param platform What do we have underneath (openstack/k8s)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700413 * @param output_dir Directory for results
Oleg Basov40e502c2018-09-04 20:42:21 +0200414 * @param config_repo Git repository with with files for Rally
415 * @param config_branch Git config repo branch which will be used during the checkout
416 * @param plugins_repo Git repository with Rally plugins
417 * @param plugins_branch Git plugins repo branch which will be used during the checkout
Oleg Basov20afb152018-06-10 03:09:25 +0200418 * @param scenarios Directory inside repo with specific scenarios
Oleg Basov40e502c2018-09-04 20:42:21 +0200419 * @param sl_scenarios Directory inside repo with specific scenarios for stacklight
Oleg Basov20afb152018-06-10 03:09:25 +0200420 * @param tasks_args_file Argument file that is used for throttling settings
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700421 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400422 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700423 */
Oleg Basov40e502c2018-09-04 20:42:21 +0200424def runRallyTests(master, target, dockerImageLink, platform, output_dir, config_repo, config_branch, plugins_repo, plugins_branch, scenarios, sl_scenarios = '', tasks_args_file = '', ext_variables = [], results = '/root/qa_results', skip_list = '') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700425 def salt = new com.mirantis.mk.Salt()
426 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700427 def dest_folder = '/home/rally/qa_results'
Oleg Basov20afb152018-06-10 03:09:25 +0200428 def env_vars = []
429 def rally_extra_args = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200430 def cmd_rally_plugins =
431 "git clone -b ${plugins_branch ?: 'master'} ${plugins_repo} /tmp/plugins; " +
432 "sudo pip install --upgrade /tmp/plugins; "
Oleg Basov20afb152018-06-10 03:09:25 +0200433 def cmd_rally_init = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200434 def cmd_rally_checkout = "git clone -b ${config_branch ?: 'master'} ${config_repo} test_config; "
Oleg Basov20afb152018-06-10 03:09:25 +0200435 def cmd_rally_start = ''
436 def cmd_rally_task_args = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200437 def cmd_rally_stacklight = ''
438 def cmd_rally_report = ''
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700439 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
440 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
Oleg Basov40e502c2018-09-04 20:42:21 +0200441 if (platform['type'] == 'openstack') {
Oleg Basov4a697fc2018-11-06 18:34:08 +0100442 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone')
Oleg Basov20afb152018-06-10 03:09:25 +0200443 def keystone = _pillar['return'][0].values()[0]
444 env_vars = ( ['tempest_version=15.0.0',
Oleg Basov4a697fc2018-11-06 18:34:08 +0100445 "OS_USERNAME=${keystone.server.admin_name}",
446 "OS_PASSWORD=${keystone.server.admin_password}",
447 "OS_TENANT_NAME=${keystone.server.admin_tenant}",
448 "OS_AUTH_URL=http://${keystone.server.bind.private_address}:${keystone.server.bind.private_port}" +
449 "/v${keystone.client.os_client_config.cfgs.root.content.clouds.admin_identity.identity_api_version}",
450 "OS_REGION_NAME=${keystone.server.region}",
Oleg Basov20afb152018-06-10 03:09:25 +0200451 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
Oleg Basov40e502c2018-09-04 20:42:21 +0200452 cmd_rally_init = 'rally db create; ' +
453 'rally deployment create --fromenv --name=existing; ' +
454 'rally deployment config; '
455 if (platform['stacklight_enabled'] == true) {
Oleg Basov418bfc42018-10-28 15:01:22 +0100456 def _pillar_grafana = salt.getPillar(master, 'I@grafana:client', 'grafana:client:server')
457 def grafana = _pillar_grafana['return'][0].values()[0]
Oleg Basov40e502c2018-09-04 20:42:21 +0200458 cmd_rally_stacklight = bundle_up_scenarios(sl_scenarios, skip_list, "scenarios_${platform.type}_stacklight.yaml")
Oleg Basov418bfc42018-10-28 15:01:22 +0100459 cmd_rally_stacklight += "sed -i 's/grafana_password: .*/grafana_password: ${grafana.password}/' " +
460 "test_config/job-params-stacklight.yaml; " +
461 "rally $rally_extra_args task start scenarios_${platform.type}_stacklight.yaml " +
Oleg Basov40e502c2018-09-04 20:42:21 +0200462 "--task-args-file test_config/job-params-stacklight.yaml; "
Oleg Basov20afb152018-06-10 03:09:25 +0200463 }
Oleg Basov40e502c2018-09-04 20:42:21 +0200464 } else if (platform['type'] == 'k8s') {
Oleg Basov20afb152018-06-10 03:09:25 +0200465 rally_extra_args = "--debug --log-file ${dest_folder}/task.log"
Oleg Basov3e050d32018-07-03 22:10:56 +0200466 def _pillar = salt.getPillar(master, 'I@kubernetes:master and *01*', 'kubernetes:master')
467 def kubernetes = _pillar['return'][0].values()[0]
468 env_vars = [
Oleg Basov491942d2018-10-17 16:11:25 +0200469 "KUBERNETES_HOST=http://${kubernetes.apiserver.vip_address}" +
Oleg Basov3e050d32018-07-03 22:10:56 +0200470 ":${kubernetes.apiserver.insecure_port}",
471 "KUBERNETES_CERT_AUTH=${dest_folder}/k8s-ca.crt",
472 "KUBERNETES_CLIENT_KEY=${dest_folder}/k8s-client.key",
473 "KUBERNETES_CLIENT_CERT=${dest_folder}/k8s-client.crt"].join(' -e ')
474 def k8s_ca = salt.getReturnValues(salt.runSaltProcessStep(master,
Oleg Basov20afb152018-06-10 03:09:25 +0200475 'I@kubernetes:master and *01*', 'cmd.run',
Oleg Basov3e050d32018-07-03 22:10:56 +0200476 ["cat /etc/kubernetes/ssl/ca-kubernetes.crt"]))
477 def k8s_client_key = salt.getReturnValues(salt.runSaltProcessStep(master,
478 'I@kubernetes:master and *01*', 'cmd.run',
479 ["cat /etc/kubernetes/ssl/kubelet-client.key"]))
480 def k8s_client_crt = salt.getReturnValues(salt.runSaltProcessStep(master,
481 'I@kubernetes:master and *01*', 'cmd.run',
482 ["cat /etc/kubernetes/ssl/kubelet-client.crt"]))
Oleg Basov20afb152018-06-10 03:09:25 +0200483 def tmp_dir = '/tmp/kube'
484 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${tmp_dir}", "mode=777"])
Oleg Basov3e050d32018-07-03 22:10:56 +0200485 writeFile file: "${tmp_dir}/k8s-ca.crt", text: k8s_ca
486 writeFile file: "${tmp_dir}/k8s-client.key", text: k8s_client_key
487 writeFile file: "${tmp_dir}/k8s-client.crt", text: k8s_client_crt
Oleg Basov20afb152018-06-10 03:09:25 +0200488 salt.cmdRun(master, target, "mv ${tmp_dir}/* ${results}/")
489 salt.runSaltProcessStep(master, target, 'file.rmdir', ["${tmp_dir}"])
Oleg Basov40e502c2018-09-04 20:42:21 +0200490 cmd_rally_init = "rally db recreate; " +
Oleg Basov3e050d32018-07-03 22:10:56 +0200491 "rally env create --name k8s --from-sysenv; " +
Oleg Basov20afb152018-06-10 03:09:25 +0200492 "rally env check k8s; "
Oleg Basov20afb152018-06-10 03:09:25 +0200493 } else {
494 throw new Exception("Platform ${platform} is not supported yet")
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800495 }
Oleg Basov06fce2a2018-11-09 21:39:03 +0100496 switch(tasks_args_file) {
497 case 'none':
498 cmd_rally_task_args = '; '
Oleg Basov20afb152018-06-10 03:09:25 +0200499 break
Oleg Basov06fce2a2018-11-09 21:39:03 +0100500 case '':
501 cmd_rally_task_args = '--task-args-file test_config/job-params-light.yaml; '
502 break
503 default:
504 cmd_rally_task_args = "--task-args-file ${tasks_args_file}; "
505 break
506 }
507 if (platform['type'] == 'k8s') {
508 cmd_rally_start = "for task in \\\$(" + bundle_up_scenarios(scenarios, skip_list) +
509 "); do " +
510 "rally $rally_extra_args task start \\\$task ${cmd_rally_task_args}" +
511 "done; "
512 } else {
513 cmd_rally_checkout += bundle_up_scenarios(scenarios, skip_list, "scenarios_${platform.type}.yaml")
514 cmd_rally_start = "rally $rally_extra_args task start " +
515 "scenarios_${platform.type}.yaml ${cmd_rally_task_args}"
Oleg Basov20afb152018-06-10 03:09:25 +0200516 }
Oleg Basovaaeb51f2018-10-17 01:07:10 +0200517 cmd_rally_report= "rally task export --uuid \\\$(rally task list --uuids-only --status finished) " +
518 "--type junit-xml --to ${dest_folder}/report-rally.xml; " +
519 "rally task report --uuid \\\$(rally task list --uuids-only --status finished) " +
520 "--out ${dest_folder}/report-rally.html"
521
Oleg Basov40e502c2018-09-04 20:42:21 +0200522 full_cmd = 'set -xe; ' + cmd_rally_plugins +
523 cmd_rally_init + cmd_rally_checkout +
524 'set +e; ' + cmd_rally_start +
Oleg Basov06fce2a2018-11-09 21:39:03 +0100525 cmd_rally_stacklight +
Oleg Basov40e502c2018-09-04 20:42:21 +0200526 cmd_rally_report
Sergey Galkinf89509d2018-03-19 15:24:17 +0400527 salt.runSaltProcessStep(master, target, 'file.touch', ["${results}/rally.db"])
528 salt.cmdRun(master, target, "chmod 666 ${results}/rally.db")
mkraynovd49daf52018-07-12 16:11:14 +0400529 salt.cmdRun(master, target, "docker run -w /home/rally -i --rm --net=host -e ${env_vars} " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400530 "-v ${results}:${dest_folder} " +
mkraynovd49daf52018-07-12 16:11:14 +0400531 "-v ${results}/rally.db:/home/rally/data/rally.db " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400532 "--entrypoint /bin/bash ${dockerImageLink} " +
533 "-c \"${full_cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700534 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700535}
536
537/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700538 * Generate test report
539 *
540 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700541 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700542 * @param output_dir Directory for results
Sergey Galkind1068e22018-02-13 13:59:32 +0400543 * @param results The reports directory
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700544 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400545def generateTestReport(master, target, dockerImageLink, output_dir, results = '/root/qa_results') {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700546 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700547 def salt = new com.mirantis.mk.Salt()
548 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700549 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
550 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
551 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
552 def reports = ['report-tempest.json',
553 'report-rally.xml',
554 'report-k8s-e2e-tests.txt',
555 'report-ha.json',
556 'report-spt.txt']
557 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700558 if ( fileExists("${output_dir}${report}") ) {
559 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700560 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
561 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
562 "rm ${output_dir}${report}_encoded; " +
563 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
564 for ( item in items.tokenize() ) {
565 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
566 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
567 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700568 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700569 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
570 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700571 }
572 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700573
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700574 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
575 "cp ${report_file} ${dest_folder}/${report_file}"
576 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
577 "-v ${results}:${dest_folder} ${dockerImageLink} " +
578 "/bin/bash -c \"${cmd}\"")
579 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700580 writeFile file: "${output_dir}${report_file}", text: report_content
581}
582
583/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700584 * Execute SPT tests
585 *
586 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700587 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700588 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700589 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400590 * @param results The reports directory
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700591 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400592def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = [], results = '/root/qa_results') {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700593 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700594 def dest_folder = '/home/rally/qa_results'
595 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
596 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
597 def nodes = getNodeList(master)
598 def nodes_hw = getNodeList(master, 'G@virtual:physical')
599 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
600 def keystone = _pillar['return'][0].values()[0]
601 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
602 def env_vars = ( ['tempest_version=15.0.0',
603 "OS_USERNAME=${keystone.admin_name}",
604 "OS_PASSWORD=${keystone.admin_password}",
605 "OS_TENANT_NAME=${keystone.admin_tenant}",
606 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
607 "OS_REGION_NAME=${keystone.region}",
608 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
609 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
610 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
611 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
612 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
613 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
614 'sudo chmod 600 /root/.ssh/id_rsa; ' +
615 "sudo timmy -c simplified-performance-testing/config.yaml " +
616 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
617 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
618 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
619 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
620 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
621 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
622 "\"${cmd}\" > ${results}/docker-spt.log")
623 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700624}
625
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700626/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600627 * Configure docker container
628 *
629 * @param target Host to run container
630 * @param proxy Proxy for accessing github and pip
631 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600632 * @param tempest_repo Tempest repo to clone. Can be upstream tempest (default, recommended), your customized tempest in local/remote repo or path inside container. If not specified, tempest will not be configured.
633 * @param tempest_endpoint_type internalURL or adminURL or publicURL to use in tests
Oleksii Zhurba198dd682018-09-07 18:16:59 -0500634 * @param tempest_version Version of tempest to use. This value will be just passed to configure.sh script (cvp-configuration repo).
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600635 * @param conf_script_path Path to configuration script.
636 * @param ext_variables Some custom extra variables to add into container
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500637 * @param container_name Name of container to use
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600638 */
639def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
Oleksii Zhurba198dd682018-09-07 18:16:59 -0500640 tempest_endpoint_type="internalURL", tempest_version="",
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500641 conf_script_path="", ext_variables = [], container_name="cvp") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600642 def salt = new com.mirantis.mk.Salt()
643 if (testing_tools_repo != "" ) {
Oleksii Zhurba0cda6e02018-06-20 14:53:19 -0500644 if (testing_tools_repo.contains('http://') || testing_tools_repo.contains('https://')) {
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500645 salt.cmdRun(master, target, "docker exec ${container_name} git clone ${testing_tools_repo} cvp-configuration")
Oleksii Zhurba0cda6e02018-06-20 14:53:19 -0500646 configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh"
647 }
648 else {
649 configure_script = testing_tools_repo
650 }
651 ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
652 "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
653 "tempest_version=${tempest_version}")
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500654 salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " ${container_name} bash -c ${configure_script}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600655 }
Oleksii Zhurba0cda6e02018-06-20 14:53:19 -0500656 else {
657 common.infoMsg("TOOLS_REPO is empty, no confguration is needed for container")
658 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600659}
660
661/**
662 * Run Tempest
663 *
664 * @param target Host to run container
665 * @param test_pattern Test pattern to run
666 * @param skip_list Path to skip-list
667 * @param output_dir Directory on target host for storing results (containers is not a good place)
668 */
669def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
670 def salt = new com.mirantis.mk.Salt()
671 def xml_file = "${output_filename}.xml"
Oleksii Zhurba44045312017-12-12 15:38:26 -0600672 def html_file = "${output_filename}.html"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600673 skip_list_cmd = ''
674 if (skip_list != '') {
675 skip_list_cmd = "--skip-list ${skip_list}"
676 }
Oleksii Zhurba77896d42018-05-25 18:11:30 -0500677 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} --detailed")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600678 salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600679 salt.cmdRun(master, target, "docker exec cvp rally verify report --type html --to /home/rally/${html_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600680 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600681 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
Oleksii Zhurba77896d42018-05-25 18:11:30 -0500682 return salt.cmdRun(master, target, "docker exec cvp rally verify show | head -5 | tail -1 | " +
683 "awk '{print \$4}'")['return'][0].values()[0].split()[0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600684}
685
686/**
687 * Run Rally
688 *
689 * @param target Host to run container
690 * @param test_pattern Test pattern to run
691 * @param scenarios_path Path to Rally scenarios
692 * @param output_dir Directory on target host for storing results (containers is not a good place)
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500693 * @param container_name Name of container to use
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600694 */
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500695def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally", container_name="cvp") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600696 def salt = new com.mirantis.mk.Salt()
697 def xml_file = "${output_filename}.xml"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600698 def html_file = "${output_filename}.html"
Oleksii Zhurbad2bb3f22019-05-15 12:20:28 -0500699 salt.cmdRun(master, target, "docker exec ${container_name} rally task start ${scenarios_path}")
700 salt.cmdRun(master, target, "docker exec ${container_name} rally task report --out ${html_file}")
701 salt.cmdRun(master, target, "docker exec ${container_name} rally task report --junit --out ${xml_file}")
702 salt.cmdRun(master, target, "docker cp ${container_name}:/home/rally/${xml_file} ${output_dir}")
703 salt.cmdRun(master, target, "docker cp ${container_name}:/home/rally/${html_file} ${output_dir}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600704}
705
706
707/**
708 * Shutdown node
709 *
710 * @param target Host to run command
711 * @param mode How to shutdown node
712 * @param retries # of retries to make to check node status
713 */
714def shutdown_vm_node(master, target, mode, retries=200) {
715 def salt = new com.mirantis.mk.Salt()
716 def common = new com.mirantis.mk.Common()
717 if (mode == 'reboot') {
718 try {
719 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
720 } catch (Exception e) {
721 common.warningMsg('Timeout from minion: node must be rebooting now')
722 }
723 common.warningMsg("Checking that minion is down")
724 status = "True"
725 for (i = 0; i < retries; i++) {
726 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
727 if (status != "True") {
728 break
729 }
730 }
731 if (status == "True") {
732 throw new Exception("Tired to wait for minion ${target} to stop responding")
733 }
734 }
735 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
736 kvm = locate_node_on_kvm(master, target)
737 if (mode == 'soft_shutdown') {
738 salt.cmdRun(master, target, "shutdown -h 0")
739 }
740 if (mode == 'hard_shutdown') {
741 salt.cmdRun(master, kvm, "virsh destroy ${target}")
742 }
743 common.warningMsg("Checking that vm on kvm is in power off state")
744 status = 'running'
745 for (i = 0; i < retries; i++) {
746 status = check_vm_status(master, target, kvm)
747 echo "Current status - ${status}"
748 if (status != 'running') {
749 break
750 }
751 sleep (1)
752 }
753 if (status == 'running') {
754 throw new Exception("Tired to wait for node ${target} to shutdown")
755 }
756 }
757}
758
759
760/**
761 * Locate kvm where target host is located
762 *
763 * @param target Host to check
764 */
765def locate_node_on_kvm(master, target) {
766 def salt = new com.mirantis.mk.Salt()
767 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
768 for (item in list.keySet()) {
769 if (list[item]) {
770 return item
771 }
772 }
773}
774
775/**
776 * Check target host status
777 *
778 * @param target Host to check
779 * @param kvm KVM node where target host is located
780 */
781def check_vm_status(master, target, kvm) {
782 def salt = new com.mirantis.mk.Salt()
783 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
784 for (item in list.keySet()) {
785 if (list[item]) {
786 return list[item].split()[2]
787 }
788 }
789}
790
791/**
792 * Find vip on nodes
793 *
794 * @param target Pattern, e.g. ctl*
795 */
796def get_vip_node(master, target) {
797 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba5f73cf62018-08-03 16:11:10 -0500798 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep '/32'"])['return'][0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600799 for (item in list.keySet()) {
800 if (list[item]) {
801 return item
802 }
803 }
804}
805
806/**
807 * Find vip on nodes
808 *
809 * @param target Host with cvp container
810 */
Oleksii Zhurba5250a9c2018-03-21 15:47:03 -0500811def openstack_cleanup(master, target, script_path="/home/rally/cvp-configuration/cleanup.sh") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600812 def salt = new com.mirantis.mk.Salt()
813 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
814}
815
816
817/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700818 * Cleanup
819 *
820 * @param target Host to run commands
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500821 * @param name Name of container to remove
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700822 */
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500823def runCleanup(master, target, name='cvp') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700824 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500825 if ( salt.cmdRun(master, target, "docker ps -f name=${name} -q", false, null, false)['return'][0].values()[0] ) {
826 salt.cmdRun(master, target, "docker rm -f ${name}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600827 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700828}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500829/**
830 * Prepare venv for any python project
831 * Note: <repo_name>\/requirements.txt content will be used
832 * for this venv
833 *
834 * @param repo_url Repository url to clone
835 * @param proxy Proxy address to use
836 */
dtsapikovf2e1bb12018-11-29 18:49:48 +0400837def prepareVenv(repo_url, proxy, useSystemPackages=false) {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500838 def python = new com.mirantis.mk.Python()
839 repo_name = "${repo_url}".tokenize("/").last()
Oleksii Zhurbae711ebb2018-06-15 16:36:38 -0500840 if (repo_url.tokenize().size() > 1){
841 if (repo_url.tokenize()[1] == '-b'){
842 repo_name = repo_url.tokenize()[0].tokenize("/").last()
843 }
844 }
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500845 path_venv = "${env.WORKSPACE}/venv"
846 path_req = "${env.WORKSPACE}/${repo_name}/requirements.txt"
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500847 sh "rm -rf ${repo_name}"
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500848 // this is temporary W/A for offline deployments
849 // Jenkins slave image has /opt/pip-mirror/ folder
850 // where pip wheels for cvp projects are located
851 if (proxy != 'offline') {
852 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
853 sh "git clone ${repo_url}"
dtsapikovf2e1bb12018-11-29 18:49:48 +0400854 python.setupVirtualenv(path_venv, "python2", [], path_req, true, useSystemPackages)
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500855 }
856 }
857 else {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500858 sh "git clone ${repo_url}"
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500859 sh "virtualenv ${path_venv} --python python2"
860 python.runVirtualenvCommand(path_venv, "pip install --no-index --find-links=/opt/pip-mirror/ -r ${path_req}", true)
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500861 }
862}
863
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700864/** Install docker if needed
865 *
866 * @param target Target node to install docker pkg
867 */
868def installDocker(master, target) {
869 def salt = new com.mirantis.mk.Salt()
870 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
871 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
872 }
873}