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 | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 15 | def runBasicContainer(master, target, dockerImageLink="rallyforge/rally"){ |
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 | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 27 | "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin ${dockerImageLink} /bin/bash") |
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 |
| 143 | * @param output_dir Directory for results |
| 144 | */ |
| 145 | def runSanityTests(salt_url, salt_credentials, test_set, output_dir) { |
| 146 | def common = new com.mirantis.mk.Common() |
| 147 | creds = common.getCredentials(salt_credentials) |
| 148 | username = creds.username |
| 149 | password = creds.password |
| 150 | def script = ". ${env.WORKSPACE}/venv/bin/activate; pytest --junitxml ${output_dir}cvp_sanity.xml -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}" |
| 151 | withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) { |
| 152 | def statusCode = sh script:script, returnStatus:true |
| 153 | } |
| 154 | } |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 155 | |
| 156 | /** |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 157 | * Execute tempest tests |
| 158 | * |
| 159 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 160 | * @param dockerImageLink Docker image link |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 161 | * @param pattern If not false, will run only tests matched the pattern |
| 162 | * @param output_dir Directory for results |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 163 | * @param confRepository Git repository with configuration files for Tempest |
| 164 | * @param confBranch Git branch which will be used during the checkout |
| 165 | * @param repository Git repository with Tempest |
| 166 | * @param version Version of Tempest (tag, branch or commit) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 167 | */ |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 168 | def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false") { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 169 | def salt = new com.mirantis.mk.Salt() |
| 170 | def output_file = 'docker-tempest.log' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 171 | def results = '/root/qa_results' |
| 172 | def dest_folder = '/home/rally/qa_results' |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 173 | 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] | 174 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 175 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 176 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 177 | def keystone = _pillar['return'][0].values()[0] |
| 178 | def env_vars = ['tempest_version=15.0.0', |
| 179 | "OS_USERNAME=${keystone.admin_name}", |
| 180 | "OS_PASSWORD=${keystone.admin_password}", |
| 181 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 182 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 183 | "OS_REGION_NAME=${keystone.region}", |
| 184 | 'OS_ENDPOINT_TYPE=admin'].join(' -e ') |
| 185 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 186 | if (confRepository != '' ) { |
| 187 | cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " + |
| 188 | 'rally deployment create --fromenv --name=tempest; rally deployment config; ' + |
| 189 | 'rally verify create-verifier --name tempest_verifier --type tempest ' + |
| 190 | "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " + |
| 191 | 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; ' |
| 192 | skip_list = '--skip-list test_config/tempest/skip-list.yaml' |
| 193 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 194 | if (pattern == 'false') { |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 195 | cmd += "rally verify start --pattern set=full ${skip_list} --detailed; " |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 196 | } |
| 197 | else { |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 198 | cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; " |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 199 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 200 | cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " + |
| 201 | "rally verify report --type html --to ${dest_folder}/report-tempest.html" |
| 202 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 203 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 204 | "/bin/bash -c \"${cmd}\" > ${results}/${output_file}") |
| 205 | addFiles(master, target, results, output_dir) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Execute rally tests |
| 210 | * |
| 211 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 212 | * @param dockerImageLink Docker image link |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 213 | * @param output_dir Directory for results |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 214 | * @param repository Git repository with files for Rally |
| 215 | * @param branch Git branch which will be used during the checkout |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 216 | * @param ext_variables The list of external variables |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 217 | */ |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 218 | def runRallyTests(master, target, dockerImageLink, output_dir, repository, branch, ext_variables = []) { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 219 | def salt = new com.mirantis.mk.Salt() |
| 220 | def output_file = 'docker-rally.log' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 221 | def results = '/root/qa_results' |
| 222 | def dest_folder = '/home/rally/qa_results' |
| 223 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 224 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 225 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 226 | def keystone = _pillar['return'][0].values()[0] |
| 227 | def env_vars = ( ['tempest_version=15.0.0', |
| 228 | "OS_USERNAME=${keystone.admin_name}", |
| 229 | "OS_PASSWORD=${keystone.admin_password}", |
| 230 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 231 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 232 | "OS_REGION_NAME=${keystone.region}", |
| 233 | 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ') |
| 234 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' + |
| 235 | 'rally task start combined_scenario.yaml ' + |
Dmitrii Kabanov | 999fda9 | 2017-11-10 00:18:30 -0800 | [diff] [blame^] | 236 | '--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; ' |
| 237 | if (repository != '' ) { |
| 238 | cmd = "git clone -b ${branch ?: 'master'} ${repository} test_config; " + |
| 239 | 'rally deployment create --file=test_config/rally/existing.json --name=existing; ' + |
| 240 | 'rally deployment config; ' + |
| 241 | 'rally task start test_config/rally/scenario.yaml ' + |
| 242 | '--task-args-file test_config/rally/task_arguments.yaml; ' |
| 243 | } |
| 244 | cmd += "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " + |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 245 | "rally task report --out ${dest_folder}/report-rally.html" |
| 246 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 247 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 248 | "/bin/bash -c \"${cmd}\" > ${results}/${output_file}") |
| 249 | addFiles(master, target, results, output_dir) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 253 | * Generate test report |
| 254 | * |
| 255 | * @param target Host to run script from |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 256 | * @param dockerImageLink Docker image link |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 257 | * @param output_dir Directory for results |
| 258 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 259 | def generateTestReport(master, target, dockerImageLink, output_dir) { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 260 | def report_file = 'jenkins_test_report.html' |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 261 | def salt = new com.mirantis.mk.Salt() |
| 262 | def common = new com.mirantis.mk.Common() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 263 | def results = '/root/qa_results' |
| 264 | def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results' |
| 265 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 266 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 267 | def reports = ['report-tempest.json', |
| 268 | 'report-rally.xml', |
| 269 | 'report-k8s-e2e-tests.txt', |
| 270 | 'report-ha.json', |
| 271 | 'report-spt.txt'] |
| 272 | for ( report in reports ) { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 273 | if ( fileExists("${output_dir}${report}") ) { |
| 274 | common.infoMsg("Copying ${report} to docker container") |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 275 | def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " + |
| 276 | "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " + |
| 277 | "rm ${output_dir}${report}_encoded; " + |
| 278 | "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true) |
| 279 | for ( item in items.tokenize() ) { |
| 280 | def content = sh(script: "cat ${output_dir}${item}", returnStdout: true) |
| 281 | salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false) |
| 282 | sh(script: "rm ${output_dir}${item}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 283 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 284 | salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " + |
| 285 | "rm ${results}/${report}_encoded", false, null, false) |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 288 | |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 289 | def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " + |
| 290 | "cp ${report_file} ${dest_folder}/${report_file}" |
| 291 | salt.cmdRun(master, target, "docker run -i --rm --net=host " + |
| 292 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 293 | "/bin/bash -c \"${cmd}\"") |
| 294 | def report_content = salt.getFileContent(master, target, "${results}/${report_file}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 295 | writeFile file: "${output_dir}${report_file}", text: report_content |
| 296 | } |
| 297 | |
| 298 | /** |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 299 | * Execute SPT tests |
| 300 | * |
| 301 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 302 | * @param dockerImageLink Docker image link |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 303 | * @param output_dir Directory for results |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 304 | * @param ext_variables The list of external variables |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 305 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 306 | def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 307 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 308 | def results = '/root/qa_results' |
| 309 | def dest_folder = '/home/rally/qa_results' |
| 310 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 311 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 312 | def nodes = getNodeList(master) |
| 313 | def nodes_hw = getNodeList(master, 'G@virtual:physical') |
| 314 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 315 | def keystone = _pillar['return'][0].values()[0] |
| 316 | def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa') |
| 317 | def env_vars = ( ['tempest_version=15.0.0', |
| 318 | "OS_USERNAME=${keystone.admin_name}", |
| 319 | "OS_PASSWORD=${keystone.admin_password}", |
| 320 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 321 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 322 | "OS_REGION_NAME=${keystone.region}", |
| 323 | 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ') |
| 324 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes]) |
| 325 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw]) |
| 326 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' + |
| 327 | 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' + |
| 328 | "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " + |
| 329 | 'sudo chmod 600 /root/.ssh/id_rsa; ' + |
| 330 | "sudo timmy -c simplified-performance-testing/config.yaml " + |
| 331 | "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " + |
| 332 | "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " + |
| 333 | "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " + |
| 334 | "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz" |
| 335 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 336 | "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " + |
| 337 | "\"${cmd}\" > ${results}/docker-spt.log") |
| 338 | addFiles(master, target, results, output_dir) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 341 | /** |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 342 | * Configure docker container |
| 343 | * |
| 344 | * @param target Host to run container |
| 345 | * @param proxy Proxy for accessing github and pip |
| 346 | * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc. |
| 347 | * @param tempest_repo Url to tempest for cloning. Can be github or internal gerrit. If not specified, tempest will not be configured. |
| 348 | * @param tempest_endpoint_type internalURL or adminURL or publicURL |
| 349 | * @param tempest_version Version of tempest to use |
| 350 | */ |
| 351 | def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo, |
| 352 | tempest_endpoint_type="internalURL", tempest_version="15.0.0", |
| 353 | configure_script="/home/rally/testing-stuff/configure.sh", ext_variables = []) { |
| 354 | def salt = new com.mirantis.mk.Salt() |
| 355 | if (testing_tools_repo != "" ) { |
| 356 | salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo}") |
| 357 | } |
| 358 | salt.cmdRun(master, target, "docker exec -e tempest_version=${tempest_version} -e PROXY=${proxy} " + |
| 359 | " -e TEMPEST_ENDPOINT=${tempest_repo} -e TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type} " + |
| 360 | ext_variables.join(' -e ') + |
| 361 | " cvp bash -c ${configure_script}") |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Run Tempest |
| 366 | * |
| 367 | * @param target Host to run container |
| 368 | * @param test_pattern Test pattern to run |
| 369 | * @param skip_list Path to skip-list |
| 370 | * @param output_dir Directory on target host for storing results (containers is not a good place) |
| 371 | */ |
| 372 | def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") { |
| 373 | def salt = new com.mirantis.mk.Salt() |
| 374 | def xml_file = "${output_filename}.xml" |
| 375 | def log_file = "${output_filename}.log" |
| 376 | skip_list_cmd = '' |
| 377 | if (skip_list != '') { |
| 378 | skip_list_cmd = "--skip-list ${skip_list}" |
| 379 | } |
| 380 | salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " + |
| 381 | "--detailed > ${log_file}", false) |
| 382 | salt.cmdRun(master, target, "cat ${log_file}") |
| 383 | salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}") |
| 384 | salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}") |
| 385 | return salt.cmdRun(master, target, "docker exec cvp rally verify list | tail -n 2 | grep -v '+' | awk '{print \$16}'")['return'][0].values()[0].split()[0] |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Run Rally |
| 390 | * |
| 391 | * @param target Host to run container |
| 392 | * @param test_pattern Test pattern to run |
| 393 | * @param scenarios_path Path to Rally scenarios |
| 394 | * @param output_dir Directory on target host for storing results (containers is not a good place) |
| 395 | */ |
| 396 | def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") { |
| 397 | def salt = new com.mirantis.mk.Salt() |
| 398 | def xml_file = "${output_filename}.xml" |
| 399 | def log_file = "${output_filename}.log" |
| 400 | def html_file = "${output_filename}.html" |
| 401 | salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false) |
| 402 | salt.cmdRun(master, target, "cat ${log_file}") |
| 403 | salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}") |
| 404 | salt.cmdRun(master, target, "docker exec cvp rally task export --type junit-xml --to ${xml_file}") |
| 405 | salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}") |
| 406 | salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}") |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /** |
| 411 | * Shutdown node |
| 412 | * |
| 413 | * @param target Host to run command |
| 414 | * @param mode How to shutdown node |
| 415 | * @param retries # of retries to make to check node status |
| 416 | */ |
| 417 | def shutdown_vm_node(master, target, mode, retries=200) { |
| 418 | def salt = new com.mirantis.mk.Salt() |
| 419 | def common = new com.mirantis.mk.Common() |
| 420 | if (mode == 'reboot') { |
| 421 | try { |
| 422 | def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3) |
| 423 | } catch (Exception e) { |
| 424 | common.warningMsg('Timeout from minion: node must be rebooting now') |
| 425 | } |
| 426 | common.warningMsg("Checking that minion is down") |
| 427 | status = "True" |
| 428 | for (i = 0; i < retries; i++) { |
| 429 | status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1) |
| 430 | if (status != "True") { |
| 431 | break |
| 432 | } |
| 433 | } |
| 434 | if (status == "True") { |
| 435 | throw new Exception("Tired to wait for minion ${target} to stop responding") |
| 436 | } |
| 437 | } |
| 438 | if (mode == 'hard_shutdown' || mode == 'soft_shutdown') { |
| 439 | kvm = locate_node_on_kvm(master, target) |
| 440 | if (mode == 'soft_shutdown') { |
| 441 | salt.cmdRun(master, target, "shutdown -h 0") |
| 442 | } |
| 443 | if (mode == 'hard_shutdown') { |
| 444 | salt.cmdRun(master, kvm, "virsh destroy ${target}") |
| 445 | } |
| 446 | common.warningMsg("Checking that vm on kvm is in power off state") |
| 447 | status = 'running' |
| 448 | for (i = 0; i < retries; i++) { |
| 449 | status = check_vm_status(master, target, kvm) |
| 450 | echo "Current status - ${status}" |
| 451 | if (status != 'running') { |
| 452 | break |
| 453 | } |
| 454 | sleep (1) |
| 455 | } |
| 456 | if (status == 'running') { |
| 457 | throw new Exception("Tired to wait for node ${target} to shutdown") |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
| 463 | /** |
| 464 | * Locate kvm where target host is located |
| 465 | * |
| 466 | * @param target Host to check |
| 467 | */ |
| 468 | def locate_node_on_kvm(master, target) { |
| 469 | def salt = new com.mirantis.mk.Salt() |
| 470 | def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0] |
| 471 | for (item in list.keySet()) { |
| 472 | if (list[item]) { |
| 473 | return item |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Check target host status |
| 480 | * |
| 481 | * @param target Host to check |
| 482 | * @param kvm KVM node where target host is located |
| 483 | */ |
| 484 | def check_vm_status(master, target, kvm) { |
| 485 | def salt = new com.mirantis.mk.Salt() |
| 486 | def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0] |
| 487 | for (item in list.keySet()) { |
| 488 | if (list[item]) { |
| 489 | return list[item].split()[2] |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Find vip on nodes |
| 496 | * |
| 497 | * @param target Pattern, e.g. ctl* |
| 498 | */ |
| 499 | def get_vip_node(master, target) { |
| 500 | def salt = new com.mirantis.mk.Salt() |
| 501 | def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0] |
| 502 | for (item in list.keySet()) { |
| 503 | if (list[item]) { |
| 504 | return item |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Find vip on nodes |
| 511 | * |
| 512 | * @param target Host with cvp container |
| 513 | */ |
| 514 | def openstack_cleanup(master, target, script_path="/home/rally/testing-stuff/clean.sh") { |
| 515 | def salt = new com.mirantis.mk.Salt() |
| 516 | salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"]) |
| 517 | } |
| 518 | |
| 519 | |
| 520 | /** |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 521 | * Cleanup |
| 522 | * |
| 523 | * @param target Host to run commands |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 524 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame] | 525 | def runCleanup(master, target) { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 526 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 321405a | 2017-08-16 16:38:51 -0700 | [diff] [blame] | 527 | if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) { |
| 528 | salt.cmdRun(master, target, "docker rm -f qa_tools") |
| 529 | } |
Oleksii Zhurba | 7b44ef1 | 2017-11-13 17:50:16 -0600 | [diff] [blame] | 530 | if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) { |
| 531 | salt.cmdRun(master, target, "docker rm -f cvp") |
| 532 | } |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 533 | } |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 534 | /** |
| 535 | * Prepare venv for any python project |
| 536 | * Note: <repo_name>\/requirements.txt content will be used |
| 537 | * for this venv |
| 538 | * |
| 539 | * @param repo_url Repository url to clone |
| 540 | * @param proxy Proxy address to use |
| 541 | */ |
| 542 | def prepareVenv(repo_url, proxy) { |
| 543 | def python = new com.mirantis.mk.Python() |
| 544 | repo_name = "${repo_url}".tokenize("/").last() |
| 545 | sh "rm -rf ${repo_name}" |
| 546 | withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) { |
| 547 | sh "git clone ${repo_url}" |
| 548 | python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true) |
| 549 | } |
| 550 | } |
| 551 | |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 552 | /** Install docker if needed |
| 553 | * |
| 554 | * @param target Target node to install docker pkg |
| 555 | */ |
| 556 | def installDocker(master, target) { |
| 557 | def salt = new com.mirantis.mk.Salt() |
| 558 | if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) { |
| 559 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
| 560 | } |
| 561 | } |