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 |
Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 48 | * @param pattern If not false, will run only tests matched the pattern |
| 49 | * @param logDir Directory to store tempest/rally reports |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 50 | */ |
Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 51 | def runTempestTests(master, dockerImageLink, target, pattern = "false", logDir = '/home/rally/rally_reports/') { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 52 | def salt = new com.mirantis.mk.Salt() |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 53 | if (pattern == "false") { |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 54 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 55 | "-e TEMPEST_CONF=mcp.conf " + |
| 56 | "-e SKIP_LIST=mcp_skip.list " + |
| 57 | "-e SOURCE_FILE=keystonercv3 " + |
Jakub Pavlik | 0bfc263 | 2017-08-18 10:07:09 +0200 | [diff] [blame] | 58 | "-e LOG_DIR=${logDir} " + |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 59 | "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log") |
| 60 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 61 | else { |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 62 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 63 | "-e TEMPEST_CONF=mcp.conf " + |
| 64 | "-e SKIP_LIST=mcp_skip.list " + |
| 65 | "-e SOURCE_FILE=keystonercv3 " + |
Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 66 | "-e LOG_DIR=${logDir} " + |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 67 | "-e CUSTOM='--pattern ${pattern}' " + |
| 68 | "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log") |
| 69 | } |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 73 | * Upload results to cfg01 node |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 74 | * |
| 75 | */ |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 76 | def copyTempestResults(master, target) { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 77 | def salt = new com.mirantis.mk.Salt() |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 78 | if (! target.contains('cfg')) { |
| 79 | salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["mkdir /root/rally_reports/ && " + |
| 80 | "rsync -av /root/rally_reports/ cfg01:/root/rally_reports/"]) |
| 81 | } |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 85 | /** Store tests results on host |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 86 | * |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 87 | * @param image Docker image name |
| 88 | */ |
| 89 | def catTestsOutput(master, image) { |
| 90 | def salt = new com.mirantis.mk.Salt() |
| 91 | salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"]) |
| 92 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 93 | |
| 94 | |
| 95 | /** Install docker if needed |
| 96 | * |
| 97 | * @param target Target node to install docker pkg |
| 98 | */ |
| 99 | def install_docker(master, target) { |
| 100 | def salt = new com.mirantis.mk.Salt() |
| 101 | salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"]) |
| 102 | } |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 103 | |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 104 | /** Upload Tempest test results to Testrail |
| 105 | * |
| 106 | * @param report Source report to upload |
| 107 | * @param image Testrail reporter image |
| 108 | * @param testGroup Testrail test group |
| 109 | * @param credentialsId Testrail credentials id |
| 110 | * @param plan Testrail test plan |
| 111 | * @param milestone Testrail test milestone |
| 112 | * @param suite Testrail test suite |
| 113 | * @param type Use local shell or remote salt connection |
| 114 | * @param master Salt connection. |
| 115 | * @param target Target node to install docker pkg |
| 116 | */ |
| 117 | |
| 118 | def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') { |
| 119 | def salt = new com.mirantis.mk.Salt() |
| 120 | def common = new com.mirantis.mk.Common() |
| 121 | creds = common.getPasswordCredentials(credentialsId) |
| 122 | command = "docker run --rm --net=host " + |
| 123 | "-v ${report}:/srv/report.xml " + |
| 124 | "-e TESTRAIL_USER=${creds.username} " + |
| 125 | "-e PASS=${creds.password.toString()} " + |
| 126 | "-e TESTRAIL_PLAN_NAME=${plan} " + |
| 127 | "-e TESTRAIL_MILESTONE=${milestone} " + |
| 128 | "-e TESTRAIL_SUITE=${suite} " + |
Mykyta Karpin | a5761a2 | 2017-08-16 16:09:56 +0300 | [diff] [blame^] | 129 | "-e TEST_GROUP=${testGroup} " + |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 130 | "${image}" |
| 131 | if (master == null) { |
| 132 | sh("${command}") |
| 133 | } else { |
| 134 | salt.cmdRun(master, "${target}", "${command}") |
| 135 | } |
| 136 | } |
| 137 | |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 138 | /** Archive Rally results in Artifacts |
| 139 | * |
| 140 | * @param master Salt connection. |
| 141 | * @param target Target node to install docker pkg |
| 142 | * @param reports_dir Source directory to archive |
| 143 | */ |
| 144 | |
| 145 | def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') { |
| 146 | def salt = new com.mirantis.mk.Salt() |
| 147 | |
| 148 | def artifacts_dir = '_artifacts/' |
| 149 | def output_file = 'rally_reports.tar' |
| 150 | |
Mykyta Karpin | f4be9e2 | 2017-08-09 18:59:57 +0300 | [diff] [blame] | 151 | salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["tar -cf /root/${output_file} -C ${reports_dir} ."]) |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 152 | sh "mkdir -p ${artifacts_dir}" |
| 153 | |
Mykyta Karpin | f4be9e2 | 2017-08-09 18:59:57 +0300 | [diff] [blame] | 154 | encoded = salt.cmdRun(master, target, "cat /root/${output_file}", true, null, false)['return'][0].values()[0].replaceAll('Salt command execution success','') |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 155 | |
| 156 | writeFile file: "${artifacts_dir}${output_file}", text: encoded |
| 157 | |
| 158 | // collect artifacts |
| 159 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 160 | } |
Jakub Josef | 1462c4b | 2017-08-18 11:15:03 +0200 | [diff] [blame] | 161 | /** |
| 162 | * Helper function for collecting junit tests results |
| 163 | * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class) |
| 164 | * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 165 | */ |
| 166 | @NonCPS |
| 167 | def collectJUnitResults(testResultAction) { |
| 168 | if (testResultAction != null) { |
| 169 | def total = testResultAction.totalCount |
| 170 | def failed = testResultAction.failCount |
| 171 | def skipped = testResultAction.skipCount |
| 172 | def passed = total - failed - skipped |
| 173 | return ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 174 | }else{ |
| 175 | def common = new com.mirantis.mk.Common() |
| 176 | common.errorMsg("Cannot collect jUnit tests results, given result is null") |
| 177 | } |
| 178 | return [:] |
| 179 | } |