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() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 23 | def python = new com.mirantis.mk.Python() |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 24 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 25 | def pepperEnv = "pepperEnv" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 26 | timeout(time: 12, unit: 'HOURS') { |
| 27 | node("python") { |
| 28 | try { |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 29 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 30 | stage('Setup virtualenv for Pepper') { |
| 31 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 32 | } |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 33 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 34 | // |
| 35 | // Test |
| 36 | // |
| 37 | def artifacts_dir = '_artifacts/' |
| 38 | |
| 39 | if (common.checkContains('TEST_SERVICE', 'k8s')) { |
| 40 | stage('Run k8s bootstrap tests') { |
| 41 | def image = 'tomkukral/k8s-scripts' |
| 42 | def output_file = image.replaceAll('/', '-') + '.output' |
| 43 | |
| 44 | // run image |
| 45 | test.runConformanceTests(pepperEnv, 'ctl01*', TEST_K8S_API_SERVER, image) |
| 46 | |
| 47 | // collect output |
| 48 | sh "mkdir -p ${artifacts_dir}" |
| 49 | file_content = salt.getFileContent(pepperEnv, 'ctl01*', '/tmp/' + output_file) |
| 50 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 51 | sh "cat ${artifacts_dir}${output_file}" |
| 52 | |
| 53 | // collect artifacts |
| 54 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 55 | } |
| 56 | |
| 57 | stage('Run k8s conformance e2e tests') { |
| 58 | def image = K8S_CONFORMANCE_IMAGE |
| 59 | def output_file = image.replaceAll('/', '-') + '.output' |
| 60 | |
| 61 | // run image |
| 62 | test.runConformanceTests(pepperEnv, 'ctl01*', TEST_K8S_API_SERVER, image) |
| 63 | |
| 64 | // collect output |
| 65 | sh "mkdir -p ${artifacts_dir}" |
| 66 | file_content = salt.getFileContent(pepperEnv, 'ctl01*', '/tmp/' + output_file) |
| 67 | writeFile file: "${artifacts_dir}${output_file}", text: file_content |
| 68 | sh "cat ${artifacts_dir}${output_file}" |
| 69 | |
| 70 | // collect artifacts |
| 71 | archiveArtifacts artifacts: "${artifacts_dir}${output_file}" |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if (common.checkContains('TEST_SERVICE', 'openstack')) { |
| 76 | if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) { |
| 77 | test.install_docker(pepperEnv, TEST_TEMPEST_TARGET) |
| 78 | } |
| 79 | |
| 80 | stage('Run OpenStack tests') { |
| 81 | test.runTempestTests(pepperEnv, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN) |
| 82 | } |
| 83 | |
| 84 | writeFile(file: 'report.xml', text: salt.getFileContent(pepperEnv, TEST_TEMPEST_TARGET, '/root/report.xml')) |
| 85 | junit(keepLongStdio: true, testResults: 'report.xml', healthScaleFactor: Double.parseDouble(TEST_JUNIT_RATIO)) |
| 86 | def testResults = test.collectJUnitResults(currentBuild.rawBuild.getAction(hudson.tasks.test.AbstractTestResultAction.class)) |
| 87 | if(testResults){ |
| 88 | currentBuild.desc = String.format("result: %s", testResults["failed"] / testResults["total"]) |
| 89 | } |
| 90 | } |
| 91 | } catch (Throwable e) { |
| 92 | currentBuild.result = 'FAILURE' |
| 93 | throw e |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 94 | } |
Ales Komarek | 1ebb7a8 | 2017-08-04 14:58:51 +0200 | [diff] [blame] | 95 | } |
| 96 | } |