blob: 7a0c1e68c3d18dcefdde23ac538e8626542c41d3 [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
chnyda5ef7fe92017-10-02 14:17:43 +020040 /* unlike other models, mk-ci and infra don't generate nodes dynamically
41 and therefore it is not possible to use the standard way for testing */
42 def is_mk_infra
chnyda3c6680a2017-05-29 16:55:34 +020043 try {
chnyda5ef7fe92017-10-02 14:17:43 +020044 is_mk_infra = DEFAULT_GIT_URL.contains("mk-ci") || DEFAULT_GIT_URL.contains("salt-models/infra")
chnyda3c6680a2017-05-29 16:55:34 +020045 } catch (Throwable e) {
chnyda5ef7fe92017-10-02 14:17:43 +020046 is_mk_infra = false
chnyda3c6680a2017-05-29 16:55:34 +020047 }
48
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040049 if (!imageFound) {
Jakub Josef0603a232017-08-17 16:45:25 +020050 sh("apt-get update && apt-get install -y curl git python-pip sudo python-pip python-dev zlib1g-dev git")
51 sh("pip install git+https://github.com/salt-formulas/reclass.git --upgrade")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040052 }
chnydae41c61c2017-08-09 12:49:07 +020053 sh("mkdir -p /srv/salt/scripts/ || true")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040054 sh("cp -r ${testDir} /srv/salt/reclass")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040055 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
56 sh("git config --global user.name || git config --global user.name 'CI'")
chnyda53f10bb2017-08-17 14:50:46 +020057 sh("git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts")
chnydaf14ea2a2017-05-26 15:07:47 +020058
Jakub Josef2d01c842017-08-17 13:37:26 +020059 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 +040060 sh("bash -c 'echo $MASTER_HOSTNAME'")
Petr Michalec7a94b852017-08-16 21:58:53 +020061 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && system_config_master'")
62 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_bootstrap'")
63 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020064
chnyda5ef7fe92017-10-02 14:17:43 +020065 if (!is_mk_infra) {
chnydae41c61c2017-08-09 12:49:07 +020066 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040067 }
68 }
chnydaf14ea2a2017-05-26 15:07:47 +020069
chnyda5ef7fe92017-10-02 14:17:43 +020070 if (is_mk_infra) {
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040071 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
72 for (minion in nodes.tokenize()) {
73 def basename = sh script: "basename ${minion} .yml", returnStdout: true
74 if (!basename.trim().contains(masterName)) {
75 testMinion(basename.trim())
chnydaf14ea2a2017-05-26 15:07:47 +020076 }
77 }
chnydaf14ea2a2017-05-26 15:07:47 +020078 }
79 }
80}
81
82/**
83 * Test salt-minion
84 *
85 * @param minion salt minion
86 */
87
88def testMinion(minionName)
89{
chnyda532239d2017-10-05 13:36:01 +020090 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'")
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020091}