blob: 6214a477ad7ef01dffb85a73e9d960862cf2af54 [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
Jakub Josef2d01c842017-08-17 13:37:26 +02007 * @param clusterName model cluster name
chnyda85f72e62017-05-26 15:43:27 +02008 * @param extraFormulas extraFormulas to install
Mykyta Karpin1cb8d3f2017-06-23 15:42:17 +03009 * @param formulasSource formulas source (git or pkg)
chnydaf4e5eb42017-05-26 15:34:38 +020010 * @param testDir directory of model
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040011 * @param formulasSource Salt formulas source type (optional, default pkg)
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020012 * @param formulasRevision APT revision for formulas (optional default stable)
chnydaf14ea2a2017-05-26 15:07:47 +020013 */
14
Jakub Josef2d01c842017-08-17 13:37:26 +020015def setupAndTestNode(masterName, clusterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable', dockerMaxCpus = 0) {
chnydaf14ea2a2017-05-26 15:07:47 +020016 def saltOpts = "--retcode-passthrough --force-color"
17 def common = new com.mirantis.mk.Common()
18 def workspace = common.getWorkspace()
19 def imageFound = true
20 def img
21 try {
22 img = docker.image("tcpcloud/salt-models-testing")
23 img.pull()
24 } catch (Throwable e) {
25 img = docker.image("ubuntu:latest")
26 imageFound = false
27 }
28
chnydaf6a0c952017-05-29 10:34:45 +020029 if (!extraFormulas || extraFormulas == "") {
chnyda77e46972017-05-26 16:14:27 +020030 extraFormulas = "linux"
chnyda66bfc582017-05-26 16:24:21 +020031 }
chnyda77e46972017-05-26 16:14:27 +020032
Dennis Dmitriev3c3ee6d2017-07-25 20:02:44 +030033 def dockerMaxCpusOption = ""
34 if (dockerMaxCpus > 0) {
35 dockerMaxCpusOption = "--cpus=${dockerMaxCpus}"
36 }
37
Jakub Josefb7d10142017-07-31 18:32:37 +020038 img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOption}") {
chnyda3c6680a2017-05-29 16:55:34 +020039
40 def is_mk_ci
41 try {
42 is_mk_ci = DEFAULT_GIT_URL.contains("mk-ci")
43 } catch (Throwable e) {
44 is_mk_ci = false
45 }
46
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040047 if (!imageFound) {
Jakub Josef0603a232017-08-17 16:45:25 +020048 sh("apt-get update && apt-get install -y curl git python-pip sudo python-pip python-dev zlib1g-dev git")
49 sh("pip install git+https://github.com/salt-formulas/reclass.git --upgrade")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040050 }
chnydae41c61c2017-08-09 12:49:07 +020051 sh("mkdir -p /srv/salt/scripts/ || true")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040052 sh("cp -r ${testDir} /srv/salt/reclass")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040053 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
54 sh("git config --global user.name || git config --global user.name 'CI'")
chnyda53f10bb2017-08-17 14:50:46 +020055 sh("git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts")
chnydaf14ea2a2017-05-26 15:07:47 +020056
Jakub Josef2d01c842017-08-17 13:37:26 +020057 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040058 sh("bash -c 'echo $MASTER_HOSTNAME'")
Petr Michalec7a94b852017-08-16 21:58:53 +020059 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && system_config_master'")
60 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_bootstrap'")
61 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020062
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040063 if (!is_mk_ci) {
chnydae41c61c2017-08-09 12:49:07 +020064 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040065 }
66 }
chnydaf14ea2a2017-05-26 15:07:47 +020067
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040068 if (is_mk_ci) {
69 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
70 for (minion in nodes.tokenize()) {
71 def basename = sh script: "basename ${minion} .yml", returnStdout: true
72 if (!basename.trim().contains(masterName)) {
73 testMinion(basename.trim())
chnydaf14ea2a2017-05-26 15:07:47 +020074 }
75 }
chnydaf14ea2a2017-05-26 15:07:47 +020076 }
77 }
78}
79
80/**
81 * Test salt-minion
82 *
83 * @param minion salt minion
84 */
85
86def testMinion(minionName)
87{
chnydae41c61c2017-08-09 12:49:07 +020088 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 +020089}