chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * setup and test salt-master |
| 5 | * |
| 6 | * @param masterName salt master's name |
chnyda | 85f72e6 | 2017-05-26 15:43:27 +0200 | [diff] [blame] | 7 | * @param extraFormulas extraFormulas to install |
chnyda | f4e5eb4 | 2017-05-26 15:34:38 +0200 | [diff] [blame] | 8 | * @param testDir directory of model |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame^] | 11 | def setupAndTestNode(masterName, extraFormulas, testDir) { |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 12 | def saltOpts = "--retcode-passthrough --force-color" |
| 13 | def common = new com.mirantis.mk.Common() |
| 14 | def workspace = common.getWorkspace() |
| 15 | def imageFound = true |
| 16 | def img |
| 17 | try { |
| 18 | img = docker.image("tcpcloud/salt-models-testing") |
| 19 | img.pull() |
| 20 | } catch (Throwable e) { |
| 21 | img = docker.image("ubuntu:latest") |
| 22 | imageFound = false |
| 23 | } |
| 24 | |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame^] | 25 | if (extraFormulas == "") |
| 26 | extraFormulas = "linux" |
| 27 | |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 28 | img.inside("-u root:root --hostname=${masterName}") { |
| 29 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 30 | if (!imageFound) { |
| 31 | sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git") |
| 32 | sh("pip install git+https://github.com/epcim/reclass.git@pr/fix/fix_raise_UndefinedVariableError") |
| 33 | } |
| 34 | sh("mkdir -p /srv/salt/ || true") |
chnyda | f4e5eb4 | 2017-05-26 15:34:38 +0200 | [diff] [blame] | 35 | sh("cp -r ${testDir} /srv/salt/reclass") |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 36 | sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts") |
| 37 | sh("git config --global user.email || git config --global user.email 'ci@ci.local'") |
| 38 | sh("git config --global user.name || git config --global user.name 'CI'") |
| 39 | |
chnyda | 85f72e6 | 2017-05-26 15:43:27 +0200 | [diff] [blame] | 40 | withEnv(["FORMULAS_SOURCE=pkg", "EXTRA_FORMULAS=${extraFormulas}}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){ |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 41 | sh("bash -c 'echo $MASTER_HOSTNAME'") |
| 42 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'") |
| 43 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'") |
| 44 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'") |
| 45 | } |
| 46 | |
| 47 | def nodes |
| 48 | if (DEFAULT_GIT_URL.contains("mk-ci")) { |
| 49 | nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true |
| 50 | } else { |
| 51 | nodes = sh script:"find /srv/salt/reclass/nodes/_generated -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true |
| 52 | } |
| 53 | for (minion in nodes.tokenize()) { |
| 54 | def basename = sh script: "basename ${minion} .yml", returnStdout: true |
| 55 | if (!basename.trim().contains(masterName)) { |
| 56 | testMinion(basename.trim()) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Test salt-minion |
| 65 | * |
| 66 | * @param minion salt minion |
| 67 | */ |
| 68 | |
| 69 | def testMinion(minionName) |
| 70 | { |
| 71 | sh("service salt-master restart && service salt-minion restart && sleep 5 && bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'") |
| 72 | } |