blob: 095aa98bb749d24996f203e496e6a783d15365f4 [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
Mykyta Karpin1cb8d3f2017-06-23 15:42:17 +03008 * @param formulasSource formulas source (git or pkg)
chnydaf4e5eb42017-05-26 15:34:38 +02009 * @param testDir directory of model
chnydaf14ea2a2017-05-26 15:07:47 +020010 */
11
Mykyta Karpin1cb8d3f2017-06-23 15:42:17 +030012def setupAndTestNode(masterName, extraFormulas, testDir, formulasSource = 'pkg') {
chnydaf14ea2a2017-05-26 15:07:47 +020013 def saltOpts = "--retcode-passthrough --force-color"
14 def common = new com.mirantis.mk.Common()
15 def workspace = common.getWorkspace()
16 def imageFound = true
17 def img
18 try {
19 img = docker.image("tcpcloud/salt-models-testing")
20 img.pull()
21 } catch (Throwable e) {
22 img = docker.image("ubuntu:latest")
23 imageFound = false
24 }
25
chnydaf6a0c952017-05-29 10:34:45 +020026 if (!extraFormulas || extraFormulas == "") {
chnyda77e46972017-05-26 16:14:27 +020027 extraFormulas = "linux"
chnyda66bfc582017-05-26 16:24:21 +020028 }
chnyda77e46972017-05-26 16:14:27 +020029
chnydaf14ea2a2017-05-26 15:07:47 +020030 img.inside("-u root:root --hostname=${masterName}") {
chnyda3c6680a2017-05-29 16:55:34 +020031
32 def is_mk_ci
33 try {
34 is_mk_ci = DEFAULT_GIT_URL.contains("mk-ci")
35 } catch (Throwable e) {
36 is_mk_ci = false
37 }
38
chnydaf14ea2a2017-05-26 15:07:47 +020039 wrap([$class: 'AnsiColorBuildWrapper']) {
40 if (!imageFound) {
41 sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git")
42 sh("pip install git+https://github.com/epcim/reclass.git@pr/fix/fix_raise_UndefinedVariableError")
43 }
44 sh("mkdir -p /srv/salt/ || true")
chnydaf4e5eb42017-05-26 15:34:38 +020045 sh("cp -r ${testDir} /srv/salt/reclass")
chnydaf14ea2a2017-05-26 15:07:47 +020046 sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts")
47 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
48 sh("git config --global user.name || git config --global user.name 'CI'")
49
Mykyta Karpin1cb8d3f2017-06-23 15:42:17 +030050 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){
chnydaf14ea2a2017-05-26 15:07:47 +020051 sh("bash -c 'echo $MASTER_HOSTNAME'")
52 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'")
53 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'")
54 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020055
56 if (!is_mk_ci) {
57 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && verify_salt_minions'")
58 }
chnydaf14ea2a2017-05-26 15:07:47 +020059 }
60
chnyda4967e4d2017-05-29 16:07:53 +020061 if (is_mk_ci) {
chnyda3c6680a2017-05-29 16:55:34 +020062 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
63 for (minion in nodes.tokenize()) {
64 def basename = sh script: "basename ${minion} .yml", returnStdout: true
65 if (!basename.trim().contains(masterName)) {
66 testMinion(basename.trim())
67 }
chnydaf14ea2a2017-05-26 15:07:47 +020068 }
69 }
chnyda3c6680a2017-05-29 16:55:34 +020070
chnydaf14ea2a2017-05-26 15:07:47 +020071 }
72 }
73}
74
75/**
76 * Test salt-minion
77 *
78 * @param minion salt minion
79 */
80
81def testMinion(minionName)
82{
83 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}'")
84}