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 | * |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 12 | * @param target Kubernetes node to run tests from |
| 13 | * @param k8s_api Kubernetes api address |
| 14 | * @param image Docker image with tests |
| 15 | * @param timeout Timeout waiting for e2e conformance tests |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 16 | */ |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 17 | def runConformanceTests(master, target, k8s_api, image, timeout=2400) { |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 18 | def salt = new com.mirantis.mk.Salt() |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 19 | def containerName = 'conformance_tests' |
Tomáš Kukrál | a7318f5 | 2017-04-21 16:15:29 +0200 | [diff] [blame] | 20 | def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output' |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 21 | salt.cmdRun(master, target, "docker rm -f ${containerName}", false) |
| 22 | salt.cmdRun(master, target, "docker run -d --name ${containerName} --net=host -e API_SERVER=${k8s_api} ${image}") |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 23 | sleep(10) |
| 24 | |
| 25 | print("Waiting for tests to run...") |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 26 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker wait ${containerName}"], null, false, timeout) |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 27 | |
| 28 | print("Writing test results to output file...") |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 29 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker logs -t ${containerName} > ${outfile}"]) |
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 | |
vrovachev | c3b47f4 | 2018-01-25 16:08:50 +0400 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Upload conformance results to cfg node |
| 36 | * |
| 37 | * @param target Kubernetes node for copy test results |
| 38 | * @param artifacts_dir Path with test results |
| 39 | */ |
| 40 | def CopyConformanceResults(master, target, artifacts_dir, output_file) { |
| 41 | def salt = new com.mirantis.mk.Salt() |
| 42 | def containerName = 'conformance_tests' |
| 43 | def test_node = target.replace("*", "") |
| 44 | |
| 45 | out = salt.runSaltProcessStep(master, target, 'cmd.run', ["docker cp ${containerName}:/report /tmp"]) |
| 46 | if (! out['return'][0].values()[0].contains('Error')) { |
| 47 | print("Copy XML test results for junit artifacts...") |
| 48 | salt.runSaltProcessStep(master, target, 'cmd.run', ["tar -cf /tmp/${output_file} -C /tmp/report ."]) |
| 49 | |
| 50 | writeFile file: "${artifacts_dir}${output_file}", text: salt.getFileContent(master, |
| 51 | target, "/tmp/${output_file}") |
| 52 | |
| 53 | sh "mkdir -p ${artifacts_dir}/conformance_tests" |
| 54 | sh "tar -xf ${artifacts_dir}${output_file} -C ${artifacts_dir}/conformance_tests" |
| 55 | |
| 56 | // collect artifacts |
| 57 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 58 | |
| 59 | junit(keepLongStdio: true, testResults: "${artifacts_dir}conformance_tests/**.xml") |
| 60 | } |
| 61 | } |
| 62 | |
Tatyana Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 63 | /** |
| 64 | * Copy test output to cfg node |
| 65 | * |
| 66 | * @param image Docker image with tests |
| 67 | */ |
| 68 | def copyTestsOutput(master, image) { |
| 69 | def salt = new com.mirantis.mk.Salt() |
| 70 | salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["scp ctl01:/root/${image}.output /home/ubuntu/"]) |
| 71 | } |
| 72 | |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 73 | /** |
| 74 | * Execute tempest tests |
| 75 | * |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 76 | * @param dockerImageLink Docker image link with rally and tempest |
| 77 | * @param target Host to run tests |
Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 78 | * @param pattern If not false, will run only tests matched the pattern |
| 79 | * @param logDir Directory to store tempest/rally reports |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 80 | * @param sourceFile Path to the keystonerc file in the container |
| 81 | * @param set Predefined set for tempest tests |
| 82 | * @param concurrency How many processes to use to run Tempest tests |
| 83 | * @param tempestConf A tempest.conf's file name |
| 84 | * @param skipList A skip.list's file name |
| 85 | * @param localKeystone Path to the keystonerc file in the local host |
| 86 | * @param localLogDir Path to local destination folder for logs |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 87 | */ |
ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 88 | def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/", |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 89 | sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf", |
| 90 | skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports", |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 91 | doCleanupResources = "false") { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 92 | def salt = new com.mirantis.mk.Salt() |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 93 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"]) |
| 94 | def custom = '' |
ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 95 | if (pattern) { |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 96 | custom = "--pattern " + pattern |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 97 | } |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 98 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 99 | "-e SOURCE_FILE=${sourceFile} " + |
| 100 | "-e LOG_DIR=${logDir} " + |
| 101 | "-e SET=${set} " + |
Mykyta Karpin | 292c066 | 2017-11-13 12:07:52 +0200 | [diff] [blame] | 102 | "-e CUSTOM='${custom}' " + |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 103 | "-e CONCURRENCY=${concurrency} " + |
| 104 | "-e TEMPEST_CONF=${tempestConf} " + |
| 105 | "-e SKIP_LIST=${skipList} " + |
| 106 | "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " + |
| 107 | "-v ${localKeystone}:${sourceFile} " + |
| 108 | "-v ${localLogDir}:/home/rally/rally_reports " + |
| 109 | "-v /etc/ssl/certs/:/etc/ssl/certs/ " + |
| 110 | "${dockerImageLink} >> docker-tempest.log") |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 111 | } |
| 112 | |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Execute Rally scenarios |
| 116 | * |
| 117 | * @param dockerImageLink Docker image link with rally and tempest |
| 118 | * @param target Host to run scenarios |
| 119 | * @param scenario Specify the scenario as a string |
| 120 | * @param containerName Docker container name |
| 121 | * @param doCleanupResources Do run clean-up script after tests? Cleans up OpenStack test resources |
| 122 | */ |
| 123 | def runRallyScenarios(master, dockerImageLink, target, scenario, logDir = "/home/rally/rally_reports/", |
| 124 | doCleanupResources = "false", containerName = "rally_ci") { |
| 125 | def salt = new com.mirantis.mk.Salt() |
Ievgeniia Zadorozhna | 5b97023 | 2017-09-13 13:31:43 +0300 | [diff] [blame] | 126 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"]) |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 127 | salt.cmdRun(master, target, "docker run --net=host -dit " + |
| 128 | "--name ${containerName} " + |
| 129 | "-e SOURCE_FILE=keystonercv3 " + |
| 130 | "-e SCENARIO=${scenario} " + |
| 131 | "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " + |
| 132 | "-e LOG_DIR=${logDir} " + |
| 133 | "--entrypoint /bin/bash -v /root/:/home/rally ${dockerImageLink}") |
| 134 | salt.cmdRun(master, target, "docker exec ${containerName} " + |
| 135 | "bash -c /usr/bin/run-rally | tee -a docker-rally.log") |
| 136 | } |
| 137 | |
| 138 | |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 139 | /** |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 140 | * Upload results to cfg01 node |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 141 | * |
| 142 | */ |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 143 | def copyTempestResults(master, target) { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 144 | def salt = new com.mirantis.mk.Salt() |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 145 | if (! target.contains('cfg')) { |
ibumarskov | 5c31e28 | 2018-02-14 15:05:20 +0400 | [diff] [blame] | 146 | salt.cmdRun(master, target, "mkdir -p /root/rally_reports/ && rsync -av /root/rally_reports/ cfg01:/root/rally_reports/") |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 147 | } |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 151 | /** Store tests results on host |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 152 | * |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 153 | * @param image Docker image name |
| 154 | */ |
| 155 | def catTestsOutput(master, image) { |
| 156 | def salt = new com.mirantis.mk.Salt() |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 157 | salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output") |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 158 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 159 | |
| 160 | |
| 161 | /** Install docker if needed |
| 162 | * |
| 163 | * @param target Target node to install docker pkg |
| 164 | */ |
| 165 | def install_docker(master, target) { |
| 166 | def salt = new com.mirantis.mk.Salt() |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 167 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 168 | } |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 169 | |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 170 | |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 171 | /** Upload Tempest test results to Testrail |
| 172 | * |
| 173 | * @param report Source report to upload |
| 174 | * @param image Testrail reporter image |
| 175 | * @param testGroup Testrail test group |
| 176 | * @param credentialsId Testrail credentials id |
| 177 | * @param plan Testrail test plan |
| 178 | * @param milestone Testrail test milestone |
| 179 | * @param suite Testrail test suite |
| 180 | * @param type Use local shell or remote salt connection |
| 181 | * @param master Salt connection. |
| 182 | * @param target Target node to install docker pkg |
| 183 | */ |
| 184 | |
| 185 | def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') { |
| 186 | def salt = new com.mirantis.mk.Salt() |
| 187 | def common = new com.mirantis.mk.Common() |
| 188 | creds = common.getPasswordCredentials(credentialsId) |
| 189 | command = "docker run --rm --net=host " + |
| 190 | "-v ${report}:/srv/report.xml " + |
| 191 | "-e TESTRAIL_USER=${creds.username} " + |
| 192 | "-e PASS=${creds.password.toString()} " + |
| 193 | "-e TESTRAIL_PLAN_NAME=${plan} " + |
| 194 | "-e TESTRAIL_MILESTONE=${milestone} " + |
| 195 | "-e TESTRAIL_SUITE=${suite} " + |
Mykyta Karpin | a5761a2 | 2017-08-16 16:09:56 +0300 | [diff] [blame] | 196 | "-e TEST_GROUP=${testGroup} " + |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 197 | "${image}" |
| 198 | if (master == null) { |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 199 | sh(command) |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 200 | } else { |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 201 | salt.cmdRun(master, target, command) |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 205 | /** Archive Rally results in Artifacts |
| 206 | * |
| 207 | * @param master Salt connection. |
| 208 | * @param target Target node to install docker pkg |
| 209 | * @param reports_dir Source directory to archive |
| 210 | */ |
| 211 | |
| 212 | def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') { |
| 213 | def salt = new com.mirantis.mk.Salt() |
| 214 | |
| 215 | def artifacts_dir = '_artifacts/' |
| 216 | def output_file = 'rally_reports.tar' |
| 217 | |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 218 | salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .") |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 219 | sh "mkdir -p ${artifacts_dir}" |
| 220 | |
Mykyta Karpin | f4be9e2 | 2017-08-09 18:59:57 +0300 | [diff] [blame] | 221 | 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] | 222 | |
| 223 | writeFile file: "${artifacts_dir}${output_file}", text: encoded |
| 224 | |
| 225 | // collect artifacts |
| 226 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 227 | } |
Jakub Josef | 1462c4b | 2017-08-18 11:15:03 +0200 | [diff] [blame] | 228 | /** |
| 229 | * Helper function for collecting junit tests results |
| 230 | * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class) |
| 231 | * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 232 | */ |
| 233 | @NonCPS |
| 234 | def collectJUnitResults(testResultAction) { |
| 235 | if (testResultAction != null) { |
| 236 | def total = testResultAction.totalCount |
| 237 | def failed = testResultAction.failCount |
| 238 | def skipped = testResultAction.skipCount |
| 239 | def passed = total - failed - skipped |
| 240 | return ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 241 | }else{ |
| 242 | def common = new com.mirantis.mk.Common() |
| 243 | common.errorMsg("Cannot collect jUnit tests results, given result is null") |
| 244 | } |
| 245 | return [:] |
| 246 | } |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 247 | |
| 248 | |
| 249 | /** Cleanup: Remove reports directory |
| 250 | * |
| 251 | * @param target Target node to remove repo |
| 252 | * @param reports_dir_name Reports directory name to be removed (that is in /root/ on target node) |
| 253 | * @param archive_artifacts_name Archive of the artifacts |
| 254 | */ |
| 255 | def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') { |
| 256 | def salt = new com.mirantis.mk.Salt() |
| 257 | salt.runSaltProcessStep(master, target, 'file.find', ["/root/${reports_dir_name}", '\\*', 'delete']) |
| 258 | salt.runSaltProcessStep(master, target, 'file.remove', ["/root/${archive_artifacts_name}"]) |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /** Cleanup: Remove Docker container |
| 263 | * |
| 264 | * @param target Target node to remove Docker container |
| 265 | * @param image_link The link of the Docker image that was used for the container |
| 266 | */ |
Ievgeniia Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 267 | def removeDockerContainer(master, target, containerName) { |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 268 | def salt = new com.mirantis.mk.Salt() |
Ievgeniia Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 269 | salt.cmdRun(master, target, "docker rm -f ${containerName}") |
Oleh Hryhorov | 8365833 | 2017-10-10 10:45:12 +0300 | [diff] [blame] | 270 | } |