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. |
| 8 | * formulasRevision - (optional) Revision of packages to use (default stable). |
| 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) |
| 29 | def formulasRevision = config.get('formulasRevision', 'proposed') |
| 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) |
| 34 | def dockerImageName = config.get('image', "mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7") |
| 35 | def dockerMaxCpus = config.get('dockerMaxCpus', 4) |
| 36 | def dockerExtraOpts = config.get('dockerExtraOpts', []) |
| 37 | def envOpts = config.get('envOpts', []) |
| 38 | envOpts.add("DISTRIB_REVISION=${formulasRevision}") |
| 39 | def dockerBaseOpts = [ |
| 40 | '-u root:root', |
| 41 | "--hostname=${dockerHostname}", |
| 42 | '--ulimit nofile=4096:8192', |
| 43 | "--name=${dockerContainerName}", |
| 44 | "--cpus=${dockerMaxCpus}" |
| 45 | ] |
| 46 | |
| 47 | def dockerOptsFinal = (dockerBaseOpts + dockerExtraOpts).join(' ') |
| 48 | def img = docker.image(dockerImageName) |
| 49 | img.pull() |
| 50 | |
| 51 | try { |
| 52 | img.inside(dockerOptsFinal) { |
| 53 | withEnv(envOpts) { |
| 54 | try { |
| 55 | // Currently, we don't have any other point to install |
| 56 | // runtime dependencies for tests. |
| 57 | if (baseRepoPreConfig) { |
| 58 | sh("""#!/bin/bash -xe |
| 59 | echo "Installing extra-deb dependencies inside docker:" |
| 60 | echo "APT::Get::AllowUnauthenticated 'true';" > /etc/apt/apt.conf.d/99setupAndTestNode |
| 61 | echo "APT::Get::Install-Suggests 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 62 | echo "APT::Get::Install-Recommends 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 63 | rm -vf /etc/apt/sources.list.d/* || true |
| 64 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial main restricted universe' > /etc/apt/sources.list |
| 65 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial-updates main restricted universe' >> /etc/apt/sources.list |
| 66 | apt-get update |
| 67 | apt-get install -y python-netaddr |
| 68 | """) |
| 69 | } |
| 70 | runCommands.sort().each { command, body -> |
| 71 | common.warningMsg("Running command: ${command}") |
| 72 | // doCall is the closure implementation in groovy, allow to pass arguments to closure |
| 73 | body.call() |
| 74 | } |
| 75 | // If we didn't dropped for now - test has been passed. |
| 76 | TestMarkerResult = true |
| 77 | } |
| 78 | finally { |
| 79 | runFinally.sort().each { command, body -> |
| 80 | common.warningMsg("Running ${command} command.") |
| 81 | // doCall is the closure implementation in groovy, allow to pass arguments to closure |
| 82 | body.call() |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | catch (Exception er) { |
| 89 | common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString()) |
| 90 | } |
| 91 | |
| 92 | try { |
| 93 | common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors") |
| 94 | timeout(time: 10, unit: 'SECONDS') { |
| 95 | sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true) |
| 96 | } |
| 97 | timeout(time: 10, unit: 'SECONDS') { |
| 98 | sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true) |
| 99 | } |
| 100 | } |
| 101 | catch (Exception er) { |
| 102 | common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString()) |
| 103 | } |
| 104 | |
| 105 | if (TestMarkerResult) { |
| 106 | common.infoMsg("Test finished: SUCCESS") |
| 107 | } else { |
| 108 | common.warningMsg("Test finished: FAILURE") |
| 109 | } |
| 110 | return TestMarkerResult |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Wrapper over setupDockerAndTest, to test CC model. |
| 115 | * |
| 116 | * @param config - dict with params: |
| 117 | * dockerHostname - (required) salt master's name |
| 118 | * clusterName - (optional) model cluster name |
| 119 | * extraFormulas - (optional) extraFormulas to install. DEPRECATED |
| 120 | * formulasSource - (optional) formulas source (git or pkg, default pkg) |
| 121 | * reclassVersion - (optional) Version of used reclass (branch, tag, ...) (optional, default master) |
| 122 | * reclassEnv - (require) directory of model |
| 123 | * ignoreClassNotfound - (optional) Ignore missing classes for reclass model (default false) |
| 124 | * aptRepoUrl - (optional) package repository with salt formulas |
| 125 | * aptRepoGPG - (optional) GPG key for apt repository with formulas |
| 126 | * testContext - (optional) Description of test |
| 127 | Return: true\exception |
| 128 | */ |
| 129 | |
| 130 | def testNode(LinkedHashMap config) { |
| 131 | def common = new com.mirantis.mk.Common() |
| 132 | def result = '' |
| 133 | def dockerHostname = config.get('dockerHostname') |
| 134 | def reclassEnv = config.get('reclassEnv') |
| 135 | def clusterName = config.get('clusterName', "") |
| 136 | def formulasSource = config.get('formulasSource', 'pkg') |
| 137 | def extraFormulas = config.get('extraFormulas', 'linux') |
| 138 | def reclassVersion = config.get('reclassVersion', 'master') |
| 139 | def ignoreClassNotfound = config.get('ignoreClassNotfound', false) |
| 140 | def aptRepoUrl = config.get('aptRepoUrl', "") |
| 141 | def aptRepoGPG = config.get('aptRepoGPG', "") |
| 142 | def testContext = config.get('testContext', 'test') |
| 143 | config['envOpts'] = [ |
| 144 | "RECLASS_ENV=${reclassEnv}", "SALT_STOPSTART_WAIT=5", |
| 145 | "MASTER_HOSTNAME=${dockerHostname}", "CLUSTER_NAME=${clusterName}", |
| 146 | "MINION_ID=${dockerHostname}", "FORMULAS_SOURCE=${formulasSource}", |
| 147 | "EXTRA_FORMULAS=${extraFormulas}", "RECLASS_VERSION=${reclassVersion}", |
| 148 | "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "DEBUG=1", |
| 149 | "APT_REPOSITORY=${aptRepoUrl}", "APT_REPOSITORY_GPG=${aptRepoGPG}", |
| 150 | "EXTRA_FORMULAS_PKG_ALL=true" |
| 151 | ] |
| 152 | |
| 153 | config['runCommands'] = [ |
| 154 | '001_Clone_salt_formulas_scripts': { |
| 155 | sh(script: 'git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts', returnStdout: true) |
| 156 | }, |
| 157 | |
| 158 | '002_Prepare_something': { |
| 159 | sh('''rsync -ah ${RECLASS_ENV}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts |
| 160 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\; |
| 161 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\; |
| 162 | ''') |
| 163 | }, |
| 164 | |
| 165 | // should be switched on packages later |
| 166 | '003_Install_reclass': { |
| 167 | sh('''for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do |
| 168 | sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \ |
| 169 | -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${RECLASS_VERSION}; |
| 170 | done |
| 171 | ''') |
| 172 | }, |
| 173 | |
| 174 | '004_Run_tests': { |
| 175 | def testTimeout = 40 * 60 |
| 176 | timeout(time: testTimeout, unit: 'SECONDS') { |
| 177 | sh('''#!/bin/bash |
| 178 | source /srv/salt/scripts/bootstrap.sh |
| 179 | cd /srv/salt/scripts |
| 180 | source_local_envs |
| 181 | configure_salt_master |
| 182 | configure_salt_minion |
| 183 | install_salt_formula_pkg |
| 184 | source /srv/salt/scripts/bootstrap.sh |
| 185 | cd /srv/salt/scripts |
| 186 | saltservice_restart''') |
| 187 | |
| 188 | sh('''#!/bin/bash |
| 189 | source /srv/salt/scripts/bootstrap.sh |
| 190 | cd /srv/salt/scripts |
| 191 | source_local_envs |
| 192 | saltmaster_init''') |
| 193 | |
| 194 | sh('''#!/bin/bash |
| 195 | source /srv/salt/scripts/bootstrap.sh |
| 196 | cd /srv/salt/scripts |
| 197 | verify_salt_minions''') |
| 198 | } |
| 199 | } |
| 200 | ] |
| 201 | config['runFinally'] = [ |
| 202 | '001_Archive_artefacts': { |
| 203 | sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true) |
| 204 | archiveArtifacts artifacts: "nodesinfo.tar.gz" |
| 205 | } |
| 206 | ] |
| 207 | testResult = setupDockerAndTest(config) |
| 208 | if (testResult) { |
| 209 | common.infoMsg("Node test for context: ${testContext} model: ${reclassEnv} finished: SUCCESS") |
| 210 | } else { |
| 211 | throw new RuntimeException("Node test for context: ${testContext} model: ${reclassEnv} finished: FAILURE") |
| 212 | } |
| 213 | return testResult |
| 214 | } |
| 215 | |
| 216 | /** |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 217 | * setup and test salt-master |
| 218 | * |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 219 | * @param masterName salt master's name |
| 220 | * @param clusterName model cluster name |
| 221 | * @param extraFormulas extraFormulas to install. DEPRECATED |
| 222 | * @param formulasSource formulas source (git or pkg) |
| 223 | * @param reclassVersion Version of used reclass (branch, tag, ...) (optional, default master) |
| 224 | * @param testDir directory of model |
| 225 | * @param formulasSource Salt formulas source type (optional, default pkg) |
| 226 | * @param formulasRevision APT revision for formulas (optional default stable) |
Petr Michalec | 6414aa5 | 2017-08-17 14:32:52 +0200 | [diff] [blame] | 227 | * @param ignoreClassNotfound Ignore missing classes for reclass model |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 228 | * @param dockerMaxCpus max cpus passed to docker (default 0, disabled) |
| 229 | * @param legacyTestingMode do you want to enable legacy testing mode (iterating through the nodes directory definitions instead of reading cluster models) |
| 230 | * @param aptRepoUrl package repository with salt formulas |
| 231 | * @param aptRepoGPG GPG key for apt repository with formulas |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 232 | * Return true | false |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 233 | */ |
| 234 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 235 | def setupAndTestNode(masterName, clusterName, extraFormulas = '*', testDir, formulasSource = 'pkg', |
Vasyl Saienko | 369ed90 | 2018-07-23 11:49:32 +0000 | [diff] [blame] | 236 | formulasRevision = 'stable', reclassVersion = "master", dockerMaxCpus = 0, |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 237 | ignoreClassNotfound = false, legacyTestingMode = false, aptRepoUrl = '', aptRepoGPG = '', dockerContainerName = false) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 238 | def common = new com.mirantis.mk.Common() |
| 239 | // timeout for test execution (40min) |
| 240 | def testTimeout = 40 * 60 |
| 241 | def TestMarkerResult = false |
| 242 | def saltOpts = "--retcode-passthrough --force-color" |
| 243 | def workspace = common.getWorkspace() |
| 244 | def img = docker.image("mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7") |
| 245 | img.pull() |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 246 | |
azvyagintsev | 635affb | 2018-09-13 13:02:54 +0300 | [diff] [blame] | 247 | if (formulasSource == 'pkg') { |
| 248 | if (extraFormulas) { |
| 249 | common.warningMsg("You have passed deprecated variable:extraFormulas=${extraFormulas}. " + |
| 250 | "\n It would be ignored, and all formulas would be installed anyway") |
| 251 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 252 | } |
| 253 | if (!dockerContainerName) { |
| 254 | dockerContainerName = 'setupAndTestNode' + UUID.randomUUID().toString() |
| 255 | } |
| 256 | def dockerMaxCpusOpt = "--cpus=4" |
| 257 | if (dockerMaxCpus > 0) { |
| 258 | dockerMaxCpusOpt = "--cpus=${dockerMaxCpus}" |
| 259 | } |
| 260 | try { |
| 261 | 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] | 262 | withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "EXTRA_FORMULAS_PKG_ALL=true", |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 263 | "DISTRIB_REVISION=${formulasRevision}", |
| 264 | "DEBUG=1", "MASTER_HOSTNAME=${masterName}", |
| 265 | "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}", |
| 266 | "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", |
| 267 | "APT_REPOSITORY=${aptRepoUrl}", "SALT_STOPSTART_WAIT=5", |
| 268 | "APT_REPOSITORY_GPG=${aptRepoGPG}"]) { |
| 269 | try { |
| 270 | // Currently, we don't have any other point to install |
| 271 | // runtime dependencies for tests. |
| 272 | sh("""#!/bin/bash -xe |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 273 | echo "Installing extra-deb dependencies inside docker:" |
| 274 | echo "APT::Get::AllowUnauthenticated 'true';" > /etc/apt/apt.conf.d/99setupAndTestNode |
| 275 | echo "APT::Get::Install-Suggests 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 276 | echo "APT::Get::Install-Recommends 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode |
| 277 | rm -vf /etc/apt/sources.list.d/* || true |
| 278 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial main restricted universe' > /etc/apt/sources.list |
| 279 | echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial-updates main restricted universe' >> /etc/apt/sources.list |
| 280 | apt-get update |
| 281 | apt-get install -y python-netaddr |
| 282 | """) |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 283 | sh(script: "git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts", returnStdout: true) |
| 284 | sh("""rsync -ah ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 285 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\; |
| 286 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\; |
| 287 | """) |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 288 | // FIXME: should be changed to use reclass from mcp_extra_nigtly? |
| 289 | sh("""for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 290 | sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \ |
| 291 | -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${reclassVersion}; |
| 292 | done""") |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 293 | timeout(time: testTimeout, unit: 'SECONDS') { |
| 294 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 295 | source /srv/salt/scripts/bootstrap.sh |
| 296 | cd /srv/salt/scripts |
| 297 | source_local_envs |
| 298 | configure_salt_master |
| 299 | configure_salt_minion |
| 300 | install_salt_formula_pkg |
| 301 | source /srv/salt/scripts/bootstrap.sh |
| 302 | cd /srv/salt/scripts |
| 303 | saltservice_restart''') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 304 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 305 | source /srv/salt/scripts/bootstrap.sh |
| 306 | cd /srv/salt/scripts |
| 307 | source_local_envs |
| 308 | saltmaster_init''') |
| 309 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 310 | if (!legacyTestingMode.toBoolean()) { |
| 311 | sh('''#!/bin/bash |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 312 | source /srv/salt/scripts/bootstrap.sh |
| 313 | cd /srv/salt/scripts |
| 314 | verify_salt_minions |
| 315 | ''') |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | // If we didn't dropped for now - test has been passed. |
| 319 | TestMarkerResult = true |
| 320 | } |
| 321 | |
| 322 | finally { |
| 323 | // Collect rendered per-node data.Those info could be simply used |
| 324 | // for diff processing. Data was generated via reclass.cli --nodeinfo, |
| 325 | /// during verify_salt_minions. |
| 326 | sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true) |
| 327 | archiveArtifacts artifacts: "nodesinfo.tar.gz" |
| 328 | } |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 329 | } |
azvyagintsev | 1bfe684 | 2018-08-09 18:40:17 +0200 | [diff] [blame] | 330 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 331 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 332 | catch (Exception er) { |
| 333 | common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString()) |
| 334 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 335 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 336 | if (legacyTestingMode.toBoolean()) { |
| 337 | common.infoMsg("Running legacy mode test for master hostname ${masterName}") |
| 338 | def nodes = sh(script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true) |
| 339 | for (minion in nodes.tokenize()) { |
| 340 | def basename = sh(script: "set +x;basename ${minion} .yml", returnStdout: true) |
| 341 | if (!basename.trim().contains(masterName)) { |
| 342 | testMinion(basename.trim()) |
| 343 | } |
| 344 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 345 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 346 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 347 | try { |
| 348 | common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors") |
| 349 | timeout(time: 10, unit: 'SECONDS') { |
| 350 | sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true) |
| 351 | } |
| 352 | timeout(time: 10, unit: 'SECONDS') { |
| 353 | sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true) |
| 354 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 355 | } |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 356 | catch (Exception er) { |
| 357 | 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] | 358 | } |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 359 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 360 | if (TestMarkerResult) { |
| 361 | common.infoMsg("Test finished: SUCCESS") |
| 362 | } else { |
| 363 | common.warningMsg("Test finished: FAILURE") |
| 364 | } |
| 365 | return TestMarkerResult |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 366 | |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Test salt-minion |
| 371 | * |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 372 | * @param minion salt minion |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 373 | */ |
| 374 | |
azvyagintsev | 28fa9d9 | 2018-06-26 14:31:49 +0300 | [diff] [blame] | 375 | def testMinion(minionName) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 376 | 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] | 377 | } |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 378 | |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 379 | /** |
| 380 | * Wrapper over setupAndTestNode, to test exactly one CC model. |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 381 | Whole workspace and model - should be pre-rendered and passed via MODELS_TARGZ |
| 382 | Flow: grab all data, and pass to setupAndTestNode function |
| 383 | under-modell will be directly mirrored to `model/{cfg.testReclassEnv}/* /srv/salt/reclass/*` |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 384 | * |
| 385 | * @param cfg - dict with params: |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 386 | MODELS_TARGZ http link to arch with (models|contexts|global_reclass) |
| 387 | modelFile |
| 388 | DockerCName directly passed to setupAndTestNode |
| 389 | EXTRA_FORMULAS directly passed to setupAndTestNode |
| 390 | DISTRIB_REVISION directly passed to setupAndTestNode |
| 391 | reclassVersion directly passed to setupAndTestNode |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 392 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 393 | Return: true\exception |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 394 | */ |
| 395 | |
| 396 | def testCCModel(cfg) { |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 397 | def common = new com.mirantis.mk.Common() |
| 398 | sh(script: 'find . -mindepth 1 -delete || true', returnStatus: true) |
| 399 | sh(script: "wget --progress=dot:mega --auth-no-challenge -O models.tar.gz ${cfg.MODELS_TARGZ}") |
| 400 | // unpack data |
| 401 | sh(script: "tar -xzf models.tar.gz ") |
| 402 | common.infoMsg("Going to test exactly one context: ${cfg.modelFile}\n, with params: ${cfg}") |
| 403 | content = readFile(file: cfg.modelFile) |
| 404 | templateContext = readYaml text: content |
| 405 | clusterName = templateContext.default_context.cluster_name |
| 406 | clusterDomain = templateContext.default_context.cluster_domain |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 407 | |
azvyagintsev | b4e0c44 | 2018-09-12 17:00:04 +0300 | [diff] [blame] | 408 | def testResult = false |
| 409 | testResult = setupAndTestNode( |
| 410 | "cfg01.${clusterDomain}", |
| 411 | clusterName, |
| 412 | '', |
| 413 | cfg.testReclassEnv, // Sync into image exactly one env |
| 414 | 'pkg', |
| 415 | cfg.DISTRIB_REVISION, |
| 416 | cfg.reclassVersion, |
| 417 | 0, |
| 418 | false, |
| 419 | false, |
| 420 | '', |
| 421 | '', |
| 422 | cfg.DockerCName) |
| 423 | if (testResult) { |
| 424 | common.infoMsg("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: SUCCESS") |
| 425 | } else { |
| 426 | throw new RuntimeException("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: FAILURE") |
| 427 | } |
| 428 | return testResult |
azvyagintsev | 2b279d8 | 2018-08-07 17:22:54 +0200 | [diff] [blame] | 429 | } |