blob: 29402fef429620bf69e83b9ae51ae71db143ce19 [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 = ''
49 if ( salt.cmdRun(master, target, "docker ps -f name=${name} -q", false, null, false)['return'][0].values()[0] ) {
50 salt.cmdRun(master, target, "docker rm -f ${name}")
51 }
52 if (env_var.size() > 0) {
53 variables = ' -e ' + env_var.join(' -e ')
54 }
55 if (entrypoint) {
56 entry_point = '--entrypoint /bin/bash'
57 }
58 salt.cmdRun(master, target, "docker run -tid --net=host --name=${name} " +
59 "-u root ${entry_point} ${variables} ${dockerImageLink}")
60}
61
62
Petr Lomakin47fee0a2017-08-01 10:46:05 -070063/**
Oleksii Zhurba4bcf07f2018-09-11 15:23:18 -050064 * Get v2 Keystone credentials from pillars
65 *
66 */
67def _get_keystone_creds_v2(master){
68 def salt = new com.mirantis.mk.Salt()
69 def common = new com.mirantis.mk.Common()
70 def keystone = []
71 common.infoMsg("Fetching Keystone v2 credentials")
72 _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')['return'][0].values()[0]
73 keystone.add("OS_USERNAME=${_pillar.admin_name}")
74 keystone.add("OS_PASSWORD=${_pillar.admin_password}")
75 keystone.add("OS_TENANT_NAME=${_pillar.admin_tenant}")
76 keystone.add("OS_AUTH_URL=http://${_pillar.bind.private_address}:${_pillar.bind.private_port}/v2.0")
77 keystone.add("OS_REGION_NAME=${_pillar.region}")
78 keystone.add("OS_ENDPOINT_TYPE=admin")
79 return keystone
80}
81
82/**
83 * Get v3 Keystone credentials from pillars
84 *
85 */
86def _get_keystone_creds_v3(master){
87 def salt = new com.mirantis.mk.Salt()
88 def common = new com.mirantis.mk.Common()
89 pillar_name = 'keystone:client:os_client_config:cfgs:root:content:clouds:admin_identity'
90 common.infoMsg("Fetching Keystone v3 credentials")
91 def _pillar = salt.getPillar(master, 'I@keystone:client', pillar_name)['return'][0].values()[0]
92 def keystone = []
93 if (_pillar) {
94 keystone.add("OS_USERNAME=${_pillar.auth.username}")
95 keystone.add("OS_PASSWORD=${_pillar.auth.password}")
96 keystone.add("OS_TENANT_NAME=${_pillar.auth.project_name}")
97 keystone.add("OS_PROJECT_NAME=${_pillar.auth.project_name}")
98 keystone.add("OS_AUTH_URL=${_pillar.auth.auth_url}/v3")
99 keystone.add("OS_REGION_NAME=${_pillar.region_name}")
100 keystone.add("OS_IDENTITY_API_VERSION=${_pillar.identity_api_version}")
101 keystone.add("OS_ENDPOINT_TYPE=admin")
102 keystone.add("OS_PROJECT_DOMAIN_NAME=${_pillar.auth.project_domain_name}")
103 keystone.add("OS_USER_DOMAIN_NAME=${_pillar.auth.user_domain_name}")
104 return keystone
105 }
106 else {
107 common.warningMsg("Failed to fetch Keystone v3 credentials")
108 return false
109 }
110}
111
112/**
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700113 * Get file content (encoded). The content encoded by Base64.
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700114 *
115 * @param target Compound target (should target only one host)
116 * @param file File path to read
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700117 * @return The encoded content of the file
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700118 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700119def getFileContentEncoded(master, target, file) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700120 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700121 def file_content = ''
122 def cmd = "base64 -w0 ${file} > ${file}_encoded; " +
123 "split -b 1MB -d ${file}_encoded ${file}__; " +
124 "rm ${file}_encoded"
125 salt.cmdRun(master, target, cmd, false, null, false)
126 def filename = file.tokenize('/').last()
127 def folder = file - filename
128 def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"])
129 for ( part in parts['return'][0].values()[0]) {
130 def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false)
131 file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','')
132 }
133 salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"])
134 return file_content
135}
136
137/**
138 * Copy files from remote to local directory. The content of files will be
139 * decoded by Base64.
140 *
141 * @param target Compound target (should target only one host)
142 * @param folder The path to remote folder.
143 * @param output_dir The path to local folder.
144 */
145def addFiles(master, target, folder, output_dir) {
146 def salt = new com.mirantis.mk.Salt()
147 def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"])
148 def files = _result['return'][0].values()[0]
149 for (file in files) {
150 def file_content = getFileContentEncoded(master, target, "${file}")
151 def fileName = file.tokenize('/').last()
152 writeFile file: "${output_dir}${fileName}_encoded", text: file_content
153 def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " +
154 "rm ${output_dir}${fileName}_encoded"
155 sh(script: cmd)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700156 }
157}
158
159/**
160 * Get reclass value
161 *
162 * @param target The host for which the values will be provided
163 * @param filter Parameters divided by dots
164 * @return The pillar data
165 */
166def getReclassValue(master, target, filter) {
167 def common = new com.mirantis.mk.Common()
168 def salt = new com.mirantis.mk.Salt()
169 def items = filter.tokenize('.')
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700170 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${target}", false, null, false)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700171 _result = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700172 for (int k = 0; k < items.size(); k++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700173 if ( _result ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700174 _result = _result["${items[k]}"]
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700175 }
176 }
177 return _result
178}
179
180/**
181 * Create list of nodes in JSON format.
182 *
183 * @param filter The Salt's matcher
184 * @return JSON list of nodes
185 */
186def getNodeList(master, filter = null) {
187 def salt = new com.mirantis.mk.Salt()
188 def common = new com.mirantis.mk.Common()
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700189 def nodes = []
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700190 def filtered_list = null
191 def controllers = salt.getMinions(master, 'I@nova:controller')
192 def hw_nodes = salt.getMinions(master, 'G@virtual:physical')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700193 if ( filter ) {
194 filtered_list = salt.getMinions(master, filter)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700195 }
196 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false)
197 def reclass_top = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700198 def nodesList = reclass_top['base'].keySet()
199 for (int i = 0; i < nodesList.size(); i++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700200 if ( filtered_list ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700201 if ( ! filtered_list.contains(nodesList[i]) ) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700202 continue
203 }
204 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700205 def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address')
206 def network_data = [ip: ip, name: 'management']
207 def roles = [nodesList[i].tokenize('.')[0]]
208 if ( controllers.contains(nodesList[i]) ) {
209 roles.add('controller')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700210 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700211 if ( hw_nodes.contains(nodesList[i]) ) {
212 roles.add('hw_node')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700213 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700214 nodes.add([id: i+1, ip: ip, roles: roles, network_data: [network_data]])
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700215 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700216 return common.prettify(nodes)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700217}
218
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500219/**
220 * Execute mcp sanity tests
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500221 * Deprecated. Will be removed soon
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500222 *
223 * @param salt_url Salt master url
224 * @param salt_credentials Salt credentials
225 * @param test_set Test set for mcp sanity framework
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600226 * @param env_vars Additional environment variables for cvp-sanity-checks
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500227 * @param output_dir Directory for results
228 */
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600229def runSanityTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500230 def common = new com.mirantis.mk.Common()
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600231 def creds = common.getCredentials(salt_credentials)
232 def username = creds.username
233 def password = creds.password
234 def settings = ""
235 if ( env_vars != "" ) {
236 for (var in env_vars.tokenize(";")) {
237 settings += "export ${var}; "
238 }
239 }
240 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
Oleksii Zhurba5250a9c2018-03-21 15:47:03 -0500241 "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 -0500242 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
243 def statusCode = sh script:script, returnStatus:true
244 }
245}
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700246
247/**
Oleksii Zhurba4e366ff2018-02-16 20:06:52 -0600248 * Execute pytest framework tests
249 *
250 * @param salt_url Salt master url
251 * @param salt_credentials Salt credentials
252 * @param test_set Test set to run
253 * @param env_vars Additional environment variables for cvp-sanity-checks
254 * @param output_dir Directory for results
255 */
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500256def runPyTests(salt_url, salt_credentials, test_set="", env_vars="", name='cvp', container_node="", remote_dir='/root/qa_results/', artifacts_dir='validation_artifacts/') {
257 def xml_file = "${name}_report.xml"
258 def common = new com.mirantis.mk.Common()
259 def salt = new com.mirantis.mk.Salt()
260 def creds = common.getCredentials(salt_credentials)
261 def username = creds.username
262 def password = creds.password
263 if (container_node != "") {
264 def saltMaster
265 saltMaster = salt.connection(salt_url, salt_credentials)
266 def script = "pytest --junitxml ${xml_file} --tb=short -sv ${test_set}"
267 env_vars.addAll("SALT_USERNAME=${username}", "SALT_PASSWORD=${password}",
268 "SALT_URL=${salt_url}")
269 variables = ' -e ' + env_vars.join(' -e ')
270 salt.cmdRun(saltMaster, container_node, "docker exec ${variables} ${name} bash -c '${script}'", false)
271 salt.cmdRun(saltMaster, container_node, "docker cp ${name}:/var/lib/${xml_file} ${remote_dir}${xml_file}")
272 addFiles(saltMaster, container_node, remote_dir+xml_file, artifacts_dir)
273 }
274 else {
275 if (env_vars.size() > 0) {
276 variables = 'export ' + env_vars.join(';export ')
277 }
278 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${variables}; " +
279 "pytest --junitxml ${artifacts_dir}${xml_file} --tb=short -sv ${env.WORKSPACE}/${test_set}"
280 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
281 def statusCode = sh script:script, returnStatus:true
282 }
283 }
284}
285
286/**
287 * Execute pytest framework tests
288 * For backward compatibility
289 * Will be removed soon
290 *
291 * @param salt_url Salt master url
292 * @param salt_credentials Salt credentials
293 * @param test_set Test set to run
294 * @param env_vars Additional environment variables for cvp-sanity-checks
295 * @param output_dir Directory for results
296 */
Oleksii Zhurba4e366ff2018-02-16 20:06:52 -0600297def runTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
298 def common = new com.mirantis.mk.Common()
299 def creds = common.getCredentials(salt_credentials)
300 def username = creds.username
301 def password = creds.password
302 def settings = ""
303 if ( env_vars != "" ) {
304 for (var in env_vars.tokenize(";")) {
305 settings += "export ${var}; "
306 }
307 }
308 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
309 "pytest --junitxml ${output_dir}report.xml --tb=short -sv ${env.WORKSPACE}/${test_set}"
310 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
311 def statusCode = sh script:script, returnStatus:true
312 }
313}
314
315/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700316 * Execute tempest tests
317 *
318 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700319 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700320 * @param pattern If not false, will run only tests matched the pattern
321 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800322 * @param confRepository Git repository with configuration files for Tempest
323 * @param confBranch Git branch which will be used during the checkout
324 * @param repository Git repository with Tempest
325 * @param version Version of Tempest (tag, branch or commit)
Sergey Galkind1068e22018-02-13 13:59:32 +0400326 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700327 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400328def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false", results = '/root/qa_results') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700329 def salt = new com.mirantis.mk.Salt()
330 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700331 def dest_folder = '/home/rally/qa_results'
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800332 def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700333 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
334 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
335 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
336 def keystone = _pillar['return'][0].values()[0]
Dmitry Tsapikovb6911922018-07-24 15:21:23 +0000337 def env_vars = ['tempest_version=15.0.0',
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700338 "OS_USERNAME=${keystone.admin_name}",
339 "OS_PASSWORD=${keystone.admin_password}",
340 "OS_TENANT_NAME=${keystone.admin_tenant}",
341 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
342 "OS_REGION_NAME=${keystone.region}",
343 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
344 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800345 if (confRepository != '' ) {
346 cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " +
347 'rally deployment create --fromenv --name=tempest; rally deployment config; ' +
348 'rally verify create-verifier --name tempest_verifier --type tempest ' +
Dmitry Tsapikovb6911922018-07-24 15:21:23 +0000349 "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800350 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; '
351 skip_list = '--skip-list test_config/tempest/skip-list.yaml'
352 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700353 if (pattern == 'false') {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800354 cmd += "rally verify start --pattern set=full ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700355 }
356 else {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800357 cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700358 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700359 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
360 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
mkraynovd49daf52018-07-12 16:11:14 +0400361 salt.cmdRun(master, target, "docker run -w /home/rally -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400362 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
363 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700364 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700365}
366
367/**
Oleg Basov40e502c2018-09-04 20:42:21 +0200368 * Make all-in-one scenario cmd for rally tests
369 *
370 * @param scenarios_path Path to scenarios folder/file
371 * @param skip_scenarios Comma-delimited list of scenarios names to skip
372 * @param bundle_file Bundle name to create
373*/
Oleg Basov06fce2a2018-11-09 21:39:03 +0100374def bundle_up_scenarios(scenarios_path, skip_scenarios, bundle_file = '' ) {
Oleg Basov40e502c2018-09-04 20:42:21 +0200375 def skip_names = ''
376 def skip_dirs = ''
377 def result = ''
378 if (skip_scenarios != ''){
379 for ( scen in skip_scenarios.split(',') ) {
380 if ( scen.contains('yaml')) {
381 skip_names += "! -name ${scen} "
382 }
383 else {
384 skip_dirs += "-path ${scenarios_path}/${scen} -prune -o "
385 }
386 }
387 }
Oleg Basov06fce2a2018-11-09 21:39:03 +0100388 if (bundle_file != '') {
389 result = "if [ -f ${scenarios_path} ]; then cp ${scenarios_path} ${bundle_file}; " +
Oleg Basov40e502c2018-09-04 20:42:21 +0200390 "else " +
391 "find -L ${scenarios_path} " + skip_dirs +
392 " -name '*.yaml' " + skip_names +
393 "-exec cat {} >> ${bundle_file} \\; ; " +
394 "sed -i '/---/d' ${bundle_file}; fi; "
Oleg Basov06fce2a2018-11-09 21:39:03 +0100395 } else {
396 result = "find -L ${scenarios_path} " + skip_dirs +
397 " -name '*.yaml' " + skip_names
398 }
Oleg Basov40e502c2018-09-04 20:42:21 +0200399
400 return result
401}
402
403/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700404 * Execute rally tests
405 *
406 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700407 * @param dockerImageLink Docker image link
Oleg Basov20afb152018-06-10 03:09:25 +0200408 * @param platform What do we have underneath (openstack/k8s)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700409 * @param output_dir Directory for results
Oleg Basov40e502c2018-09-04 20:42:21 +0200410 * @param config_repo Git repository with with files for Rally
411 * @param config_branch Git config repo branch which will be used during the checkout
412 * @param plugins_repo Git repository with Rally plugins
413 * @param plugins_branch Git plugins repo branch which will be used during the checkout
Oleg Basov20afb152018-06-10 03:09:25 +0200414 * @param scenarios Directory inside repo with specific scenarios
Oleg Basov40e502c2018-09-04 20:42:21 +0200415 * @param sl_scenarios Directory inside repo with specific scenarios for stacklight
Oleg Basov20afb152018-06-10 03:09:25 +0200416 * @param tasks_args_file Argument file that is used for throttling settings
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700417 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400418 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700419 */
Oleg Basov40e502c2018-09-04 20:42:21 +0200420def 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 -0700421 def salt = new com.mirantis.mk.Salt()
422 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700423 def dest_folder = '/home/rally/qa_results'
Oleg Basov20afb152018-06-10 03:09:25 +0200424 def env_vars = []
425 def rally_extra_args = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200426 def cmd_rally_plugins =
427 "git clone -b ${plugins_branch ?: 'master'} ${plugins_repo} /tmp/plugins; " +
428 "sudo pip install --upgrade /tmp/plugins; "
Oleg Basov20afb152018-06-10 03:09:25 +0200429 def cmd_rally_init = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200430 def cmd_rally_checkout = "git clone -b ${config_branch ?: 'master'} ${config_repo} test_config; "
Oleg Basov20afb152018-06-10 03:09:25 +0200431 def cmd_rally_start = ''
432 def cmd_rally_task_args = ''
Oleg Basov40e502c2018-09-04 20:42:21 +0200433 def cmd_rally_stacklight = ''
434 def cmd_rally_report = ''
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700435 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
436 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
Oleg Basov40e502c2018-09-04 20:42:21 +0200437 if (platform['type'] == 'openstack') {
Oleg Basov4a697fc2018-11-06 18:34:08 +0100438 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone')
Oleg Basov20afb152018-06-10 03:09:25 +0200439 def keystone = _pillar['return'][0].values()[0]
440 env_vars = ( ['tempest_version=15.0.0',
Oleg Basov4a697fc2018-11-06 18:34:08 +0100441 "OS_USERNAME=${keystone.server.admin_name}",
442 "OS_PASSWORD=${keystone.server.admin_password}",
443 "OS_TENANT_NAME=${keystone.server.admin_tenant}",
444 "OS_AUTH_URL=http://${keystone.server.bind.private_address}:${keystone.server.bind.private_port}" +
445 "/v${keystone.client.os_client_config.cfgs.root.content.clouds.admin_identity.identity_api_version}",
446 "OS_REGION_NAME=${keystone.server.region}",
Oleg Basov20afb152018-06-10 03:09:25 +0200447 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
Oleg Basov40e502c2018-09-04 20:42:21 +0200448 cmd_rally_init = 'rally db create; ' +
449 'rally deployment create --fromenv --name=existing; ' +
450 'rally deployment config; '
451 if (platform['stacklight_enabled'] == true) {
Oleg Basov418bfc42018-10-28 15:01:22 +0100452 def _pillar_grafana = salt.getPillar(master, 'I@grafana:client', 'grafana:client:server')
453 def grafana = _pillar_grafana['return'][0].values()[0]
Oleg Basov40e502c2018-09-04 20:42:21 +0200454 cmd_rally_stacklight = bundle_up_scenarios(sl_scenarios, skip_list, "scenarios_${platform.type}_stacklight.yaml")
Oleg Basov418bfc42018-10-28 15:01:22 +0100455 cmd_rally_stacklight += "sed -i 's/grafana_password: .*/grafana_password: ${grafana.password}/' " +
456 "test_config/job-params-stacklight.yaml; " +
457 "rally $rally_extra_args task start scenarios_${platform.type}_stacklight.yaml " +
Oleg Basov40e502c2018-09-04 20:42:21 +0200458 "--task-args-file test_config/job-params-stacklight.yaml; "
Oleg Basov20afb152018-06-10 03:09:25 +0200459 }
Oleg Basov40e502c2018-09-04 20:42:21 +0200460 } else if (platform['type'] == 'k8s') {
Oleg Basov20afb152018-06-10 03:09:25 +0200461 rally_extra_args = "--debug --log-file ${dest_folder}/task.log"
Oleg Basov3e050d32018-07-03 22:10:56 +0200462 def _pillar = salt.getPillar(master, 'I@kubernetes:master and *01*', 'kubernetes:master')
463 def kubernetes = _pillar['return'][0].values()[0]
464 env_vars = [
Oleg Basov491942d2018-10-17 16:11:25 +0200465 "KUBERNETES_HOST=http://${kubernetes.apiserver.vip_address}" +
Oleg Basov3e050d32018-07-03 22:10:56 +0200466 ":${kubernetes.apiserver.insecure_port}",
467 "KUBERNETES_CERT_AUTH=${dest_folder}/k8s-ca.crt",
468 "KUBERNETES_CLIENT_KEY=${dest_folder}/k8s-client.key",
469 "KUBERNETES_CLIENT_CERT=${dest_folder}/k8s-client.crt"].join(' -e ')
470 def k8s_ca = salt.getReturnValues(salt.runSaltProcessStep(master,
Oleg Basov20afb152018-06-10 03:09:25 +0200471 'I@kubernetes:master and *01*', 'cmd.run',
Oleg Basov3e050d32018-07-03 22:10:56 +0200472 ["cat /etc/kubernetes/ssl/ca-kubernetes.crt"]))
473 def k8s_client_key = salt.getReturnValues(salt.runSaltProcessStep(master,
474 'I@kubernetes:master and *01*', 'cmd.run',
475 ["cat /etc/kubernetes/ssl/kubelet-client.key"]))
476 def k8s_client_crt = salt.getReturnValues(salt.runSaltProcessStep(master,
477 'I@kubernetes:master and *01*', 'cmd.run',
478 ["cat /etc/kubernetes/ssl/kubelet-client.crt"]))
Oleg Basov20afb152018-06-10 03:09:25 +0200479 def tmp_dir = '/tmp/kube'
480 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${tmp_dir}", "mode=777"])
Oleg Basov3e050d32018-07-03 22:10:56 +0200481 writeFile file: "${tmp_dir}/k8s-ca.crt", text: k8s_ca
482 writeFile file: "${tmp_dir}/k8s-client.key", text: k8s_client_key
483 writeFile file: "${tmp_dir}/k8s-client.crt", text: k8s_client_crt
Oleg Basov20afb152018-06-10 03:09:25 +0200484 salt.cmdRun(master, target, "mv ${tmp_dir}/* ${results}/")
485 salt.runSaltProcessStep(master, target, 'file.rmdir', ["${tmp_dir}"])
Oleg Basov40e502c2018-09-04 20:42:21 +0200486 cmd_rally_init = "rally db recreate; " +
Oleg Basov3e050d32018-07-03 22:10:56 +0200487 "rally env create --name k8s --from-sysenv; " +
Oleg Basov20afb152018-06-10 03:09:25 +0200488 "rally env check k8s; "
Oleg Basov20afb152018-06-10 03:09:25 +0200489 } else {
490 throw new Exception("Platform ${platform} is not supported yet")
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800491 }
Oleg Basov06fce2a2018-11-09 21:39:03 +0100492 switch(tasks_args_file) {
493 case 'none':
494 cmd_rally_task_args = '; '
Oleg Basov20afb152018-06-10 03:09:25 +0200495 break
Oleg Basov06fce2a2018-11-09 21:39:03 +0100496 case '':
497 cmd_rally_task_args = '--task-args-file test_config/job-params-light.yaml; '
498 break
499 default:
500 cmd_rally_task_args = "--task-args-file ${tasks_args_file}; "
501 break
502 }
503 if (platform['type'] == 'k8s') {
504 cmd_rally_start = "for task in \\\$(" + bundle_up_scenarios(scenarios, skip_list) +
505 "); do " +
506 "rally $rally_extra_args task start \\\$task ${cmd_rally_task_args}" +
507 "done; "
508 } else {
509 cmd_rally_checkout += bundle_up_scenarios(scenarios, skip_list, "scenarios_${platform.type}.yaml")
510 cmd_rally_start = "rally $rally_extra_args task start " +
511 "scenarios_${platform.type}.yaml ${cmd_rally_task_args}"
Oleg Basov20afb152018-06-10 03:09:25 +0200512 }
Oleg Basovaaeb51f2018-10-17 01:07:10 +0200513 cmd_rally_report= "rally task export --uuid \\\$(rally task list --uuids-only --status finished) " +
514 "--type junit-xml --to ${dest_folder}/report-rally.xml; " +
515 "rally task report --uuid \\\$(rally task list --uuids-only --status finished) " +
516 "--out ${dest_folder}/report-rally.html"
517
Oleg Basov40e502c2018-09-04 20:42:21 +0200518 full_cmd = 'set -xe; ' + cmd_rally_plugins +
519 cmd_rally_init + cmd_rally_checkout +
520 'set +e; ' + cmd_rally_start +
Oleg Basov06fce2a2018-11-09 21:39:03 +0100521 cmd_rally_stacklight +
Oleg Basov40e502c2018-09-04 20:42:21 +0200522 cmd_rally_report
Sergey Galkinf89509d2018-03-19 15:24:17 +0400523 salt.runSaltProcessStep(master, target, 'file.touch', ["${results}/rally.db"])
524 salt.cmdRun(master, target, "chmod 666 ${results}/rally.db")
mkraynovd49daf52018-07-12 16:11:14 +0400525 salt.cmdRun(master, target, "docker run -w /home/rally -i --rm --net=host -e ${env_vars} " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400526 "-v ${results}:${dest_folder} " +
mkraynovd49daf52018-07-12 16:11:14 +0400527 "-v ${results}/rally.db:/home/rally/data/rally.db " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400528 "--entrypoint /bin/bash ${dockerImageLink} " +
529 "-c \"${full_cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700530 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700531}
532
533/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700534 * Generate test report
535 *
536 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700537 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700538 * @param output_dir Directory for results
Sergey Galkind1068e22018-02-13 13:59:32 +0400539 * @param results The reports directory
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700540 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400541def generateTestReport(master, target, dockerImageLink, output_dir, results = '/root/qa_results') {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700542 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700543 def salt = new com.mirantis.mk.Salt()
544 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700545 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
546 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
547 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
548 def reports = ['report-tempest.json',
549 'report-rally.xml',
550 'report-k8s-e2e-tests.txt',
551 'report-ha.json',
552 'report-spt.txt']
553 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700554 if ( fileExists("${output_dir}${report}") ) {
555 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700556 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
557 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
558 "rm ${output_dir}${report}_encoded; " +
559 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
560 for ( item in items.tokenize() ) {
561 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
562 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
563 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700564 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700565 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
566 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700567 }
568 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700569
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700570 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
571 "cp ${report_file} ${dest_folder}/${report_file}"
572 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
573 "-v ${results}:${dest_folder} ${dockerImageLink} " +
574 "/bin/bash -c \"${cmd}\"")
575 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700576 writeFile file: "${output_dir}${report_file}", text: report_content
577}
578
579/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700580 * Execute SPT tests
581 *
582 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700583 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700584 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700585 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400586 * @param results The reports directory
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700587 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400588def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = [], results = '/root/qa_results') {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700589 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700590 def dest_folder = '/home/rally/qa_results'
591 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
592 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
593 def nodes = getNodeList(master)
594 def nodes_hw = getNodeList(master, 'G@virtual:physical')
595 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
596 def keystone = _pillar['return'][0].values()[0]
597 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
598 def env_vars = ( ['tempest_version=15.0.0',
599 "OS_USERNAME=${keystone.admin_name}",
600 "OS_PASSWORD=${keystone.admin_password}",
601 "OS_TENANT_NAME=${keystone.admin_tenant}",
602 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
603 "OS_REGION_NAME=${keystone.region}",
604 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
605 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
606 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
607 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
608 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
609 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
610 'sudo chmod 600 /root/.ssh/id_rsa; ' +
611 "sudo timmy -c simplified-performance-testing/config.yaml " +
612 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
613 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
614 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
615 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
616 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
617 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
618 "\"${cmd}\" > ${results}/docker-spt.log")
619 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700620}
621
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700622/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600623 * Configure docker container
624 *
625 * @param target Host to run container
626 * @param proxy Proxy for accessing github and pip
627 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600628 * @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.
629 * @param tempest_endpoint_type internalURL or adminURL or publicURL to use in tests
Oleksii Zhurba198dd682018-09-07 18:16:59 -0500630 * @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 -0600631 * @param conf_script_path Path to configuration script.
632 * @param ext_variables Some custom extra variables to add into container
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600633 */
634def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
Oleksii Zhurba198dd682018-09-07 18:16:59 -0500635 tempest_endpoint_type="internalURL", tempest_version="",
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600636 conf_script_path="", ext_variables = []) {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600637 def salt = new com.mirantis.mk.Salt()
638 if (testing_tools_repo != "" ) {
Oleksii Zhurba0cda6e02018-06-20 14:53:19 -0500639 if (testing_tools_repo.contains('http://') || testing_tools_repo.contains('https://')) {
640 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo} cvp-configuration")
641 configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh"
642 }
643 else {
644 configure_script = testing_tools_repo
645 }
646 ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
647 "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
648 "tempest_version=${tempest_version}")
649 salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " cvp bash -c ${configure_script}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600650 }
Oleksii Zhurba0cda6e02018-06-20 14:53:19 -0500651 else {
652 common.infoMsg("TOOLS_REPO is empty, no confguration is needed for container")
653 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600654}
655
656/**
657 * Run Tempest
658 *
659 * @param target Host to run container
660 * @param test_pattern Test pattern to run
661 * @param skip_list Path to skip-list
662 * @param output_dir Directory on target host for storing results (containers is not a good place)
663 */
664def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
665 def salt = new com.mirantis.mk.Salt()
666 def xml_file = "${output_filename}.xml"
Oleksii Zhurba44045312017-12-12 15:38:26 -0600667 def html_file = "${output_filename}.html"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600668 skip_list_cmd = ''
669 if (skip_list != '') {
670 skip_list_cmd = "--skip-list ${skip_list}"
671 }
Oleksii Zhurba77896d42018-05-25 18:11:30 -0500672 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} --detailed")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600673 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 -0600674 salt.cmdRun(master, target, "docker exec cvp rally verify report --type html --to /home/rally/${html_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600675 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600676 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
Oleksii Zhurba77896d42018-05-25 18:11:30 -0500677 return salt.cmdRun(master, target, "docker exec cvp rally verify show | head -5 | tail -1 | " +
678 "awk '{print \$4}'")['return'][0].values()[0].split()[0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600679}
680
681/**
682 * Run Rally
683 *
684 * @param target Host to run container
685 * @param test_pattern Test pattern to run
686 * @param scenarios_path Path to Rally scenarios
687 * @param output_dir Directory on target host for storing results (containers is not a good place)
688 */
689def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
690 def salt = new com.mirantis.mk.Salt()
691 def xml_file = "${output_filename}.xml"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600692 def html_file = "${output_filename}.html"
Oleksii Zhurba77896d42018-05-25 18:11:30 -0500693 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600694 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
Oleksii Zhurba1bf9be12018-01-17 15:20:00 -0600695 salt.cmdRun(master, target, "docker exec cvp rally task report --junit --out ${xml_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600696 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
697 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
698}
699
700
701/**
702 * Shutdown node
703 *
704 * @param target Host to run command
705 * @param mode How to shutdown node
706 * @param retries # of retries to make to check node status
707 */
708def shutdown_vm_node(master, target, mode, retries=200) {
709 def salt = new com.mirantis.mk.Salt()
710 def common = new com.mirantis.mk.Common()
711 if (mode == 'reboot') {
712 try {
713 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
714 } catch (Exception e) {
715 common.warningMsg('Timeout from minion: node must be rebooting now')
716 }
717 common.warningMsg("Checking that minion is down")
718 status = "True"
719 for (i = 0; i < retries; i++) {
720 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
721 if (status != "True") {
722 break
723 }
724 }
725 if (status == "True") {
726 throw new Exception("Tired to wait for minion ${target} to stop responding")
727 }
728 }
729 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
730 kvm = locate_node_on_kvm(master, target)
731 if (mode == 'soft_shutdown') {
732 salt.cmdRun(master, target, "shutdown -h 0")
733 }
734 if (mode == 'hard_shutdown') {
735 salt.cmdRun(master, kvm, "virsh destroy ${target}")
736 }
737 common.warningMsg("Checking that vm on kvm is in power off state")
738 status = 'running'
739 for (i = 0; i < retries; i++) {
740 status = check_vm_status(master, target, kvm)
741 echo "Current status - ${status}"
742 if (status != 'running') {
743 break
744 }
745 sleep (1)
746 }
747 if (status == 'running') {
748 throw new Exception("Tired to wait for node ${target} to shutdown")
749 }
750 }
751}
752
753
754/**
755 * Locate kvm where target host is located
756 *
757 * @param target Host to check
758 */
759def locate_node_on_kvm(master, target) {
760 def salt = new com.mirantis.mk.Salt()
761 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
762 for (item in list.keySet()) {
763 if (list[item]) {
764 return item
765 }
766 }
767}
768
769/**
770 * Check target host status
771 *
772 * @param target Host to check
773 * @param kvm KVM node where target host is located
774 */
775def check_vm_status(master, target, kvm) {
776 def salt = new com.mirantis.mk.Salt()
777 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
778 for (item in list.keySet()) {
779 if (list[item]) {
780 return list[item].split()[2]
781 }
782 }
783}
784
785/**
786 * Find vip on nodes
787 *
788 * @param target Pattern, e.g. ctl*
789 */
790def get_vip_node(master, target) {
791 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba5f73cf62018-08-03 16:11:10 -0500792 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep '/32'"])['return'][0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600793 for (item in list.keySet()) {
794 if (list[item]) {
795 return item
796 }
797 }
798}
799
800/**
801 * Find vip on nodes
802 *
803 * @param target Host with cvp container
804 */
Oleksii Zhurba5250a9c2018-03-21 15:47:03 -0500805def openstack_cleanup(master, target, script_path="/home/rally/cvp-configuration/cleanup.sh") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600806 def salt = new com.mirantis.mk.Salt()
807 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
808}
809
810
811/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700812 * Cleanup
813 *
814 * @param target Host to run commands
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500815 * @param name Name of container to remove
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700816 */
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500817def runCleanup(master, target, name='cvp') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700818 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba1f4a6ff2018-06-27 16:45:17 -0500819 if ( salt.cmdRun(master, target, "docker ps -f name=${name} -q", false, null, false)['return'][0].values()[0] ) {
820 salt.cmdRun(master, target, "docker rm -f ${name}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600821 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700822}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500823/**
824 * Prepare venv for any python project
825 * Note: <repo_name>\/requirements.txt content will be used
826 * for this venv
827 *
828 * @param repo_url Repository url to clone
829 * @param proxy Proxy address to use
830 */
dtsapikovf2e1bb12018-11-29 18:49:48 +0400831def prepareVenv(repo_url, proxy, useSystemPackages=false) {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500832 def python = new com.mirantis.mk.Python()
833 repo_name = "${repo_url}".tokenize("/").last()
Oleksii Zhurbae711ebb2018-06-15 16:36:38 -0500834 if (repo_url.tokenize().size() > 1){
835 if (repo_url.tokenize()[1] == '-b'){
836 repo_name = repo_url.tokenize()[0].tokenize("/").last()
837 }
838 }
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500839 path_venv = "${env.WORKSPACE}/venv"
840 path_req = "${env.WORKSPACE}/${repo_name}/requirements.txt"
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500841 sh "rm -rf ${repo_name}"
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500842 // this is temporary W/A for offline deployments
843 // Jenkins slave image has /opt/pip-mirror/ folder
844 // where pip wheels for cvp projects are located
845 if (proxy != 'offline') {
846 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
847 sh "git clone ${repo_url}"
dtsapikovf2e1bb12018-11-29 18:49:48 +0400848 python.setupVirtualenv(path_venv, "python2", [], path_req, true, useSystemPackages)
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500849 }
850 }
851 else {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500852 sh "git clone ${repo_url}"
Oleksii Zhurba83e3e5c2018-06-27 16:59:29 -0500853 sh "virtualenv ${path_venv} --python python2"
854 python.runVirtualenvCommand(path_venv, "pip install --no-index --find-links=/opt/pip-mirror/ -r ${path_req}", true)
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500855 }
856}
857
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700858/** Install docker if needed
859 *
860 * @param target Target node to install docker pkg
861 */
862def installDocker(master, target) {
863 def salt = new com.mirantis.mk.Salt()
864 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
865 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
866 }
867}