blob: e6c074dd205b8e67c9599c2ab51930ee33073f5e [file] [log] [blame]
chnydaf14ea2a2017-05-26 15:07:47 +02001package com.mirantis.mk
2
3/**
4 * setup and test salt-master
5 *
6 * @param masterName salt master's name
chnyda85f72e62017-05-26 15:43:27 +02007 * @param extraFormulas extraFormulas to install
chnydaf4e5eb42017-05-26 15:34:38 +02008 * @param testDir directory of model
chnydaf14ea2a2017-05-26 15:07:47 +02009 */
10
chnyda77e46972017-05-26 16:14:27 +020011def setupAndTestNode(masterName, extraFormulas, testDir) {
chnydaf14ea2a2017-05-26 15:07:47 +020012 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
chnydaf6a0c952017-05-29 10:34:45 +020025 if (!extraFormulas || extraFormulas == "") {
chnyda77e46972017-05-26 16:14:27 +020026 extraFormulas = "linux"
chnyda66bfc582017-05-26 16:24:21 +020027 }
chnyda77e46972017-05-26 16:14:27 +020028
chnydaf14ea2a2017-05-26 15:07:47 +020029 img.inside("-u root:root --hostname=${masterName}") {
30 wrap([$class: 'AnsiColorBuildWrapper']) {
31 if (!imageFound) {
32 sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git")
33 sh("pip install git+https://github.com/epcim/reclass.git@pr/fix/fix_raise_UndefinedVariableError")
34 }
35 sh("mkdir -p /srv/salt/ || true")
chnydaf4e5eb42017-05-26 15:34:38 +020036 sh("cp -r ${testDir} /srv/salt/reclass")
chnydaf14ea2a2017-05-26 15:07:47 +020037 sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts")
38 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
39 sh("git config --global user.name || git config --global user.name 'CI'")
40
chnydaf6a0c952017-05-29 10:34:45 +020041 withEnv(["FORMULAS_SOURCE=pkg", "EXTRA_FORMULAS=${extraFormulas}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){
chnydaf14ea2a2017-05-26 15:07:47 +020042 sh("bash -c 'echo $MASTER_HOSTNAME'")
43 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'")
44 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'")
45 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'")
46 }
47
chnyda4967e4d2017-05-29 16:07:53 +020048 def is_mk_ci
49 try {
50 is_mk_ci = DEFAULT_GIT_URL.contains("mk-ci")
51 } catch (Throwable e) {
52 is_mk_ci = false
53 }
54
chnydaf14ea2a2017-05-26 15:07:47 +020055 def nodes
chnyda4967e4d2017-05-29 16:07:53 +020056 if (is_mk_ci) {
chnydaf14ea2a2017-05-26 15:07:47 +020057 nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
58 } else {
59 nodes = sh script:"find /srv/salt/reclass/nodes/_generated -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
60 }
61 for (minion in nodes.tokenize()) {
62 def basename = sh script: "basename ${minion} .yml", returnStdout: true
63 if (!basename.trim().contains(masterName)) {
64 testMinion(basename.trim())
65 }
66 }
67 }
68 }
69}
70
71/**
72 * Test salt-minion
73 *
74 * @param minion salt minion
75 */
76
77def testMinion(minionName)
78{
79 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}'")
80}