| Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 1 | package com.mirantis.mk | 
|  | 2 |  | 
|  | 3 | /** | 
|  | 4 | * | 
|  | 5 | * Tests providing functions | 
|  | 6 | * | 
|  | 7 | */ | 
|  | 8 |  | 
|  | 9 | /** | 
| Victor Ryzhenkin | 46da67a | 2018-11-30 00:17:55 +0400 | [diff] [blame] | 10 | * Get conformance pod statuses | 
|  | 11 | * | 
|  | 12 | * @param target   Any control node of k8s | 
|  | 13 | */ | 
|  | 14 | def 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 | */ | 
|  | 27 | def 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 | */ | 
|  | 51 | def 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 | */ | 
|  | 113 | def 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 | */ | 
|  | 128 | def 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 | */ | 
|  | 180 | def 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 | */ | 
|  | 201 | def 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 | */ | 
|  | 225 | def 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 Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 256 | * Run e2e conformance tests | 
|  | 257 | * | 
| Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 258 | * @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 Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 262 | */ | 
| Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 263 | def runConformanceTests(master, target, k8s_api, image, timeout=2400) { | 
| Jakub Josef | 79ecec3 | 2017-02-17 14:36:28 +0100 | [diff] [blame] | 264 | def salt = new com.mirantis.mk.Salt() | 
| Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 265 | def containerName = 'conformance_tests' | 
| Tomáš Kukrál | a7318f5 | 2017-04-21 16:15:29 +0200 | [diff] [blame] | 266 | def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output' | 
| Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 267 | 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 Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 269 | sleep(10) | 
|  | 270 |  | 
|  | 271 | print("Waiting for tests to run...") | 
| Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 272 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker wait ${containerName}"], null, false, timeout) | 
| Matthew Mosesohn | e5c07e8 | 2017-06-14 11:55:01 +0300 | [diff] [blame] | 273 |  | 
|  | 274 | print("Writing test results to output file...") | 
| Tetiana Korchak | f500ab9 | 2017-09-27 14:53:51 -0700 | [diff] [blame] | 275 | salt.runSaltProcessStep(master, target, 'cmd.run', ["docker logs -t ${containerName} > ${outfile}"]) | 
| Tomáš Kukrál | 798b3f5 | 2017-04-28 13:19:32 +0200 | [diff] [blame] | 276 | print("Conformance test output saved in " + outfile) | 
| Tatyana Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 277 | } | 
|  | 278 |  | 
| vrovachev | c3b47f4 | 2018-01-25 16:08:50 +0400 | [diff] [blame] | 279 | /** | 
|  | 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 | */ | 
|  | 285 | def 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 Leontovich | c73d63c | 2017-02-28 14:41:38 +0200 | [diff] [blame] | 308 | /** | 
|  | 309 | * Copy test output to cfg node | 
|  | 310 | * | 
|  | 311 | * @param image      Docker image with tests | 
|  | 312 | */ | 
|  | 313 | def 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 Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 318 | /** | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 319 | * DEPRECATED | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 320 | * Execute tempest tests | 
|  | 321 | * | 
| Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 322 | * @param dockerImageLink   Docker image link with rally and tempest | 
|  | 323 | * @param target            Host to run tests | 
| Mykyta Karpin | 80f527e | 2017-08-14 15:18:03 +0300 | [diff] [blame] | 324 | * @param pattern           If not false, will run only tests matched the pattern | 
|  | 325 | * @param logDir            Directory to store tempest/rally reports | 
| Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 326 | * @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 Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 333 | */ | 
| ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 334 | def runTempestTests(master, dockerImageLink, target, pattern = "", logDir = "/home/rally/rally_reports/", | 
| Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 335 | sourceFile="/home/rally/keystonercv3", set="full", concurrency="0", tempestConf="mcp.conf", | 
|  | 336 | skipList="mcp_skip.list", localKeystone="/root/keystonercv3" , localLogDir="/root/rally_reports", | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 337 | doCleanupResources = "false") { | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 338 | def salt = new com.mirantis.mk.Salt() | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 339 | 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 Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 342 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["${localLogDir}"]) | 
|  | 343 | def custom = '' | 
| ibumarskov | 374188e | 2017-12-14 10:54:09 +0400 | [diff] [blame] | 344 | if (pattern) { | 
| Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 345 | custom = "--pattern " + pattern | 
| Mykyta Karpin | 07ba87f | 2017-07-27 13:56:33 +0300 | [diff] [blame] | 346 | } | 
| Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 347 | salt.cmdRun(master, "${target}", "docker run --rm --net=host " + | 
|  | 348 | "-e SOURCE_FILE=${sourceFile} " + | 
|  | 349 | "-e LOG_DIR=${logDir} " + | 
|  | 350 | "-e SET=${set} " + | 
| Mykyta Karpin | 292c066 | 2017-11-13 12:07:52 +0200 | [diff] [blame] | 351 | "-e CUSTOM='${custom}' " + | 
| Oleksandr Kosse | 74bbab7 | 2017-10-11 13:48:18 +0300 | [diff] [blame] | 352 | "-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 Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 360 | } | 
|  | 361 |  | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 362 |  | 
|  | 363 | /** | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 364 | * DEPRECATED | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 365 | * 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 | */ | 
|  | 373 | def 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 Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 376 | 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 Zadorozhna | 5b97023 | 2017-09-13 13:31:43 +0300 | [diff] [blame] | 379 | salt.runSaltProcessStep(master, target, 'file.mkdir', ["/root/rally_reports"]) | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 380 | 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 Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 392 | /** | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 393 | * DEPRECATED | 
| Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 394 | * Upload results to cfg01 node | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 395 | * | 
|  | 396 | */ | 
| Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 397 | def copyTempestResults(master, target) { | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 398 | def salt = new com.mirantis.mk.Salt() | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 399 | 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 Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 402 | if (! target.contains('cfg')) { | 
| ibumarskov | 5c31e28 | 2018-02-14 15:05:20 +0400 | [diff] [blame] | 403 | salt.cmdRun(master, target, "mkdir -p /root/rally_reports/ && rsync -av /root/rally_reports/ cfg01:/root/rally_reports/") | 
| Vasyl Saienko | d1dd133 | 2017-08-03 15:22:42 +0300 | [diff] [blame] | 404 | } | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
|  | 407 |  | 
| Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 408 | /** Store tests results on host | 
| Victor Ryzhenkin | c5b3029 | 2017-02-21 19:26:24 +0400 | [diff] [blame] | 409 | * | 
| Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 410 | * @param image      Docker image name | 
|  | 411 | */ | 
|  | 412 | def catTestsOutput(master, image) { | 
|  | 413 | def salt = new com.mirantis.mk.Salt() | 
| Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 414 | salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output") | 
| Tatyana Leontovich | 01704b3 | 2017-03-06 12:26:33 +0200 | [diff] [blame] | 415 | } | 
| Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 416 |  | 
|  | 417 |  | 
|  | 418 | /** Install docker if needed | 
|  | 419 | * | 
|  | 420 | * @param target              Target node to install docker pkg | 
|  | 421 | */ | 
|  | 422 | def install_docker(master, target) { | 
|  | 423 | def salt = new com.mirantis.mk.Salt() | 
| Ivan Berezovskiy | a147b48 | 2018-12-12 19:56:30 +0400 | [diff] [blame] | 424 | def dockerPackagesPillar = salt.getPillar(master, target, 'docker:host:pkgs') | 
|  | 425 | def dockerPackages = salt.getReturnValues(dockerPackagesPillar) ?: ['docker.io'] | 
| Mykyta Karpin | 495d029 | 2019-01-25 10:58:19 +0200 | [diff] [blame] | 426 | salt.runSaltProcessStep(master, target, 'pkg.install', [dockerPackages.join(',')]) | 
| Tatyana Leontovich | 060e115 | 2017-07-10 17:25:37 +0300 | [diff] [blame] | 427 | } | 
| Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 428 |  | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 429 |  | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 430 | /** Upload Tempest test results to Testrail | 
|  | 431 | * | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 432 | * DEPRECATED | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 433 | * @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 |  | 
|  | 445 | def 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 Zhurba | 757bc58 | 2019-04-11 10:27:12 -0500 | [diff] [blame^] | 448 | common.errorMsg('We may deprecated this method! Check tcp_qa Common.uploadResultsTestRail instead.') | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 449 | 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 Karpin | a5761a2 | 2017-08-16 16:09:56 +0300 | [diff] [blame] | 457 | "-e TEST_GROUP=${testGroup} " + | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 458 | "${image}" | 
|  | 459 | if (master == null) { | 
| Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 460 | sh(command) | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 461 | } else { | 
| Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 462 | salt.cmdRun(master, target, command) | 
| Mykyta Karpin | 94d82a8 | 2017-08-08 19:03:36 +0300 | [diff] [blame] | 463 | } | 
|  | 464 | } | 
|  | 465 |  | 
| Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 466 | /** Archive Rally results in Artifacts | 
|  | 467 | * | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 468 | * DEPRECATED | 
| Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 469 | * @param master              Salt connection. | 
|  | 470 | * @param target              Target node to install docker pkg | 
|  | 471 | * @param reports_dir         Source directory to archive | 
|  | 472 | */ | 
|  | 473 |  | 
|  | 474 | def archiveRallyArtifacts(master, target, reports_dir='/root/rally_reports') { | 
|  | 475 | def salt = new com.mirantis.mk.Salt() | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 476 | 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 Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 479 | def artifacts_dir = '_artifacts/' | 
|  | 480 | def output_file = 'rally_reports.tar' | 
|  | 481 |  | 
| Jakub Josef | 432e9d9 | 2018-02-06 18:28:37 +0100 | [diff] [blame] | 482 | salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .") | 
| Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 483 | sh "mkdir -p ${artifacts_dir}" | 
|  | 484 |  | 
| Mykyta Karpin | f4be9e2 | 2017-08-09 18:59:57 +0300 | [diff] [blame] | 485 | encoded = salt.cmdRun(master, target, "cat /root/${output_file}", true, null, false)['return'][0].values()[0].replaceAll('Salt command execution success','') | 
| Vasyl Saienko | df02e9d | 2017-08-04 09:55:13 +0300 | [diff] [blame] | 486 |  | 
|  | 487 | writeFile file: "${artifacts_dir}${output_file}", text: encoded | 
|  | 488 |  | 
|  | 489 | // collect artifacts | 
|  | 490 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" | 
|  | 491 | } | 
| Jakub Josef | 1462c4b | 2017-08-18 11:15:03 +0200 | [diff] [blame] | 492 | /** | 
|  | 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 | 
|  | 498 | def 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 Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 511 |  | 
|  | 512 |  | 
|  | 513 | /** Cleanup: Remove reports directory | 
|  | 514 | * | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 515 | * DEPRECATED | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 516 | * @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 | */ | 
|  | 520 | def removeReports(master, target, reports_dir_name = 'rally_reports', archive_artifacts_name = 'rally_reports.tar') { | 
|  | 521 | def salt = new com.mirantis.mk.Salt() | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 522 | 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 Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 525 | 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 Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 532 | * DEPREACTED | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 533 | * @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 Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 536 | def removeDockerContainer(master, target, containerName) { | 
| Consatntine Kalinovskiy | 8463475 | 2017-08-30 15:31:26 +0300 | [diff] [blame] | 537 | def salt = new com.mirantis.mk.Salt() | 
| Oleksii Zhurba | 9c456a7 | 2019-03-26 18:05:34 -0500 | [diff] [blame] | 538 | 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 Zadorozhna | ffea7ef | 2017-10-31 16:18:46 +0300 | [diff] [blame] | 541 | salt.cmdRun(master, target, "docker rm -f ${containerName}") | 
| Oleh Hryhorov | 8365833 | 2017-10-10 10:45:12 +0300 | [diff] [blame] | 542 | } |