blob: d6a01d6094d2a849a4cf9cdb2b8a20308dee085a [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
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040010 * @param formulasSource Salt formulas source type (optional, default pkg)
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020011 * @param formulasRevision APT revision for formulas (optional default stable)
chnydaf14ea2a2017-05-26 15:07:47 +020012 */
13
Dennis Dmitriev3c3ee6d2017-07-25 20:02:44 +030014def setupAndTestNode(masterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable', dockerMaxCpus = 0) {
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
Dennis Dmitriev3c3ee6d2017-07-25 20:02:44 +030032 def dockerMaxCpusOption = ""
33 if (dockerMaxCpus > 0) {
34 dockerMaxCpusOption = "--cpus=${dockerMaxCpus}"
35 }
36
Jakub Josefb7d10142017-07-31 18:32:37 +020037 img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOption}") {
chnyda3c6680a2017-05-29 16:55:34 +020038
39 def is_mk_ci
40 try {
41 is_mk_ci = DEFAULT_GIT_URL.contains("mk-ci")
42 } catch (Throwable e) {
43 is_mk_ci = false
44 }
45
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040046 if (!imageFound) {
47 sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git")
chnyda77b9a972017-08-16 16:17:56 +020048 sh("pip install git+https://github.com/salt-formulas/reclass.git")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040049 }
chnydae41c61c2017-08-09 12:49:07 +020050 sh("mkdir -p /srv/salt/scripts/ || true")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040051 sh("cp -r ${testDir} /srv/salt/reclass")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040052 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
53 sh("git config --global user.name || git config --global user.name 'CI'")
chnyda53f10bb2017-08-17 14:50:46 +020054 sh("git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts")
chnydaf14ea2a2017-05-26 15:07:47 +020055
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040056 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){
57 sh("bash -c 'echo $MASTER_HOSTNAME'")
Petr Michalec7a94b852017-08-16 21:58:53 +020058 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && system_config_master'")
59 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_bootstrap'")
60 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020061
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040062 if (!is_mk_ci) {
chnydae41c61c2017-08-09 12:49:07 +020063 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040064 }
65 }
chnydaf14ea2a2017-05-26 15:07:47 +020066
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040067 if (is_mk_ci) {
68 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
69 for (minion in nodes.tokenize()) {
70 def basename = sh script: "basename ${minion} .yml", returnStdout: true
71 if (!basename.trim().contains(masterName)) {
72 testMinion(basename.trim())
chnydaf14ea2a2017-05-26 15:07:47 +020073 }
74 }
chnydaf14ea2a2017-05-26 15:07:47 +020075 }
76 }
77}
78
79/**
80 * Test salt-minion
81 *
82 * @param minion salt minion
83 */
84
85def testMinion(minionName)
86{
chnydae41c61c2017-08-09 12:49:07 +020087 sh("service salt-master restart && service salt-minion restart && sleep 5 && bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'")
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020088}