Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 1 | package com.mirantis.mcp |
| 2 | |
| 3 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 4 | * DEPRECATED |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 5 | * Tests providing functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 10 | * Run docker container with basic (keystone) parameters |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 11 | * For backward compatibility. Deprecated. |
| 12 | * Will be removed soon. |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 13 | * |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 14 | * @param target Host to run container |
| 15 | * @param dockerImageLink Docker image link. May be custom or default rally image |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 16 | */ |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 17 | def runBasicContainer(master, target, dockerImageLink="xrally/xrally-openstack:0.10.1"){ |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 18 | def salt = new com.mirantis.mk.Salt() |
| 19 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 20 | common.errorMsg('You are using deprecated method! Please migrate to validate.runContainer. This method will be removed') |
| 21 | error('You are using deprecated method! Please migrate to validate.runContainer. This method will be removed') |
Sam Stoelinga | 28bdb72 | 2017-09-25 18:29:59 -0700 | [diff] [blame] | 22 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 23 | def keystone = _pillar['return'][0].values()[0] |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 24 | if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) { |
| 25 | salt.cmdRun(master, target, "docker rm -f cvp") |
| 26 | } |
| 27 | salt.cmdRun(master, target, "docker run -tid --net=host --name=cvp " + |
| 28 | "-u root -e OS_USERNAME=${keystone.admin_name} " + |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 29 | "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " + |
| 30 | "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " + |
Oleksii Zhurba | 1bf9be1 | 2018-01-17 15:20:00 -0600 | [diff] [blame] | 31 | "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin --entrypoint /bin/bash ${dockerImageLink}") |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Run docker container with parameters |
| 37 | * |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 38 | * @param target Host to run container |
| 39 | * @param dockerImageLink Docker image link. May be custom or default rally image |
| 40 | * @param name Name for container |
| 41 | * @param env_var Environment variables to set in container |
| 42 | * @param entrypoint Set entrypoint to /bin/bash or leave default |
| 43 | * @param mounts Map with mounts for container |
Sergey Galkin | 7137ad0 | 2019-11-07 14:52:13 +0400 | [diff] [blame] | 44 | * @param output_replacing Maps with regex with should be hide from output (passwords, etc) |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 45 | **/ |
| 46 | |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 47 | def runContainer(Map params){ |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 48 | def common = new com.mirantis.mk.Common() |
Sergey Galkin | 7137ad0 | 2019-11-07 14:52:13 +0400 | [diff] [blame] | 49 | defaults = ["name": "cvp", "env_var": [], "entrypoint": true, "mounts": [:], "output_replacing": []] |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 50 | params = defaults + params |
| 51 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 52 | def variables = '' |
| 53 | def entry_point = '' |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 54 | def tempest_conf_mount = '' |
| 55 | def mounts = '' |
| 56 | def cluster_name = salt.getPillar(params.master, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0] |
| 57 | default_mounts = ["/etc/ssl/certs/": "/etc/ssl/certs/", |
| 58 | "/srv/salt/pki/${cluster_name}/": "/etc/certs", |
| 59 | "/root/test/": "/root/tempest/", |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 60 | "/etc/hosts": "/etc/hosts"] |
| 61 | params.mounts = default_mounts + params.mounts |
Ievgeniia Zadorozhna | 07306f2 | 2019-12-16 18:15:19 +0300 | [diff] [blame] | 62 | if ( salt.cmdRun(params.master, params.target, "docker ps -f name=^${params.name}\$ -q", false, null, false)['return'][0].values()[0] ) { |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 63 | salt.cmdRun(params.master, params.target, "docker rm -f ${params.name}") |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 64 | } |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 65 | if (params.env_var.size() > 0) { |
| 66 | variables = ' -e ' + params.env_var.join(' -e ') |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 67 | } |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 68 | if (params.entrypoint) { |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 69 | entry_point = '--entrypoint /bin/bash' |
| 70 | } |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 71 | params.mounts.each { local, container -> |
| 72 | mounts = mounts + " -v ${local}:${container}" |
| 73 | } |
Sergey Galkin | 7137ad0 | 2019-11-07 14:52:13 +0400 | [diff] [blame] | 74 | salt.cmdRun(params.master, params.target, |
| 75 | "docker run -tid --net=host --name=${params.name}" + |
| 76 | "${mounts} -u root ${entry_point} ${variables} ${params.dockerImageLink}", |
| 77 | true, null, true, [], |
| 78 | params.output_replacing) |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Oleksii Zhurba | f1138b2 | 2019-03-26 16:15:56 -0500 | [diff] [blame] | 81 | def runContainer(master, target, dockerImageLink, name='cvp', env_var=[], entrypoint=true, mounts=[:]){ |
| 82 | def common = new com.mirantis.mk.Common() |
| 83 | common.infoMsg("This method will be deprecated. Convert you method call to use Map as input parameter") |
| 84 | // Convert to Map |
| 85 | params = ['master': master, 'target': target, 'dockerImageLink': dockerImageLink, 'name': name, 'env_var': env_var, |
| 86 | 'entrypoint': entrypoint, 'mounts': mounts] |
| 87 | // Call new method with Map as parameter |
| 88 | return runContainer(params) |
| 89 | } |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 90 | |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 91 | /** |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 92 | * Get v2 Keystone credentials from pillars |
| 93 | * |
| 94 | */ |
| 95 | def _get_keystone_creds_v2(master){ |
| 96 | def salt = new com.mirantis.mk.Salt() |
| 97 | def common = new com.mirantis.mk.Common() |
| 98 | def keystone = [] |
Oleksii Zhurba | 62ca88d | 2019-04-29 15:25:42 -0500 | [diff] [blame] | 99 | _pillar = false |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 100 | common.infoMsg("Fetching Keystone v2 credentials") |
Oleksii Zhurba | 62ca88d | 2019-04-29 15:25:42 -0500 | [diff] [blame] | 101 | _response = salt.runSaltProcessStep(master, 'I@keystone:server', 'pillar.get', 'keystone:server', null, false, 1)['return'][0] |
| 102 | for (i = 0; i < _response.keySet().size(); i++) { |
| 103 | if ( _response.values()[i] ) { |
| 104 | _pillar = _response.values()[i] |
| 105 | } |
| 106 | } |
| 107 | if (_pillar) { |
| 108 | keystone.add("OS_USERNAME=${_pillar.admin_name}") |
| 109 | keystone.add("OS_PASSWORD=${_pillar.admin_password}") |
| 110 | keystone.add("OS_TENANT_NAME=${_pillar.admin_tenant}") |
| 111 | keystone.add("OS_AUTH_URL=http://${_pillar.bind.private_address}:${_pillar.bind.private_port}/v2.0") |
| 112 | keystone.add("OS_REGION_NAME=${_pillar.region}") |
| 113 | keystone.add("OS_ENDPOINT_TYPE=admin") |
| 114 | return keystone |
| 115 | } |
| 116 | else { |
| 117 | throw new Exception("Cannot fetch Keystone v2 credentials. Response: ${_response}") |
| 118 | } |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get v3 Keystone credentials from pillars |
| 123 | * |
| 124 | */ |
| 125 | def _get_keystone_creds_v3(master){ |
| 126 | def salt = new com.mirantis.mk.Salt() |
| 127 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 62ca88d | 2019-04-29 15:25:42 -0500 | [diff] [blame] | 128 | _pillar = false |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 129 | pillar_name = 'keystone:client:os_client_config:cfgs:root:content:clouds:admin_identity' |
| 130 | common.infoMsg("Fetching Keystone v3 credentials") |
Oleksii Zhurba | 62ca88d | 2019-04-29 15:25:42 -0500 | [diff] [blame] | 131 | _response = salt.runSaltProcessStep(master, 'I@keystone:server', 'pillar.get', pillar_name, null, false, 1)['return'][0] |
| 132 | for (i = 0; i < _response.keySet().size(); i++) { |
| 133 | if ( _response.values()[i] ) { |
| 134 | _pillar = _response.values()[i] |
| 135 | } |
| 136 | } |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 137 | def keystone = [] |
| 138 | if (_pillar) { |
| 139 | keystone.add("OS_USERNAME=${_pillar.auth.username}") |
| 140 | keystone.add("OS_PASSWORD=${_pillar.auth.password}") |
| 141 | keystone.add("OS_TENANT_NAME=${_pillar.auth.project_name}") |
| 142 | keystone.add("OS_PROJECT_NAME=${_pillar.auth.project_name}") |
| 143 | keystone.add("OS_AUTH_URL=${_pillar.auth.auth_url}/v3") |
| 144 | keystone.add("OS_REGION_NAME=${_pillar.region_name}") |
| 145 | keystone.add("OS_IDENTITY_API_VERSION=${_pillar.identity_api_version}") |
Oleksii Zhurba | fa885ed | 2019-02-13 18:27:31 -0600 | [diff] [blame] | 146 | keystone.add("OS_ENDPOINT_TYPE=internal") |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 147 | keystone.add("OS_PROJECT_DOMAIN_NAME=${_pillar.auth.project_domain_name}") |
| 148 | keystone.add("OS_USER_DOMAIN_NAME=${_pillar.auth.user_domain_name}") |
Oleksii Zhurba | fa885ed | 2019-02-13 18:27:31 -0600 | [diff] [blame] | 149 | // we mount /srv/salt/pki/${cluster_name}/:/etc/certs with certs for cvp container |
| 150 | keystone.add("OS_CACERT='/etc/certs/proxy-with-chain.crt'") |
Oleksii Zhurba | 4bcf07f | 2018-09-11 15:23:18 -0500 | [diff] [blame] | 151 | return keystone |
| 152 | } |
| 153 | else { |
| 154 | common.warningMsg("Failed to fetch Keystone v3 credentials") |
| 155 | return false |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 160 | * Get file content (encoded). The content encoded by Base64. |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 161 | * |
| 162 | * @param target Compound target (should target only one host) |
| 163 | * @param file File path to read |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 164 | * @return The encoded content of the file |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 165 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 166 | def getFileContentEncoded(master, target, file) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 167 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 168 | def file_content = '' |
| 169 | def cmd = "base64 -w0 ${file} > ${file}_encoded; " + |
| 170 | "split -b 1MB -d ${file}_encoded ${file}__; " + |
| 171 | "rm ${file}_encoded" |
| 172 | salt.cmdRun(master, target, cmd, false, null, false) |
| 173 | def filename = file.tokenize('/').last() |
| 174 | def folder = file - filename |
| 175 | def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"]) |
| 176 | for ( part in parts['return'][0].values()[0]) { |
| 177 | def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false) |
| 178 | file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','') |
| 179 | } |
| 180 | salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"]) |
| 181 | return file_content |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Copy files from remote to local directory. The content of files will be |
| 186 | * decoded by Base64. |
| 187 | * |
| 188 | * @param target Compound target (should target only one host) |
| 189 | * @param folder The path to remote folder. |
| 190 | * @param output_dir The path to local folder. |
| 191 | */ |
| 192 | def addFiles(master, target, folder, output_dir) { |
| 193 | def salt = new com.mirantis.mk.Salt() |
| 194 | def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"]) |
| 195 | def files = _result['return'][0].values()[0] |
| 196 | for (file in files) { |
| 197 | def file_content = getFileContentEncoded(master, target, "${file}") |
| 198 | def fileName = file.tokenize('/').last() |
| 199 | writeFile file: "${output_dir}${fileName}_encoded", text: file_content |
| 200 | def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " + |
| 201 | "rm ${output_dir}${fileName}_encoded" |
| 202 | sh(script: cmd) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 207 | * DEPRECATED |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 208 | * Get reclass value |
| 209 | * |
| 210 | * @param target The host for which the values will be provided |
| 211 | * @param filter Parameters divided by dots |
| 212 | * @return The pillar data |
| 213 | */ |
| 214 | def getReclassValue(master, target, filter) { |
| 215 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 216 | common.errorMsg('You are using deprecated method! This method will be removed') |
| 217 | error('You are using deprecated method! This method will be removed') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 218 | def salt = new com.mirantis.mk.Salt() |
| 219 | def items = filter.tokenize('.') |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 220 | def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${target}", false, null, false) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 221 | _result = common.parseJSON(_result['return'][0].values()[0]) |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 222 | for (int k = 0; k < items.size(); k++) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 223 | if ( _result ) { |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 224 | _result = _result["${items[k]}"] |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | return _result |
| 228 | } |
| 229 | |
| 230 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 231 | * DEPRECATED |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 232 | * Create list of nodes in JSON format. |
| 233 | * |
| 234 | * @param filter The Salt's matcher |
| 235 | * @return JSON list of nodes |
| 236 | */ |
| 237 | def getNodeList(master, filter = null) { |
| 238 | def salt = new com.mirantis.mk.Salt() |
| 239 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 240 | common.errorMsg('You are using deprecated method! This method will be removed') |
| 241 | error('You are using deprecated method! This method will be removed') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 242 | def nodes = [] |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 243 | def filtered_list = null |
| 244 | def controllers = salt.getMinions(master, 'I@nova:controller') |
| 245 | def hw_nodes = salt.getMinions(master, 'G@virtual:physical') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 246 | if ( filter ) { |
| 247 | filtered_list = salt.getMinions(master, filter) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 248 | } |
| 249 | def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false) |
| 250 | def reclass_top = common.parseJSON(_result['return'][0].values()[0]) |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 251 | def nodesList = reclass_top['base'].keySet() |
| 252 | for (int i = 0; i < nodesList.size(); i++) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 253 | if ( filtered_list ) { |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 254 | if ( ! filtered_list.contains(nodesList[i]) ) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 255 | continue |
| 256 | } |
| 257 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 258 | def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address') |
| 259 | def network_data = [ip: ip, name: 'management'] |
| 260 | def roles = [nodesList[i].tokenize('.')[0]] |
| 261 | if ( controllers.contains(nodesList[i]) ) { |
| 262 | roles.add('controller') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 263 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 264 | if ( hw_nodes.contains(nodesList[i]) ) { |
| 265 | roles.add('hw_node') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 266 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 267 | nodes.add([id: i+1, ip: ip, roles: roles, network_data: [network_data]]) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 268 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 269 | return common.prettify(nodes) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 272 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 273 | * DEPRECATED |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 274 | * Execute mcp sanity tests |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 275 | * Deprecated. Will be removed soon |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 276 | * |
| 277 | * @param salt_url Salt master url |
| 278 | * @param salt_credentials Salt credentials |
| 279 | * @param test_set Test set for mcp sanity framework |
Oleksii Zhurba | 0a7b070 | 2017-11-10 16:02:16 -0600 | [diff] [blame] | 280 | * @param env_vars Additional environment variables for cvp-sanity-checks |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 281 | * @param output_dir Directory for results |
| 282 | */ |
Oleksii Zhurba | 0a7b070 | 2017-11-10 16:02:16 -0600 | [diff] [blame] | 283 | def runSanityTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") { |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 284 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 285 | common.errorMsg('You are using deprecated method! Please migrate to validate.runTests. This method will be removed') |
| 286 | error('You are using deprecated method! Please migrate to validate.runTests. This method will be removed') |
Oleksii Zhurba | 0a7b070 | 2017-11-10 16:02:16 -0600 | [diff] [blame] | 287 | def creds = common.getCredentials(salt_credentials) |
| 288 | def username = creds.username |
| 289 | def password = creds.password |
| 290 | def settings = "" |
| 291 | if ( env_vars != "" ) { |
| 292 | for (var in env_vars.tokenize(";")) { |
| 293 | settings += "export ${var}; " |
| 294 | } |
| 295 | } |
| 296 | def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" + |
Ievgeniia Zadorozhna | c215217 | 2019-10-11 13:23:46 +0300 | [diff] [blame] | 297 | "pytest --junitxml ${output_dir}cvp_sanity.xml --tb=short -rs -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}" |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 298 | withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) { |
| 299 | def statusCode = sh script:script, returnStatus:true |
| 300 | } |
| 301 | } |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 302 | |
| 303 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 304 | * DEPRECATED |
Oleksii Zhurba | 4e366ff | 2018-02-16 20:06:52 -0600 | [diff] [blame] | 305 | * Execute pytest framework tests |
| 306 | * |
| 307 | * @param salt_url Salt master url |
| 308 | * @param salt_credentials Salt credentials |
| 309 | * @param test_set Test set to run |
| 310 | * @param env_vars Additional environment variables for cvp-sanity-checks |
| 311 | * @param output_dir Directory for results |
| 312 | */ |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 313 | def runPyTests(salt_url, salt_credentials, test_set="", env_vars="", name='cvp', container_node="", remote_dir='/root/qa_results/', artifacts_dir='validation_artifacts/') { |
| 314 | def xml_file = "${name}_report.xml" |
| 315 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 316 | common.errorMsg('You are using deprecated method! Please migrate to validate.runTests. This method will be removed') |
| 317 | error('You are using deprecated method! Please migrate to validate.runTests. This method will be removed') |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 318 | def salt = new com.mirantis.mk.Salt() |
| 319 | def creds = common.getCredentials(salt_credentials) |
| 320 | def username = creds.username |
| 321 | def password = creds.password |
| 322 | if (container_node != "") { |
| 323 | def saltMaster |
| 324 | saltMaster = salt.connection(salt_url, salt_credentials) |
| 325 | def script = "pytest --junitxml ${xml_file} --tb=short -sv ${test_set}" |
| 326 | env_vars.addAll("SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", |
| 327 | "SALT_URL=${salt_url}") |
| 328 | variables = ' -e ' + env_vars.join(' -e ') |
| 329 | salt.cmdRun(saltMaster, container_node, "docker exec ${variables} ${name} bash -c '${script}'", false) |
| 330 | salt.cmdRun(saltMaster, container_node, "docker cp ${name}:/var/lib/${xml_file} ${remote_dir}${xml_file}") |
| 331 | addFiles(saltMaster, container_node, remote_dir+xml_file, artifacts_dir) |
| 332 | } |
| 333 | else { |
| 334 | if (env_vars.size() > 0) { |
| 335 | variables = 'export ' + env_vars.join(';export ') |
| 336 | } |
| 337 | def script = ". ${env.WORKSPACE}/venv/bin/activate; ${variables}; " + |
| 338 | "pytest --junitxml ${artifacts_dir}${xml_file} --tb=short -sv ${env.WORKSPACE}/${test_set}" |
| 339 | withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) { |
| 340 | def statusCode = sh script:script, returnStatus:true |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Execute pytest framework tests |
| 347 | * For backward compatibility |
| 348 | * Will be removed soon |
| 349 | * |
| 350 | * @param salt_url Salt master url |
| 351 | * @param salt_credentials Salt credentials |
| 352 | * @param test_set Test set to run |
| 353 | * @param env_vars Additional environment variables for cvp-sanity-checks |
| 354 | * @param output_dir Directory for results |
| 355 | */ |
Oleksii Zhurba | 4e366ff | 2018-02-16 20:06:52 -0600 | [diff] [blame] | 356 | def runTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") { |
| 357 | def common = new com.mirantis.mk.Common() |
| 358 | def creds = common.getCredentials(salt_credentials) |
| 359 | def username = creds.username |
| 360 | def password = creds.password |
| 361 | def settings = "" |
| 362 | if ( env_vars != "" ) { |
| 363 | for (var in env_vars.tokenize(";")) { |
| 364 | settings += "export ${var}; " |
| 365 | } |
| 366 | } |
| 367 | def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" + |
Ievgeniia Zadorozhna | c215217 | 2019-10-11 13:23:46 +0300 | [diff] [blame] | 368 | "pytest --junitxml ${output_dir}report.xml --tb=short -rs -sv ${env.WORKSPACE}/${test_set}" |
Oleksii Zhurba | 4e366ff | 2018-02-16 20:06:52 -0600 | [diff] [blame] | 369 | withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) { |
| 370 | def statusCode = sh script:script, returnStatus:true |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 375 | * DEPRECATED |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 376 | * Execute tempest tests |
| 377 | * |
| 378 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 379 | * @param dockerImageLink Docker image link |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 380 | * @param pattern If not false, will run only tests matched the pattern |
| 381 | * @param output_dir Directory for results |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 382 | * @param confRepository Git repository with configuration files for Tempest |
| 383 | * @param confBranch Git branch which will be used during the checkout |
| 384 | * @param repository Git repository with Tempest |
| 385 | * @param version Version of Tempest (tag, branch or commit) |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 386 | * @param results The reports directory |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 387 | */ |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 388 | def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false", results = '/root/qa_results') { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 389 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 390 | def common = new com.mirantis.mk.Common() |
| 391 | common.errorMsg('You are using deprecated method! This method will be removed') |
| 392 | error('You are using deprecated method! This method will be removed') |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 393 | def output_file = 'docker-tempest.log' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 394 | def dest_folder = '/home/rally/qa_results' |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 395 | def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 396 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 397 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 398 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 399 | def keystone = _pillar['return'][0].values()[0] |
Dmitry Tsapikov | b691192 | 2018-07-24 15:21:23 +0000 | [diff] [blame] | 400 | def env_vars = ['tempest_version=15.0.0', |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 401 | "OS_USERNAME=${keystone.admin_name}", |
| 402 | "OS_PASSWORD=${keystone.admin_password}", |
| 403 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 404 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 405 | "OS_REGION_NAME=${keystone.region}", |
| 406 | 'OS_ENDPOINT_TYPE=admin'].join(' -e ') |
| 407 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 408 | if (confRepository != '' ) { |
| 409 | cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " + |
| 410 | 'rally deployment create --fromenv --name=tempest; rally deployment config; ' + |
| 411 | 'rally verify create-verifier --name tempest_verifier --type tempest ' + |
Dmitry Tsapikov | b691192 | 2018-07-24 15:21:23 +0000 | [diff] [blame] | 412 | "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " + |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 413 | 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; ' |
| 414 | skip_list = '--skip-list test_config/tempest/skip-list.yaml' |
| 415 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 416 | if (pattern == 'false') { |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 417 | cmd += "rally verify start --pattern set=full ${skip_list} --detailed; " |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 418 | } |
| 419 | else { |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 420 | cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; " |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 421 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 422 | cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " + |
| 423 | "rally verify report --type html --to ${dest_folder}/report-tempest.html" |
mkraynov | d49daf5 | 2018-07-12 16:11:14 +0400 | [diff] [blame] | 424 | salt.cmdRun(master, target, "docker run -w /home/rally -i --rm --net=host -e ${env_vars} " + |
Sergey Galkin | 193ef87 | 2017-11-29 14:20:35 +0400 | [diff] [blame] | 425 | "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " + |
| 426 | "-c \"${cmd}\" > ${results}/${output_file}") |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 427 | addFiles(master, target, results, output_dir) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 431 | * Make all-in-one scenario cmd for rally tests |
| 432 | * |
| 433 | * @param scenarios_path Path to scenarios folder/file |
| 434 | * @param skip_scenarios Comma-delimited list of scenarios names to skip |
| 435 | * @param bundle_file Bundle name to create |
| 436 | */ |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 437 | def bundle_up_scenarios(scenarios_path, skip_scenarios, bundle_file = '' ) { |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 438 | def skip_names = '' |
| 439 | def skip_dirs = '' |
| 440 | def result = '' |
| 441 | if (skip_scenarios != ''){ |
| 442 | for ( scen in skip_scenarios.split(',') ) { |
| 443 | if ( scen.contains('yaml')) { |
| 444 | skip_names += "! -name ${scen} " |
| 445 | } |
| 446 | else { |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 447 | skip_dirs += "-path '${scenarios_path}/${scen}' -prune -o " |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | } |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 451 | if (bundle_file != '') { |
| 452 | result = "if [ -f ${scenarios_path} ]; then cp ${scenarios_path} ${bundle_file}; " + |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 453 | "else " + |
| 454 | "find -L ${scenarios_path} " + skip_dirs + |
| 455 | " -name '*.yaml' " + skip_names + |
| 456 | "-exec cat {} >> ${bundle_file} \\; ; " + |
| 457 | "sed -i '/---/d' ${bundle_file}; fi; " |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 458 | } else { |
| 459 | result = "find -L ${scenarios_path} " + skip_dirs + |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 460 | " -name '*.yaml' -print " + skip_names |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 461 | } |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 462 | |
| 463 | return result |
| 464 | } |
| 465 | |
| 466 | /** |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 467 | * Prepare setupDockerAndTest() commands to start Rally tests (optionally with K8S/Stacklight plugins) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 468 | * |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 469 | * @param platform Map with underlay platform data |
Oleg Basov | 20afb15 | 2018-06-10 03:09:25 +0200 | [diff] [blame] | 470 | * @param scenarios Directory inside repo with specific scenarios |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 471 | * @param sl_scenarios Directory inside repo with specific scenarios for stacklight |
Oleg Basov | 20afb15 | 2018-06-10 03:09:25 +0200 | [diff] [blame] | 472 | * @param tasks_args_file Argument file that is used for throttling settings |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 473 | * @param db_connection_str Rally-compliant external DB connection string |
| 474 | * @param tags Additional tags used for tagging tasks or building trends |
| 475 | * @param trends Build rally trends if enabled |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 476 | * |
| 477 | * Returns: map |
| 478 | * |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 479 | */ |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 480 | def runRallyTests( |
Oleg Basov | 698bec7 | 2019-05-28 11:49:16 +0200 | [diff] [blame] | 481 | platform, scenarios = '', sl_scenarios = '', |
| 482 | tasks_args_file = '', db_connection_str = '', tags = [], |
| 483 | trends = false, skip_list = '', generateReport = true |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 484 | ) { |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 485 | |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 486 | def dest_folder = '/home/rally' |
| 487 | def pluginsDir = "${dest_folder}/rally-plugins" |
| 488 | def scenariosDir = "${dest_folder}/rally-scenarios" |
| 489 | def resultsDir = "${dest_folder}/test_results" |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 490 | def date = new Date() |
| 491 | date = date.format("yyyyMMddHHmm") |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 492 | // compile rally deployment name |
| 493 | deployment_name = "env=${platform.cluster_name}:platform=${platform.type}:" + |
| 494 | "date=${date}:cmp=${platform.cmp_count}" |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 495 | |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 496 | // set up Rally DB |
| 497 | def cmd_rally_init = '' |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 498 | if (db_connection_str) { |
| 499 | cmd_rally_init = "sudo sed -i -e " + |
| 500 | "'s#connection=.*#connection=${db_connection_str}#' " + |
| 501 | "/etc/rally/rally.conf; " |
| 502 | } |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 503 | cmd_rally_init += 'rally db ensure; ' |
| 504 | // if several jobs are running in parallel (same deployment name), |
| 505 | // then try to find and use existing in db env |
| 506 | if (db_connection_str) { |
| 507 | cmd_rally_init += 'rally env use --env $(rally env list|awk \'/' + |
| 508 | deployment_name + '/ {print $2}\') ||' |
| 509 | } |
| 510 | |
| 511 | def cmd_rally_start |
| 512 | def cmd_rally_stacklight |
| 513 | def cmd_rally_task_args = tasks_args_file ?: 'job-params-light.yaml' |
Oleg Basov | 698bec7 | 2019-05-28 11:49:16 +0200 | [diff] [blame] | 514 | def cmd_rally_report = '' |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 515 | def cmd_filter_tags = '' |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 516 | def trends_limit = 20 |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 517 | |
Oleg Basov | 698bec7 | 2019-05-28 11:49:16 +0200 | [diff] [blame] | 518 | // generate html report if required |
| 519 | if (generateReport) { |
| 520 | cmd_rally_report = 'rally task export ' + |
| 521 | '--uuid $(rally task list --uuids-only --status finished) ' + |
| 522 | "--type junit-xml --to ${resultsDir}/report-rally.xml; " + |
| 523 | 'rally task report --uuid $(rally task list --uuids-only --status finished) ' + |
| 524 | "--out ${resultsDir}/report-rally.html; " |
| 525 | } |
| 526 | |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 527 | // build rally trends if required |
| 528 | if (trends && db_connection_str) { |
| 529 | if (tags) { |
| 530 | cmd_filter_tags = "--tag " + tags.join(' ') |
| 531 | } |
Oleg Basov | 698bec7 | 2019-05-28 11:49:16 +0200 | [diff] [blame] | 532 | cmd_rally_report += 'rally task trends --tasks ' + |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 533 | '$(rally task list ' + cmd_filter_tags + |
| 534 | ' --all-deployments --uuids-only --status finished ' + |
| 535 | "| head -${trends_limit} ) " + |
| 536 | "--out ${resultsDir}/trends-rally.html" |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // add default env tags for inserting into rally tasks |
| 540 | tags = tags + [ |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 541 | "env=${platform.cluster_name}", |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 542 | "platform=${platform.type}", |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 543 | "cmp=${platform.cmp_count}" |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 544 | ] |
| 545 | |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 546 | // set up rally deployment cmd |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 547 | if (platform['type'] == 'openstack') { |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 548 | cmd_rally_init += "rally deployment create --name='${deployment_name}' --fromenv; " + |
| 549 | "rally deployment check; " |
Oleg Basov | 40e502c | 2018-09-04 20:42:21 +0200 | [diff] [blame] | 550 | } else if (platform['type'] == 'k8s') { |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 551 | cmd_rally_init += "rally env create --name='${deployment_name}' --from-sysenv; " + |
| 552 | "rally env check; " |
Oleg Basov | 20afb15 | 2018-06-10 03:09:25 +0200 | [diff] [blame] | 553 | } else { |
| 554 | throw new Exception("Platform ${platform} is not supported yet") |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame] | 555 | } |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 556 | |
| 557 | // set up rally task args file |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 558 | switch(tasks_args_file) { |
| 559 | case 'none': |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 560 | cmd_rally_task_args = '' |
Oleg Basov | 20afb15 | 2018-06-10 03:09:25 +0200 | [diff] [blame] | 561 | break |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 562 | case '': |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 563 | cmd_rally_task_args = "--task-args-file ${scenariosDir}/job-params-light.yaml" |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 564 | break |
| 565 | default: |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 566 | cmd_rally_task_args = "--task-args-file ${scenariosDir}/${tasks_args_file}" |
Oleg Basov | 06fce2a | 2018-11-09 21:39:03 +0100 | [diff] [blame] | 567 | break |
| 568 | } |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 569 | |
| 570 | // configure Rally for Stacklight (only with Openstack for now) |
| 571 | if (platform['stacklight']['enabled'] && (platform['type'] == 'openstack')) { |
| 572 | if (! sl_scenarios) { |
| 573 | throw new Exception("There's no Stacklight scenarios to execute") |
| 574 | } |
| 575 | def scenBundle = "${resultsDir}/scenarios_${platform.type}_stacklight.yaml" |
| 576 | cmd_rally_stacklight = bundle_up_scenarios( |
| 577 | scenariosDir + '/' + sl_scenarios, |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 578 | skip_list, |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 579 | scenBundle, |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 580 | ) |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 581 | tags.add('stacklight') |
| 582 | cmd_rally_stacklight += "sed -i 's/grafana_password: .*/grafana_password: ${platform.stacklight.grafanaPass}/' " + |
| 583 | "${scenariosDir}/${tasks_args_file}; rally --log-file ${resultsDir}/tasks_stacklight.log task start --tag " + tags.join(' ') + |
| 584 | " --task ${scenBundle} ${cmd_rally_task_args} || true " |
Oleg Basov | 20afb15 | 2018-06-10 03:09:25 +0200 | [diff] [blame] | 585 | } |
Oleg Basov | aaeb51f | 2018-10-17 01:07:10 +0200 | [diff] [blame] | 586 | |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 587 | // prepare scenarios and rally task cmd |
| 588 | if (scenarios) { |
| 589 | switch (platform['type']) { |
| 590 | case 'openstack': |
| 591 | def scenBundle = "${resultsDir}/scenarios_${platform.type}.yaml" |
| 592 | cmd_rally_start = bundle_up_scenarios( |
| 593 | scenariosDir + '/' + scenarios, |
| 594 | skip_list, |
| 595 | scenBundle, |
| 596 | ) |
| 597 | cmd_rally_start += "rally --log-file ${resultsDir}/tasks_openstack.log task start --tag " + tags.join(' ') + |
| 598 | " --task ${scenBundle} ${cmd_rally_task_args} || true; " |
| 599 | break |
| 600 | // due to the bug in Rally threads, K8S plugin gets stuck on big all-in-one scenarios |
| 601 | // so we have to feed them separately for K8S case |
| 602 | case 'k8s': |
| 603 | cmd_rally_start = 'for task in $(' + |
| 604 | bundle_up_scenarios(scenariosDir + '/' + scenarios, skip_list) + '); do ' + |
| 605 | "rally --log-file ${resultsDir}/tasks_k8s.log task start --tag " + tags.join(' ') + |
| 606 | ' --task $task ' + cmd_rally_task_args + ' || true; done; ' |
| 607 | break |
| 608 | } |
| 609 | } else { |
| 610 | if (! cmd_rally_stacklight) { |
| 611 | throw new Exception("No scenarios found to run Rally on") |
| 612 | } |
Oleg Basov | 1fa6c66 | 2019-03-05 22:04:01 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 615 | // compile full rally cmd map |
| 616 | def full_cmd = [ |
| 617 | '001_install_plugins': "sudo pip install --upgrade ${pluginsDir}", |
| 618 | '002_init_rally': cmd_rally_init, |
| 619 | '003_start_rally': cmd_rally_start ?: "echo no tasks to run", |
| 620 | '004_start_rally_stacklight': cmd_rally_stacklight ?: "echo no tasks to run", |
Oleg Basov | 698bec7 | 2019-05-28 11:49:16 +0200 | [diff] [blame] | 621 | '005_rally_report': cmd_rally_report ?: "echo no tasks to run", |
Oleg Basov | de899e0 | 2019-03-26 12:31:27 +0100 | [diff] [blame] | 622 | ] |
| 623 | |
| 624 | return full_cmd |
| 625 | |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 629 | * DEPRECATED |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 630 | * Generate test report |
| 631 | * |
| 632 | * @param target Host to run script from |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 633 | * @param dockerImageLink Docker image link |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 634 | * @param output_dir Directory for results |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 635 | * @param results The reports directory |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 636 | */ |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 637 | def generateTestReport(master, target, dockerImageLink, output_dir, results = '/root/qa_results') { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 638 | def report_file = 'jenkins_test_report.html' |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 639 | def salt = new com.mirantis.mk.Salt() |
| 640 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 641 | common.errorMsg('You are using deprecated method! This method will be removed') |
| 642 | error('You are using deprecated method! This method will be removed') |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 643 | def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results' |
| 644 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 645 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 646 | def reports = ['report-tempest.json', |
| 647 | 'report-rally.xml', |
| 648 | 'report-k8s-e2e-tests.txt', |
| 649 | 'report-ha.json', |
| 650 | 'report-spt.txt'] |
| 651 | for ( report in reports ) { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 652 | if ( fileExists("${output_dir}${report}") ) { |
| 653 | common.infoMsg("Copying ${report} to docker container") |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 654 | def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " + |
| 655 | "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " + |
| 656 | "rm ${output_dir}${report}_encoded; " + |
| 657 | "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true) |
| 658 | for ( item in items.tokenize() ) { |
| 659 | def content = sh(script: "cat ${output_dir}${item}", returnStdout: true) |
| 660 | salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false) |
| 661 | sh(script: "rm ${output_dir}${item}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 662 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 663 | salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " + |
| 664 | "rm ${results}/${report}_encoded", false, null, false) |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 665 | } |
| 666 | } |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 667 | |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 668 | def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " + |
| 669 | "cp ${report_file} ${dest_folder}/${report_file}" |
| 670 | salt.cmdRun(master, target, "docker run -i --rm --net=host " + |
| 671 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 672 | "/bin/bash -c \"${cmd}\"") |
| 673 | def report_content = salt.getFileContent(master, target, "${results}/${report_file}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 674 | writeFile file: "${output_dir}${report_file}", text: report_content |
| 675 | } |
| 676 | |
| 677 | /** |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 678 | * DEPRECATED |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 679 | * Execute SPT tests |
| 680 | * |
| 681 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 682 | * @param dockerImageLink Docker image link |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 683 | * @param output_dir Directory for results |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 684 | * @param ext_variables The list of external variables |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 685 | * @param results The reports directory |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 686 | */ |
Sergey Galkin | d1068e2 | 2018-02-13 13:59:32 +0400 | [diff] [blame] | 687 | def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = [], results = '/root/qa_results') { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 688 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 689 | def common = new com.mirantis.mk.Common() |
| 690 | common.errorMsg('You are using deprecated method! This method will be removed') |
| 691 | error('You are using deprecated method! This method will be removed') |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 692 | def dest_folder = '/home/rally/qa_results' |
| 693 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 694 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 695 | def nodes = getNodeList(master) |
| 696 | def nodes_hw = getNodeList(master, 'G@virtual:physical') |
| 697 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 698 | def keystone = _pillar['return'][0].values()[0] |
| 699 | def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa') |
| 700 | def env_vars = ( ['tempest_version=15.0.0', |
| 701 | "OS_USERNAME=${keystone.admin_name}", |
| 702 | "OS_PASSWORD=${keystone.admin_password}", |
| 703 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 704 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 705 | "OS_REGION_NAME=${keystone.region}", |
| 706 | 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ') |
| 707 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes]) |
| 708 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw]) |
| 709 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' + |
| 710 | 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' + |
| 711 | "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " + |
| 712 | 'sudo chmod 600 /root/.ssh/id_rsa; ' + |
| 713 | "sudo timmy -c simplified-performance-testing/config.yaml " + |
| 714 | "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " + |
| 715 | "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " + |
| 716 | "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " + |
| 717 | "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz" |
| 718 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 719 | "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " + |
| 720 | "\"${cmd}\" > ${results}/docker-spt.log") |
| 721 | addFiles(master, target, results, output_dir) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 724 | /** |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 725 | * Configure docker container |
| 726 | * |
| 727 | * @param target Host to run container |
| 728 | * @param proxy Proxy for accessing github and pip |
| 729 | * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc. |
Oleksii Zhurba | 1579b97 | 2017-12-14 15:21:56 -0600 | [diff] [blame] | 730 | * @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. |
| 731 | * @param tempest_endpoint_type internalURL or adminURL or publicURL to use in tests |
Oleksii Zhurba | 198dd68 | 2018-09-07 18:16:59 -0500 | [diff] [blame] | 732 | * @param tempest_version Version of tempest to use. This value will be just passed to configure.sh script (cvp-configuration repo). |
Oleksii Zhurba | 1579b97 | 2017-12-14 15:21:56 -0600 | [diff] [blame] | 733 | * @param conf_script_path Path to configuration script. |
| 734 | * @param ext_variables Some custom extra variables to add into container |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 735 | * @param container_name Name of container to use |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 736 | */ |
| 737 | def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo, |
Oleksii Zhurba | 198dd68 | 2018-09-07 18:16:59 -0500 | [diff] [blame] | 738 | tempest_endpoint_type="internalURL", tempest_version="", |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 739 | conf_script_path="", ext_variables = [], container_name="cvp") { |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 740 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 95c9885 | 2019-05-15 15:51:30 -0500 | [diff] [blame] | 741 | def common = new com.mirantis.mk.Common() |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 742 | if (testing_tools_repo != "" ) { |
Oleksii Zhurba | 95c9885 | 2019-05-15 15:51:30 -0500 | [diff] [blame] | 743 | workdir = '' |
Oleksii Zhurba | 0cda6e0 | 2018-06-20 14:53:19 -0500 | [diff] [blame] | 744 | if (testing_tools_repo.contains('http://') || testing_tools_repo.contains('https://')) { |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 745 | salt.cmdRun(master, target, "docker exec ${container_name} git clone ${testing_tools_repo} cvp-configuration") |
Oleksii Zhurba | 0cda6e0 | 2018-06-20 14:53:19 -0500 | [diff] [blame] | 746 | configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh" |
| 747 | } |
| 748 | else { |
| 749 | configure_script = testing_tools_repo |
Oleksii Zhurba | 95c9885 | 2019-05-15 15:51:30 -0500 | [diff] [blame] | 750 | workdir = ' -w /var/lib/' |
Oleksii Zhurba | 0cda6e0 | 2018-06-20 14:53:19 -0500 | [diff] [blame] | 751 | } |
| 752 | ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}", |
| 753 | "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}", |
| 754 | "tempest_version=${tempest_version}") |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 755 | salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " ${workdir} ${container_name} bash -c ${configure_script}") |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 756 | } |
Oleksii Zhurba | 0cda6e0 | 2018-06-20 14:53:19 -0500 | [diff] [blame] | 757 | else { |
Oleksii Zhurba | 95c9885 | 2019-05-15 15:51:30 -0500 | [diff] [blame] | 758 | common.infoMsg("TOOLS_REPO is empty, no configuration is needed for this container") |
Oleksii Zhurba | 0cda6e0 | 2018-06-20 14:53:19 -0500 | [diff] [blame] | 759 | } |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Run Tempest |
| 764 | * |
| 765 | * @param target Host to run container |
| 766 | * @param test_pattern Test pattern to run |
| 767 | * @param skip_list Path to skip-list |
| 768 | * @param output_dir Directory on target host for storing results (containers is not a good place) |
| 769 | */ |
| 770 | def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") { |
| 771 | def salt = new com.mirantis.mk.Salt() |
| 772 | def xml_file = "${output_filename}.xml" |
Oleksii Zhurba | 4404531 | 2017-12-12 15:38:26 -0600 | [diff] [blame] | 773 | def html_file = "${output_filename}.html" |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 774 | skip_list_cmd = '' |
| 775 | if (skip_list != '') { |
| 776 | skip_list_cmd = "--skip-list ${skip_list}" |
| 777 | } |
Oleksii Zhurba | 77896d4 | 2018-05-25 18:11:30 -0500 | [diff] [blame] | 778 | salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} --detailed") |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 779 | salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}") |
Oleksii Zhurba | 4404531 | 2017-12-12 15:38:26 -0600 | [diff] [blame] | 780 | salt.cmdRun(master, target, "docker exec cvp rally verify report --type html --to /home/rally/${html_file}") |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 781 | salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}") |
Oleksii Zhurba | 4404531 | 2017-12-12 15:38:26 -0600 | [diff] [blame] | 782 | salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}") |
Oleksii Zhurba | 77896d4 | 2018-05-25 18:11:30 -0500 | [diff] [blame] | 783 | return salt.cmdRun(master, target, "docker exec cvp rally verify show | head -5 | tail -1 | " + |
| 784 | "awk '{print \$4}'")['return'][0].values()[0].split()[0] |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Run Rally |
| 789 | * |
| 790 | * @param target Host to run container |
| 791 | * @param test_pattern Test pattern to run |
| 792 | * @param scenarios_path Path to Rally scenarios |
| 793 | * @param output_dir Directory on target host for storing results (containers is not a good place) |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 794 | * @param container_name Name of container to use |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 795 | */ |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 796 | def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally", container_name="cvp") { |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 797 | def salt = new com.mirantis.mk.Salt() |
| 798 | def xml_file = "${output_filename}.xml" |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 799 | def html_file = "${output_filename}.html" |
Oleksii Zhurba | 5efe0ea | 2019-05-20 14:25:49 -0500 | [diff] [blame] | 800 | salt.cmdRun(master, target, "docker exec ${container_name} rally task start ${scenarios_path}", false) |
| 801 | salt.cmdRun(master, target, "docker exec ${container_name} rally task report --out /home/rally/${html_file}", false) |
| 802 | salt.cmdRun(master, target, "docker exec ${container_name} rally task report --junit --out /home/rally/${xml_file}", false) |
Oleksii Zhurba | 1fbc956 | 2019-05-15 12:20:28 -0500 | [diff] [blame] | 803 | salt.cmdRun(master, target, "docker cp ${container_name}:/home/rally/${xml_file} ${output_dir}") |
| 804 | salt.cmdRun(master, target, "docker cp ${container_name}:/home/rally/${html_file} ${output_dir}") |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | |
| 808 | /** |
| 809 | * Shutdown node |
| 810 | * |
| 811 | * @param target Host to run command |
| 812 | * @param mode How to shutdown node |
| 813 | * @param retries # of retries to make to check node status |
| 814 | */ |
| 815 | def shutdown_vm_node(master, target, mode, retries=200) { |
| 816 | def salt = new com.mirantis.mk.Salt() |
| 817 | def common = new com.mirantis.mk.Common() |
| 818 | if (mode == 'reboot') { |
| 819 | try { |
| 820 | def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3) |
| 821 | } catch (Exception e) { |
| 822 | common.warningMsg('Timeout from minion: node must be rebooting now') |
| 823 | } |
| 824 | common.warningMsg("Checking that minion is down") |
| 825 | status = "True" |
| 826 | for (i = 0; i < retries; i++) { |
| 827 | status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1) |
| 828 | if (status != "True") { |
| 829 | break |
| 830 | } |
| 831 | } |
| 832 | if (status == "True") { |
| 833 | throw new Exception("Tired to wait for minion ${target} to stop responding") |
| 834 | } |
| 835 | } |
| 836 | if (mode == 'hard_shutdown' || mode == 'soft_shutdown') { |
| 837 | kvm = locate_node_on_kvm(master, target) |
| 838 | if (mode == 'soft_shutdown') { |
| 839 | salt.cmdRun(master, target, "shutdown -h 0") |
| 840 | } |
| 841 | if (mode == 'hard_shutdown') { |
| 842 | salt.cmdRun(master, kvm, "virsh destroy ${target}") |
| 843 | } |
| 844 | common.warningMsg("Checking that vm on kvm is in power off state") |
| 845 | status = 'running' |
| 846 | for (i = 0; i < retries; i++) { |
| 847 | status = check_vm_status(master, target, kvm) |
| 848 | echo "Current status - ${status}" |
| 849 | if (status != 'running') { |
| 850 | break |
| 851 | } |
| 852 | sleep (1) |
| 853 | } |
| 854 | if (status == 'running') { |
| 855 | throw new Exception("Tired to wait for node ${target} to shutdown") |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | |
| 861 | /** |
| 862 | * Locate kvm where target host is located |
| 863 | * |
| 864 | * @param target Host to check |
| 865 | */ |
| 866 | def locate_node_on_kvm(master, target) { |
| 867 | def salt = new com.mirantis.mk.Salt() |
| 868 | def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0] |
| 869 | for (item in list.keySet()) { |
| 870 | if (list[item]) { |
| 871 | return item |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Check target host status |
| 878 | * |
| 879 | * @param target Host to check |
| 880 | * @param kvm KVM node where target host is located |
| 881 | */ |
| 882 | def check_vm_status(master, target, kvm) { |
| 883 | def salt = new com.mirantis.mk.Salt() |
| 884 | def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0] |
| 885 | for (item in list.keySet()) { |
| 886 | if (list[item]) { |
| 887 | return list[item].split()[2] |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Find vip on nodes |
| 894 | * |
| 895 | * @param target Pattern, e.g. ctl* |
| 896 | */ |
| 897 | def get_vip_node(master, target) { |
| 898 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 5f73cf6 | 2018-08-03 16:11:10 -0500 | [diff] [blame] | 899 | def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep '/32'"])['return'][0] |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 900 | for (item in list.keySet()) { |
| 901 | if (list[item]) { |
| 902 | return item |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Find vip on nodes |
| 909 | * |
| 910 | * @param target Host with cvp container |
Oleksii Zhurba | 81fef10 | 2019-05-20 21:40:25 -0500 | [diff] [blame] | 911 | * @param container_name Name of container |
| 912 | * @param script_path Path to cleanup script (inside container) |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 913 | */ |
Oleksii Zhurba | 81fef10 | 2019-05-20 21:40:25 -0500 | [diff] [blame] | 914 | def openstack_cleanup(master, target, container_name="cvp", script_path="/home/rally/cleanup.sh") { |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 915 | def salt = new com.mirantis.mk.Salt() |
Oleksii Zhurba | 81fef10 | 2019-05-20 21:40:25 -0500 | [diff] [blame] | 916 | salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec ${container_name} bash -c ${script_path}"]) |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | /** |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 921 | * Cleanup |
| 922 | * |
| 923 | * @param target Host to run commands |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 924 | * @param name Name of container to remove |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 925 | */ |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 926 | def runCleanup(master, target, name='cvp') { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 927 | def salt = new com.mirantis.mk.Salt() |
Ievgeniia Zadorozhna | 07306f2 | 2019-12-16 18:15:19 +0300 | [diff] [blame] | 928 | if ( salt.cmdRun(master, target, "docker ps -f name=^${name}\$ -q", false, null, false)['return'][0].values()[0] ) { |
Oleksii Zhurba | 1f4a6ff | 2018-06-27 16:45:17 -0500 | [diff] [blame] | 929 | salt.cmdRun(master, target, "docker rm -f ${name}") |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 930 | } |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 931 | } |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 932 | /** |
| 933 | * Prepare venv for any python project |
| 934 | * Note: <repo_name>\/requirements.txt content will be used |
| 935 | * for this venv |
| 936 | * |
| 937 | * @param repo_url Repository url to clone |
| 938 | * @param proxy Proxy address to use |
| 939 | */ |
dtsapikov | f2e1bb1 | 2018-11-29 18:49:48 +0400 | [diff] [blame] | 940 | def prepareVenv(repo_url, proxy, useSystemPackages=false) { |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 941 | def python = new com.mirantis.mk.Python() |
| 942 | repo_name = "${repo_url}".tokenize("/").last() |
Oleksii Zhurba | e711ebb | 2018-06-15 16:36:38 -0500 | [diff] [blame] | 943 | if (repo_url.tokenize().size() > 1){ |
| 944 | if (repo_url.tokenize()[1] == '-b'){ |
| 945 | repo_name = repo_url.tokenize()[0].tokenize("/").last() |
| 946 | } |
| 947 | } |
Oleksii Zhurba | 83e3e5c | 2018-06-27 16:59:29 -0500 | [diff] [blame] | 948 | path_venv = "${env.WORKSPACE}/venv" |
| 949 | path_req = "${env.WORKSPACE}/${repo_name}/requirements.txt" |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 950 | sh "rm -rf ${repo_name}" |
Oleksii Zhurba | 83e3e5c | 2018-06-27 16:59:29 -0500 | [diff] [blame] | 951 | // this is temporary W/A for offline deployments |
| 952 | // Jenkins slave image has /opt/pip-mirror/ folder |
| 953 | // where pip wheels for cvp projects are located |
| 954 | if (proxy != 'offline') { |
| 955 | withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) { |
| 956 | sh "git clone ${repo_url}" |
dtsapikov | f2e1bb1 | 2018-11-29 18:49:48 +0400 | [diff] [blame] | 957 | python.setupVirtualenv(path_venv, "python2", [], path_req, true, useSystemPackages) |
Oleksii Zhurba | 83e3e5c | 2018-06-27 16:59:29 -0500 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | else { |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 961 | sh "git clone ${repo_url}" |
Oleksii Zhurba | 83e3e5c | 2018-06-27 16:59:29 -0500 | [diff] [blame] | 962 | sh "virtualenv ${path_venv} --python python2" |
| 963 | python.runVirtualenvCommand(path_venv, "pip install --no-index --find-links=/opt/pip-mirror/ -r ${path_req}", true) |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 967 | /** Install docker if needed |
| 968 | * |
| 969 | * @param target Target node to install docker pkg |
| 970 | */ |
| 971 | def installDocker(master, target) { |
| 972 | def salt = new com.mirantis.mk.Salt() |
| 973 | if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) { |
| 974 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
| 975 | } |
| 976 | } |