blob: 465b048d35af324b3a31386b2958cb35470f96af [file] [log] [blame]
Martin Polreicha3e30122017-08-22 12:43:55 +02001/**
2 * Test salt formulas pipeline
3 * DEFAULT_GIT_REF
4 * DEFAULT_GIT_URL
5 * CREDENTIALS_ID
6 */
7def common = new com.mirantis.mk.Common()
8def ruby = new com.mirantis.mk.Ruby()
Martin Polreich9a1d16b2017-08-29 17:16:12 +02009def gerrit = new com.mirantis.mk.Gerrit()
Martin Polreicha3e30122017-08-22 12:43:55 +020010
11def defaultGitRef, defaultGitUrl
12try {
13 defaultGitRef = DEFAULT_GIT_REF
14 defaultGitUrl = DEFAULT_GIT_URL
15} catch (MissingPropertyException e) {
16 defaultGitRef = null
17 defaultGitUrl = null
18}
19
Martin Polreichc39edae2018-11-07 08:42:11 +010020def openstack_credentials_id = ''
21if (env.OPENSTACK_API_CREDENTIALS) {
22 openstack_credentials_id = OPENSTACK_API_CREDENTIALS
23}
24
Martin Polreicha3e30122017-08-22 12:43:55 +020025def checkouted = false
Martin Polreichc0995dc2018-11-05 14:40:02 +010026def openstackTest = false
Martin Polreicha3e30122017-08-22 12:43:55 +020027
chnyda03f3ad42017-09-19 14:41:07 +020028throttle(['test-formula']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010029 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010030 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010031 try {
32 stage("checkout") {
33 if (defaultGitRef && defaultGitUrl) {
34 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
chnyda03f3ad42017-09-19 14:41:07 +020035 } else {
Jakub Josefa63f9862018-01-11 17:58:38 +010036 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
chnyda03f3ad42017-09-19 14:41:07 +020037 }
38 }
Jakub Josefa63f9862018-01-11 17:58:38 +010039 stage("cleanup") {
40 if (checkouted) {
41 sh("make clean")
42 }
43 }
44 stage("kitchen") {
45 if (checkouted) {
Martin Polreichc0995dc2018-11-05 14:40:02 +010046 if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
47 if (fileExists(".kitchen.openstack.yml")) {
48 common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
49 if (fileExists(".kitchen.yml")) {
50 common.infoMsg("Ignoring the docker Kitchen test configuration file.")
51 }
52 openstackTest = true
53 } else {
54 common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
55 }
Jakub Josefa63f9862018-01-11 17:58:38 +010056 ruby.ensureRubyEnv()
57 if (fileExists(".travis.yml")) {
58 common.infoMsg(".travis.yml found, running custom kitchen init")
59 def kitchenConfigYML = readYaml(file: ".travis.yml")
60 def kitchenInit = kitchenConfigYML["install"]
61 def kitchenInstalled = false
62 if (kitchenInit && !kitchenInit.isEmpty()) {
Martin Polreichc39edae2018-11-07 08:42:11 +010063 for (int i = 0; i < kitchenInit.size(); i++) {
64 if (kitchenInit[i].trim().startsWith("if [ ! -e Gemfile ]")) { //found Gemfile config
65 common.infoMsg("Custom Gemfile configuration found, using them")
66 if (openstackTest) {
67 withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id,
68 usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) {
69 env.OS_USERNAME = OS_USERNAME
70 env.OS_PASSWORD = OS_PASSWORD
71 env.OS_AUTH_URL = OS_AUTH_URL
72 env.OS_PROJECT_NAME = OS_PROJECT_NAME
73 env.OS_DOMAIN_NAME = OS_DOMAIN_NAME
74 env.OS_AZ = OS_AZ
75 }
Martin Polreichc0995dc2018-11-05 14:40:02 +010076 }
Martin Polreichc39edae2018-11-07 08:42:11 +010077 ruby.installKitchen(kitchenInit[i].trim())
78 kitchenInstalled = true
Jakub Josefa63f9862018-01-11 17:58:38 +010079 }
80 }
81 }
82 if (!kitchenInstalled) {
83 ruby.installKitchen()
84 }
85 } else {
86 common.infoMsg(".travis.yml not found, running default kitchen init")
87 ruby.installKitchen()
88 }
89 common.infoMsg("Running part of kitchen test")
90 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
91 def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
Dzmitry Stremkouski8e8633b2018-11-06 19:13:25 +010092 if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv }
Alexander Evseev227b8c72018-10-25 15:40:34 +020093 sh("find . -type f -exec sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {} \\;")
94 sh("find . -type f -exec sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {} \\;")
Jakub Josefa63f9862018-01-11 17:58:38 +010095 def suite = ruby.getSuiteName(KITCHEN_ENV)
96 if (suite && suite != "") {
97 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
98 ruby.runKitchenTests(cleanEnv, suite)
99 } else {
100 common.warningMsg("No SUITE was found. Running with all suites.")
101 ruby.runKitchenTests(cleanEnv, "")
102 }
103 } else {
104 throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
105 }
106 } else {
107 throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
108 }
109 }
110 }
111 } catch (Throwable e) {
112 // If there was an error or exception thrown, the build failed
113 currentBuild.result = "FAILURE"
114 ruby.runKitchenCommand("destroy")
115 throw e
116 } finally {
117 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
118 common.errorMsg("----------------KITCHEN LOG:---------------")
119 println readFile(".kitchen/logs/kitchen.log")
120 }
chnyda03f3ad42017-09-19 14:41:07 +0200121 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200122 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200123 }
Martin Polreichb33d23e2017-09-01 15:22:16 +0000124}