blob: d6f37ee0bdbb7026a2b6799e6f3aa1fbb6479434 [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/**
10 * Run e2e conformance tests
11 *
12 * @param k8s_api Kubernetes api address
13 * @param image Docker image with tests
Matthew Mosesohne5c07e82017-06-14 11:55:01 +030014 * @param timeout Timeout waiting for e2e conformance tests
Jakub Josef79ecec32017-02-17 14:36:28 +010015 */
Matthew Mosesohne5c07e82017-06-14 11:55:01 +030016def runConformanceTests(master, k8s_api, image, timeout=2400) {
Jakub Josef79ecec32017-02-17 14:36:28 +010017 def salt = new com.mirantis.mk.Salt()
Matthew Mosesohne5c07e82017-06-14 11:55:01 +030018 def containerName = 'conformance_tests'
Tomáš Kukrála7318f52017-04-21 16:15:29 +020019 def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output'
Matthew Mosesohne5c07e82017-06-14 11:55:01 +030020 salt.cmdRun(master, 'ctl01*', "docker rm -f ${containerName}", false)
21 salt.cmdRun(master, 'ctl01*', "docker run -d --name ${containerName} --net=host -e API_SERVER=${k8s_api} ${image}")
22 sleep(10)
23
24 print("Waiting for tests to run...")
25 salt.runSaltProcessStep(master, 'ctl01*', 'cmd.run', ["docker wait ${containerName}"], null, false, timeout)
26
27 print("Writing test results to output file...")
28 salt.runSaltProcessStep(master, 'ctl01*', 'cmd.run', ["docker logs -t ${containerName} &> ${outfile}"])
29
Tomáš Kukrál798b3f52017-04-28 13:19:32 +020030 print("Conformance test output saved in " + outfile)
Tatyana Leontovichc73d63c2017-02-28 14:41:38 +020031}
32
33/**
34 * Copy test output to cfg node
35 *
36 * @param image Docker image with tests
37 */
38def copyTestsOutput(master, image) {
39 def salt = new com.mirantis.mk.Salt()
40 salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["scp ctl01:/root/${image}.output /home/ubuntu/"])
41}
42
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040043/**
44 * Execute tempest tests
45 *
Tatyana Leontovich060e1152017-07-10 17:25:37 +030046 * @param dockerImageLink Docker image link with rally and tempest
47 * @param target Host to run tests
48 * @param pattern If not false, will run only tests matched the pattern
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040049 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +030050def runTempestTests(master, dockerImageLink, target, pattern = "false") {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040051 def salt = new com.mirantis.mk.Salt()
Tatyana Leontovich060e1152017-07-10 17:25:37 +030052 if (pattern == "false") {
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030053 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
54 "-e TEMPEST_CONF=mcp.conf " +
55 "-e SKIP_LIST=mcp_skip.list " +
56 "-e SOURCE_FILE=keystonercv3 " +
57 "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log")
58 }
Tatyana Leontovich060e1152017-07-10 17:25:37 +030059 else {
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030060 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
61 "-e TEMPEST_CONF=mcp.conf " +
62 "-e SKIP_LIST=mcp_skip.list " +
63 "-e SOURCE_FILE=keystonercv3 " +
64 "-e CUSTOM='--pattern ${pattern}' " +
65 "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log")
66 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040067}
68
69/**
70 * Upload results to worker
71 *
72 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +030073def copyTempestResults(master, target) {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040074 def salt = new com.mirantis.mk.Salt()
Tatyana Leontovich060e1152017-07-10 17:25:37 +030075 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["scp /root/docker-tempest.log cfg01:/home/ubuntu/ && " +
76 "find /root -name result.xml -exec scp {} cfg01:/home/ubuntu \\;"])
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040077}
78
79
Tatyana Leontovich01704b32017-03-06 12:26:33 +020080/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040081 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +020082 * @param image Docker image name
83 */
84def catTestsOutput(master, image) {
85 def salt = new com.mirantis.mk.Salt()
86 salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"])
87}
Tatyana Leontovich060e1152017-07-10 17:25:37 +030088
89
90/** Install docker if needed
91 *
92 * @param target Target node to install docker pkg
93 */
94def install_docker(master, target) {
95 def salt = new com.mirantis.mk.Salt()
96 salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"])
97}