blob: 8c663e5ae748cde71fb7efedd817881a395447f2 [file] [log] [blame]
Jakub Josef79ecec32017-02-17 14:36:28 +01001package com.mirantis.mk
2
3/**
4 *
5 * Tests providing functions
6 *
7 */
8
9/**
Victor Ryzhenkin46da67a2018-11-30 00:17:55 +040010 * Get conformance pod statuses
11 *
12 * @param target Any control node of k8s
13 */
14def 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 */
27def 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 */
51def 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 */
113def 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 */
128def 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 */
180def 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 */
201def 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 */
225def 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 Josef79ecec32017-02-17 14:36:28 +0100256 * Run e2e conformance tests
257 *
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700258 * @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 Josef79ecec32017-02-17 14:36:28 +0100262 */
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700263def runConformanceTests(master, target, k8s_api, image, timeout=2400) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100264 def salt = new com.mirantis.mk.Salt()
Matthew Mosesohne5c07e82017-06-14 11:55:01 +0300265 def containerName = 'conformance_tests'
Tomáš Kukrála7318f52017-04-21 16:15:29 +0200266 def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output'
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700267 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 Mosesohne5c07e82017-06-14 11:55:01 +0300269 sleep(10)
270
271 print("Waiting for tests to run...")
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700272 salt.runSaltProcessStep(master, target, 'cmd.run', ["docker wait ${containerName}"], null, false, timeout)
Matthew Mosesohne5c07e82017-06-14 11:55:01 +0300273
274 print("Writing test results to output file...")
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700275 salt.runSaltProcessStep(master, target, 'cmd.run', ["docker logs -t ${containerName} > ${outfile}"])
Tomáš Kukrál798b3f52017-04-28 13:19:32 +0200276 print("Conformance test output saved in " + outfile)
Tatyana Leontovichc73d63c2017-02-28 14:41:38 +0200277}
278
vrovachevc3b47f42018-01-25 16:08:50 +0400279/**
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 */
285def 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 Leontovichc73d63c2017-02-28 14:41:38 +0200308/**
309 * Copy test output to cfg node
310 *
311 * @param image Docker image with tests
312 */
313def 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 Ryzhenkinc5b30292017-02-21 19:26:24 +0400318/**
319 * Execute tempest tests
320 *
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300321 * @param dockerImageLink Docker image link with rally and tempest
322 * @param target Host to run tests
Mykyta Karpin80f527e2017-08-14 15:18:03 +0300323 * @param pattern If not false, will run only tests matched the pattern
324 * @param logDir Directory to store tempest/rally reports
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300325 * @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 Ryzhenkinc5b30292017-02-21 19:26:24 +0400332 */
ibumarskov374188e2017-12-14 10:54:09 +0400333def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/",
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300334 sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf",
335 skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports",
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300336 doCleanupResources = "false") {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400337 def salt = new com.mirantis.mk.Salt()
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300338 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"])
339 def custom = ''
ibumarskov374188e2017-12-14 10:54:09 +0400340 if (pattern) {
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300341 custom = "--pattern " + pattern
Mykyta Karpin07ba87f2017-07-27 13:56:33 +0300342 }
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300343 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
344 "-e SOURCE_FILE=${sourceFile} " +
345 "-e LOG_DIR=${logDir} " +
346 "-e SET=${set} " +
Mykyta Karpin292c0662017-11-13 12:07:52 +0200347 "-e CUSTOM='${custom}' " +
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300348 "-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 Ryzhenkinc5b30292017-02-21 19:26:24 +0400356}
357
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300358
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 */
368def 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 Zadorozhna5b970232017-09-13 13:31:43 +0300371 salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"])
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300372 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 Ryzhenkinc5b30292017-02-21 19:26:24 +0400384/**
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300385 * Upload results to cfg01 node
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400386 *
387 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300388def copyTempestResults(master, target) {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400389 def salt = new com.mirantis.mk.Salt()
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300390 if (! target.contains('cfg')) {
ibumarskov5c31e282018-02-14 15:05:20 +0400391 salt.cmdRun(master, target, "mkdir -p /root/rally_reports/ && rsync -av /root/rally_reports/ cfg01:/root/rally_reports/")
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300392 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400393}
394
395
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200396/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400397 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200398 * @param image Docker image name
399 */
400def catTestsOutput(master, image) {
401 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100402 salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output")
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200403}
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300404
405
406/** Install docker if needed
407 *
408 * @param target Target node to install docker pkg
409 */
410def install_docker(master, target) {
411 def salt = new com.mirantis.mk.Salt()
Ivan Berezovskiya147b482018-12-12 19:56:30 +0400412 def dockerPackagesPillar = salt.getPillar(master, target, 'docker:host:pkgs')
413 def dockerPackages = salt.getReturnValues(dockerPackagesPillar) ?: ['docker.io']
414 salt.runSaltProcessStep(master, target, 'pkg.install', dockerPackages)
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300415}
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300416
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300417
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300418/** Upload Tempest test results to Testrail
419 *
420 * @param report Source report to upload
421 * @param image Testrail reporter image
422 * @param testGroup Testrail test group
423 * @param credentialsId Testrail credentials id
424 * @param plan Testrail test plan
425 * @param milestone Testrail test milestone
426 * @param suite Testrail test suite
427 * @param type Use local shell or remote salt connection
428 * @param master Salt connection.
429 * @param target Target node to install docker pkg
430 */
431
432def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') {
433 def salt = new com.mirantis.mk.Salt()
434 def common = new com.mirantis.mk.Common()
435 creds = common.getPasswordCredentials(credentialsId)
436 command = "docker run --rm --net=host " +
437 "-v ${report}:/srv/report.xml " +
438 "-e TESTRAIL_USER=${creds.username} " +
439 "-e PASS=${creds.password.toString()} " +
440 "-e TESTRAIL_PLAN_NAME=${plan} " +
441 "-e TESTRAIL_MILESTONE=${milestone} " +
442 "-e TESTRAIL_SUITE=${suite} " +
Mykyta Karpina5761a22017-08-16 16:09:56 +0300443 "-e TEST_GROUP=${testGroup} " +
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300444 "${image}"
445 if (master == null) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100446 sh(command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300447 } else {
Jakub Josef432e9d92018-02-06 18:28:37 +0100448 salt.cmdRun(master, target, command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300449 }
450}
451
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300452/** Archive Rally results in Artifacts
453 *
454 * @param master Salt connection.
455 * @param target Target node to install docker pkg
456 * @param reports_dir Source directory to archive
457 */
458
459def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') {
460 def salt = new com.mirantis.mk.Salt()
461
462 def artifacts_dir = '_artifacts/'
463 def output_file = 'rally_reports.tar'
464
Jakub Josef432e9d92018-02-06 18:28:37 +0100465 salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .")
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300466 sh "mkdir -p ${artifacts_dir}"
467
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300468 encoded = salt.cmdRun(master, target, "cat /root/${output_file}", true, null, false)['return'][0].values()[0].replaceAll('Salt command execution success','')
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300469
470 writeFile file: "${artifacts_dir}${output_file}", text: encoded
471
472 // collect artifacts
473 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
474}
Jakub Josef1462c4b2017-08-18 11:15:03 +0200475/**
476 * Helper function for collecting junit tests results
477 * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
478 * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
479 */
480@NonCPS
481def collectJUnitResults(testResultAction) {
482 if (testResultAction != null) {
483 def total = testResultAction.totalCount
484 def failed = testResultAction.failCount
485 def skipped = testResultAction.skipCount
486 def passed = total - failed - skipped
487 return ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
488 }else{
489 def common = new com.mirantis.mk.Common()
490 common.errorMsg("Cannot collect jUnit tests results, given result is null")
491 }
492 return [:]
493}
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300494
495
496/** Cleanup: Remove reports directory
497 *
498 * @param target Target node to remove repo
499 * @param reports_dir_name Reports directory name to be removed (that is in /root/ on target node)
500 * @param archive_artifacts_name Archive of the artifacts
501 */
502def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') {
503 def salt = new com.mirantis.mk.Salt()
504 salt.runSaltProcessStep(master, target, 'file.find', ["/root/${reports_dir_name}", '\\*', 'delete'])
505 salt.runSaltProcessStep(master, target, 'file.remove', ["/root/${archive_artifacts_name}"])
506}
507
508
509/** Cleanup: Remove Docker container
510 *
511 * @param target Target node to remove Docker container
512 * @param image_link The link of the Docker image that was used for the container
513 */
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300514def removeDockerContainer(master, target, containerName) {
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300515 def salt = new com.mirantis.mk.Salt()
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300516 salt.cmdRun(master, target, "docker rm -f ${containerName}")
Oleh Hryhorov83658332017-10-10 10:45:12 +0300517}