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