blob: 404c6f8a73be7c1320181a3f43e020dc117916e7 [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')
ibumarskov4e96bd02019-05-30 12:27:00 +0200136 def k8s_pool_target = config.get('k8s_pool_target', 'I@kubernetes:pool')
Victor Ryzhenkin46da67a2018-11-30 00:17:55 +0400137 def results_dir = config.get('results_dir', '/tmp/conformance')
138 def artifacts_dir = config.get('artifacts_dir', '_artifacts/')
139 def output_file = config.get('output_file', 'conformance.tar')
140 def junitResults = config.get('junitResults', false)
141 // End listing defaults
142
143 def short_node = locateConformancePod(master, target)
144 print("Pod located on $short_node")
145
ibumarskov4e96bd02019-05-30 12:27:00 +0200146 minions = salt.getMinionsSorted(master, k8s_pool_target)
Victor Ryzhenkin46da67a2018-11-30 00:17:55 +0400147 conformance_target = minions.find {it =~ short_node}
148
149 if (status == 'NOTEXECUTED') {
150 salt.cmdRun(master, conformance_target, "test -e ${results_dir}/conformance.log || kubectl logs conformance -n conformance > ${results_dir}/conformance.log")
151 } else if (status == "PULLERR") {
152 print("Conformance image failed to pull. Skipping logs publishing")
153 return conformance_target
154 } else if (status == "UNKNOWN") {
155 print("Can not recognize pod status as acceptable. Skipping logs publishing")
156 return conformance_target
157 }
158
159 print("Copy XML test results for junit artifacts and logs")
160 salt.runSaltProcessStep(master, conformance_target, 'cmd.run', ["tar -cf /tmp/${output_file} -C ${results_dir} ."])
161
162 writeFile file: "${artifacts_dir}${output_file}", text: salt.getFileContent(master, conformance_target, "/tmp/${output_file}")
163 sh "mkdir -p ${artifacts_dir}/conformance_tests"
164 sh "tar -xf ${artifacts_dir}${output_file} -C ${artifacts_dir}/conformance_tests"
165 sh "cat ${artifacts_dir}/conformance_tests/conformance.log"
166 if (junitResults.toBoolean() && (status == 'OK' || status == 'ERR')) {
167 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
168 archiveArtifacts artifacts: "${artifacts_dir}conformance_tests/conformance.log"
169 junit(keepLongStdio: true, testResults: "${artifacts_dir}conformance_tests/**.xml")
170 }
171 return conformance_target
172}
173
174
175/**
176 * Clean conformance pod and tmp files
177 *
178 * @param target Node where conformance was executed\
179 * @param results_dir Directory to clean up
180 */
181def cleanUpConformancePod(LinkedHashMap config) {
182 def salt = new com.mirantis.mk.Salt()
183
184 // Listing defaults
185 def master = config.get('master', 'pepperVenv')
186 def target = config.get('target', 'I@kubernetes:master and ctl01*')
ibumarskov4e96bd02019-05-30 12:27:00 +0200187 def ctl_target = config.get('ctl_target', 'I@kubernetes:master and ctl01*')
Victor Ryzhenkin46da67a2018-11-30 00:17:55 +0400188 def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml')
189 def results_dir = config.get('results_dir', '/tmp/conformance')
190 def output_file = config.get('output_file', )
191 // End listing defaults
192
ibumarskov4e96bd02019-05-30 12:27:00 +0200193 salt.cmdRun(master, ctl_target, "kubectl delete -f ${pod_path}")
Victor Ryzhenkin46da67a2018-11-30 00:17:55 +0400194 salt.cmdRun(master, target, "rm -rf ${results_dir}", false)
195 salt.cmdRun(master, target, "rm -f ${output_file}", false)
196}
197
198/**
199 * Throw exception if any
200 *
201 * @param status Conformance tests status
202 */
203def conformanceStatusReact(status) {
204 if (status == "ERR" || status == "NOTEXECUTED") {
205 throw new RuntimeException("Conformance tests failed")
206 } else if (status == "TIMEDOUT") {
207 throw new RuntimeException("Conformance tests timed out")
208 } else if (status == "PULLERR") {
209 throw new RuntimeException("Image is not exists or can not reach repository")
210 } else if (status == "UNKNOWN") {
211 throw new RuntimeException("Pod status unacceptable. Please check pipeline logs for more information")
212 }
213}
214
215/**
216 * Orchestrate conformance tests inside kubernetes cluster
217 *
218 * @param junitResults Whether or not build junit graph
219 * @param autodetect Default behaviour - use version discovered on deployment. Non default - use image provided via image param
220 * @param image Can be used only if autodetection disabled. Overriding pod image.
221 * @param ctl_target Target maps to all k8s masters
222 * @param pod_path Path where conformance pod located
223 * @param results_dir Directory with results after conformance run
224 * @param artifacts_dir Local artifacts dir
225 * @param output_file Conformance tar output
226 */
227def executeConformance(LinkedHashMap config) {
228 // Listing defaults
229 def master = config.get('master', 'pepperVenv')
230 def target = config.get('target', 'I@kubernetes:master and ctl01*')
231 def junitResults = config.get('junitResults', false)
232 def autodetect = config.get('autodetect', true)
233 def image = config.get('image', null)
234 def ctl_target = config.get('ctl_target', 'I@kubernetes:master')
235 def pod_path = config.get('pod_path', '/srv/kubernetes/conformance.yml')
236 def results_dir = config.get('results_dir', '/tmp/conformance')
237 def artifacts_dir = config.get('artifacts_dir', '_artifacts/')
238 def output_file = config.get('output_file', 'conformance.tar')
239 // End listing defaults
240
241 // Check whether or not custom image is defined and apply it
242 passCustomConformanceImage(['master': master, 'ctl_target': ctl_target, 'pod_path': pod_path, 'autodetect': autodetect, 'image': image])
243
244 // Start conformance pod and get its status
245 status = runConformanceTestsOnContainerD('master': master, 'target': target, 'pod_path': pod_path)
246
247 // Manage results
248 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)
249
250 // Do cleanup
251 cleanUpConformancePod('master': master, 'target': cleanup_target, 'pod_path': pod_path, 'results_dir': results_dir, 'output_file': output_file)
252
253 // Throw exception to Jenkins if any
254 conformanceStatusReact(status)
255}
256
257/**
Jakub Josef79ecec32017-02-17 14:36:28 +0100258 * Run e2e conformance tests
259 *
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700260 * @param target Kubernetes node to run tests from
261 * @param k8s_api Kubernetes api address
262 * @param image Docker image with tests
263 * @param timeout Timeout waiting for e2e conformance tests
Jakub Josef79ecec32017-02-17 14:36:28 +0100264 */
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700265def runConformanceTests(master, target, k8s_api, image, timeout=2400) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100266 def salt = new com.mirantis.mk.Salt()
Matthew Mosesohne5c07e82017-06-14 11:55:01 +0300267 def containerName = 'conformance_tests'
Tomáš Kukrála7318f52017-04-21 16:15:29 +0200268 def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output'
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700269 salt.cmdRun(master, target, "docker rm -f ${containerName}", false)
270 salt.cmdRun(master, target, "docker run -d --name ${containerName} --net=host -e API_SERVER=${k8s_api} ${image}")
Matthew Mosesohne5c07e82017-06-14 11:55:01 +0300271 sleep(10)
272
273 print("Waiting for tests to run...")
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700274 salt.runSaltProcessStep(master, target, 'cmd.run', ["docker wait ${containerName}"], null, false, timeout)
Matthew Mosesohne5c07e82017-06-14 11:55:01 +0300275
276 print("Writing test results to output file...")
Tetiana Korchakf500ab92017-09-27 14:53:51 -0700277 salt.runSaltProcessStep(master, target, 'cmd.run', ["docker logs -t ${containerName} > ${outfile}"])
Tomáš Kukrál798b3f52017-04-28 13:19:32 +0200278 print("Conformance test output saved in " + outfile)
Tatyana Leontovichc73d63c2017-02-28 14:41:38 +0200279}
280
vrovachevc3b47f42018-01-25 16:08:50 +0400281/**
282 * Upload conformance results to cfg node
283 *
284 * @param target Kubernetes node for copy test results
285 * @param artifacts_dir Path with test results
286 */
287def CopyConformanceResults(master, target, artifacts_dir, output_file) {
288 def salt = new com.mirantis.mk.Salt()
289 def containerName = 'conformance_tests'
290 def test_node = target.replace("*", "")
291
292 out = salt.runSaltProcessStep(master, target, 'cmd.run', ["docker cp ${containerName}:/report /tmp"])
293 if (! out['return'][0].values()[0].contains('Error')) {
294 print("Copy XML test results for junit artifacts...")
295 salt.runSaltProcessStep(master, target, 'cmd.run', ["tar -cf /tmp/${output_file} -C /tmp/report ."])
296
297 writeFile file: "${artifacts_dir}${output_file}", text: salt.getFileContent(master,
298 target, "/tmp/${output_file}")
299
300 sh "mkdir -p ${artifacts_dir}/conformance_tests"
301 sh "tar -xf ${artifacts_dir}${output_file} -C ${artifacts_dir}/conformance_tests"
302
303 // collect artifacts
304 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
305
306 junit(keepLongStdio: true, testResults: "${artifacts_dir}conformance_tests/**.xml")
307 }
308}
309
Tatyana Leontovichc73d63c2017-02-28 14:41:38 +0200310/**
311 * Copy test output to cfg node
312 *
313 * @param image Docker image with tests
314 */
315def copyTestsOutput(master, image) {
316 def salt = new com.mirantis.mk.Salt()
317 salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["scp ctl01:/root/${image}.output /home/ubuntu/"])
318}
319
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400320/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500321 * DEPRECATED
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400322 * Execute tempest tests
323 *
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300324 * @param dockerImageLink Docker image link with rally and tempest
325 * @param target Host to run tests
Mykyta Karpin80f527e2017-08-14 15:18:03 +0300326 * @param pattern If not false, will run only tests matched the pattern
327 * @param logDir Directory to store tempest/rally reports
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300328 * @param sourceFile Path to the keystonerc file in the container
329 * @param set Predefined set for tempest tests
330 * @param concurrency How many processes to use to run Tempest tests
331 * @param tempestConf A tempest.conf's file name
332 * @param skipList A skip.list's file name
333 * @param localKeystone Path to the keystonerc file in the local host
334 * @param localLogDir Path to local destination folder for logs
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400335 */
ibumarskov374188e2017-12-14 10:54:09 +0400336def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/",
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300337 sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf",
338 skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports",
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300339 doCleanupResources = "false") {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400340 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500341 def common = new com.mirantis.mk.Common()
342 common.errorMsg('You are using deprecated method! This method will be removed')
343 error('You are using deprecated method! This method will be removed')
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300344 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"])
345 def custom = ''
ibumarskov374188e2017-12-14 10:54:09 +0400346 if (pattern) {
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300347 custom = "--pattern " + pattern
Mykyta Karpin07ba87f2017-07-27 13:56:33 +0300348 }
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300349 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
350 "-e SOURCE_FILE=${sourceFile} " +
351 "-e LOG_DIR=${logDir} " +
352 "-e SET=${set} " +
Mykyta Karpin292c0662017-11-13 12:07:52 +0200353 "-e CUSTOM='${custom}' " +
Oleksandr Kosse74bbab72017-10-11 13:48:18 +0300354 "-e CONCURRENCY=${concurrency} " +
355 "-e TEMPEST_CONF=${tempestConf} " +
356 "-e SKIP_LIST=${skipList} " +
357 "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " +
358 "-v ${localKeystone}:${sourceFile} " +
359 "-v ${localLogDir}:/home/rally/rally_reports " +
360 "-v /etc/ssl/certs/:/etc/ssl/certs/ " +
361 "${dockerImageLink} >> docker-tempest.log")
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400362}
363
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300364
365/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500366 * DEPRECATED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300367 * Execute Rally scenarios
368 *
369 * @param dockerImageLink Docker image link with rally and tempest
370 * @param target Host to run scenarios
371 * @param scenario Specify the scenario as a string
372 * @param containerName Docker container name
373 * @param doCleanupResources Do run clean-up script after tests? Cleans up OpenStack test resources
374 */
375def runRallyScenarios(master, dockerImageLink, target, scenario, logDir = "/home/rally/rally_reports/",
376 doCleanupResources = "false", containerName = "rally_ci") {
377 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500378 def common = new com.mirantis.mk.Common()
379 common.errorMsg('You are using deprecated method! This method will be removed')
380 error('You are using deprecated method! This method will be removed')
Ievgeniia Zadorozhna5b970232017-09-13 13:31:43 +0300381 salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"])
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300382 salt.cmdRun(master, target, "docker run --net=host -dit " +
383 "--name ${containerName} " +
384 "-e SOURCE_FILE=keystonercv3 " +
385 "-e SCENARIO=${scenario} " +
386 "-e DO_CLEANUP_RESOURCES=${doCleanupResources} " +
387 "-e LOG_DIR=${logDir} " +
388 "--entrypoint /bin/bash -v /root/:/home/rally ${dockerImageLink}")
389 salt.cmdRun(master, target, "docker exec ${containerName} " +
390 "bash -c /usr/bin/run-rally | tee -a docker-rally.log")
391}
392
393
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400394/**
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500395 * DEPRECATED
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300396 * Upload results to cfg01 node
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400397 *
398 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300399def copyTempestResults(master, target) {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400400 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500401 def common = new com.mirantis.mk.Common()
402 common.errorMsg('You are using deprecated method! Use validate.addFiles instead. This method will be removed')
403 error('You are using deprecated method! Use validate.addFiles instead. This method will be removed')
Vasyl Saienkod1dd1332017-08-03 15:22:42 +0300404 if (! target.contains('cfg')) {
ibumarskov5c31e282018-02-14 15:05:20 +0400405 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 +0300406 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400407}
408
409
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200410/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +0400411 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200412 * @param image Docker image name
413 */
414def catTestsOutput(master, image) {
415 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100416 salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output")
Tatyana Leontovich01704b32017-03-06 12:26:33 +0200417}
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300418
419
420/** Install docker if needed
421 *
422 * @param target Target node to install docker pkg
423 */
424def install_docker(master, target) {
425 def salt = new com.mirantis.mk.Salt()
Ivan Berezovskiya147b482018-12-12 19:56:30 +0400426 def dockerPackagesPillar = salt.getPillar(master, target, 'docker:host:pkgs')
427 def dockerPackages = salt.getReturnValues(dockerPackagesPillar) ?: ['docker.io']
Mykyta Karpin495d0292019-01-25 10:58:19 +0200428 salt.runSaltProcessStep(master, target, 'pkg.install', [dockerPackages.join(',')])
Tatyana Leontovich060e1152017-07-10 17:25:37 +0300429}
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300430
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300431
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300432/** Upload Tempest test results to Testrail
433 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500434 * DEPRECATED
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300435 * @param report Source report to upload
436 * @param image Testrail reporter image
437 * @param testGroup Testrail test group
438 * @param credentialsId Testrail credentials id
439 * @param plan Testrail test plan
440 * @param milestone Testrail test milestone
441 * @param suite Testrail test suite
442 * @param type Use local shell or remote salt connection
443 * @param master Salt connection.
444 * @param target Target node to install docker pkg
445 */
446
447def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') {
448 def salt = new com.mirantis.mk.Salt()
449 def common = new com.mirantis.mk.Common()
Oleksii Zhurba757bc582019-04-11 10:27:12 -0500450 common.errorMsg('We may deprecated this method! Check tcp_qa Common.uploadResultsTestRail instead.')
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300451 creds = common.getPasswordCredentials(credentialsId)
452 command = "docker run --rm --net=host " +
453 "-v ${report}:/srv/report.xml " +
454 "-e TESTRAIL_USER=${creds.username} " +
455 "-e PASS=${creds.password.toString()} " +
456 "-e TESTRAIL_PLAN_NAME=${plan} " +
457 "-e TESTRAIL_MILESTONE=${milestone} " +
458 "-e TESTRAIL_SUITE=${suite} " +
Mykyta Karpina5761a22017-08-16 16:09:56 +0300459 "-e TEST_GROUP=${testGroup} " +
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300460 "${image}"
461 if (master == null) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100462 sh(command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300463 } else {
Jakub Josef432e9d92018-02-06 18:28:37 +0100464 salt.cmdRun(master, target, command)
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300465 }
466}
467
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300468/** Archive Rally results in Artifacts
469 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500470 * DEPRECATED
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300471 * @param master Salt connection.
472 * @param target Target node to install docker pkg
473 * @param reports_dir Source directory to archive
474 */
475
476def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') {
477 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500478 def common = new com.mirantis.mk.Common()
479 common.errorMsg('You are using deprecated method! This method will be removed')
480 error('You are using deprecated method! This method will be removed')
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300481 def artifacts_dir = '_artifacts/'
482 def output_file = 'rally_reports.tar'
483
Jakub Josef432e9d92018-02-06 18:28:37 +0100484 salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .")
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300485 sh "mkdir -p ${artifacts_dir}"
486
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300487 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 +0300488
489 writeFile file: "${artifacts_dir}${output_file}", text: encoded
490
491 // collect artifacts
492 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
493}
Jakub Josef1462c4b2017-08-18 11:15:03 +0200494/**
495 * Helper function for collecting junit tests results
496 * @param testResultAction - test result from build - use: currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
497 * @return resultMap with structure ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
498 */
499@NonCPS
500def collectJUnitResults(testResultAction) {
501 if (testResultAction != null) {
502 def total = testResultAction.totalCount
503 def failed = testResultAction.failCount
504 def skipped = testResultAction.skipCount
505 def passed = total - failed - skipped
506 return ["total": total, "passed": passed, "skipped": skipped, "failed": failed]
507 }else{
508 def common = new com.mirantis.mk.Common()
509 common.errorMsg("Cannot collect jUnit tests results, given result is null")
510 }
511 return [:]
512}
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300513
514
515/** Cleanup: Remove reports directory
516 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500517 * DEPRECATED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300518 * @param target Target node to remove repo
519 * @param reports_dir_name Reports directory name to be removed (that is in /root/ on target node)
520 * @param archive_artifacts_name Archive of the artifacts
521 */
522def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') {
523 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500524 def common = new com.mirantis.mk.Common()
525 common.errorMsg('You are using deprecated method! This method will be removed')
526 error('You are using deprecated method! This method will be removed')
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300527 salt.runSaltProcessStep(master, target, 'file.find', ["/root/${reports_dir_name}", '\\*', 'delete'])
528 salt.runSaltProcessStep(master, target, 'file.remove', ["/root/${archive_artifacts_name}"])
529}
530
531
532/** Cleanup: Remove Docker container
533 *
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500534 * DEPREACTED
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300535 * @param target Target node to remove Docker container
536 * @param image_link The link of the Docker image that was used for the container
537 */
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300538def removeDockerContainer(master, target, containerName) {
Consatntine Kalinovskiy84634752017-08-30 15:31:26 +0300539 def salt = new com.mirantis.mk.Salt()
Oleksii Zhurba9c456a72019-03-26 18:05:34 -0500540 def common = new com.mirantis.mk.Common()
541 common.errorMsg('You are using deprecated method! Use validate.runCleanup instead. This method will be removed')
542 error('You are using deprecated method! Use validate.runCleanup instead. This method will be removed')
Ievgeniia Zadorozhnaffea7ef2017-10-31 16:18:46 +0300543 salt.cmdRun(master, target, "docker rm -f ${containerName}")
Oleh Hryhorov83658332017-10-10 10:45:12 +0300544}