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