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 |
| 15 | */ |
| 16 | def runContainerConfiguration(master, dockerImageLink, target, output_dir){ |
| 17 | def salt = new com.mirantis.mk.Salt() |
| 18 | def common = new com.mirantis.mk.Common() |
| 19 | def output_file = 'docker.log' |
Dmitrii Kabanov | e38aff4 | 2017-08-16 15:11:44 -0700 | [diff] [blame] | 20 | def controller = salt.minionPresent(master, 'I@salt:master', 'ctl01', true, null, true, 200, 1)['return'][0].values()[0] |
| 21 | def _pillar = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${controller} | " + |
| 22 | "python -c 'import json,sys; print(json.dumps(json.loads(sys.stdin.read())[\"keystone\"][\"server\"]))'") |
| 23 | def keystone = common.parseJSON(_pillar['return'][0].values()[0]) |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 24 | salt.cmdRun(master, target, "docker run -tid --net=host --name=qa_tools " + |
| 25 | "-e tempest_version=15.0.0 -e OS_USERNAME=${keystone.admin_name} " + |
| 26 | "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " + |
| 27 | "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " + |
| 28 | "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin ${dockerImageLink} /bin/bash") |
| 29 | salt.cmdRun(master, target, "docker exec qa_tools bash -c /opt/devops-qa-tools/deployment/configure.sh > ${output_file}") |
| 30 | def file_content = salt.getFileContent(master, target, output_file) |
| 31 | writeFile file: "${output_dir}${output_file}", text: file_content |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Execute tempest tests |
| 36 | * |
| 37 | * @param target Host to run tests |
| 38 | * @param pattern If not false, will run only tests matched the pattern |
| 39 | * @param output_dir Directory for results |
| 40 | */ |
| 41 | def runTempestTests(master, target, output_dir, pattern = "false") { |
| 42 | def salt = new com.mirantis.mk.Salt() |
| 43 | def output_file = 'docker-tempest.log' |
| 44 | if (pattern == "false") { |
| 45 | salt.cmdRun(master, target, "docker exec qa_tools rally verify start --pattern set=full " + |
| 46 | "--detailed > ${output_file}") |
| 47 | } |
| 48 | else { |
| 49 | salt.cmdRun(master, target, "docker exec qa_tools rally verify start --pattern ${pattern} " + |
| 50 | "--detailed > ${output_file}") |
| 51 | } |
| 52 | def file_content = salt.getFileContent(master, target, output_file) |
| 53 | writeFile file: "${output_dir}${output_file}", text: file_content |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Execute rally tests |
| 58 | * |
| 59 | * @param target Host to run tests |
| 60 | * @param pattern If not false, will run only tests matched the pattern |
| 61 | * @param output_dir Directory for results |
| 62 | */ |
| 63 | def runRallyTests(master, target, output_dir, pattern = "false") { |
| 64 | def salt = new com.mirantis.mk.Salt() |
| 65 | def output_file = 'docker-rally.log' |
| 66 | salt.cmdRun(master, target, "docker exec qa_tools rally task start combined_scenario.yaml --task-args-file " + |
| 67 | "/opt/devops-qa-tools/rally-scenarios/task_arguments.yaml | tee ${output_file}") |
| 68 | def file_content = salt.getFileContent(master, target, output_file) |
| 69 | writeFile file: "${output_dir}${output_file}", text: file_content |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Cleanup |
| 74 | * |
| 75 | * @param target Host to run commands |
| 76 | * @param output_dir Directory for results |
| 77 | */ |
| 78 | def runCleanup(master, target, output_dir) { |
| 79 | def salt = new com.mirantis.mk.Salt() |
Dmitrii Kabanov | 321405a | 2017-08-16 16:38:51 -0700 | [diff] [blame] | 80 | if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) { |
| 81 | salt.cmdRun(master, target, "docker rm -f qa_tools") |
| 82 | } |
Petr Lomakin | 47fee0a | 2017-08-01 10:46:05 -0700 | [diff] [blame] | 83 | sh "rm -r ${output_dir}" |
| 84 | } |
| 85 | |
| 86 | /** Install docker if needed |
| 87 | * |
| 88 | * @param target Target node to install docker pkg |
| 89 | */ |
| 90 | def installDocker(master, target) { |
| 91 | def salt = new com.mirantis.mk.Salt() |
| 92 | if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) { |
| 93 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
| 94 | } |
| 95 | } |