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 | /** |
| 10 | * Configure docker image with tests |
| 11 | * |
| 12 | * @param dockerImageLink Docker image link with rally and tempest |
| 13 | * @param target Host to run tests |
| 14 | * @param output_dir Directory for results |
Dmitrii Kabanov | 65fdc28 | 2017-09-29 10:53:08 -0700 | [diff] [blame] | 15 | * @param ext_variables The set of external variables |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 16 | */ |
Dmitrii Kabanov | 65fdc28 | 2017-09-29 10:53:08 -0700 | [diff] [blame] | 17 | def runContainerConfiguration(master, dockerImageLink, target, output_dir, ext_variables){ |
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() |
| 20 | def output_file = 'docker.log' |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 21 | def nodes = getNodeList(master) |
| 22 | def nodes_hw = getNodeList(master, 'G@virtual:physical') |
Sam Stoelinga | 28bdb72 | 2017-09-25 18:29:59 -0700 | [diff] [blame] | 23 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 24 | def keystone = _pillar['return'][0].values()[0] |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 25 | def ssh_key = getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa') |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 26 | salt.cmdRun(master, target, "docker run -tid --net=host --name=qa_tools " + |
Dmitrii Kabanov | 65fdc28 | 2017-09-29 10:53:08 -0700 | [diff] [blame] | 27 | " ${ext_variables} " + |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 28 | "-e tempest_version=15.0.0 -e OS_USERNAME=${keystone.admin_name} " + |
| 29 | "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " + |
| 30 | "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " + |
| 31 | "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin ${dockerImageLink} /bin/bash") |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 32 | salt.cmdRun(master, target, "docker exec qa_tools bash -c \"sudo mkdir -p /root/.ssh; " + |
| 33 | "echo \'${ssh_key}\' | sudo tee /root/.ssh/id_rsa > /dev/null; " + |
| 34 | "sudo chmod 700 /root/.ssh; sudo chmod 600 /root/.ssh/id_rsa; " + |
| 35 | "echo -e '${nodes}' > nodes.json; echo -e '${nodes_hw}' > nodes_hw.json\"") |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 36 | salt.cmdRun(master, target, "docker exec qa_tools bash -c /opt/devops-qa-tools/deployment/configure.sh > ${output_file}") |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 37 | def file_content = getFileContent(master, target, output_file) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 38 | writeFile file: "${output_dir}${output_file}", text: file_content |
| 39 | } |
| 40 | |
| 41 | /** |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 42 | * Get file content (encoded). The content encoded by Base64. |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 43 | * |
| 44 | * @param target Compound target (should target only one host) |
| 45 | * @param file File path to read |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 46 | * @return The encoded content of the file |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 47 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 48 | def getFileContentEncoded(master, target, file) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 49 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 50 | def file_content = '' |
| 51 | def cmd = "base64 -w0 ${file} > ${file}_encoded; " + |
| 52 | "split -b 1MB -d ${file}_encoded ${file}__; " + |
| 53 | "rm ${file}_encoded" |
| 54 | salt.cmdRun(master, target, cmd, false, null, false) |
| 55 | def filename = file.tokenize('/').last() |
| 56 | def folder = file - filename |
| 57 | def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"]) |
| 58 | for ( part in parts['return'][0].values()[0]) { |
| 59 | def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false) |
| 60 | file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','') |
| 61 | } |
| 62 | salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"]) |
| 63 | return file_content |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Copy files from remote to local directory. The content of files will be |
| 68 | * decoded by Base64. |
| 69 | * |
| 70 | * @param target Compound target (should target only one host) |
| 71 | * @param folder The path to remote folder. |
| 72 | * @param output_dir The path to local folder. |
| 73 | */ |
| 74 | def addFiles(master, target, folder, output_dir) { |
| 75 | def salt = new com.mirantis.mk.Salt() |
| 76 | def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"]) |
| 77 | def files = _result['return'][0].values()[0] |
| 78 | for (file in files) { |
| 79 | def file_content = getFileContentEncoded(master, target, "${file}") |
| 80 | def fileName = file.tokenize('/').last() |
| 81 | writeFile file: "${output_dir}${fileName}_encoded", text: file_content |
| 82 | def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " + |
| 83 | "rm ${output_dir}${fileName}_encoded" |
| 84 | sh(script: cmd) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get reclass value |
| 90 | * |
| 91 | * @param target The host for which the values will be provided |
| 92 | * @param filter Parameters divided by dots |
| 93 | * @return The pillar data |
| 94 | */ |
| 95 | def getReclassValue(master, target, filter) { |
| 96 | def common = new com.mirantis.mk.Common() |
| 97 | def salt = new com.mirantis.mk.Salt() |
| 98 | def items = filter.tokenize('.') |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 99 | 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] | 100 | _result = common.parseJSON(_result['return'][0].values()[0]) |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 101 | for (int k = 0; k < items.size(); k++) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 102 | if ( _result ) { |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 103 | _result = _result["${items[k]}"] |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | return _result |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Create list of nodes in JSON format. |
| 111 | * |
| 112 | * @param filter The Salt's matcher |
| 113 | * @return JSON list of nodes |
| 114 | */ |
| 115 | def getNodeList(master, filter = null) { |
| 116 | def salt = new com.mirantis.mk.Salt() |
| 117 | def common = new com.mirantis.mk.Common() |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 118 | def nodes = [] |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 119 | def filtered_list = null |
| 120 | def controllers = salt.getMinions(master, 'I@nova:controller') |
| 121 | def hw_nodes = salt.getMinions(master, 'G@virtual:physical') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 122 | if ( filter ) { |
| 123 | filtered_list = salt.getMinions(master, filter) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 124 | } |
| 125 | def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false) |
| 126 | def reclass_top = common.parseJSON(_result['return'][0].values()[0]) |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 127 | def nodesList = reclass_top['base'].keySet() |
| 128 | for (int i = 0; i < nodesList.size(); i++) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 129 | if ( filtered_list ) { |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 130 | if ( ! filtered_list.contains(nodesList[i]) ) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 131 | continue |
| 132 | } |
| 133 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 134 | def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address') |
| 135 | def network_data = [ip: ip, name: 'management'] |
| 136 | def roles = [nodesList[i].tokenize('.')[0]] |
| 137 | if ( controllers.contains(nodesList[i]) ) { |
| 138 | roles.add('controller') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 139 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 140 | if ( hw_nodes.contains(nodesList[i]) ) { |
| 141 | roles.add('hw_node') |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 142 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 143 | 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] | 144 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 145 | return common.prettify(nodes) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 148 | /** |
| 149 | * Execute mcp sanity tests |
| 150 | * |
| 151 | * @param salt_url Salt master url |
| 152 | * @param salt_credentials Salt credentials |
| 153 | * @param test_set Test set for mcp sanity framework |
| 154 | * @param output_dir Directory for results |
| 155 | */ |
| 156 | def runSanityTests(salt_url, salt_credentials, test_set, output_dir) { |
| 157 | def common = new com.mirantis.mk.Common() |
| 158 | creds = common.getCredentials(salt_credentials) |
| 159 | username = creds.username |
| 160 | password = creds.password |
| 161 | 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}" |
| 162 | withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) { |
| 163 | def statusCode = sh script:script, returnStatus:true |
| 164 | } |
| 165 | } |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 168 | * Execute tempest tests |
| 169 | * |
| 170 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 171 | * @param dockerImageLink Docker image link |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 172 | * @param pattern If not false, will run only tests matched the pattern |
| 173 | * @param output_dir Directory for results |
| 174 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 175 | def runTempestTests(master, target, dockerImageLink, output_dir, pattern = "false") { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 176 | def salt = new com.mirantis.mk.Salt() |
| 177 | def output_file = 'docker-tempest.log' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 178 | def results = '/root/qa_results' |
| 179 | def dest_folder = '/home/rally/qa_results' |
| 180 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 181 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 182 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 183 | def keystone = _pillar['return'][0].values()[0] |
| 184 | def env_vars = ['tempest_version=15.0.0', |
| 185 | "OS_USERNAME=${keystone.admin_name}", |
| 186 | "OS_PASSWORD=${keystone.admin_password}", |
| 187 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 188 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 189 | "OS_REGION_NAME=${keystone.region}", |
| 190 | 'OS_ENDPOINT_TYPE=admin'].join(' -e ') |
| 191 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' |
| 192 | if (pattern == 'false') { |
| 193 | cmd += 'rally verify start --pattern set=full --detailed; ' |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 194 | } |
| 195 | else { |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 196 | cmd += "rally verify start --pattern set=${pattern} --detailed; " |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 197 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 198 | cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " + |
| 199 | "rally verify report --type html --to ${dest_folder}/report-tempest.html" |
| 200 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 201 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 202 | "/bin/bash -c \"${cmd}\" > ${results}/${output_file}") |
| 203 | addFiles(master, target, results, output_dir) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Execute rally tests |
| 208 | * |
| 209 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 210 | * @param dockerImageLink Docker image link |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 211 | * @param pattern If not false, will run only tests matched the pattern |
| 212 | * @param output_dir Directory for results |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 213 | * @param ext_variables The list of external variables |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 214 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 215 | def runRallyTests(master, target, dockerImageLink, output_dir, ext_variables = []) { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 216 | def salt = new com.mirantis.mk.Salt() |
| 217 | def output_file = 'docker-rally.log' |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 218 | def results = '/root/qa_results' |
| 219 | def dest_folder = '/home/rally/qa_results' |
| 220 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 221 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 222 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 223 | def keystone = _pillar['return'][0].values()[0] |
| 224 | def env_vars = ( ['tempest_version=15.0.0', |
| 225 | "OS_USERNAME=${keystone.admin_name}", |
| 226 | "OS_PASSWORD=${keystone.admin_password}", |
| 227 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 228 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 229 | "OS_REGION_NAME=${keystone.region}", |
| 230 | 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ') |
| 231 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' + |
| 232 | 'rally task start combined_scenario.yaml ' + |
| 233 | "--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; " + |
| 234 | "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " + |
| 235 | "rally task report --out ${dest_folder}/report-rally.html" |
| 236 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 237 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 238 | "/bin/bash -c \"${cmd}\" > ${results}/${output_file}") |
| 239 | addFiles(master, target, results, output_dir) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /** |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 243 | * Generate test report |
| 244 | * |
| 245 | * @param target Host to run script from |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 246 | * @param dockerImageLink Docker image link |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 247 | * @param output_dir Directory for results |
| 248 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 249 | def generateTestReport(master, target, dockerImageLink, output_dir) { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 250 | def report_file = 'jenkins_test_report.html' |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 251 | def salt = new com.mirantis.mk.Salt() |
| 252 | def common = new com.mirantis.mk.Common() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 253 | def results = '/root/qa_results' |
| 254 | def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results' |
| 255 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 256 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 257 | def reports = ['report-tempest.json', |
| 258 | 'report-rally.xml', |
| 259 | 'report-k8s-e2e-tests.txt', |
| 260 | 'report-ha.json', |
| 261 | 'report-spt.txt'] |
| 262 | for ( report in reports ) { |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 263 | if ( fileExists("${output_dir}${report}") ) { |
| 264 | common.infoMsg("Copying ${report} to docker container") |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 265 | def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " + |
| 266 | "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " + |
| 267 | "rm ${output_dir}${report}_encoded; " + |
| 268 | "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true) |
| 269 | for ( item in items.tokenize() ) { |
| 270 | def content = sh(script: "cat ${output_dir}${item}", returnStdout: true) |
| 271 | salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false) |
| 272 | sh(script: "rm ${output_dir}${item}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 273 | } |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 274 | salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " + |
| 275 | "rm ${results}/${report}_encoded", false, null, false) |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 278 | |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 279 | def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " + |
| 280 | "cp ${report_file} ${dest_folder}/${report_file}" |
| 281 | salt.cmdRun(master, target, "docker run -i --rm --net=host " + |
| 282 | "-v ${results}:${dest_folder} ${dockerImageLink} " + |
| 283 | "/bin/bash -c \"${cmd}\"") |
| 284 | def report_content = salt.getFileContent(master, target, "${results}/${report_file}") |
Tetiana Korchak | 3383cc9 | 2017-08-25 09:36:19 -0700 | [diff] [blame] | 285 | writeFile file: "${output_dir}${report_file}", text: report_content |
| 286 | } |
| 287 | |
| 288 | /** |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 289 | * Execute SPT tests |
| 290 | * |
| 291 | * @param target Host to run tests |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 292 | * @param dockerImageLink Docker image link |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 293 | * @param output_dir Directory for results |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 294 | * @param ext_variables The list of external variables |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 295 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 296 | def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) { |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 297 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 298 | def results = '/root/qa_results' |
| 299 | def dest_folder = '/home/rally/qa_results' |
| 300 | salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"]) |
| 301 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"]) |
| 302 | def nodes = getNodeList(master) |
| 303 | def nodes_hw = getNodeList(master, 'G@virtual:physical') |
| 304 | def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server') |
| 305 | def keystone = _pillar['return'][0].values()[0] |
| 306 | def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa') |
| 307 | def env_vars = ( ['tempest_version=15.0.0', |
| 308 | "OS_USERNAME=${keystone.admin_name}", |
| 309 | "OS_PASSWORD=${keystone.admin_password}", |
| 310 | "OS_TENANT_NAME=${keystone.admin_tenant}", |
| 311 | "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0", |
| 312 | "OS_REGION_NAME=${keystone.region}", |
| 313 | 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ') |
| 314 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes]) |
| 315 | salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw]) |
| 316 | def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' + |
| 317 | 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' + |
| 318 | "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " + |
| 319 | 'sudo chmod 600 /root/.ssh/id_rsa; ' + |
| 320 | "sudo timmy -c simplified-performance-testing/config.yaml " + |
| 321 | "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " + |
| 322 | "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " + |
| 323 | "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " + |
| 324 | "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz" |
| 325 | salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " + |
| 326 | "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " + |
| 327 | "\"${cmd}\" > ${results}/docker-spt.log") |
| 328 | addFiles(master, target, results, output_dir) |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Dmitrii Kabanov | d5f1c5f | 2017-08-30 14:51:41 -0700 | [diff] [blame] | 331 | /** |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 332 | * Cleanup |
| 333 | * |
| 334 | * @param target Host to run commands |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 335 | */ |
Dmitrii Kabanov | 23901c2 | 2017-10-20 10:25:36 -0700 | [diff] [blame^] | 336 | def runCleanup(master, target) { |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 337 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 321405a | 2017-08-16 16:38:51 -0700 | [diff] [blame] | 338 | if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) { |
| 339 | salt.cmdRun(master, target, "docker rm -f qa_tools") |
| 340 | } |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Oleksii Zhurba | bcb97e2 | 2017-10-05 14:10:39 -0500 | [diff] [blame] | 343 | /** |
| 344 | * Prepare venv for any python project |
| 345 | * Note: <repo_name>\/requirements.txt content will be used |
| 346 | * for this venv |
| 347 | * |
| 348 | * @param repo_url Repository url to clone |
| 349 | * @param proxy Proxy address to use |
| 350 | */ |
| 351 | def prepareVenv(repo_url, proxy) { |
| 352 | def python = new com.mirantis.mk.Python() |
| 353 | repo_name = "${repo_url}".tokenize("/").last() |
| 354 | sh "rm -rf ${repo_name}" |
| 355 | withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) { |
| 356 | sh "git clone ${repo_url}" |
| 357 | python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true) |
| 358 | } |
| 359 | } |
| 360 | |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 361 | /** Install docker if needed |
| 362 | * |
| 363 | * @param target Target node to install docker pkg |
| 364 | */ |
| 365 | def installDocker(master, target) { |
| 366 | def salt = new com.mirantis.mk.Salt() |
| 367 | if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) { |
| 368 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
| 369 | } |
| 370 | } |