chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 1 | common = new com.mirantis.mk.Common() |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 2 | gerrit = new com.mirantis.mk.Gerrit() |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 3 | git = new com.mirantis.mk.Git() |
| 4 | python = new com.mirantis.mk.Python() |
| 5 | saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
| 6 | |
Vasyl Saienko | 682043d | 2018-07-23 16:04:10 +0300 | [diff] [blame] | 7 | def reclassVersion = 'v1.5.4' |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 8 | if (common.validInputParam('RECLASS_VERSION')) { |
| 9 | reclassVersion = RECLASS_VERSION |
| 10 | } |
| 11 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 12 | def generateSaltMaster(modEnv, clusterDomain, clusterName) { |
| 13 | def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 14 | def nodeString = """classes: |
| 15 | - cluster.${clusterName}.infra.config |
| 16 | parameters: |
| 17 | _param: |
| 18 | linux_system_codename: xenial |
| 19 | reclass_data_revision: master |
| 20 | linux: |
| 21 | system: |
| 22 | name: cfg01 |
| 23 | domain: ${clusterDomain} |
| 24 | """ |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 25 | sh "mkdir -p ${modEnv}/nodes/" |
| 26 | println "Create file ${nodeFile}" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 27 | writeFile(file: nodeFile, text: nodeString) |
| 28 | } |
| 29 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 30 | def generateModel(modelFile, cutterEnv) { |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 31 | def templateEnv = "${env.WORKSPACE}" |
| 32 | def modelEnv = "${env.WORKSPACE}/model" |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 33 | def basename = sh(script: "basename ${modelFile} .yml", returnStdout: true).trim() |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 34 | def generatedModel = "${modelEnv}/${basename}" |
| 35 | def testEnv = "${env.WORKSPACE}/test" |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 36 | def content = readFile(file: "${templateEnv}/contexts/${modelFile}") |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 37 | def templateContext = readYaml text: content |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 38 | def clusterDomain = templateContext.default_context.cluster_domain |
| 39 | def clusterName = templateContext.default_context.cluster_name |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 40 | def outputDestination = "${generatedModel}/classes/cluster/${clusterName}" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 41 | def targetBranch = "feature/${clusterName}" |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 42 | def templateBaseDir = "${env.WORKSPACE}" |
| 43 | def templateDir = "${templateEnv}/dir" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 44 | def templateOutputDir = templateBaseDir |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 45 | sh "rm -rf ${generatedModel} || true" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 46 | |
Tomáš Kukrál | 9a6821e | 2017-07-24 11:07:01 +0200 | [diff] [blame] | 47 | common.infoMsg("Generating model from context ${modelFile}") |
chnyda | e79b94e | 2017-07-10 09:46:25 +0200 | [diff] [blame] | 48 | |
Mikhail Ivanov | 30c91f4 | 2017-11-07 20:42:26 +0400 | [diff] [blame] | 49 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 50 | for (product in productList) { |
Tomáš Kukrál | 9a6821e | 2017-07-24 11:07:01 +0200 | [diff] [blame] | 51 | |
| 52 | // get templateOutputDir and productDir |
| 53 | if (product.startsWith("stacklight")) { |
| 54 | templateOutputDir = "${env.WORKSPACE}/output/stacklight" |
| 55 | try { |
| 56 | productDir = "stacklight" + templateContext.default_context['stacklight_version'] |
| 57 | } catch (Throwable e) { |
| 58 | productDir = "stacklight1" |
| 59 | } |
| 60 | } else { |
| 61 | templateOutputDir = "${env.WORKSPACE}/output/${product}" |
| 62 | productDir = product |
| 63 | } |
| 64 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 65 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 66 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
Tomáš Kukrál | 9a6821e | 2017-07-24 11:07:01 +0200 | [diff] [blame] | 67 | |
| 68 | templateDir = "${templateEnv}/cluster_product/${productDir}" |
| 69 | common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir) |
| 70 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 71 | sh "rm -rf ${templateOutputDir} || true" |
| 72 | sh "mkdir -p ${templateOutputDir}" |
| 73 | sh "mkdir -p ${outputDestination}" |
Tomáš Kukrál | 9a6821e | 2017-07-24 11:07:01 +0200 | [diff] [blame] | 74 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 75 | python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, cutterEnv, templateBaseDir) |
| 76 | sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}" |
Tomáš Kukrál | 9a6821e | 2017-07-24 11:07:01 +0200 | [diff] [blame] | 77 | } else { |
| 78 | common.warningMsg("Product " + product + " is disabled") |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 79 | } |
| 80 | } |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 81 | generateSaltMaster(generatedModel, clusterDomain, clusterName) |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Vasyl Saienko | 682043d | 2018-07-23 16:04:10 +0300 | [diff] [blame] | 84 | def testModel(modelFile, testEnv, reclassVersion='v1.5.4') { |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 85 | def templateEnv = "${env.WORKSPACE}" |
| 86 | def content = readFile(file: "${templateEnv}/contexts/${modelFile}.yml") |
| 87 | def templateContext = readYaml text: content |
| 88 | def clusterName = templateContext.default_context.cluster_name |
| 89 | def clusterDomain = templateContext.default_context.cluster_domain |
| 90 | if (SYSTEM_GIT_URL == "") { |
| 91 | git.checkoutGitRepository("${testEnv}/classes/system", RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, CREDENTIALS_ID) |
| 92 | } else { |
| 93 | dir("${testEnv}/classes/system") { |
| 94 | if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) { |
| 95 | common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}") |
| 96 | } |
chnyda | 6f78a9d | 2017-12-19 11:34:26 +0100 | [diff] [blame] | 97 | } |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 98 | } |
chnyda | 7dd8cd9 | 2017-12-18 10:19:25 +0100 | [diff] [blame] | 99 | |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 100 | def testResult = false |
| 101 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
| 102 | testResult = saltModelTesting.setupAndTestNode( |
| 103 | "cfg01.${clusterDomain}", |
| 104 | clusterName, |
| 105 | EXTRA_FORMULAS, |
| 106 | testEnv, |
| 107 | 'pkg', |
| 108 | DISTRIB_REVISION, |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 109 | reclassVersion, |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 110 | 0, |
| 111 | false, |
| 112 | false, |
| 113 | '', |
| 114 | '', |
| 115 | DockerCName) |
| 116 | if (testResult) { |
| 117 | common.infoMsg("testModel finished: SUCCESS") |
| 118 | } else { |
| 119 | error('testModel finished: FAILURE') |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 120 | throw new RuntimeException('Test stage finished: FAILURE') |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 121 | } |
chnyda | 7dd8cd9 | 2017-12-18 10:19:25 +0100 | [diff] [blame] | 122 | |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | def gerritRef |
| 126 | try { |
| 127 | gerritRef = GERRIT_REFSPEC |
| 128 | } catch (MissingPropertyException e) { |
| 129 | gerritRef = null |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 130 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 131 | timeout(time: 12, unit: 'HOURS') { |
| 132 | node("python&&docker") { |
| 133 | def templateEnv = "${env.WORKSPACE}" |
| 134 | def cutterEnv = "${env.WORKSPACE}/cutter" |
| 135 | def jinjaEnv = "${env.WORKSPACE}/jinja" |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 136 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 137 | try { |
| 138 | stage("Cleanup") { |
| 139 | sh("rm -rf * || true") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 140 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 141 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 142 | stage ('Download Cookiecutter template') { |
| 143 | if (gerritRef) { |
| 144 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID) |
| 145 | merged = gerritChange.status == "MERGED" |
| 146 | if(!merged){ |
| 147 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 148 | credentialsId : CREDENTIALS_ID |
| 149 | ]) |
| 150 | } else{ |
| 151 | common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them") |
| 152 | } |
| 153 | } else { |
| 154 | git.checkoutGitRepository(templateEnv, COOKIECUTTER_TEMPLATE_URL, COOKIECUTTER_TEMPLATE_BRANCH, CREDENTIALS_ID) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 155 | } |
| 156 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 157 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 158 | stage("Setup") { |
| 159 | python.setupCookiecutterVirtualenv(cutterEnv) |
| 160 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 161 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 162 | stage("Check workflow_definition") { |
| 163 | sh "python ${env.WORKSPACE}/workflow_definition_test.py" |
| 164 | } |
| 165 | |
| 166 | def contextFiles |
| 167 | dir("${templateEnv}/contexts") { |
| 168 | contextFiles = findFiles(glob: "*.yml") |
| 169 | } |
| 170 | |
| 171 | def contextFileList = [] |
| 172 | for (int i = 0; i < contextFiles.size(); i++) { |
| 173 | contextFileList << contextFiles[i] |
| 174 | } |
| 175 | |
| 176 | stage("generate-model") { |
| 177 | for (contextFile in contextFileList) { |
| 178 | generateModel(contextFile, cutterEnv) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | dir("${env.WORKSPACE}") { |
| 183 | sh(returnStatus: true, script: "tar -zcvf model.tar.gz -C model .") |
| 184 | archiveArtifacts artifacts: "model.tar.gz" |
| 185 | } |
| 186 | |
| 187 | stage("test-nodes") { |
| 188 | def partitions = common.partitionList(contextFileList, PARALLEL_NODE_GROUP_SIZE.toInteger()) |
| 189 | def buildSteps = [:] |
Richard Felkl | 9351d03 | 2018-06-28 15:03:14 +0200 | [diff] [blame] | 190 | partitions.eachWithIndex { partition, i -> |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 191 | buildSteps.put("partition-${i}", new HashMap<String,org.jenkinsci.plugins.workflow.cps.CpsClosure2>()) |
Richard Felkl | 9351d03 | 2018-06-28 15:03:14 +0200 | [diff] [blame] | 192 | for(part in partition){ |
| 193 | def basename = sh(script: "basename ${part} .yml", returnStdout: true).trim() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 194 | def testEnv = "${env.WORKSPACE}/model/${basename}" |
Vasyl Saienko | c777bb8 | 2018-07-23 14:56:01 +0300 | [diff] [blame] | 195 | buildSteps.get("partition-${i}").put(basename, { testModel(basename, testEnv, reclassVersion) }) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | common.serial(buildSteps) |
| 199 | } |
| 200 | |
| 201 | stage ('Clean workspace directories') { |
| 202 | sh(returnStatus: true, script: "rm -rfv * > /dev/null || true") |
| 203 | } |
| 204 | |
| 205 | } catch (Throwable e) { |
| 206 | currentBuild.result = "FAILURE" |
| 207 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 208 | throw e |
| 209 | } finally { |
| 210 | def dummy = "dummy" |
| 211 | //FAILING common.sendNotification(currentBuild.result,"",["slack"]) |
| 212 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 213 | } |
| 214 | } |