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