Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Service test pipeline |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * Test settings: |
| 9 | * TEST_SERVICE Comma separated list of services to test |
| 10 | * TEST_K8S_API_SERVER Kubernetes API address |
| 11 | * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests |
| 12 | * TEST_DOCKER_INSTALL Install docker on the target if true |
| 13 | * TEST_TEMPEST_IMAGE Tempest image link |
| 14 | * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only |
| 15 | * TEST_TEMPEST_TARGET Salt target for tempest node |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | common = new com.mirantis.mk.Common() |
| 20 | git = new com.mirantis.mk.Git() |
| 21 | salt = new com.mirantis.mk.Salt() |
| 22 | test = new com.mirantis.mk.Test() |
| 23 | |
| 24 | // Define global variables |
| 25 | def saltMaster |
| 26 | |
| 27 | node("python") { |
| 28 | try { |
| 29 | |
| 30 | // |
| 31 | // Prepare connection |
| 32 | // |
| 33 | stage ('Connect to salt master') { |
| 34 | // Connect to Salt master |
| 35 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 36 | } |
| 37 | |
| 38 | // |
| 39 | // Test |
| 40 | // |
| 41 | def artifacts_dir = '_artifacts/' |
| 42 | |
| 43 | if (common.checkContains('TEST_SERVICE', 'k8s')) { |
| 44 | stage('Run k8s bootstrap tests') { |
| 45 | def image = 'tomkukral/k8s-scripts' |
| 46 | def output_file = image.replaceAll('/', '-') + '.output' |
| 47 | |
| 48 | // run image |
| 49 | test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image) |
| 50 | |
| 51 | // collect output |
| 52 | sh "mkdir -p ${artifacts_dir}" |
| 53 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 54 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 55 | sh "cat ${artifacts_dir}${output_file}" |
| 56 | |
| 57 | // collect artifacts |
| 58 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 59 | } |
| 60 | |
| 61 | stage('Run k8s conformance e2e tests') { |
| 62 | def image = K8S_CONFORMANCE_IMAGE |
| 63 | def output_file = image.replaceAll('/', '-') + '.output' |
| 64 | |
| 65 | // run image |
| 66 | test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image) |
| 67 | |
| 68 | // collect output |
| 69 | sh "mkdir -p ${artifacts_dir}" |
| 70 | file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file) |
| 71 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 72 | sh "cat ${artifacts_dir}${output_file}" |
| 73 | |
| 74 | // collect artifacts |
| 75 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (common.checkContains('TEST_SERVICE', 'openstack')) { |
Tomáš Kukrál | e785929 | 2017-08-11 13:52:06 +0200 | [diff] [blame] | 80 | if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) { |
| 81 | test.install_docker(saltMaster, TEST_TEMPEST_TARGET) |
| 82 | } |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 83 | |
Tomáš Kukrál | e785929 | 2017-08-11 13:52:06 +0200 | [diff] [blame] | 84 | stage('Run OpenStack tests') { |
| 85 | test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN) |
| 86 | } |
Tomáš Kukrál | 503d491 | 2017-08-11 13:01:12 +0200 | [diff] [blame] | 87 | |
Tomáš Kukrál | 457b7c6 | 2017-08-11 14:02:40 +0200 | [diff] [blame] | 88 | writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, TEST_TEMPEST_TARGET, '/root/report.xml')) |
Tomáš Kukrál | 8689fb3 | 2017-08-11 14:13:45 +0200 | [diff] [blame] | 89 | junit(keepLongStdio: true, testResults: 'report.xml', healthScaleFactor: Double.parseDouble(TEST_JUNIT_RATIO)) |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 90 | } |
Jakub Josef | b08a94b | 2017-08-16 13:54:28 +0200 | [diff] [blame^] | 91 | stage("Approve test results"){ |
| 92 | try { |
| 93 | timeout(time: 1, unit: 'HOURS'){ |
| 94 | userInput = input message: 'Do you want to approve test results?' |
| 95 | } |
| 96 | common.successMsg("Test results approved") |
| 97 | currentBuild.desc = "result: true" |
| 98 | } catch(err) { // timeout reached or input false |
| 99 | common.errorMsg("Test results not approved") |
| 100 | currentBuild.desc = "result: false" |
| 101 | } |
| 102 | } |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 103 | } catch (Throwable e) { |
| 104 | currentBuild.result = 'FAILURE' |
| 105 | throw e |
| 106 | } |
| 107 | } |