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