blob: 9c41af1e73e493d27e0f641cc5a7eedac26a3308 [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
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020010 * @param formulasSource Salt formulas source type (optional, default pkg)
11 * @param formulasRevision APT revision for formulas (optional default stable)
chnydaf14ea2a2017-05-26 15:07:47 +020012 */
13
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020014def setupAndTestNode(masterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable') {
chnydaf14ea2a2017-05-26 15:07:47 +020015 def saltOpts = "--retcode-passthrough --force-color"
16 def common = new com.mirantis.mk.Common()
17 def workspace = common.getWorkspace()
18 def imageFound = true
19 def img
20 try {
21 img = docker.image("tcpcloud/salt-models-testing")
22 img.pull()
23 } catch (Throwable e) {
24 img = docker.image("ubuntu:latest")
25 imageFound = false
26 }
27
chnydaf6a0c952017-05-29 10:34:45 +020028 if (!extraFormulas || extraFormulas == "") {
chnyda77e46972017-05-26 16:14:27 +020029 extraFormulas = "linux"
chnyda66bfc582017-05-26 16:24:21 +020030 }
chnyda77e46972017-05-26 16:14:27 +020031
chnydaf14ea2a2017-05-26 15:07:47 +020032 img.inside("-u root:root --hostname=${masterName}") {
chnyda3c6680a2017-05-29 16:55:34 +020033
34 def is_mk_ci
35 try {
36 is_mk_ci = DEFAULT_GIT_URL.contains("mk-ci")
37 } catch (Throwable e) {
38 is_mk_ci = false
39 }
40
chnydaf14ea2a2017-05-26 15:07:47 +020041 wrap([$class: 'AnsiColorBuildWrapper']) {
42 if (!imageFound) {
43 sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git")
44 sh("pip install git+https://github.com/epcim/reclass.git@pr/fix/fix_raise_UndefinedVariableError")
45 }
46 sh("mkdir -p /srv/salt/ || true")
chnydaf4e5eb42017-05-26 15:34:38 +020047 sh("cp -r ${testDir} /srv/salt/reclass")
chnydaf14ea2a2017-05-26 15:07:47 +020048 sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts")
49 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
50 sh("git config --global user.name || git config --global user.name 'CI'")
51
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020052 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){
chnydaf14ea2a2017-05-26 15:07:47 +020053 sh("bash -c 'echo $MASTER_HOSTNAME'")
54 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'")
55 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'")
56 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020057
58 if (!is_mk_ci) {
59 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && verify_salt_minions'")
60 }
chnydaf14ea2a2017-05-26 15:07:47 +020061 }
62
chnyda4967e4d2017-05-29 16:07:53 +020063 if (is_mk_ci) {
chnyda3c6680a2017-05-29 16:55:34 +020064 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
65 for (minion in nodes.tokenize()) {
66 def basename = sh script: "basename ${minion} .yml", returnStdout: true
67 if (!basename.trim().contains(masterName)) {
68 testMinion(basename.trim())
69 }
chnydaf14ea2a2017-05-26 15:07:47 +020070 }
71 }
chnyda3c6680a2017-05-29 16:55:34 +020072
chnydaf14ea2a2017-05-26 15:07:47 +020073 }
74 }
75}
76
77/**
78 * Test salt-minion
79 *
80 * @param minion salt minion
81 */
82
83def testMinion(minionName)
84{
85 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}'")
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020086}