Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * Tests providing functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Run e2e conformance tests |
| 11 | * |
| 12 | * @param k8s_api Kubernetes api address |
| 13 | * @param image Docker image with tests |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 14 | * @param timeout Timeout waiting for e2e conformance tests |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 15 | */ |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 16 | def runConformanceTests(master, k8s_api, image, timeout=2400) { |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 17 | def salt = new com.mirantis.mk.Salt() |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 18 | def containerName = 'conformance_tests' |
Tomáš Kukrál | a7318f5 | 2017-04-21 16:15:29 +0200 | [diff] [blame] | 19 | def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output' |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 20 | salt.cmdRun(master, 'ctl01*', "docker rm -f ${containerName}", false) |
| 21 | salt.cmdRun(master, 'ctl01*', "docker run -d --name ${containerName} --net=host -e API_SERVER=${k8s_api} ${image}") |
| 22 | sleep(10) |
| 23 | |
| 24 | print("Waiting for tests to run...") |
| 25 | salt.runSaltProcessStep(master, 'ctl01*', 'cmd.run', ["docker wait ${containerName}"], null, false, timeout) |
| 26 | |
| 27 | print("Writing test results to output file...") |
| 28 | salt.runSaltProcessStep(master, 'ctl01*', 'cmd.run', ["docker logs -t ${containerName} &> ${outfile}"]) |
| 29 | |
Tomáš Kukrál | 798b3f5 | 2017-04-28 13:19:32 +0200 | [diff] [blame] | 30 | print("Conformance test output saved in " + outfile) |
Tatyana Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Copy test output to cfg node |
| 35 | * |
| 36 | * @param image Docker image with tests |
| 37 | */ |
| 38 | def copyTestsOutput(master, image) { |
| 39 | def salt = new com.mirantis.mk.Salt() |
| 40 | salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["scp ctl01:/root/${image}.output /home/ubuntu/"]) |
| 41 | } |
| 42 | |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 43 | /** |
| 44 | * Execute tempest tests |
| 45 | * |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 46 | * @param dockerImageLink Docker image link with rally and tempest |
| 47 | * @param target Host to run tests |
| 48 | * @param pattern If not false, will run only tests matched the pattern |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 49 | */ |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 50 | def runTempestTests(master, dockerImageLink, target, pattern = "false") { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 51 | def salt = new com.mirantis.mk.Salt() |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 52 | if (pattern == "false") { |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame^] | 53 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 54 | "-e TEMPEST_CONF=mcp.conf " + |
| 55 | "-e SKIP_LIST=mcp_skip.list " + |
| 56 | "-e SOURCE_FILE=keystonercv3 " + |
| 57 | "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log") |
| 58 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 59 | else { |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame^] | 60 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 61 | "-e TEMPEST_CONF=mcp.conf " + |
| 62 | "-e SKIP_LIST=mcp_skip.list " + |
| 63 | "-e SOURCE_FILE=keystonercv3 " + |
| 64 | "-e CUSTOM='--pattern ${pattern}' " + |
| 65 | "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log") |
| 66 | } |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Upload results to worker |
| 71 | * |
| 72 | */ |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 73 | def copyTempestResults(master, target) { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 74 | def salt = new com.mirantis.mk.Salt() |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 75 | salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["scp /root/docker-tempest.log cfg01:/home/ubuntu/ && " + |
| 76 | "find /root -name result.xml -exec scp {} cfg01:/home/ubuntu \\;"]) |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 80 | /** Store tests results on host |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 81 | * |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 82 | * @param image Docker image name |
| 83 | */ |
| 84 | def catTestsOutput(master, image) { |
| 85 | def salt = new com.mirantis.mk.Salt() |
| 86 | salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"]) |
| 87 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 88 | |
| 89 | |
| 90 | /** Install docker if needed |
| 91 | * |
| 92 | * @param target Target node to install docker pkg |
| 93 | */ |
| 94 | def install_docker(master, target) { |
| 95 | def salt = new com.mirantis.mk.Salt() |
| 96 | salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"]) |
| 97 | } |