blob: 60686cfd6f0c326d90e5bb9d539d7ce6a9b58363 [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
Mykyta Karpin80f527e2017-08-14 15:18:03 +030048 * @param pattern If not false, will run only tests matched the pattern
49 * @param logDir Directory to store tempest/rally reports
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040050 */
Mykyta Karpin80f527e2017-08-14 15:18:03 +030051def runTempestTests(master, dockerImageLink, target, pattern = "false", logDir = '/home/rally/rally_reports/') {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040052 def salt = new com.mirantis.mk.Salt()
Tatyana Leontovich060e1152017-07-10 17:25:37 +030053 if (pattern == "false") {
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030054 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
55 "-e TEMPEST_CONF=mcp.conf " +
56 "-e SKIP_LIST=mcp_skip.list " +
57 "-e SOURCE_FILE=keystonercv3 " +
Mykyta Karpin80f527e2017-08-14 15:18:03 +030058 "-e LOG_DIR=${logDir}" +
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030059 "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log")
60 }
Tatyana Leontovich060e1152017-07-10 17:25:37 +030061 else {
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030062 salt.cmdRun(master, "${target}", "docker run --rm --net=host " +
63 "-e TEMPEST_CONF=mcp.conf " +
64 "-e SKIP_LIST=mcp_skip.list " +
65 "-e SOURCE_FILE=keystonercv3 " +
Mykyta Karpin80f527e2017-08-14 15:18:03 +030066 "-e LOG_DIR=${logDir} " +
Mykyta Karpin07ba87f2017-07-27 13:56:33 +030067 "-e CUSTOM='--pattern ${pattern}' " +
68 "-v /root/:/home/rally ${dockerImageLink} >> docker-tempest.log")
69 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040070}
71
72/**
Vasyl Saienkod1dd1332017-08-03 15:22:42 +030073 * Upload results to cfg01 node
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040074 *
75 */
Tatyana Leontovich060e1152017-07-10 17:25:37 +030076def copyTempestResults(master, target) {
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040077 def salt = new com.mirantis.mk.Salt()
Vasyl Saienkod1dd1332017-08-03 15:22:42 +030078 if (! target.contains('cfg')) {
79 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["mkdir /root/rally_reports/ && " +
80 "rsync -av /root/rally_reports/ cfg01:/root/rally_reports/"])
81 }
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040082}
83
84
Tatyana Leontovich01704b32017-03-06 12:26:33 +020085/** Store tests results on host
Victor Ryzhenkinc5b30292017-02-21 19:26:24 +040086 *
Tatyana Leontovich01704b32017-03-06 12:26:33 +020087 * @param image Docker image name
88 */
89def catTestsOutput(master, image) {
90 def salt = new com.mirantis.mk.Salt()
91 salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"])
92}
Tatyana Leontovich060e1152017-07-10 17:25:37 +030093
94
95/** Install docker if needed
96 *
97 * @param target Target node to install docker pkg
98 */
99def install_docker(master, target) {
100 def salt = new com.mirantis.mk.Salt()
101 salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"])
102}
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300103
Mykyta Karpin94d82a82017-08-08 19:03:36 +0300104/** Upload Tempest test results to Testrail
105 *
106 * @param report Source report to upload
107 * @param image Testrail reporter image
108 * @param testGroup Testrail test group
109 * @param credentialsId Testrail credentials id
110 * @param plan Testrail test plan
111 * @param milestone Testrail test milestone
112 * @param suite Testrail test suite
113 * @param type Use local shell or remote salt connection
114 * @param master Salt connection.
115 * @param target Target node to install docker pkg
116 */
117
118def uploadResultsTestrail(report, image, testGroup, credentialsId, plan, milestone, suite, master = null, target = 'cfg01*') {
119 def salt = new com.mirantis.mk.Salt()
120 def common = new com.mirantis.mk.Common()
121 creds = common.getPasswordCredentials(credentialsId)
122 command = "docker run --rm --net=host " +
123 "-v ${report}:/srv/report.xml " +
124 "-e TESTRAIL_USER=${creds.username} " +
125 "-e PASS=${creds.password.toString()} " +
126 "-e TESTRAIL_PLAN_NAME=${plan} " +
127 "-e TESTRAIL_MILESTONE=${milestone} " +
128 "-e TESTRAIL_SUITE=${suite} " +
129 "-e SHORT_TEST_GROUP=${testGroup} " +
130 "${image}"
131 if (master == null) {
132 sh("${command}")
133 } else {
134 salt.cmdRun(master, "${target}", "${command}")
135 }
136}
137
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300138/** Archive Rally results in Artifacts
139 *
140 * @param master Salt connection.
141 * @param target Target node to install docker pkg
142 * @param reports_dir Source directory to archive
143 */
144
145def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') {
146 def salt = new com.mirantis.mk.Salt()
147
148 def artifacts_dir = '_artifacts/'
149 def output_file = 'rally_reports.tar'
150
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300151 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["tar -cf /root/${output_file} -C ${reports_dir} ."])
Vasyl Saienkodf02e9d2017-08-04 09:55:13 +0300152 sh "mkdir -p ${artifacts_dir}"
153
Mykyta Karpinf4be9e22017-08-09 18:59:57 +0300154 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 +0300155
156 writeFile file: "${artifacts_dir}${output_file}", text: encoded
157
158 // collect artifacts
159 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
160}