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 | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 25 | def checkouted = false |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 26 | def openstackTest = false |
Martin Polreich | 32fbc01 | 2018-11-07 12:23:18 +0100 | [diff] [blame] | 27 | def cleanEnv = '' |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 28 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 29 | throttle(['test-formula']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 30 | timeout(time: 1, unit: 'HOURS') { |
Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 31 | node("python&&docker") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 32 | try { |
| 33 | stage("checkout") { |
| 34 | if (defaultGitRef && defaultGitUrl) { |
| 35 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 36 | } else { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 37 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null") |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 38 | } |
| 39 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 40 | stage("cleanup") { |
| 41 | if (checkouted) { |
| 42 | sh("make clean") |
| 43 | } |
| 44 | } |
| 45 | stage("kitchen") { |
| 46 | if (checkouted) { |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 47 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 57 | 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 Polreich | c39edae | 2018-11-07 08:42:11 +0100 | [diff] [blame] | 64 | 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 Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame] | 77 | } |
Martin Polreich | c39edae | 2018-11-07 08:42:11 +0100 | [diff] [blame] | 78 | ruby.installKitchen(kitchenInit[i].trim()) |
| 79 | kitchenInstalled = true |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 80 | } |
| 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 Polreich | 32fbc01 | 2018-11-07 12:23:18 +0100 | [diff] [blame] | 92 | cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "") |
Dzmitry Stremkouski | 8e8633b | 2018-11-06 19:13:25 +0100 | [diff] [blame] | 93 | if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv } |
Martin Polreich | 32fbc01 | 2018-11-07 12:23:18 +0100 | [diff] [blame] | 94 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 96 | 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 Stremkouski | ca76bfa | 2018-11-07 14:19:58 +0100 | [diff] [blame] | 115 | sh(script: 'find .kitchen/logs/ -type f -iname "*.log" | xargs -I{} bash -c "echo {}; cat {}"') |
Martin Polreich | 32fbc01 | 2018-11-07 12:23:18 +0100 | [diff] [blame] | 116 | ruby.runKitchenCommand("destroy", cleanEnv) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 117 | 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 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 123 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 124 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 125 | } |
Martin Polreich | b33d23e | 2017-09-01 15:22:16 +0000 | [diff] [blame] | 126 | } |