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