Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 1 | |
| 2 | /** |
| 3 | * Test salt models pipeline |
| 4 | * DEFAULT_GIT_REF |
| 5 | * DEFAULT_GIT_URL |
| 6 | * CREDENTIALS_ID |
Jakub Josef | 27424bc | 2017-05-22 16:56:27 +0200 | [diff] [blame] | 7 | * EXTRA_FORMULAS |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 8 | * SYSTEM_GIT_URL |
| 9 | * SYSTEM_GIT_REF |
chnyda | bb6d2a6 | 2017-07-31 14:09:16 +0200 | [diff] [blame] | 10 | * MAX_CPU_PER_JOB |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 13 | def common = new com.mirantis.mk.Common() |
| 14 | def gerrit = new com.mirantis.mk.Gerrit() |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 15 | def ssh = new com.mirantis.mk.Ssh() |
| 16 | def git = new com.mirantis.mk.Git() |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 17 | |
chnyda | 64b7358 | 2017-07-19 12:01:32 +0200 | [diff] [blame] | 18 | def config_node_name_pattern |
| 19 | try { |
| 20 | config_node_name_pattern = CONFIG_NODE_NAME_PATTERN |
| 21 | } catch (MissingPropertyException e) { |
| 22 | config_node_name_pattern = "cfg01" |
| 23 | } |
| 24 | |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 25 | def gerritRef |
| 26 | try { |
| 27 | gerritRef = GERRIT_REFSPEC |
| 28 | } catch (MissingPropertyException e) { |
| 29 | gerritRef = null |
| 30 | } |
| 31 | |
Mykyta Karpin | c0758f3 | 2017-06-23 18:10:24 +0300 | [diff] [blame] | 32 | def formulasSource |
| 33 | try { |
| 34 | formulasSource = FORMULAS_SOURCE |
| 35 | } catch (MissingPropertyException e) { |
| 36 | formulasSource = "pkg" |
| 37 | } |
| 38 | |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 39 | def defaultGitRef, defaultGitUrl |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 40 | try { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 41 | defaultGitRef = DEFAULT_GIT_REF |
| 42 | defaultGitUrl = DEFAULT_GIT_URL |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 43 | } catch (MissingPropertyException e) { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 44 | defaultGitRef = null |
| 45 | defaultGitUrl = null |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 46 | } |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 47 | def checkouted = false |
chnyda | 3b1d2a6 | 2017-06-13 10:08:12 +0200 | [diff] [blame] | 48 | node("python") { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 49 | try{ |
| 50 | stage("checkout") { |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 51 | if (gerritRef) { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 52 | // job is triggered by Gerrit |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 53 | // test if change aren't already merged |
Jakub Josef | b223590 | 2017-06-16 12:49:16 +0200 | [diff] [blame] | 54 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true) |
| 55 | // test if gerrit change is already Verified |
Jakub Josef | 2ed5081 | 2017-06-16 14:56:58 +0200 | [diff] [blame] | 56 | if(gerrit.patchsetHasApproval(gerritChange.currentPatchSet,"Verified", "+")){ |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 57 | common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 58 | // test WIP contains in commit message |
Jakub Josef | b223590 | 2017-06-16 12:49:16 +0200 | [diff] [blame] | 59 | }else if (gerritChange.commitMessage.contains("WIP")) { |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 60 | common.successMsg("Commit message contains WIP, skipping tests") // do nothing |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 61 | } else { |
| 62 | def merged = gerritChange.status == "MERGED" |
| 63 | if(!merged){ |
| 64 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 65 | credentialsId : CREDENTIALS_ID |
| 66 | ]) |
| 67 | } else{ |
| 68 | common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them") |
| 69 | } |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 70 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 71 | // defaultGitUrl is passed to the triggered job |
| 72 | defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}" |
| 73 | defaultGitRef = GERRIT_REFSPEC |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 74 | } else if(defaultGitRef && defaultGitUrl) { |
Jakub Josef | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 75 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 76 | } else { |
| 77 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 78 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 79 | } |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 80 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame] | 81 | stage("test-nodes") { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 82 | if(checkouted) { |
Jakub Josef | 990013b | 2017-09-22 00:42:59 +0200 | [diff] [blame] | 83 | def infraYMLs = sh(script: "find ./classes/ -regex '.*cluster/[-_a-zA-Z0-9]*/[infra/]*init\\.yml' -exec grep -il 'cluster_name' {} \\;", returnStdout: true).tokenize() |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 84 | def branches = [:] |
Cedric Hnyda | c87fc6c | 2017-09-22 13:12:36 +0000 | [diff] [blame] | 85 | def acc = 0 |
chnyda | 32c6d9d | 2017-09-27 10:18:09 +0200 | [diff] [blame^] | 86 | |
| 87 | def modifiedClusters = null |
| 88 | if (gerritRef) { |
| 89 | checkChange = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v classes/cluster", returnStatus: true) |
| 90 | if (checkChange == 1) { |
| 91 | modifiedClusters = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep classes/cluster/ | awk -F/ '{print \$3}' | uniq", returnStdout: true).tokenize() |
| 92 | } |
| 93 | } |
| 94 | |
Jakub Josef | 990013b | 2017-09-22 00:42:59 +0200 | [diff] [blame] | 95 | for (int i = 0; i < infraYMLs.size(); i++) { |
| 96 | def infraYMLConfig = readYaml(file: infraYMLs[i]) |
| 97 | if(!infraYMLConfig["parameters"].containsKey("_param")){ |
| 98 | common.warningMsg("ERROR: Cannot find soft params (_param) in file " + infraYMLs[i] + " for obtain a cluster info. Skipping test.") |
| 99 | continue |
| 100 | } |
| 101 | def infraParams = infraYMLConfig["parameters"]["_param"]; |
| 102 | if(!infraParams.containsKey("infra_config_hostname") || !infraParams.containsKey("cluster_name") || !infraParams.containsKey("cluster_domain")){ |
| 103 | common.warningMsg("ERROR: Cannot find _param:infra_config_hostname or _param:cluster_name or _param:cluster_domain in file " + infraYMLs[i] + " for obtain a cluster info. Skipping test.") |
| 104 | continue |
| 105 | } |
| 106 | def clusterName = infraParams["cluster_name"] |
| 107 | def clusterDomain = infraParams["cluster_domain"] |
| 108 | def configHostname = infraParams["infra_config_hostname"] |
| 109 | def testTarget = String.format("%s.%s", configHostname, clusterDomain) |
Cedric Hnyda | c87fc6c | 2017-09-22 13:12:36 +0000 | [diff] [blame] | 110 | if (acc >= PARALLEL_NODE_GROUP_SIZE.toInteger()) { |
| 111 | parallel branches |
| 112 | branches = [:] |
| 113 | acc = 0 |
| 114 | } |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 115 | |
chnyda | 32c6d9d | 2017-09-27 10:18:09 +0200 | [diff] [blame^] | 116 | if (gerritRef && modifiedClusters && !modifiedClusters.contains(clusterName)) { |
| 117 | continue |
| 118 | } |
| 119 | |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 120 | branches[testTarget] = { |
| 121 | build job: "test-salt-model-node", parameters: [ |
| 122 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl], |
| 123 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef], |
Jakub Josef | 107769c | 2017-08-17 13:38:15 +0200 | [diff] [blame] | 124 | [$class: 'StringParameterValue', name: 'CLUSTER_NAME', value: clusterName], |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 125 | [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget], |
chnyda | ab82fd4 | 2017-06-26 13:30:02 +0200 | [diff] [blame] | 126 | [$class: 'StringParameterValue', name: 'FORMULAS_SOURCE', value: formulasSource], |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 127 | [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS], |
Jakub Josef | 09251c9 | 2017-06-27 11:49:33 +0200 | [diff] [blame] | 128 | [$class: 'StringParameterValue', name: 'FORMULAS_REVISION', value: FORMULAS_REVISION], |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 129 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID], |
| 130 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: SYSTEM_GIT_URL], |
chnyda | bb6d2a6 | 2017-07-31 14:09:16 +0200 | [diff] [blame] | 131 | [$class: 'StringParameterValue', name: 'MAX_CPU_PER_JOB', value: MAX_CPU_PER_JOB], |
chnyda | 1186a9c | 2017-06-26 13:13:32 +0200 | [diff] [blame] | 132 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: SYSTEM_GIT_REF] |
| 133 | ]} |
Cedric Hnyda | c87fc6c | 2017-09-22 13:12:36 +0000 | [diff] [blame] | 134 | acc++; |
chnyda | 81ae93d | 2017-06-22 15:49:52 +0200 | [diff] [blame] | 135 | } |
Cedric Hnyda | c87fc6c | 2017-09-22 13:12:36 +0000 | [diff] [blame] | 136 | if (acc != 0) { |
| 137 | parallel branches |
| 138 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 139 | } |
chnyda | 51b0314 | 2017-05-10 17:15:27 +0200 | [diff] [blame] | 140 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 141 | } catch (Throwable e) { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 142 | currentBuild.result = "FAILURE" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 143 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 144 | throw e |
| 145 | } finally { |
| 146 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 147 | } |
Tomáš Kukrál | 500c018 | 2017-05-11 13:46:19 +0200 | [diff] [blame] | 148 | } |
Jakub Josef | 8d02477 | 2017-05-15 18:07:45 +0200 | [diff] [blame] | 149 | |
chnyda | 32c6d9d | 2017-09-27 10:18:09 +0200 | [diff] [blame^] | 150 | x |