blob: e0148ee0ca6fe05a05e71231cefe000b1316439b [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/**
Vasyl Saienkod1dd1332017-08-03 15:22:42 +030070 * Upload results to cfg01 node
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040071 *
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()
Vasyl Saienkod1dd1332017-08-03 15:22:42 +030075 if (! target.contains('cfg')) {
76 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["mkdir /root/rally_reports/ && " +
77 "rsync -av /root/rally_reports/ cfg01:/root/rally_reports/"])
78 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040079}
80
81
Tatyana Leontovich01704b32017-03-06 12:26:33 +020082/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040083 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +020084 * @param image Docker image name
85 */
86def catTestsOutput(master, image) {
87 def salt = new com.mirantis.mk.Salt()
88 salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"])
89}
Tatyana Leontovich060e1152017-07-10 17:25:37 +030090
91
92/** Install docker if needed
93 *
94 * @param target Target node to install docker pkg
95 */
96def install_docker(master, target) {
97 def salt = new com.mirantis.mk.Salt()
98 salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"])
99}
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300100
101/** Archive Rally results in Artifacts
102 *
103 * @param master Salt connection.
104 * @param target Target node to install docker pkg
105 * @param reports_dir Source directory to archive
106 */
107
108def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') {
109 def salt = new com.mirantis.mk.Salt()
110
111 def artifacts_dir = '_artifacts/'
112 def output_file = 'rally_reports.tar'
113
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300114 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["tar -cf /root/${output_file} -C ${reports_dir} ."])
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300115 sh "mkdir -p ${artifacts_dir}"
116
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300117 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 +0300118
119 writeFile file: "${artifacts_dir}${output_file}", text: encoded
120
121 // collect artifacts
122 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
123}