Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
| 6 | */ |
| 7 | def common = new com.mirantis.mk.Common() |
| 8 | def ruby = new com.mirantis.mk.Ruby() |
Martin Polreich | 9a1d16b | 2017-08-29 17:16:12 +0200 | [diff] [blame] | 9 | def gerrit = new com.mirantis.mk.Gerrit() |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 10 | |
| 11 | def defaultGitRef, defaultGitUrl |
| 12 | try { |
| 13 | defaultGitRef = DEFAULT_GIT_REF |
| 14 | defaultGitUrl = DEFAULT_GIT_URL |
| 15 | } catch (MissingPropertyException e) { |
| 16 | defaultGitRef = null |
| 17 | defaultGitUrl = null |
| 18 | } |
| 19 | |
Martin Polreich | c39edae | 2018-11-07 08:42:11 +0100 | [diff] [blame] | 20 | def openstack_credentials_id = '' |
| 21 | if (env.OPENSTACK_API_CREDENTIALS) { |
| 22 | openstack_credentials_id = OPENSTACK_API_CREDENTIALS |
| 23 | } |
| 24 | |
Martin Polreich | 4dedbcf | 2019-04-09 09:28:46 +0200 | [diff] [blame] | 25 | env.GERRIT_BRANCH = 'master' |
Martin Polreich | 37da131 | 2019-04-09 15:41:46 +0200 | [diff] [blame] | 26 | if (common.validInputParam('GERRIT_PARENT_BRANCH')) { |
Martin Polreich | 4dedbcf | 2019-04-09 09:28:46 +0200 | [diff] [blame] | 27 | env.GERRIT_BRANCH = GERRIT_PARENT_BRANCH |
| 28 | } |
| 29 | |
Vladimir Khlyunev | 81a3c90 | 2021-02-01 18:51:15 +0400 | [diff] [blame] | 30 | def nodeLabel = 'old16.04' |
| 31 | |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 32 | def checkouted = false |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 33 | def openstackTest = false |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 34 | def travisLess = false /** TODO: Remove once formulas are witched to new config */ |
| 35 | def cleanEnv = '' /** TODO: Remove once formulas are witched to new config */ |
| 36 | def testSuite = '' |
Martin Polreich | 5be29e3 | 2019-02-26 11:11:51 +0100 | [diff] [blame] | 37 | envOverrides = [] |
| 38 | kitchenFileName = '' |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 39 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 40 | throttle(['test-formula']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 41 | timeout(time: 1, unit: 'HOURS') { |
Vladimir Khlyunev | 81a3c90 | 2021-02-01 18:51:15 +0400 | [diff] [blame] | 42 | node(nodeLabel) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 43 | try { |
| 44 | stage("checkout") { |
| 45 | if (defaultGitRef && defaultGitUrl) { |
| 46 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 47 | } else { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 48 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null") |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 49 | } |
| 50 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 51 | stage("cleanup") { |
| 52 | if (checkouted) { |
| 53 | sh("make clean") |
| 54 | } |
| 55 | } |
| 56 | stage("kitchen") { |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 57 | if (fileExists(".travis.yml")) {/** TODO: Remove this legacy block once formulas are witched to new config */ |
| 58 | if (checkouted) { |
| 59 | if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) { |
| 60 | if (fileExists(".kitchen.openstack.yml")) { |
| 61 | common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.") |
| 62 | if (fileExists(".kitchen.yml")) { |
| 63 | common.infoMsg("Ignoring the docker Kitchen test configuration file.") |
| 64 | } |
| 65 | openstackTest = true |
| 66 | } else { |
| 67 | common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.") |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 68 | } |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 69 | ruby.ensureRubyEnv() |
| 70 | if (fileExists(".travis.yml")) { |
| 71 | common.infoMsg(".travis.yml found, running custom kitchen init") |
| 72 | def kitchenConfigYML = readYaml(file: ".travis.yml") |
| 73 | def kitchenInit = kitchenConfigYML["install"] |
| 74 | def kitchenInstalled = false |
| 75 | if (kitchenInit && !kitchenInit.isEmpty()) { |
| 76 | for (int i = 0; i < kitchenInit.size(); i++) { |
| 77 | if (kitchenInit[i].trim().startsWith("if [ ! -e Gemfile ]")) { //found Gemfile config |
| 78 | common.infoMsg("Custom Gemfile configuration found, using them") |
| 79 | if (openstackTest) { |
| 80 | withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id, |
| 81 | usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) { |
| 82 | env.OS_USERNAME = OS_USERNAME |
| 83 | env.OS_PASSWORD = OS_PASSWORD |
| 84 | env.OS_AUTH_URL = OS_AUTH_URL |
| 85 | env.OS_PROJECT_NAME = OS_PROJECT_NAME |
| 86 | env.OS_DOMAIN_NAME = OS_DOMAIN_NAME |
| 87 | env.OS_AZ = OS_AZ |
| 88 | } |
Martin Polreich | c39edae | 2018-11-07 08:42:11 +0100 | [diff] [blame] | 89 | } |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 90 | ruby.installKitchen(kitchenInit[i].trim()) |
| 91 | kitchenInstalled = true |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 92 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 93 | } |
| 94 | } |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 95 | if (!kitchenInstalled) { |
| 96 | ruby.installKitchen() |
| 97 | } |
| 98 | } else { |
| 99 | common.infoMsg(".travis.yml not found, running default kitchen init") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 100 | ruby.installKitchen() |
| 101 | } |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 102 | common.infoMsg("Running part of kitchen test") |
| 103 | if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") { |
| 104 | cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "") |
| 105 | if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv } |
| 106 | sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"") |
| 107 | sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"") |
| 108 | def suite = ruby.getSuiteName(KITCHEN_ENV) |
| 109 | if (suite && suite != "") { |
| 110 | common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim()) |
| 111 | ruby.runKitchenTests(cleanEnv, suite) |
| 112 | } else { |
| 113 | common.warningMsg("No SUITE was found. Running with all suites.") |
| 114 | ruby.runKitchenTests(cleanEnv, "") |
| 115 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 116 | } else { |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 117 | throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 118 | } |
| 119 | } else { |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 120 | throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 121 | } |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 122 | }/** TODO: End of block for removal */ |
| 123 | } else { |
| 124 | if (checkouted) { |
| 125 | travisLess = true |
Martin Polreich | 5be29e3 | 2019-02-26 11:11:51 +0100 | [diff] [blame] | 126 | if (fileExists(".kitchen.openstack.yml")) { |
| 127 | common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.") |
| 128 | kitchenFileName = ".kitchen.openstack.yml" |
| 129 | envOverrides.add("KITCHEN_YAML=${kitchenFileName}") |
| 130 | withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id, |
| 131 | usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) { |
| 132 | env.OS_USERNAME = OS_USERNAME |
| 133 | env.OS_PASSWORD = OS_PASSWORD |
| 134 | env.OS_AUTH_URL = OS_AUTH_URL |
| 135 | env.OS_PROJECT_NAME = OS_PROJECT_NAME |
| 136 | env.OS_DOMAIN_NAME = OS_DOMAIN_NAME |
| 137 | env.OS_AZ = OS_AZ |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 138 | } |
Martin Polreich | 5be29e3 | 2019-02-26 11:11:51 +0100 | [diff] [blame] | 139 | } else if (fileExists(".kitchen.yml")) { |
| 140 | common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.") |
| 141 | kitchenFileName = ".kitchen.yml" |
| 142 | } |
| 143 | if (kitchenFileName) { |
Denis Egorenko | 5884e31 | 2020-12-16 15:46:20 +0400 | [diff] [blame] | 144 | ruby.ensureRubyEnv() |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 145 | if (!fileExists("Gemfile")) { |
Taras Khlivnyak | 7a7bf1e | 2021-02-17 13:17:20 +0200 | [diff] [blame^] | 146 | sh("curl -s 'https://gerrit.mcp.mirantis.com/projects/salt-formulas%2Fsalt-formulas-scripts/branches/master/files/Gemfile/content' | base64 -d > ./Gemfile") |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 147 | ruby.installKitchen() |
| 148 | } else { |
| 149 | common.infoMsg("Override Gemfile found in the kitchen directory, using it.") |
| 150 | ruby.installKitchen() |
| 151 | } |
| 152 | common.infoMsg("Running part of kitchen test") |
| 153 | if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") { |
| 154 | testSuite = KITCHEN_ENV.replaceAll("_", "-").trim() |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 155 | sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"") |
| 156 | sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"") |
| 157 | common.infoMsg("Running kitchen test with environment:" + testSuite) |
Martin Polreich | 5be29e3 | 2019-02-26 11:11:51 +0100 | [diff] [blame] | 158 | ruby.runKitchenTests(envOverrides.join(' '), testSuite) |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 159 | } else { |
| 160 | throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.") |
| 161 | } |
| 162 | } else { |
Martin Polreich | 5be29e3 | 2019-02-26 11:11:51 +0100 | [diff] [blame] | 163 | throw new Exception(".kitchen.yml nor .kitchen.openstack.yml file not found, no kitchen tests triggered.") |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 164 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | } |
| 168 | } catch (Throwable e) { |
| 169 | // If there was an error or exception thrown, the build failed |
| 170 | currentBuild.result = "FAILURE" |
Dzmitry Stremkouski | ca76bfa | 2018-11-07 14:19:58 +0100 | [diff] [blame] | 171 | sh(script: 'find .kitchen/logs/ -type f -iname "*.log" | xargs -I{} bash -c "echo {}; cat {}"') |
Martin Polreich | 32b8222 | 2018-11-21 14:01:39 +0100 | [diff] [blame] | 172 | if (travisLess) { |
| 173 | ruby.runKitchenCommand("destroy", testSuite) |
| 174 | } else { |
| 175 | ruby.runKitchenCommand("destroy", cleanEnv) /** TODO: Remove once formulas are witched to new config */ |
| 176 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 177 | throw e |
| 178 | } finally { |
| 179 | if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) { |
| 180 | common.errorMsg("----------------KITCHEN LOG:---------------") |
| 181 | println readFile(".kitchen/logs/kitchen.log") |
| 182 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 183 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 184 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 185 | } |
Martin Polreich | b33d23e | 2017-09-01 15:22:16 +0000 | [diff] [blame] | 186 | } |