blob: aadeb8ae4a0875973026ab202f8aa6af879ffc7b [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/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500319 * DEPRECATED
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400320 * Execute tempest tests
321 *
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300322 * @param dockerImageLink Docker image link with rally and tempest
323 * @param target Host to run tests
Mykyta Karpin80f527e2017-08-14 15:18:03 +0300324 * @param pattern If not false, will run only tests matched the pattern
325 * @param logDir Directory to store tempest/rally reports
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300326 * @param sourceFile Path to the keystonerc file in the container
327 * @param set Predefined set for tempest tests
328 * @param concurrency How many processes to use to run Tempest tests
329 * @param tempestConf A tempest.conf's file name
330 * @param skipList A skip.list's file name
331 * @param localKeystone Path to the keystonerc file in the local host
332 * @param localLogDir Path to local destination folder for logs
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400333 */
ibumarskov374188e2017-12-14 10:54:09 +0400334def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/",
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300335 sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf",
336 skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports",
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300337 doCleanupResources = "false") {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400338 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500339 def common = new com.mirantis.mk.Common()
340 common.errorMsg('You are using deprecated method! This method will be removed')
341 error('You are using deprecated method! This method will be removed')
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300342 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"])
343 def custom = ''
ibumarskov374188e2017-12-14 10:54:09 +0400344 if (pattern) {
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300345 custom = "--pattern " + pattern
Mykyta Karpin07ba87f2017-07-27 13:56:33 +0300346 }
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300347 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
348 "-e SOURCE_FILE=${sourceFile} " +
349 "-e LOG_DIR=${logDir} " +
350 "-e SET=${set} " +
Mykyta Karpin292c0662017-11-13 12:07:52 +0200351 "-e CUSTOM='${custom}' " +
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300352 "-e CONCURRENCY=${concurrency} " +
353 "-e TEMPEST_CONF=${tempestConf} " +
354 "-e SKIP_LIST=${skipList} " +
355 "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " +
356 "-v ${localKeystone}:${sourceFile} " +
357 "-v ${localLogDir}:/home/rally/rally_reports " +
358 "-v /etc/ssl/certs/:/etc/ssl/certs/ " +
359 "${dockerImageLink} >> docker-tempest.log")
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400360}
361
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300362
363/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500364 * DEPRECATED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300365 * Execute Rally scenarios
366 *
367 * @param dockerImageLink Docker image link with rally and tempest
368 * @param target Host to run scenarios
369 * @param scenario Specify the scenario as a string
370 * @param containerName Docker container name
371 * @param doCleanupResources Do run clean-up script after tests? Cleans up OpenStack test resources
372 */
373def runRallyScenarios(master, dockerImageLink, target, scenario, logDir = "/home/rally/rally_reports/",
374 doCleanupResources = "false", containerName = "rally_ci") {
375 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500376 def common = new com.mirantis.mk.Common()
377 common.errorMsg('You are using deprecated method! This method will be removed')
378 error('You are using deprecated method! This method will be removed')
Ievgeniia Zadorozhna5b970232017-09-13 13:31:43 +0300379 salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"])
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300380 salt.cmdRun(master, target, "docker run --net=host -dit " +
381 "--name ${containerName} " +
382 "-e SOURCE_FILE=keystonercv3 " +
383 "-e SCENARIO=${scenario} " +
384 "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " +
385 "-e LOG_DIR=${logDir} " +
386 "--entrypoint /bin/bash -v /root/:/home/rally ${dockerImageLink}")
387 salt.cmdRun(master, target, "docker exec ${containerName} " +
388 "bash -c /usr/bin/run-rally | tee -a docker-rally.log")
389}
390
391
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400392/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500393 * DEPRECATED
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300394 * Upload results to cfg01 node
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400395 *
396 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300397def copyTempestResults(master, target) {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400398 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500399 def common = new com.mirantis.mk.Common()
400 common.errorMsg('You are using deprecated method! Use validate.addFiles instead. This method will be removed')
401 error('You are using deprecated method! Use validate.addFiles instead. This method will be removed')
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300402 if (! target.contains('cfg')) {
ibumarskov5c31e282018-02-14 15:05:20 +0400403 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 +0300404 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400405}
406
407
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200408/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400409 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200410 * @param image Docker image name
411 */
412def catTestsOutput(master, image) {
413 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100414 salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output")
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200415}
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300416
417
418/** Install docker if needed
419 *
420 * @param target Target node to install docker pkg
421 */
422def install_docker(master, target) {
423 def salt = new com.mirantis.mk.Salt()
Ivan Berezovskiya147b482018-12-12 19:56:30 +0400424 def dockerPackagesPillar = salt.getPillar(master, target, 'docker:host:pkgs')
425 def dockerPackages = salt.getReturnValues(dockerPackagesPillar) ?: ['docker.io']
Mykyta Karpin495d0292019-01-25 10:58:19 +0200426 salt.runSaltProcessStep(master, target, 'pkg.install', [dockerPackages.join(',')])
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300427}
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300428
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300429
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300430/** Upload Tempest test results to Testrail
431 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500432 * DEPRECATED
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300433 * @param report Source report to upload
434 * @param image Testrail reporter image
435 * @param testGroup Testrail test group
436 * @param credentialsId Testrail credentials id
437 * @param plan Testrail test plan
438 * @param milestone Testrail test milestone
439 * @param suite Testrail test suite
440 * @param type Use local shell or remote salt connection
441 * @param master Salt connection.
442 * @param target Target node to install docker pkg
443 */
444
445def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') {
446 def salt = new com.mirantis.mk.Salt()
447 def common = new com.mirantis.mk.Common()
Oleksii Zhurba757bc582019-04-11 10:27:12 -0500448 common.errorMsg('We may deprecated this method! Check tcp_qa Common.uploadResultsTestRail instead.')
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300449 creds = common.getPasswordCredentials(credentialsId)
450 command = "docker run --rm --net=host " +
451 "-v ${report}:/srv/report.xml " +
452 "-e TESTRAIL_USER=${creds.username} " +
453 "-e PASS=${creds.password.toString()} " +
454 "-e TESTRAIL_PLAN_NAME=${plan} " +
455 "-e TESTRAIL_MILESTONE=${milestone} " +
456 "-e TESTRAIL_SUITE=${suite} " +
Mykyta Karpina5761a22017-08-16 16:09:56 +0300457 "-e TEST_GROUP=${testGroup} " +
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300458 "${image}"
459 if (master == null) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100460 sh(command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300461 } else {
Jakub Josef432e9d92018-02-06 18:28:37 +0100462 salt.cmdRun(master, target, command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300463 }
464}
465
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300466/** Archive Rally results in Artifacts
467 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500468 * DEPRECATED
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300469 * @param master Salt connection.
470 * @param target Target node to install docker pkg
471 * @param reports_dir Source directory to archive
472 */
473
474def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') {
475 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500476 def common = new com.mirantis.mk.Common()
477 common.errorMsg('You are using deprecated method! This method will be removed')
478 error('You are using deprecated method! This method will be removed')
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300479 def artifacts_dir = '_artifacts/'
480 def output_file = 'rally_reports.tar'
481
Jakub Josef432e9d92018-02-06 18:28:37 +0100482 salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .")
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300483 sh "mkdir -p ${artifacts_dir}"
484
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300485 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 +0300486
487 writeFile file: "${artifacts_dir}${output_file}", text: encoded
488
489 // collect artifacts
490 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
491}
Jakub Josef1462c4b2017-08-18 11:15:03 +0200492/**
493 * Helper function for collecting junit tests results
494 * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
495 * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
496 */
497@NonCPS
498def collectJUnitResults(testResultAction) {
499 if (testResultAction != null) {
500 def total = testResultAction.totalCount
501 def failed = testResultAction.failCount
502 def skipped = testResultAction.skipCount
503 def passed = total - failed - skipped
504 return ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
505 }else{
506 def common = new com.mirantis.mk.Common()
507 common.errorMsg("Cannot collect jUnit tests results, given result is null")
508 }
509 return [:]
510}
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300511
512
513/** Cleanup: Remove reports directory
514 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500515 * DEPRECATED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300516 * @param target Target node to remove repo
517 * @param reports_dir_name Reports directory name to be removed (that is in /root/ on target node)
518 * @param archive_artifacts_name Archive of the artifacts
519 */
520def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') {
521 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500522 def common = new com.mirantis.mk.Common()
523 common.errorMsg('You are using deprecated method! This method will be removed')
524 error('You are using deprecated method! This method will be removed')
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300525 salt.runSaltProcessStep(master, target, 'file.find', ["/root/${reports_dir_name}", '\\*', 'delete'])
526 salt.runSaltProcessStep(master, target, 'file.remove', ["/root/${archive_artifacts_name}"])
527}
528
529
530/** Cleanup: Remove Docker container
531 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500532 * DEPREACTED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300533 * @param target Target node to remove Docker container
534 * @param image_link The link of the Docker image that was used for the container
535 */
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300536def removeDockerContainer(master, target, containerName) {
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300537 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500538 def common = new com.mirantis.mk.Common()
539 common.errorMsg('You are using deprecated method! Use validate.runCleanup instead. This method will be removed')
540 error('You are using deprecated method! Use validate.runCleanup instead. This method will be removed')
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300541 salt.cmdRun(master, target, "docker rm -f ${containerName}")
Oleh Hryhorov83658332017-10-10 10:45:12 +0300542}