blob: 486bd3a2e77901f3a7884ce4bcbd48a2e4985597 [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 Polreich32fbc012018-11-07 12:23:18 +010027def cleanEnv = ''
Martin Polreicha3e30122017-08-22 12:43:55 +020028
chnyda03f3ad42017-09-19 14:41:07 +020029throttle(['test-formula']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010030 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010031 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010032 try {
33 stage("checkout") {
34 if (defaultGitRef && defaultGitUrl) {
35 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
chnyda03f3ad42017-09-19 14:41:07 +020036 } else {
Jakub Josefa63f9862018-01-11 17:58:38 +010037 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
chnyda03f3ad42017-09-19 14:41:07 +020038 }
39 }
Jakub Josefa63f9862018-01-11 17:58:38 +010040 stage("cleanup") {
41 if (checkouted) {
42 sh("make clean")
43 }
44 }
45 stage("kitchen") {
46 if (checkouted) {
Martin Polreichc0995dc2018-11-05 14:40:02 +010047 if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
48 if (fileExists(".kitchen.openstack.yml")) {
49 common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
50 if (fileExists(".kitchen.yml")) {
51 common.infoMsg("Ignoring the docker Kitchen test configuration file.")
52 }
53 openstackTest = true
54 } else {
55 common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
56 }
Jakub Josefa63f9862018-01-11 17:58:38 +010057 ruby.ensureRubyEnv()
58 if (fileExists(".travis.yml")) {
59 common.infoMsg(".travis.yml found, running custom kitchen init")
60 def kitchenConfigYML = readYaml(file: ".travis.yml")
61 def kitchenInit = kitchenConfigYML["install"]
62 def kitchenInstalled = false
63 if (kitchenInit && !kitchenInit.isEmpty()) {
Martin Polreichc39edae2018-11-07 08:42:11 +010064 for (int i = 0; i < kitchenInit.size(); i++) {
65 if (kitchenInit[i].trim().startsWith("if [ ! -e Gemfile ]")) { //found Gemfile config
66 common.infoMsg("Custom Gemfile configuration found, using them")
67 if (openstackTest) {
68 withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id,
69 usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) {
70 env.OS_USERNAME = OS_USERNAME
71 env.OS_PASSWORD = OS_PASSWORD
72 env.OS_AUTH_URL = OS_AUTH_URL
73 env.OS_PROJECT_NAME = OS_PROJECT_NAME
74 env.OS_DOMAIN_NAME = OS_DOMAIN_NAME
75 env.OS_AZ = OS_AZ
76 }
Martin Polreichc0995dc2018-11-05 14:40:02 +010077 }
Martin Polreichc39edae2018-11-07 08:42:11 +010078 ruby.installKitchen(kitchenInit[i].trim())
79 kitchenInstalled = true
Jakub Josefa63f9862018-01-11 17:58:38 +010080 }
81 }
82 }
83 if (!kitchenInstalled) {
84 ruby.installKitchen()
85 }
86 } else {
87 common.infoMsg(".travis.yml not found, running default kitchen init")
88 ruby.installKitchen()
89 }
90 common.infoMsg("Running part of kitchen test")
91 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
Martin Polreich32fbc012018-11-07 12:23:18 +010092 cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
Dzmitry Stremkouski8e8633b2018-11-06 19:13:25 +010093 if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv }
Martin Polreich32fbc012018-11-07 12:23:18 +010094 sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
95 sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
Jakub Josefa63f9862018-01-11 17:58:38 +010096 def suite = ruby.getSuiteName(KITCHEN_ENV)
97 if (suite && suite != "") {
98 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
99 ruby.runKitchenTests(cleanEnv, suite)
100 } else {
101 common.warningMsg("No SUITE was found. Running with all suites.")
102 ruby.runKitchenTests(cleanEnv, "")
103 }
104 } else {
105 throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
106 }
107 } else {
108 throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
109 }
110 }
111 }
112 } catch (Throwable e) {
113 // If there was an error or exception thrown, the build failed
114 currentBuild.result = "FAILURE"
Dzmitry Stremkouskica76bfa2018-11-07 14:19:58 +0100115 sh(script: 'find .kitchen/logs/ -type f -iname "*.log" | xargs -I{} bash -c "echo {}; cat {}"')
Martin Polreich32fbc012018-11-07 12:23:18 +0100116 ruby.runKitchenCommand("destroy", cleanEnv)
Jakub Josefa63f9862018-01-11 17:58:38 +0100117 throw e
118 } finally {
119 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
120 common.errorMsg("----------------KITCHEN LOG:---------------")
121 println readFile(".kitchen/logs/kitchen.log")
122 }
chnyda03f3ad42017-09-19 14:41:07 +0200123 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200124 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200125 }
Martin Polreichb33d23e2017-09-01 15:22:16 +0000126}