blob: 7190eb6040ecab208a39a9ba22a8d00b94b30ba6 [file] [log] [blame]
Jakub Josef83379312017-03-29 18:12:34 +02001
2/**
3 * Test salt models pipeline
4 * DEFAULT_GIT_REF
5 * DEFAULT_GIT_URL
6 * CREDENTIALS_ID
Jakub Josef27424bc2017-05-22 16:56:27 +02007 * EXTRA_FORMULAS
chnydad66d6fa2017-06-22 09:34:43 +02008 * SYSTEM_GIT_URL
9 * SYSTEM_GIT_REF
chnydabb6d2a62017-07-31 14:09:16 +020010 * MAX_CPU_PER_JOB
Jakub Josef83379312017-03-29 18:12:34 +020011 */
12
Jakub Josefc5a223a2017-03-01 14:40:08 +010013def common = new com.mirantis.mk.Common()
14def gerrit = new com.mirantis.mk.Gerrit()
Filip Pytloun38005aa2017-03-06 10:26:38 +010015def ssh = new com.mirantis.mk.Ssh()
16def git = new com.mirantis.mk.Git()
Jakub Josefc5a223a2017-03-01 14:40:08 +010017
chnyda64b73582017-07-19 12:01:32 +020018def config_node_name_pattern
19try {
20 config_node_name_pattern = CONFIG_NODE_NAME_PATTERN
21} catch (MissingPropertyException e) {
22 config_node_name_pattern = "cfg01"
23}
24
Filip Pytloun19376a82017-03-07 12:29:00 +010025def gerritRef
26try {
27 gerritRef = GERRIT_REFSPEC
28} catch (MissingPropertyException e) {
29 gerritRef = null
30}
31
Mykyta Karpinc0758f32017-06-23 18:10:24 +030032def formulasSource
33try {
34 formulasSource = FORMULAS_SOURCE
35} catch (MissingPropertyException e) {
36 formulasSource = "pkg"
37}
38
Jakub Josef83379312017-03-29 18:12:34 +020039def defaultGitRef, defaultGitUrl
Filip Pytloun19376a82017-03-07 12:29:00 +010040try {
Jakub Josef83379312017-03-29 18:12:34 +020041 defaultGitRef = DEFAULT_GIT_REF
42 defaultGitUrl = DEFAULT_GIT_URL
Filip Pytloun19376a82017-03-07 12:29:00 +010043} catch (MissingPropertyException e) {
Jakub Josef83379312017-03-29 18:12:34 +020044 defaultGitRef = null
45 defaultGitUrl = null
Filip Pytloun19376a82017-03-07 12:29:00 +010046}
Jakub Josef83379312017-03-29 18:12:34 +020047def checkouted = false
chnyda3b1d2a62017-06-13 10:08:12 +020048node("python") {
Jakub Josefc5a223a2017-03-01 14:40:08 +010049 try{
50 stage("checkout") {
Filip Pytloun19376a82017-03-07 12:29:00 +010051 if (gerritRef) {
Jakub Josef83379312017-03-29 18:12:34 +020052 // job is triggered by Gerrit
Jakub Joseffcb615e2017-04-10 14:34:40 +020053 // test if change aren't already merged
Jakub Josefb2235902017-06-16 12:49:16 +020054 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
55 // test if gerrit change is already Verified
Jakub Josef2ed50812017-06-16 14:56:58 +020056 if(gerrit.patchsetHasApproval(gerritChange.currentPatchSet,"Verified", "+")){
Jakub Josef894f1e32017-06-19 16:24:19 +000057 common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing
Jakub Josefbcd2e902017-06-13 14:40:41 +020058 // test WIP contains in commit message
Jakub Josefb2235902017-06-16 12:49:16 +020059 }else if (gerritChange.commitMessage.contains("WIP")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000060 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
Jakub Josefbcd2e902017-06-13 14:40:41 +020061 } 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 Joseffcb615e2017-04-10 14:34:40 +020070 }
chnydad66d6fa2017-06-22 09:34:43 +020071 // defaultGitUrl is passed to the triggered job
72 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
73 defaultGitRef = GERRIT_REFSPEC
Jakub Josef83379312017-03-29 18:12:34 +020074 } else if(defaultGitRef && defaultGitUrl) {
Jakub Josefe1407ac2017-03-30 14:10:19 +020075 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josefbcd2e902017-06-13 14:40:41 +020076 } else {
77 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Filip Pytloun19376a82017-03-07 12:29:00 +010078 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010079 }
chnydaa9c88702017-05-09 16:51:07 +020080
chnyda14e44292017-05-13 19:00:06 +020081 stage("test-nodes") {
Jakub Josefbcd2e902017-06-13 14:40:41 +020082 if(checkouted) {
chnyda32c6d9d2017-09-27 10:18:09 +020083
84 def modifiedClusters = null
chnydae6572452017-09-27 14:40:15 +020085
chnyda32c6d9d2017-09-27 10:18:09 +020086 if (gerritRef) {
87 checkChange = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v classes/cluster", returnStatus: true)
88 if (checkChange == 1) {
89 modifiedClusters = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep classes/cluster/ | awk -F/ '{print \$3}' | uniq", returnStdout: true).tokenize()
90 }
91 }
92
chnydae6572452017-09-27 14:40:15 +020093 def infraYMLs = sh(script: "find ./classes/ -regex '.*cluster/[-_a-zA-Z0-9]*/[infra/]*init\\.yml' -exec grep -il 'cluster_name' {} \\;", returnStdout: true).tokenize()
Jakub Josef8a544162017-09-27 18:06:36 +020094 def clusterDirectories = sh(script: "ls -d ./classes/cluster/*/", returnStdout: true).tokenize()
chnyda0b077cb2017-09-27 16:51:46 +020095
Jakub Josef6fb10432017-09-27 17:46:01 +020096 // create a list of cluster names present in cluster folder
chnyda0b077cb2017-09-27 16:51:46 +020097 def infraList = []
98 for (elt in infraYMLs) {
99 infraList << elt.tokenize('/')[3]
100 }
101
Jakub Josef6fb10432017-09-27 17:46:01 +0200102 // verify we have all valid clusters loaded
chnyda0b077cb2017-09-27 16:51:46 +0200103 def commonList = infraList.intersect(clusterDirectories)
104 def differenceList = infraList.plus(clusterDirectories)
105 differenceList.removeAll(commonList)
Jakub Josef6fb10432017-09-27 17:46:01 +0200106 if(!differenceList.isEmpty()){
107 common.warningMsg("The following clusters are not valid : ${differenceList} - That means we cannot found cluster_name in init.yml or infra/init.yml")
108 }
chnydae6572452017-09-27 14:40:15 +0200109 if (modifiedClusters) {
110 infraYMLs.removeAll { !modifiedClusters.contains(it.tokenize('/')[3]) }
111 common.infoMsg("Testing only modified clusters: ${infraYMLs}")
112 }
113
114 def branches = [:]
115 def acc = 0
116
Jakub Josef990013b2017-09-22 00:42:59 +0200117 for (int i = 0; i < infraYMLs.size(); i++) {
118 def infraYMLConfig = readYaml(file: infraYMLs[i])
119 if(!infraYMLConfig["parameters"].containsKey("_param")){
120 common.warningMsg("ERROR: Cannot find soft params (_param) in file " + infraYMLs[i] + " for obtain a cluster info. Skipping test.")
121 continue
122 }
123 def infraParams = infraYMLConfig["parameters"]["_param"];
124 if(!infraParams.containsKey("infra_config_hostname") || !infraParams.containsKey("cluster_name") || !infraParams.containsKey("cluster_domain")){
125 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.")
126 continue
127 }
128 def clusterName = infraParams["cluster_name"]
129 def clusterDomain = infraParams["cluster_domain"]
130 def configHostname = infraParams["infra_config_hostname"]
131 def testTarget = String.format("%s.%s", configHostname, clusterDomain)
Cedric Hnydac87fc6c2017-09-22 13:12:36 +0000132 if (acc >= PARALLEL_NODE_GROUP_SIZE.toInteger()) {
133 parallel branches
134 branches = [:]
135 acc = 0
136 }
chnyda1186a9c2017-06-26 13:13:32 +0200137
Jakub Josef3b52adc2017-09-28 20:11:12 +0200138 branches[clusterName] = {
Jakub Josef8a544162017-09-27 18:06:36 +0200139 common.infoMsg("Running testing of salt model clusters - test group ${i}")
chnyda1186a9c2017-06-26 13:13:32 +0200140 build job: "test-salt-model-node", parameters: [
141 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
142 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
Jakub Josef107769c2017-08-17 13:38:15 +0200143 [$class: 'StringParameterValue', name: 'CLUSTER_NAME', value: clusterName],
chnyda1186a9c2017-06-26 13:13:32 +0200144 [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget],
chnydaab82fd42017-06-26 13:30:02 +0200145 [$class: 'StringParameterValue', name: 'FORMULAS_SOURCE', value: formulasSource],
chnyda1186a9c2017-06-26 13:13:32 +0200146 [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS],
Jakub Josef09251c92017-06-27 11:49:33 +0200147 [$class: 'StringParameterValue', name: 'FORMULAS_REVISION', value: FORMULAS_REVISION],
chnyda1186a9c2017-06-26 13:13:32 +0200148 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
149 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: SYSTEM_GIT_URL],
chnydabb6d2a62017-07-31 14:09:16 +0200150 [$class: 'StringParameterValue', name: 'MAX_CPU_PER_JOB', value: MAX_CPU_PER_JOB],
chnyda1186a9c2017-06-26 13:13:32 +0200151 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: SYSTEM_GIT_REF]
152 ]}
Cedric Hnydac87fc6c2017-09-22 13:12:36 +0000153 acc++;
chnyda81ae93d2017-06-22 15:49:52 +0200154 }
Cedric Hnydac87fc6c2017-09-22 13:12:36 +0000155 if (acc != 0) {
156 parallel branches
157 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100158 }
chnyda51b03142017-05-10 17:15:27 +0200159 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100160 } catch (Throwable e) {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100161 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200162 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +0100163 throw e
164 } finally {
165 common.sendNotification(currentBuild.result,"",["slack"])
166 }
Tomáš Kukrál500c0182017-05-11 13:46:19 +0200167}