Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
Jakub Josef | 0bbbd80 | 2017-05-22 20:28:44 +0200 | [diff] [blame] | 6 | * KITCHEN_TESTS_PARALLEL |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 7 | */ |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 8 | def common = new com.mirantis.mk.Common() |
| 9 | def gerrit = new com.mirantis.mk.Gerrit() |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 10 | def ruby = new com.mirantis.mk.Ruby() |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 11 | |
| 12 | def gerritRef |
| 13 | try { |
| 14 | gerritRef = GERRIT_REFSPEC |
| 15 | } catch (MissingPropertyException e) { |
| 16 | gerritRef = null |
| 17 | } |
| 18 | |
Martin Polreich | be93d36 | 2017-08-29 16:09:40 +0200 | [diff] [blame] | 19 | def parallelGroupSize |
| 20 | try { |
| 21 | parallelGroupSize = Integer.valueOf(PARALLEL_GROUP_SIZE) |
| 22 | } catch (MissingPropertyException e) { |
| 23 | parallelGroupSize = 4 |
| 24 | } |
| 25 | |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 26 | def defaultGitRef, defaultGitUrl |
| 27 | try { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 28 | defaultGitRef = DEFAULT_GIT_REF |
| 29 | defaultGitUrl = DEFAULT_GIT_URL |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 30 | } catch (MissingPropertyException e) { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 31 | defaultGitRef = null |
| 32 | defaultGitUrl = null |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 35 | def checkouted = false |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 36 | |
chnyda | 3b1d2a6 | 2017-06-13 10:08:12 +0200 | [diff] [blame] | 37 | node("python") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 38 | try { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 39 | stage("checkout") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 40 | if (gerritRef) { |
| 41 | // job is triggered by Gerrit |
Jakub Josef | b223590 | 2017-06-16 12:49:16 +0200 | [diff] [blame] | 42 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true) |
| 43 | // test if gerrit change is already Verified |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 44 | if (gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")) { |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 45 | common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 46 | // test WIP contains in commit message |
| 47 | } else if (gerritChange.commitMessage.contains("WIP")) { |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 48 | common.successMsg("Commit message contains WIP, skipping tests") // do nothing |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 49 | } else { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 50 | // test if change aren't already merged |
| 51 | def merged = gerritChange.status == "MERGED" |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 52 | if (!merged) { |
| 53 | checkouted = gerrit.gerritPatchsetCheckout([ |
| 54 | credentialsId: CREDENTIALS_ID |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 55 | ]) |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 56 | } else { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 57 | common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them") |
| 58 | } |
Jakub Josef | 740a788 | 2017-06-01 14:54:01 +0200 | [diff] [blame] | 59 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 60 | } else if (defaultGitRef && defaultGitUrl) { |
| 61 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 62 | } else { |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 63 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 64 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 65 | } |
| 66 | stage("test") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 67 | if (checkouted) { |
Ruslan Kamaldinov | 310ffc0 | 2017-08-08 16:07:42 +0400 | [diff] [blame] | 68 | sh("make clean") |
| 69 | sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test") |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 72 | stage("kitchen") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 73 | if (checkouted) { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 74 | if (fileExists(".kitchen.yml")) { |
| 75 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 76 | def kitchenEnvs = [] |
Martin Polreich | 9b5f5ab | 2017-07-12 13:06:14 +0200 | [diff] [blame] | 77 | def filteredEnvs = [] |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 78 | if (fileExists(".travis.yml")) { |
| 79 | common.infoMsg(".travis.yml file found.") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 80 | def kitchenConfigYML = readYaml(file: ".travis.yml") |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 81 | if (kitchenConfigYML.containsKey("env")) { |
| 82 | kitchenEnvs = kitchenConfigYML["env"] |
Ruslan Kamaldinov | 310ffc0 | 2017-08-08 16:07:42 +0400 | [diff] [blame] | 83 | } |
| 84 | } else { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 85 | common.warningMsg(".travis.yml file not found, suites must be passed via CUSTOM_KITCHEN_ENVS parameter.") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 86 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 87 | common.infoMsg("Running kitchen testing in parallel mode") |
| 88 | if (CUSTOM_KITCHEN_ENVS != null && CUSTOM_KITCHEN_ENVS != '') { |
| 89 | kitchenEnvs = CUSTOM_KITCHEN_ENVS.tokenize('\n') |
| 90 | common.infoMsg("CUSTOM_KITCHEN_ENVS not empty. Running with custom enviroments: ${kitchenEnvs}") |
| 91 | } |
| 92 | if (kitchenEnvs != null && kitchenEnvs != '') { |
Martin Polreich | a5b119d | 2017-08-29 16:32:56 +0200 | [diff] [blame^] | 93 | def acc = 0 |
| 94 | def kitchenTestRuns = [:] |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 95 | common.infoMsg("Found " + kitchenEnvs.size() + " environment(s)") |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 96 | for (int i = 0; i < kitchenEnvs.size(); i++) { |
| 97 | if (acc >= parallelGroupSize) { |
| 98 | parallel kitchenTestRuns |
Martin Polreich | a5b119d | 2017-08-29 16:32:56 +0200 | [diff] [blame^] | 99 | kitchenTestRuns = [:] |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 100 | acc = 0 |
| 101 | } |
| 102 | def testEnv = kitchenEnvs[i] |
| 103 | kitchenTestRuns[testEnv] = { |
| 104 | build job: "test-salt-formulas-env", parameters: [ |
| 105 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID], |
| 106 | [$class: 'StringParameterValue', name: 'KITCHEN_ENV', value: testEnv], |
| 107 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: DEFAULT_GIT_REF], |
| 108 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: DEFAULT_GIT_URL], |
| 109 | [$class: 'StringParameterValue', name: 'SALT_OPTS', value: SALT_OPTS], |
| 110 | [$class: 'StringParameterValue', name: 'SALT_VERSION', value: SALT_VERSION] |
| 111 | ] |
| 112 | } |
| 113 | acc++; |
| 114 | } |
| 115 | if (acc != 0) { |
| 116 | parallel kitchenTestRuns |
| 117 | } |
| 118 | } else { |
| 119 | common.warningMsg(".kitchen.yml file not found, no kitchen tests triggered.") |
| 120 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 121 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 122 | } |
| 123 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 124 | } catch (Throwable e) { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 125 | // If there was an error or exception thrown, the build failed |
| 126 | currentBuild.result = "FAILURE" |
| 127 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 128 | throw e |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 129 | } finally { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 130 | if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) { |
| 131 | common.errorMsg("----------------KITCHEN LOG:---------------") |
| 132 | println readFile(".kitchen/logs/kitchen.log") |
| 133 | } |
| 134 | common.sendNotification(currentBuild.result, "", ["slack"]) |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 135 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 136 | } |