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 | /** |
Victor Ryzhenkin | 46da67a | 2018-11-30 00:17:55 +0400 | [diff] [blame] | 10 | * Get conformance pod statuses |
| 11 | * |
| 12 | * @param target Any control node of k8s |
| 13 | */ |
| 14 | def getConformanceStatus(master, target) { |
| 15 | def salt = new com.mirantis.mk.Salt() |
| 16 | def status = salt.cmdRun(master, target, "kubectl get po conformance -n conformance | awk {'print \$3'} | tail -n +2")['return'][0].values()[0].replaceAll('Salt command execution success','').trim() |
| 17 | return status |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Replace conformance image not relying on deployed version. Will be useful for testing a new k8s builds from docker-dev |
| 22 | * |
| 23 | * @param target I@kubernetes:master target |
| 24 | * @param image Desired image for conformance |
| 25 | * @param autodetect Default behaviour - use version discovered on deployment. Non default - use image provided via image param |
| 26 | */ |
| 27 | def passCustomConformanceImage(LinkedHashMap config) { |
| 28 | def salt = new com.mirantis.mk.Salt() |
| 29 | |
| 30 | // Listing defaults |
| 31 | def master = config.get('master', 'pepperVenv') |
| 32 | def target = config.get('target', 'I@kubernetes:master') |
| 33 | def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml') |
| 34 | def autodetect = config.get('autodetect', true) |
| 35 | def image = config.get('image', null) |
| 36 | // End listing defaults |
| 37 | |
| 38 | if (!(autodetect.toBoolean()) && image) { |
| 39 | print("Replacing conformance image with ${image}") |
| 40 | salt.cmdRun(master, target, "sed -i 's|image: .*|image: ${image}|' ${pod_path}") |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Run e2e conformance on ContainerD environments |
| 46 | * |
| 47 | * @param target Any control node of k8s |
| 48 | * @param pd_path Conformance pod path to create |
| 49 | * @param timeout Test timeout |
| 50 | */ |
| 51 | def runConformanceTestsOnContainerD(LinkedHashMap config) { |
| 52 | def salt = new com.mirantis.mk.Salt() |
| 53 | |
| 54 | // Listing defaults |
| 55 | def master = config.get('master', 'pepperVenv') |
| 56 | def target = config.get('target', 'I@kubernetes:master and ctl01*') |
| 57 | def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml') |
| 58 | def timeout = config.get('timeout', 3600) |
| 59 | // End listing defaults |
| 60 | |
| 61 | def status = "" |
| 62 | salt.cmdRun(master, target, "kubectl delete -f ${pod_path}", false) |
| 63 | salt.cmdRun(master, target, "kubectl create -f ${pod_path}") |
| 64 | sleep(10) |
| 65 | |
| 66 | counter = timeout/60 |
| 67 | |
| 68 | print("Waiting for results") |
| 69 | for (i = 0; i < counter; i++) { |
| 70 | current = getConformanceStatus(master, target) |
| 71 | if (current == "Running" || current == "ContainerCreating") { |
| 72 | sleep(60) |
| 73 | print("Wait counter: $i . Cap is $counter") |
| 74 | } else if (current == "Completed") { |
| 75 | print("Conformance succeeded. Proceed with artifacts.") |
| 76 | status = "OK" |
| 77 | return status |
| 78 | } else if (current == "Error") { |
| 79 | status = "ERR" |
| 80 | print("Tests failed. Proceed with artifacts") |
| 81 | return status |
| 82 | } else if (current == "ContainerCannotRun") { |
| 83 | print("Container can not run. Please check executor logs") |
| 84 | status = "NOTEXECUTED" |
| 85 | salt.cmdRun(master, target, "kubectl describe po conformance -n conformance") |
| 86 | return status |
| 87 | } else if (current == "ImagePullBackOff" || current == "ErrImagePull") { |
| 88 | print("Can not pull conformance image. Image is not exists or can not be accessed") |
| 89 | status = "PULLERR" |
| 90 | salt.cmdRun(master, target, "kubectl describe po conformance -n conformance") |
| 91 | return status |
| 92 | } else { |
| 93 | print("Unexpected status: ${current}") |
| 94 | status = "UNKNOWN" |
| 95 | salt.cmdRun(master, target, "kubectl describe po conformance -n conformance") |
| 96 | salt.cmdRun(master, target, "kubectl get cs") |
| 97 | salt.cmdRun(master, target, "kubectl get po --all-namespaces -o wide") |
| 98 | return status |
| 99 | } |
| 100 | } |
| 101 | status = "TIMEDOUT" |
| 102 | salt.cmdRun(master, target, "kubectl describe po conformance -n conformance") |
| 103 | salt.cmdRun(master, target, "kubectl logs conformance -n conformance") |
| 104 | return status |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * Locate node where conformance pod runs |
| 110 | * |
| 111 | * @param target Any control node of k8s |
| 112 | */ |
| 113 | def locateConformancePod(master, target) { |
| 114 | def salt = new com.mirantis.mk.Salt() |
| 115 | def node = salt.cmdRun(master, target, "kubectl get po conformance -n conformance -o wide -o=custom-columns=NODE:.spec.nodeName | tail -n +2")['return'][0].values()[0].replaceAll('Salt command execution success','').trim() |
| 116 | return node |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Get conformance results and logs |
| 121 | * |
| 122 | * @param ctl_target Target maps to all k8s masters |
| 123 | * @param artifacts_dir Artifacts_dir Local directory to push artifacts to |
| 124 | * @param output_file Output tar file that will be archived and (optional) published |
| 125 | * @param status Status of conformance run to react (if NOTEXECUTED - xml will never published) |
| 126 | * @param junitResults Whether or not build test graph |
| 127 | */ |
| 128 | def uploadConformanceContainerdResults(LinkedHashMap config) { |
| 129 | def salt = new com.mirantis.mk.Salt() |
| 130 | |
| 131 | // Listing defaults |
| 132 | def master = config.get('master', 'pepperVenv') |
| 133 | def target = config.get('target', 'I@kubernetes:master and ctl01*') |
| 134 | def status = config.get('status') |
| 135 | def ctl_target = config.get('ctl_target', 'I@kubernetes:master') |
| 136 | def results_dir = config.get('results_dir', '/tmp/conformance') |
| 137 | def artifacts_dir = config.get('artifacts_dir', '_artifacts/') |
| 138 | def output_file = config.get('output_file', 'conformance.tar') |
| 139 | def junitResults = config.get('junitResults', false) |
| 140 | // End listing defaults |
| 141 | |
| 142 | def short_node = locateConformancePod(master, target) |
| 143 | print("Pod located on $short_node") |
| 144 | |
| 145 | minions = salt.getMinionsSorted(master, ctl_target) |
| 146 | conformance_target = minions.find {it =~ short_node} |
| 147 | |
| 148 | if (status == 'NOTEXECUTED') { |
| 149 | salt.cmdRun(master, conformance_target, "test -e ${results_dir}/conformance.log || kubectl logs conformance -n conformance > ${results_dir}/conformance.log") |
| 150 | } else if (status == "PULLERR") { |
| 151 | print("Conformance image failed to pull. Skipping logs publishing") |
| 152 | return conformance_target |
| 153 | } else if (status == "UNKNOWN") { |
| 154 | print("Can not recognize pod status as acceptable. Skipping logs publishing") |
| 155 | return conformance_target |
| 156 | } |
| 157 | |
| 158 | print("Copy XML test results for junit artifacts and logs") |
| 159 | salt.runSaltProcessStep(master, conformance_target, 'cmd.run', ["tar -cf /tmp/${output_file} -C ${results_dir} ."]) |
| 160 | |
| 161 | writeFile file: "${artifacts_dir}${output_file}", text: salt.getFileContent(master, conformance_target, "/tmp/${output_file}") |
| 162 | sh "mkdir -p ${artifacts_dir}/conformance_tests" |
| 163 | sh "tar -xf ${artifacts_dir}${output_file} -C ${artifacts_dir}/conformance_tests" |
| 164 | sh "cat ${artifacts_dir}/conformance_tests/conformance.log" |
| 165 | if (junitResults.toBoolean() && (status == 'OK' || status == 'ERR')) { |
| 166 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 167 | archiveArtifacts artifacts: "${artifacts_dir}conformance_tests/conformance.log" |
| 168 | junit(keepLongStdio: true, testResults: "${artifacts_dir}conformance_tests/**.xml") |
| 169 | } |
| 170 | return conformance_target |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /** |
| 175 | * Clean conformance pod and tmp files |
| 176 | * |
| 177 | * @param target Node where conformance was executed\ |
| 178 | * @param results_dir Directory to clean up |
| 179 | */ |
| 180 | def cleanUpConformancePod(LinkedHashMap config) { |
| 181 | def salt = new com.mirantis.mk.Salt() |
| 182 | |
| 183 | // Listing defaults |
| 184 | def master = config.get('master', 'pepperVenv') |
| 185 | def target = config.get('target', 'I@kubernetes:master and ctl01*') |
| 186 | def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml') |
| 187 | def results_dir = config.get('results_dir', '/tmp/conformance') |
| 188 | def output_file = config.get('output_file', ) |
| 189 | // End listing defaults |
| 190 | |
| 191 | salt.cmdRun(master, target, "kubectl delete -f ${pod_path}") |
| 192 | salt.cmdRun(master, target, "rm -rf ${results_dir}", false) |
| 193 | salt.cmdRun(master, target, "rm -f ${output_file}", false) |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Throw exception if any |
| 198 | * |
| 199 | * @param status Conformance tests status |
| 200 | */ |
| 201 | def conformanceStatusReact(status) { |
| 202 | if (status == "ERR" || status == "NOTEXECUTED") { |
| 203 | throw new RuntimeException("Conformance tests failed") |
| 204 | } else if (status == "TIMEDOUT") { |
| 205 | throw new RuntimeException("Conformance tests timed out") |
| 206 | } else if (status == "PULLERR") { |
| 207 | throw new RuntimeException("Image is not exists or can not reach repository") |
| 208 | } else if (status == "UNKNOWN") { |
| 209 | throw new RuntimeException("Pod status unacceptable. Please check pipeline logs for more information") |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Orchestrate conformance tests inside kubernetes cluster |
| 215 | * |
| 216 | * @param junitResults Whether or not build junit graph |
| 217 | * @param autodetect Default behaviour - use version discovered on deployment. Non default - use image provided via image param |
| 218 | * @param image Can be used only if autodetection disabled. Overriding pod image. |
| 219 | * @param ctl_target Target maps to all k8s masters |
| 220 | * @param pod_path Path where conformance pod located |
| 221 | * @param results_dir Directory with results after conformance run |
| 222 | * @param artifacts_dir Local artifacts dir |
| 223 | * @param output_file Conformance tar output |
| 224 | */ |
| 225 | def executeConformance(LinkedHashMap config) { |
| 226 | // Listing defaults |
| 227 | def master = config.get('master', 'pepperVenv') |
| 228 | def target = config.get('target', 'I@kubernetes:master and ctl01*') |
| 229 | def junitResults = config.get('junitResults', false) |
| 230 | def autodetect = config.get('autodetect', true) |
| 231 | def image = config.get('image', null) |
| 232 | def ctl_target = config.get('ctl_target', 'I@kubernetes:master') |
| 233 | def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml') |
| 234 | def results_dir = config.get('results_dir', '/tmp/conformance') |
| 235 | def artifacts_dir = config.get('artifacts_dir', '_artifacts/') |
| 236 | def output_file = config.get('output_file', 'conformance.tar') |
| 237 | // End listing defaults |
| 238 | |
| 239 | // Check whether or not custom image is defined and apply it |
| 240 | passCustomConformanceImage(['master': master, 'ctl_target': ctl_target, 'pod_path': pod_path, 'autodetect': autodetect, 'image': image]) |
| 241 | |
| 242 | // Start conformance pod and get its status |
| 243 | status = runConformanceTestsOnContainerD('master': master, 'target': target, 'pod_path': pod_path) |
| 244 | |
| 245 | // Manage results |
| 246 | cleanup_target = uploadConformanceContainerdResults('master': master, 'target': target, 'status': status, 'ctl_target': ctl_target, 'results_dir': results_dir, 'artifacts_dir': artifacts_dir, 'output_file': output_file, 'junitResults': junitResults) |
| 247 | |
| 248 | // Do cleanup |
| 249 | cleanUpConformancePod('master': master, 'target': cleanup_target, 'pod_path': pod_path, 'results_dir': results_dir, 'output_file': output_file) |
| 250 | |
| 251 | // Throw exception to Jenkins if any |
| 252 | conformanceStatusReact(status) |
| 253 | } |
| 254 | |
| 255 | /** |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 256 | * Run e2e conformance tests |
| 257 | * |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 258 | * @param target Kubernetes node to run tests from |
| 259 | * @param k8s_api Kubernetes api address |
| 260 | * @param image Docker image with tests |
| 261 | * @param timeout Timeout waiting for e2e conformance tests |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 262 | */ |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 263 | def runConformanceTests(master, target, k8s_api, image, timeout=2400) { |
Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 264 | def salt = new com.mirantis.mk.Salt() |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 265 | def containerName = 'conformance_tests' |
Tomáš Kukrál | a7318f5 | 2017-04-21 16:15:29 +0200 | [diff] [blame] | 266 | def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output' |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 267 | salt.cmdRun(master, target, "docker rm -f ${containerName}", false) |
| 268 | 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] | 269 | sleep(10) |
| 270 | |
| 271 | print("Waiting for tests to run...") |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 272 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker wait ${containerName}"], null, false, timeout) |
Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 273 | |
| 274 | print("Writing test results to output file...") |
Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 275 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker logs -t ${containerName} > ${outfile}"]) |
Tomáš Kukrál | 798b3f5 | 2017-04-28 13:19:32 +0200 | [diff] [blame] | 276 | print("Conformance test output saved in " + outfile) |
Tatyana Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 277 | } |
| 278 | |
vrovachev | c3b47f4 | 2018-01-25 16:08:50 +0400 | [diff] [blame] | 279 | /** |
| 280 | * Upload conformance results to cfg node |
| 281 | * |
| 282 | * @param target Kubernetes node for copy test results |
| 283 | * @param artifacts_dir Path with test results |
| 284 | */ |
| 285 | def CopyConformanceResults(master, target, artifacts_dir, output_file) { |
| 286 | def salt = new com.mirantis.mk.Salt() |
| 287 | def containerName = 'conformance_tests' |
| 288 | def test_node = target.replace("*", "") |
| 289 | |
| 290 | out = salt.runSaltProcessStep(master, target, 'cmd.run', ["docker cp ${containerName}:/report /tmp"]) |
| 291 | if (! out['return'][0].values()[0].contains('Error')) { |
| 292 | print("Copy XML test results for junit artifacts...") |
| 293 | salt.runSaltProcessStep(master, target, 'cmd.run', ["tar -cf /tmp/${output_file} -C /tmp/report ."]) |
| 294 | |
| 295 | writeFile file: "${artifacts_dir}${output_file}", text: salt.getFileContent(master, |
| 296 | target, "/tmp/${output_file}") |
| 297 | |
| 298 | sh "mkdir -p ${artifacts_dir}/conformance_tests" |
| 299 | sh "tar -xf ${artifacts_dir}${output_file} -C ${artifacts_dir}/conformance_tests" |
| 300 | |
| 301 | // collect artifacts |
| 302 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 303 | |
| 304 | junit(keepLongStdio: true, testResults: "${artifacts_dir}conformance_tests/**.xml") |
| 305 | } |
| 306 | } |
| 307 | |
Tatyana Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 308 | /** |
| 309 | * Copy test output to cfg node |
| 310 | * |
| 311 | * @param image Docker image with tests |
| 312 | */ |
| 313 | def copyTestsOutput(master, image) { |
| 314 | def salt = new com.mirantis.mk.Salt() |
| 315 | salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["scp ctl01:/root/${image}.output /home/ubuntu/"]) |
| 316 | } |
| 317 | |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 318 | /** |
| 319 | * Execute tempest tests |
| 320 | * |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 321 | * @param dockerImageLink Docker image link with rally and tempest |
| 322 | * @param target Host to run tests |
Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 323 | * @param pattern If not false, will run only tests matched the pattern |
| 324 | * @param logDir Directory to store tempest/rally reports |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 325 | * @param sourceFile Path to the keystonerc file in the container |
| 326 | * @param set Predefined set for tempest tests |
| 327 | * @param concurrency How many processes to use to run Tempest tests |
| 328 | * @param tempestConf A tempest.conf's file name |
| 329 | * @param skipList A skip.list's file name |
| 330 | * @param localKeystone Path to the keystonerc file in the local host |
| 331 | * @param localLogDir Path to local destination folder for logs |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 332 | */ |
ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 333 | def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/", |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 334 | sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf", |
| 335 | skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports", |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 336 | doCleanupResources = "false") { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 337 | def salt = new com.mirantis.mk.Salt() |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 338 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"]) |
| 339 | def custom = '' |
ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 340 | if (pattern) { |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 341 | custom = "--pattern " + pattern |
Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 342 | } |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 343 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + |
| 344 | "-e SOURCE_FILE=${sourceFile} " + |
| 345 | "-e LOG_DIR=${logDir} " + |
| 346 | "-e SET=${set} " + |
Mykyta Karpin | 292c066 | 2017-11-13 12:07:52 +0200 | [diff] [blame] | 347 | "-e CUSTOM='${custom}' " + |
Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 348 | "-e CONCURRENCY=${concurrency} " + |
| 349 | "-e TEMPEST_CONF=${tempestConf} " + |
| 350 | "-e SKIP_LIST=${skipList} " + |
| 351 | "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " + |
| 352 | "-v ${localKeystone}:${sourceFile} " + |
| 353 | "-v ${localLogDir}:/home/rally/rally_reports " + |
| 354 | "-v /etc/ssl/certs/:/etc/ssl/certs/ " + |
| 355 | "${dockerImageLink} >> docker-tempest.log") |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 356 | } |
| 357 | |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 358 | |
| 359 | /** |
| 360 | * Execute Rally scenarios |
| 361 | * |
| 362 | * @param dockerImageLink Docker image link with rally and tempest |
| 363 | * @param target Host to run scenarios |
| 364 | * @param scenario Specify the scenario as a string |
| 365 | * @param containerName Docker container name |
| 366 | * @param doCleanupResources Do run clean-up script after tests? Cleans up OpenStack test resources |
| 367 | */ |
| 368 | def runRallyScenarios(master, dockerImageLink, target, scenario, logDir = "/home/rally/rally_reports/", |
| 369 | doCleanupResources = "false", containerName = "rally_ci") { |
| 370 | def salt = new com.mirantis.mk.Salt() |
Ievgeniia Zadorozhna | 5b97023 | 2017-09-13 13:31:43 +0300 | [diff] [blame] | 371 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"]) |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 372 | salt.cmdRun(master, target, "docker run --net=host -dit " + |
| 373 | "--name ${containerName} " + |
| 374 | "-e SOURCE_FILE=keystonercv3 " + |
| 375 | "-e SCENARIO=${scenario} " + |
| 376 | "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " + |
| 377 | "-e LOG_DIR=${logDir} " + |
| 378 | "--entrypoint /bin/bash -v /root/:/home/rally ${dockerImageLink}") |
| 379 | salt.cmdRun(master, target, "docker exec ${containerName} " + |
| 380 | "bash -c /usr/bin/run-rally | tee -a docker-rally.log") |
| 381 | } |
| 382 | |
| 383 | |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 384 | /** |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 385 | * Upload results to cfg01 node |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 386 | * |
| 387 | */ |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 388 | def copyTempestResults(master, target) { |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 389 | def salt = new com.mirantis.mk.Salt() |
Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 390 | if (! target.contains('cfg')) { |
ibumarskov | 5c31e28 | 2018-02-14 15:05:20 +0400 | [diff] [blame] | 391 | 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] | 392 | } |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 396 | /** Store tests results on host |
Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 397 | * |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 398 | * @param image Docker image name |
| 399 | */ |
| 400 | def catTestsOutput(master, image) { |
| 401 | def salt = new com.mirantis.mk.Salt() |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 402 | salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output") |
Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 403 | } |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 404 | |
| 405 | |
| 406 | /** Install docker if needed |
| 407 | * |
| 408 | * @param target Target node to install docker pkg |
| 409 | */ |
| 410 | def install_docker(master, target) { |
| 411 | def salt = new com.mirantis.mk.Salt() |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 412 | salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"]) |
Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 413 | } |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 414 | |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 415 | |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 416 | /** Upload Tempest test results to Testrail |
| 417 | * |
| 418 | * @param report Source report to upload |
| 419 | * @param image Testrail reporter image |
| 420 | * @param testGroup Testrail test group |
| 421 | * @param credentialsId Testrail credentials id |
| 422 | * @param plan Testrail test plan |
| 423 | * @param milestone Testrail test milestone |
| 424 | * @param suite Testrail test suite |
| 425 | * @param type Use local shell or remote salt connection |
| 426 | * @param master Salt connection. |
| 427 | * @param target Target node to install docker pkg |
| 428 | */ |
| 429 | |
| 430 | def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') { |
| 431 | def salt = new com.mirantis.mk.Salt() |
| 432 | def common = new com.mirantis.mk.Common() |
| 433 | creds = common.getPasswordCredentials(credentialsId) |
| 434 | command = "docker run --rm --net=host " + |
| 435 | "-v ${report}:/srv/report.xml " + |
| 436 | "-e TESTRAIL_USER=${creds.username} " + |
| 437 | "-e PASS=${creds.password.toString()} " + |
| 438 | "-e TESTRAIL_PLAN_NAME=${plan} " + |
| 439 | "-e TESTRAIL_MILESTONE=${milestone} " + |
| 440 | "-e TESTRAIL_SUITE=${suite} " + |
Mykyta Karpin | a5761a2 | 2017-08-16 16:09:56 +0300 | [diff] [blame] | 441 | "-e TEST_GROUP=${testGroup} " + |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 442 | "${image}" |
| 443 | if (master == null) { |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 444 | sh(command) |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 445 | } else { |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 446 | salt.cmdRun(master, target, command) |
Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 450 | /** Archive Rally results in Artifacts |
| 451 | * |
| 452 | * @param master Salt connection. |
| 453 | * @param target Target node to install docker pkg |
| 454 | * @param reports_dir Source directory to archive |
| 455 | */ |
| 456 | |
| 457 | def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') { |
| 458 | def salt = new com.mirantis.mk.Salt() |
| 459 | |
| 460 | def artifacts_dir = '_artifacts/' |
| 461 | def output_file = 'rally_reports.tar' |
| 462 | |
Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 463 | salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .") |
Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 464 | sh "mkdir -p ${artifacts_dir}" |
| 465 | |
Mykyta Karpin | f4be9e2 | 2017-08-09 18:59:57 +0300 | [diff] [blame] | 466 | 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] | 467 | |
| 468 | writeFile file: "${artifacts_dir}${output_file}", text: encoded |
| 469 | |
| 470 | // collect artifacts |
| 471 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 472 | } |
Jakub Josef | 1462c4b | 2017-08-18 11:15:03 +0200 | [diff] [blame] | 473 | /** |
| 474 | * Helper function for collecting junit tests results |
| 475 | * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class) |
| 476 | * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 477 | */ |
| 478 | @NonCPS |
| 479 | def collectJUnitResults(testResultAction) { |
| 480 | if (testResultAction != null) { |
| 481 | def total = testResultAction.totalCount |
| 482 | def failed = testResultAction.failCount |
| 483 | def skipped = testResultAction.skipCount |
| 484 | def passed = total - failed - skipped |
| 485 | return ["total": total, "passed": passed, "skipped": skipped, "failed": failed] |
| 486 | }else{ |
| 487 | def common = new com.mirantis.mk.Common() |
| 488 | common.errorMsg("Cannot collect jUnit tests results, given result is null") |
| 489 | } |
| 490 | return [:] |
| 491 | } |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 492 | |
| 493 | |
| 494 | /** Cleanup: Remove reports directory |
| 495 | * |
| 496 | * @param target Target node to remove repo |
| 497 | * @param reports_dir_name Reports directory name to be removed (that is in /root/ on target node) |
| 498 | * @param archive_artifacts_name Archive of the artifacts |
| 499 | */ |
| 500 | def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') { |
| 501 | def salt = new com.mirantis.mk.Salt() |
| 502 | salt.runSaltProcessStep(master, target, 'file.find', ["/root/${reports_dir_name}", '\\*', 'delete']) |
| 503 | salt.runSaltProcessStep(master, target, 'file.remove', ["/root/${archive_artifacts_name}"]) |
| 504 | } |
| 505 | |
| 506 | |
| 507 | /** Cleanup: Remove Docker container |
| 508 | * |
| 509 | * @param target Target node to remove Docker container |
| 510 | * @param image_link The link of the Docker image that was used for the container |
| 511 | */ |
Ievgeniia Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 512 | def removeDockerContainer(master, target, containerName) { |
Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 513 | def salt = new com.mirantis.mk.Salt() |
Ievgeniia Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 514 | salt.cmdRun(master, target, "docker rm -f ${containerName}") |
Oleh Hryhorov | 8365833 | 2017-10-10 10:45:12 +0300 | [diff] [blame] | 515 | } |