chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 4 | * Setup Docker to run some tests. Returns true/false based on |
| 5 | were tests successful or not. |
| 6 | * @param config - LinkedHashMap with configuration params: |
| 7 | * dockerHostname - (required) Hostname to use for Docker container. |
azvyagintsev | abcf42e | 2018-10-05 20:40:27 +0300 | [diff] [blame] | 8 | * distribRevision - (optional) Revision of packages to use (default proposed). |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 9 | * runCommands - (optional) Dict with closure structure of body required tests. For example: |
| 10 | * [ '001_Test': { sh("./run-some-test") }, '002_Test': { sh("./run-another-test") } ] |
| 11 | * Before execution runCommands will be sorted by key names. Alpabetical order is preferred. |
| 12 | * runFinally - (optional) Dict with closure structure of body required commands, which should be |
| 13 | * executed in any case of test results. Same format as for runCommands |
| 14 | * updateRepo - (optional) Whether to run common repo update step. |
| 15 | * dockerContainerName - (optional) Docker container name. |
| 16 | * dockerImageName - (optional) Docker image name |
| 17 | * dockerMaxCpus - (optional) Number of CPUS to use in Docker. |
| 18 | * dockerExtraOpts - (optional) Array of Docker extra opts for container |
| 19 | * envOpts - (optional) Array of variables that should be passed as ENV vars to Docker container. |
| 20 | * Return true | false |
| 21 | */ |
| 22 | |
| 23 | def setupDockerAndTest(LinkedHashMap config) { |
| 24 | def common = new com.mirantis.mk.Common() |
| 25 | def TestMarkerResult = false |
| 26 | // setup options |
| 27 | def defaultContainerName = 'test-' + UUID.randomUUID().toString() |
| 28 | def dockerHostname = config.get('dockerHostname', defaultContainerName) |
azvyagintsev | abcf42e | 2018-10-05 20:40:27 +0300 | [diff] [blame] | 29 | def distribRevision = config.get('distribRevision', 'proposed') |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 30 | def runCommands = config.get('runCommands', [:]) |
| 31 | def runFinally = config.get('runFinally', [:]) |
| 32 | def baseRepoPreConfig = config.get('baseRepoPreConfig', true) |
| 33 | def dockerContainerName = config.get('dockerContainerName', defaultContainerName) |
azvyagintsev | e716a45 | 2018-11-25 13:41:52 +0200 | [diff] [blame] | 34 | // def dockerImageName = config.get('image', "mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7") |
| 35 | // FIXME /PROD-25244 |
Denis Egorenko | e8115c4 | 2019-04-15 20:21:25 +0400 | [diff] [blame] | 36 | def dockerImageName = config.get('image', "docker-prod-virtual.docker.mirantis.net/mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7") |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 37 | def dockerMaxCpus = config.get('dockerMaxCpus', 4) |
| 38 | def dockerExtraOpts = config.get('dockerExtraOpts', []) |
| 39 | def envOpts = config.get('envOpts', []) |
azvyagintsev | abcf42e | 2018-10-05 20:40:27 +0300 | [diff] [blame] | 40 | envOpts.add("DISTRIB_REVISION=${distribRevision}") |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 41 | def dockerBaseOpts = [ |
| 42 | '-u root:root', |
| 43 | "--hostname=${dockerHostname}", |
| 44 | '--ulimit nofile=4096:8192', |
| 45 | "--name=${dockerContainerName}", |
| 46 | "--cpus=${dockerMaxCpus}" |
| 47 | ] |
Denis Egorenko | 649cf7d | 2018-10-18 16:36:33 +0400 | [diff] [blame] | 48 | def dockerOptsFinal = (dockerBaseOpts + dockerExtraOpts).join(' ') |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 49 | def extraReposConfig = null |
| 50 | if (baseRepoPreConfig) { |
| 51 | // extra repo on mirror.mirantis.net, which is not supported before 2018.11.0 release |
| 52 | def extraRepoSource = "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/extra/xenial xenial main" |
Denis Egorenko | 7269cf3 | 2019-03-27 19:12:06 +0400 | [diff] [blame] | 53 | def releaseVersionQ4 = '2018.11.0' |
| 54 | def oldRelease = false |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 55 | try { |
| 56 | def releaseNaming = 'yyyy.MM.dd' |
| 57 | def repoDateUsed = new Date().parse(releaseNaming, distribRevision) |
Denis Egorenko | 7269cf3 | 2019-03-27 19:12:06 +0400 | [diff] [blame] | 58 | def extraAvailableFrom = new Date().parse(releaseNaming, releaseVersionQ4) |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 59 | if (repoDateUsed < extraAvailableFrom) { |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 60 | extraRepoSource = "deb http://apt.mcp.mirantis.net/xenial ${distribRevision} extra" |
Denis Egorenko | 7269cf3 | 2019-03-27 19:12:06 +0400 | [diff] [blame] | 61 | oldRelease = true |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 62 | } |
| 63 | } catch (Exception e) { |
| 64 | common.warningMsg(e) |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 65 | if (!(distribRevision in ['nightly', 'proposed', 'testing'])) { |
azvyagintsev | 62c9774 | 2019-01-02 17:53:54 +0200 | [diff] [blame] | 66 | extraRepoSource = "deb [arch=amd64] http://apt.mcp.mirantis.net/xenial ${distribRevision} extra" |
Denis Egorenko | 7269cf3 | 2019-03-27 19:12:06 +0400 | [diff] [blame] | 67 | oldRelease = true |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | def defaultExtraReposYaml = """ |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 72 | --- |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 73 | aprConfD: |- |
| 74 | APT::Get::AllowUnauthenticated 'true'; |
| 75 | APT::Get::Install-Suggests 'false'; |
| 76 | APT::Get::Install-Recommends 'false'; |
| 77 | repo: |
| 78 | mcp_saltstack: |
Denis Egorenko | 395aa21 | 2018-10-11 15:11:28 +0400 | [diff] [blame] | 79 | source: "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/saltstack-2017.7/xenial xenial main" |
Denis Egorenko | e02a1b2 | 2018-10-19 17:47:53 +0400 | [diff] [blame] | 80 | pin: |
| 81 | - package: "libsodium18" |
| 82 | pin: "release o=SaltStack" |
| 83 | priority: 50 |
| 84 | - package: "*" |
| 85 | pin: "release o=SaltStack" |
| 86 | priority: "1100" |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 87 | mcp_extra: |
Denis Egorenko | 3c752a5 | 2018-10-12 12:21:29 +0400 | [diff] [blame] | 88 | source: "${extraRepoSource}" |
Denis Egorenko | 395aa21 | 2018-10-11 15:11:28 +0400 | [diff] [blame] | 89 | mcp_saltformulas: |
azvyagintsev | 058c1f4 | 2018-12-14 18:32:33 +0200 | [diff] [blame] | 90 | source: "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/salt-formulas/xenial xenial main" |
| 91 | repo_key: "http://mirror.mirantis.com/${distribRevision}/salt-formulas/xenial/archive-salt-formulas.key" |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 92 | ubuntu: |
Denis Egorenko | 395aa21 | 2018-10-11 15:11:28 +0400 | [diff] [blame] | 93 | source: "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/ubuntu xenial main restricted universe" |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 94 | ubuntu-upd: |
Denis Egorenko | 395aa21 | 2018-10-11 15:11:28 +0400 | [diff] [blame] | 95 | source: "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/ubuntu xenial-updates main restricted universe" |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 96 | ubuntu-sec: |
Denis Egorenko | 395aa21 | 2018-10-11 15:11:28 +0400 | [diff] [blame] | 97 | source: "deb [arch=amd64] http://mirror.mirantis.com/${distribRevision}/ubuntu xenial-security main restricted universe" |
| 98 | """ |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 99 | // override for now |
| 100 | def extraRepoMergeStrategy = config.get('extraRepoMergeStrategy', 'override') |
| 101 | def extraRepos = config.get('extraRepos', [:]) |
azvyagintsev | 561ec87 | 2019-05-15 16:07:26 +0300 | [diff] [blame^] | 102 | def updateSaltFormulas = config.get('updateSaltFormulas', true).toBoolean() |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 103 | def defaultRepos = readYaml text: defaultExtraReposYaml |
azvyagintsev | 561ec87 | 2019-05-15 16:07:26 +0300 | [diff] [blame^] | 104 | // Don't check for magic, if set explicitly |
| 105 | if (updateSaltFormulas) { |
| 106 | if (!oldRelease && distribRevision != releaseVersionQ4) { |
| 107 | defaultRepos['repo']['mcp_saltformulas_update'] = [ |
| 108 | 'source' : "deb [arch=amd64] http://mirror.mirantis.com/update/${distribRevision}/salt-formulas/xenial xenial main", |
| 109 | 'repo_key': "http://mirror.mirantis.com/update/${distribRevision}/salt-formulas/xenial/archive-salt-formulas.key" |
| 110 | ] |
| 111 | } |
Denis Egorenko | 7269cf3 | 2019-03-27 19:12:06 +0400 | [diff] [blame] | 112 | } |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 113 | if (extraRepoMergeStrategy == 'merge') { |
| 114 | extraReposConfig = common.mergeMaps(defaultRepos, extraRepos) |
| 115 | } else { |
| 116 | extraReposConfig = extraRepos ? extraRepos : defaultRepos |
| 117 | } |
| 118 | } |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 119 | def img = docker.image(dockerImageName) |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 120 | |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 121 | img.pull() |
| 122 | |
| 123 | try { |
| 124 | img.inside(dockerOptsFinal) { |
| 125 | withEnv(envOpts) { |
| 126 | try { |
azvyagintsev | 4a8ccfa | 2019-04-08 16:25:08 +0300 | [diff] [blame] | 127 | sh('printenv |sort -u') |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 128 | // Currently, we don't have any other point to install |
| 129 | // runtime dependencies for tests. |
| 130 | if (baseRepoPreConfig) { |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 131 | // Warning! POssible point of 'allow-downgrades' issue |
| 132 | // Probably, need to add such flag into apt.prefs |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 133 | sh("""#!/bin/bash -xe |
| 134 | echo "Installing extra-deb dependencies inside docker:" |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 135 | echo > /etc/apt/sources.list |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 136 | rm -vf /etc/apt/sources.list.d/* || true |
Denis Egorenko | e02a1b2 | 2018-10-19 17:47:53 +0400 | [diff] [blame] | 137 | rm -vf /etc/apt/preferences.d/* || true |
Aleksey Zvyagintsev | c545334 | 2018-10-05 15:03:59 +0000 | [diff] [blame] | 138 | """) |
Denis Egorenko | 5cea141 | 2018-10-18 16:40:11 +0400 | [diff] [blame] | 139 | common.debianExtraRepos(extraReposConfig) |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 140 | sh('''#!/bin/bash -xe |
| 141 | apt-get update |
Denis Egorenko | c6b24be | 2018-10-10 17:36:04 +0400 | [diff] [blame] | 142 | apt-get install -y python-netaddr |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 143 | ''') |
| 144 | |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 145 | } |
| 146 | runCommands.sort().each { command, body -> |
| 147 | common.warningMsg("Running command: ${command}") |
| 148 | // doCall is the closure implementation in groovy, allow to pass arguments to closure |
| 149 | body.call() |
| 150 | } |
| 151 | // If we didn't dropped for now - test has been passed. |
| 152 | TestMarkerResult = true |
| 153 | } |
| 154 | finally { |
| 155 | runFinally.sort().each { command, body -> |
| 156 | common.warningMsg("Running ${command} command.") |
| 157 | // doCall is the closure implementation in groovy, allow to pass arguments to closure |
| 158 | body.call() |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | catch (Exception er) { |
| 165 | common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString()) |
| 166 | } |
| 167 | |
| 168 | try { |
| 169 | common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors") |
| 170 | timeout(time: 10, unit: 'SECONDS') { |
| 171 | sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true) |
| 172 | } |
| 173 | timeout(time: 10, unit: 'SECONDS') { |
| 174 | sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true) |
| 175 | } |
| 176 | } |
| 177 | catch (Exception er) { |
| 178 | common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString()) |
| 179 | } |
| 180 | |
| 181 | if (TestMarkerResult) { |
| 182 | common.infoMsg("Test finished: SUCCESS") |
| 183 | } else { |
| 184 | common.warningMsg("Test finished: FAILURE") |
| 185 | } |
| 186 | return TestMarkerResult |
| 187 | } |
| 188 | |
| 189 | /** |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 190 | * Wrapper around setupDockerAndTest, to run checks against new Reclass version |
| 191 | * that current model is compatible with new Reclass. |
| 192 | * |
| 193 | * @param config - LinkedHashMap with configuration params: |
| 194 | * dockerHostname - (required) Hostname to use for Docker container. |
| 195 | * distribRevision - (optional) Revision of packages to use (default proposed). |
| 196 | * extraRepo - (optional) Extra repo to use to install new Reclass version. Has |
| 197 | * high priority on distribRevision |
| 198 | * targetNodes - (required) List nodes to check pillar data. |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 199 | */ |
| 200 | def compareReclassVersions(config) { |
| 201 | def common = new com.mirantis.mk.Common() |
| 202 | def salt = new com.mirantis.mk.Salt() |
| 203 | common.infoMsg("Going to test new reclass for CFG node") |
| 204 | def distribRevision = config.get('distribRevision', 'proposed') |
| 205 | def venv = config.get('venv') |
| 206 | def extraRepo = config.get('extraRepo', '') |
| 207 | def extraRepoKey = config.get('extraRepoKey', '') |
| 208 | def targetNodes = config.get('targetNodes') |
| 209 | sh "rm -rf ${env.WORKSPACE}/old ${env.WORKSPACE}/new" |
| 210 | sh "mkdir -p ${env.WORKSPACE}/old ${env.WORKSPACE}/new" |
| 211 | def configRun = [ |
azvyagintsev | abcf42e | 2018-10-05 20:40:27 +0300 | [diff] [blame] | 212 | 'distribRevision': distribRevision, |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 213 | 'dockerExtraOpts': [ |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 214 | "-v /srv/salt/reclass:/srv/salt/reclass:ro", |
| 215 | "-v /etc/salt:/etc/salt:ro", |
| 216 | "-v /usr/share/salt-formulas/:/usr/share/salt-formulas/:ro" |
| 217 | ], |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 218 | 'envOpts' : [ |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 219 | "WORKSPACE=${env.WORKSPACE}", |
| 220 | "NODES_LIST=${targetNodes.join(' ')}" |
| 221 | ], |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 222 | 'runCommands' : [ |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 223 | '001_Update_Reclass_package' : { |
| 224 | sh('apt-get update && apt-get install -y reclass') |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 225 | }, |
| 226 | '002_Test_Reclass_Compatibility': { |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 227 | sh(''' |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 228 | reclass-salt -b /srv/salt/reclass -t > ${WORKSPACE}/new/inventory || exit 1 |
| 229 | for node in $NODES_LIST; do |
| 230 | reclass-salt -b /srv/salt/reclass -p $node > ${WORKSPACE}/new/$node || exit 1 |
| 231 | done |
| 232 | ''') |
| 233 | } |
| 234 | ] |
| 235 | ] |
| 236 | if (extraRepo) { |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 237 | // FIXME |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 238 | configRun['runCommands']['0001_Additional_Extra_Repo_Passed'] = { |
| 239 | sh(""" |
| 240 | echo "${extraRepo}" > /etc/apt/sources.list.d/mcp_extra.list |
| 241 | [ "${extraRepoKey}" ] && wget -O - ${extraRepoKey} | apt-key add - |
| 242 | """) |
| 243 | } |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 244 | } |
| 245 | if (setupDockerAndTest(configRun)) { |
| 246 | common.infoMsg("New reclass version is compatible with current model: SUCCESS") |
| 247 | def inventoryOld = salt.cmdRun(venv, "I@salt:master", "reclass-salt -b /srv/salt/reclass -t", true, null, true).get("return")[0].values()[0] |
| 248 | // [0..-31] to exclude 'echo Salt command execution success' from output |
| 249 | writeFile(file: "${env.WORKSPACE}/old/inventory", text: inventoryOld[0..-31]) |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 250 | for (String node in targetNodes) { |
Denis Egorenko | b090a76 | 2018-09-12 19:25:41 +0400 | [diff] [blame] | 251 | def nodeOut = salt.cmdRun(venv, "I@salt:master", "reclass-salt -b /srv/salt/reclass -p ${node}", true, null, true).get("return")[0].values()[0] |
| 252 | writeFile(file: "${env.WORKSPACE}/old/${node}", text: nodeOut[0..-31]) |
| 253 | } |
| 254 | def reclassDiff = common.comparePillars(env.WORKSPACE, env.BUILD_URL, '') |
| 255 | currentBuild.description = reclassDiff |
| 256 | if (reclassDiff != '<b>No job changes</b>') { |
| 257 | throw new RuntimeException("Pillars with new reclass version has been changed: FAILED") |
| 258 | } else { |
| 259 | common.infoMsg("Pillars not changed with new reclass version: SUCCESS") |
| 260 | } |
| 261 | } else { |
| 262 | throw new RuntimeException("New reclass version is not compatible with current model: FAILED") |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 267 | * Wrapper over setupDockerAndTest, to test CC model. |
| 268 | * |
| 269 | * @param config - dict with params: |
| 270 | * dockerHostname - (required) salt master's name |
| 271 | * clusterName - (optional) model cluster name |
| 272 | * extraFormulas - (optional) extraFormulas to install. DEPRECATED |
| 273 | * formulasSource - (optional) formulas source (git or pkg, default pkg) |
| 274 | * reclassVersion - (optional) Version of used reclass (branch, tag, ...) (optional, default master) |
| 275 | * reclassEnv - (require) directory of model |
| 276 | * ignoreClassNotfound - (optional) Ignore missing classes for reclass model (default false) |
| 277 | * aptRepoUrl - (optional) package repository with salt formulas |
| 278 | * aptRepoGPG - (optional) GPG key for apt repository with formulas |
| 279 | * testContext - (optional) Description of test |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 280 | Return: true\exception |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 281 | */ |
| 282 | |
| 283 | def testNode(LinkedHashMap config) { |
| 284 | def common = new com.mirantis.mk.Common() |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 285 | def dockerHostname = config.get('dockerHostname') |
Denis Egorenko | e3509c1 | 2019-02-19 14:06:26 +0400 | [diff] [blame] | 286 | def domain = config.get('domain') |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 287 | def reclassEnv = config.get('reclassEnv') |
| 288 | def clusterName = config.get('clusterName', "") |
| 289 | def formulasSource = config.get('formulasSource', 'pkg') |
| 290 | def extraFormulas = config.get('extraFormulas', 'linux') |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 291 | def ignoreClassNotfound = config.get('ignoreClassNotfound', false) |
| 292 | def aptRepoUrl = config.get('aptRepoUrl', "") |
| 293 | def aptRepoGPG = config.get('aptRepoGPG', "") |
| 294 | def testContext = config.get('testContext', 'test') |
Denis Egorenko | 66876fc | 2019-03-07 15:57:56 +0400 | [diff] [blame] | 295 | def nodegenerator = config.get('nodegenerator', false) |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 296 | config['envOpts'] = [ |
| 297 | "RECLASS_ENV=${reclassEnv}", "SALT_STOPSTART_WAIT=5", |
Denis Egorenko | e3509c1 | 2019-02-19 14:06:26 +0400 | [diff] [blame] | 298 | "HOSTNAME=${dockerHostname}", "CLUSTER_NAME=${clusterName}", |
| 299 | "DOMAIN=${domain}", "FORMULAS_SOURCE=${formulasSource}", |
Denis Egorenko | d54f60f | 2018-10-10 19:38:03 +0400 | [diff] [blame] | 300 | "EXTRA_FORMULAS=${extraFormulas}", "EXTRA_FORMULAS_PKG_ALL=true", |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 301 | "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "DEBUG=1", |
Denis Egorenko | d54f60f | 2018-10-10 19:38:03 +0400 | [diff] [blame] | 302 | "APT_REPOSITORY=${aptRepoUrl}", "APT_REPOSITORY_GPG=${aptRepoGPG}" |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 303 | ] |
| 304 | |
| 305 | config['runCommands'] = [ |
| 306 | '001_Clone_salt_formulas_scripts': { |
azvyagintsev | 62c9774 | 2019-01-02 17:53:54 +0200 | [diff] [blame] | 307 | sh(script: 'git clone http://gerrit.mcp.mirantis.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts', returnStdout: true) |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 308 | }, |
| 309 | |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 310 | '002_Prepare_something' : { |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 311 | sh('''#!/bin/bash -x |
| 312 | rsync -ah ${RECLASS_ENV}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts |
Denis Egorenko | e3509c1 | 2019-02-19 14:06:26 +0400 | [diff] [blame] | 313 | echo "127.0.0.1 ${HOSTNAME}.${DOMAIN}" >> /etc/hosts |
azvyagintsev | b9afd23 | 2019-02-11 14:22:31 +0200 | [diff] [blame] | 314 | if [ -f '/srv/salt/reclass/salt_master_pillar.asc' ] ; then |
| 315 | mkdir -p /etc/salt/gpgkeys |
| 316 | chmod 700 /etc/salt/gpgkeys |
| 317 | GNUPGHOME=/etc/salt/gpgkeys gpg --import /srv/salt/reclass/salt_master_pillar.asc |
| 318 | fi |
Alexander Evseev | 4983dec | 2018-10-25 15:49:39 +0200 | [diff] [blame] | 319 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {} \\; |
| 320 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {} \\; |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 321 | ''') |
| 322 | }, |
| 323 | |
Denis Egorenko | c6b24be | 2018-10-10 17:36:04 +0400 | [diff] [blame] | 324 | '003_Install_Reclass_package' : { |
| 325 | sh('apt-get install -y reclass') |
| 326 | }, |
| 327 | |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 328 | '004_Run_tests' : { |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 329 | def testTimeout = 40 * 60 |
| 330 | timeout(time: testTimeout, unit: 'SECONDS') { |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 331 | sh('''#!/bin/bash |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 332 | source /srv/salt/scripts/bootstrap.sh |
| 333 | cd /srv/salt/scripts |
| 334 | source_local_envs |
| 335 | configure_salt_master |
| 336 | configure_salt_minion |
| 337 | install_salt_formula_pkg |
| 338 | source /srv/salt/scripts/bootstrap.sh |
| 339 | cd /srv/salt/scripts |
| 340 | saltservice_restart''') |
| 341 | |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 342 | sh('''#!/bin/bash |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 343 | source /srv/salt/scripts/bootstrap.sh |
| 344 | cd /srv/salt/scripts |
| 345 | source_local_envs |
| 346 | saltmaster_init''') |
| 347 | |
Aleksey Zvyagintsev | b20bd26 | 2018-10-05 15:09:06 +0000 | [diff] [blame] | 348 | sh('''#!/bin/bash |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 349 | source /srv/salt/scripts/bootstrap.sh |
| 350 | cd /srv/salt/scripts |
| 351 | verify_salt_minions''') |
| 352 | } |
| 353 | } |
| 354 | ] |
| 355 | config['runFinally'] = [ |
| 356 | '001_Archive_artefacts': { |
| 357 | sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true) |
| 358 | archiveArtifacts artifacts: "nodesinfo.tar.gz" |
| 359 | } |
| 360 | ] |
Denis Egorenko | 66876fc | 2019-03-07 15:57:56 +0400 | [diff] [blame] | 361 | // this tool should be tested in master branch only |
| 362 | // and not for all jobs, as pilot will be used cc-reclass-chunk |
| 363 | if (nodegenerator) { |
| 364 | config['runCommands']['005_Test_new_nodegenerator'] = { |
| 365 | try { |
| 366 | sh('''#!/bin/bash |
| 367 | new_generated_dir=/srv/salt/_new_generated |
| 368 | mkdir -p ${new_generated_dir} |
| 369 | nodegenerator -b /srv/salt/reclass/classes/ -o ${new_generated_dir} ${CLUSTER_NAME} |
| 370 | diff -r /srv/salt/reclass/nodes/_generated ${new_generated_dir} > /tmp/nodegenerator.diff |
| 371 | tar -czf /tmp/_generated.tar.gz /srv/salt/reclass/nodes/_generated/ |
| 372 | tar -czf /tmp/_new_generated.tar.gz ${new_generated_dir}/ |
| 373 | tar -czf /tmp/_model.tar.gz /srv/salt/reclass/classes/cluster/* |
| 374 | ''') |
| 375 | } catch (Exception e) { |
| 376 | print "Test new nodegenerator tool is failed: ${e}" |
| 377 | } |
| 378 | } |
| 379 | config['runFinally']['002_Archive_nodegenerator_artefact'] = { |
| 380 | sh(script: "cd /tmp; [ -f nodegenerator.diff ] && tar -czf ${env.WORKSPACE}/nodegenerator.tar.gz nodegenerator.diff _generated.tar.gz _new_generated.tar.gz _model.tar.gz", returnStatus: true) |
| 381 | if (fileExists('nodegenerator.tar.gz')) { |
| 382 | archiveArtifacts artifacts: "nodegenerator.tar.gz" |
| 383 | } |
| 384 | } |
| 385 | } |
Denis Egorenko | 6fd79ac | 2018-09-12 13:28:21 +0400 | [diff] [blame] | 386 | testResult = setupDockerAndTest(config) |
| 387 | if (testResult) { |
| 388 | common.infoMsg("Node test for context: ${testContext} model: ${reclassEnv} finished: SUCCESS") |
| 389 | } else { |
| 390 | throw new RuntimeException("Node test for context: ${testContext} model: ${reclassEnv} finished: FAILURE") |
| 391 | } |
| 392 | return testResult |
| 393 | } |
| 394 | |
| 395 | /** |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 396 | * setup and test salt-master |
| 397 | * |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 398 | * @param masterName salt master's name |
| 399 | * @param clusterName model cluster name |
| 400 | * @param extraFormulas extraFormulas to install. DEPRECATED |
| 401 | * @param formulasSource formulas source (git or pkg) |
| 402 | * @param reclassVersion Version of used reclass (branch, tag, ...) (optional, default master) |
| 403 | * @param testDir directory of model |
| 404 | * @param formulasSource Salt formulas source type (optional, default pkg) |
| 405 | * @param formulasRevision APT revision for formulas (optional default stable) |
Petr Michalec | 6414aa5 | 2017-08-17 14:32:52 +0200 | [diff] [blame] | 406 | * @param ignoreClassNotfound Ignore missing classes for reclass model |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 407 | * @param dockerMaxCpus max cpus passed to docker (default 0, disabled) |
| 408 | * @param legacyTestingMode do you want to enable legacy testing mode (iterating through the nodes directory definitions instead of reading cluster models) |
| 409 | * @param aptRepoUrl package repository with salt formulas |
| 410 | * @param aptRepoGPG GPG key for apt repository with formulas |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 411 | * Return true | false |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 412 | */ |
| 413 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 414 | def setupAndTestNode(masterName, clusterName, extraFormulas = '*', testDir, formulasSource = 'pkg', |
Vasyl Saienko | 369ed90 | 2018-07-23 11:49:32 +0000 | [diff] [blame] | 415 | formulasRevision = 'stable', reclassVersion = "master", dockerMaxCpus = 0, |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 416 | ignoreClassNotfound = false, legacyTestingMode = false, aptRepoUrl = '', aptRepoGPG = '', dockerContainerName = false) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 417 | def common = new com.mirantis.mk.Common() |
azvyagintsev | 1cecc09 | 2018-09-14 13:19:16 +0300 | [diff] [blame] | 418 | // TODO |
| 419 | common.errorMsg('You are using deprecated function!Please migrate to "setupDockerAndTest".' + |
| 420 | 'It would be removed after 2018.q4 release!Pushing forced 60s sleep..') |
| 421 | sh('sleep 60') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 422 | // timeout for test execution (40min) |
| 423 | def testTimeout = 40 * 60 |
| 424 | def TestMarkerResult = false |
| 425 | def saltOpts = "--retcode-passthrough --force-color" |
| 426 | def workspace = common.getWorkspace() |
| 427 | def img = docker.image("mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7") |
| 428 | img.pull() |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 429 | |
azvyagintsev | 635affb | 2018-09-13 13:02:54 +0300 | [diff] [blame] | 430 | if (formulasSource == 'pkg') { |
| 431 | if (extraFormulas) { |
| 432 | common.warningMsg("You have passed deprecated variable:extraFormulas=${extraFormulas}. " + |
| 433 | "\n It would be ignored, and all formulas would be installed anyway") |
| 434 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 435 | } |
| 436 | if (!dockerContainerName) { |
| 437 | dockerContainerName = 'setupAndTestNode' + UUID.randomUUID().toString() |
| 438 | } |
| 439 | def dockerMaxCpusOpt = "--cpus=4" |
| 440 | if (dockerMaxCpus > 0) { |
| 441 | dockerMaxCpusOpt = "--cpus=${dockerMaxCpus}" |
| 442 | } |
| 443 | try { |
| 444 | img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOpt} --name=${dockerContainerName}") { |
azvyagintsev | 635affb | 2018-09-13 13:02:54 +0300 | [diff] [blame] | 445 | withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "EXTRA_FORMULAS_PKG_ALL=true", |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 446 | "DISTRIB_REVISION=${formulasRevision}", |
| 447 | "DEBUG=1", "MASTER_HOSTNAME=${masterName}", |
| 448 | "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}", |
| 449 | "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", |
| 450 | "APT_REPOSITORY=${aptRepoUrl}", "SALT_STOPSTART_WAIT=5", |
| 451 | "APT_REPOSITORY_GPG=${aptRepoGPG}"]) { |
| 452 | try { |
| 453 | // Currently, we don't have any other point to install |
| 454 | // runtime dependencies for tests. |
| 455 | sh("""#!/bin/bash -xe |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 456 | echo "Installing extra-deb dependencies inside docker:" |
| 457 | echo "APT::Get::AllowUnauthenticated 'true';" > /etc/apt/apt.conf.d/99setupAndTestNode |
| 458 | echo "APT::Get::Install-Suggests 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 459 | echo "APT::Get::Install-Recommends 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 460 | rm -vf /etc/apt/sources.list.d/* || true |
| 461 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial main restricted universe' > /etc/apt/sources.list |
| 462 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial-updates main restricted universe' >> /etc/apt/sources.list |
| 463 | apt-get update |
| 464 | apt-get install -y python-netaddr |
| 465 | """) |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 466 | sh(script: "git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts", returnStdout: true) |
| 467 | sh("""rsync -ah ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts |
Alexander Evseev | 4983dec | 2018-10-25 15:49:39 +0200 | [diff] [blame] | 468 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {} \\; |
| 469 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {} \\; |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 470 | """) |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 471 | // FIXME: should be changed to use reclass from mcp_extra_nigtly? |
| 472 | sh("""for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 473 | sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \ |
| 474 | -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${reclassVersion}; |
| 475 | done""") |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 476 | timeout(time: testTimeout, unit: 'SECONDS') { |
| 477 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 478 | source /srv/salt/scripts/bootstrap.sh |
| 479 | cd /srv/salt/scripts |
| 480 | source_local_envs |
| 481 | configure_salt_master |
| 482 | configure_salt_minion |
| 483 | install_salt_formula_pkg |
| 484 | source /srv/salt/scripts/bootstrap.sh |
| 485 | cd /srv/salt/scripts |
| 486 | saltservice_restart''') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 487 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 488 | source /srv/salt/scripts/bootstrap.sh |
| 489 | cd /srv/salt/scripts |
| 490 | source_local_envs |
| 491 | saltmaster_init''') |
| 492 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 493 | if (!legacyTestingMode.toBoolean()) { |
| 494 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 495 | source /srv/salt/scripts/bootstrap.sh |
| 496 | cd /srv/salt/scripts |
| 497 | verify_salt_minions |
| 498 | ''') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | // If we didn't dropped for now - test has been passed. |
| 502 | TestMarkerResult = true |
| 503 | } |
| 504 | |
| 505 | finally { |
| 506 | // Collect rendered per-node data.Those info could be simply used |
| 507 | // for diff processing. Data was generated via reclass.cli --nodeinfo, |
| 508 | /// during verify_salt_minions. |
| 509 | sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true) |
| 510 | archiveArtifacts artifacts: "nodesinfo.tar.gz" |
| 511 | } |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 512 | } |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 513 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 514 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 515 | catch (Exception er) { |
| 516 | common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString()) |
| 517 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 518 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 519 | if (legacyTestingMode.toBoolean()) { |
| 520 | common.infoMsg("Running legacy mode test for master hostname ${masterName}") |
| 521 | def nodes = sh(script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true) |
| 522 | for (minion in nodes.tokenize()) { |
| 523 | def basename = sh(script: "set +x;basename ${minion} .yml", returnStdout: true) |
| 524 | if (!basename.trim().contains(masterName)) { |
| 525 | testMinion(basename.trim()) |
| 526 | } |
| 527 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 528 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 529 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 530 | try { |
| 531 | common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors") |
| 532 | timeout(time: 10, unit: 'SECONDS') { |
| 533 | sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true) |
| 534 | } |
| 535 | timeout(time: 10, unit: 'SECONDS') { |
| 536 | sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true) |
| 537 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 538 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 539 | catch (Exception er) { |
| 540 | common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString()) |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 541 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 542 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 543 | if (TestMarkerResult) { |
| 544 | common.infoMsg("Test finished: SUCCESS") |
| 545 | } else { |
| 546 | common.warningMsg("Test finished: FAILURE") |
| 547 | } |
| 548 | return TestMarkerResult |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 549 | |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Test salt-minion |
| 554 | * |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 555 | * @param minion salt minion |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 556 | */ |
| 557 | |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 558 | def testMinion(minionName) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 559 | sh(script: "bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'", returnStdout: true) |
Jakub Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 560 | } |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 561 | |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 562 | /** |
| 563 | * Wrapper over setupAndTestNode, to test exactly one CC model. |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 564 | Whole workspace and model - should be pre-rendered and passed via MODELS_TARGZ |
| 565 | Flow: grab all data, and pass to setupAndTestNode function |
| 566 | under-modell will be directly mirrored to `model/{cfg.testReclassEnv}/* /srv/salt/reclass/*` |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 567 | * |
| 568 | * @param cfg - dict with params: |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 569 | MODELS_TARGZ http link to arch with (models|contexts|global_reclass) |
| 570 | modelFile |
| 571 | DockerCName directly passed to setupAndTestNode |
| 572 | EXTRA_FORMULAS directly passed to setupAndTestNode |
| 573 | DISTRIB_REVISION directly passed to setupAndTestNode |
| 574 | reclassVersion directly passed to setupAndTestNode |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 575 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 576 | Return: true\exception |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 577 | */ |
| 578 | |
| 579 | def testCCModel(cfg) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 580 | def common = new com.mirantis.mk.Common() |
azvyagintsev | 1cecc09 | 2018-09-14 13:19:16 +0300 | [diff] [blame] | 581 | common.errorMsg('You are using deprecated function!Please migrate to "testNode".' + |
| 582 | 'It would be removed after 2018.q4 release!Pushing forced 60s sleep..') |
| 583 | sh('sleep 60') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 584 | sh(script: 'find . -mindepth 1 -delete || true', returnStatus: true) |
| 585 | sh(script: "wget --progress=dot:mega --auth-no-challenge -O models.tar.gz ${cfg.MODELS_TARGZ}") |
| 586 | // unpack data |
| 587 | sh(script: "tar -xzf models.tar.gz ") |
| 588 | common.infoMsg("Going to test exactly one context: ${cfg.modelFile}\n, with params: ${cfg}") |
| 589 | content = readFile(file: cfg.modelFile) |
| 590 | templateContext = readYaml text: content |
| 591 | clusterName = templateContext.default_context.cluster_name |
| 592 | clusterDomain = templateContext.default_context.cluster_domain |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 593 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 594 | def testResult = false |
| 595 | testResult = setupAndTestNode( |
| 596 | "cfg01.${clusterDomain}", |
| 597 | clusterName, |
| 598 | '', |
| 599 | cfg.testReclassEnv, // Sync into image exactly one env |
| 600 | 'pkg', |
| 601 | cfg.DISTRIB_REVISION, |
| 602 | cfg.reclassVersion, |
| 603 | 0, |
| 604 | false, |
| 605 | false, |
| 606 | '', |
| 607 | '', |
| 608 | cfg.DockerCName) |
| 609 | if (testResult) { |
| 610 | common.infoMsg("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: SUCCESS") |
| 611 | } else { |
| 612 | throw new RuntimeException("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: FAILURE") |
| 613 | } |
| 614 | return testResult |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 615 | } |