chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * setup and test salt-master |
| 5 | * |
| 6 | * @param masterName salt master's name |
chnyda | 85f72e6 | 2017-05-26 15:43:27 +0200 | [diff] [blame] | 7 | * @param extraFormulas extraFormulas to install |
Mykyta Karpin | 1cb8d3f | 2017-06-23 15:42:17 +0300 | [diff] [blame] | 8 | * @param formulasSource formulas source (git or pkg) |
chnyda | f4e5eb4 | 2017-05-26 15:34:38 +0200 | [diff] [blame] | 9 | * @param testDir directory of model |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 10 | * @param formulasSource Salt formulas source type (optional, default pkg) |
Jakub Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 11 | * @param formulasRevision APT revision for formulas (optional default stable) |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
Dennis Dmitriev | 3c3ee6d | 2017-07-25 20:02:44 +0300 | [diff] [blame] | 14 | def setupAndTestNode(masterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable', dockerMaxCpus = 0) { |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 15 | 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 | |
chnyda | f6a0c95 | 2017-05-29 10:34:45 +0200 | [diff] [blame] | 28 | if (!extraFormulas || extraFormulas == "") { |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame] | 29 | extraFormulas = "linux" |
chnyda | 66bfc58 | 2017-05-26 16:24:21 +0200 | [diff] [blame] | 30 | } |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame] | 31 | |
Dennis Dmitriev | 3c3ee6d | 2017-07-25 20:02:44 +0300 | [diff] [blame] | 32 | def dockerMaxCpusOption = "" |
| 33 | if (dockerMaxCpus > 0) { |
| 34 | dockerMaxCpusOption = "--cpus=${dockerMaxCpus}" |
| 35 | } |
| 36 | |
Jakub Josef | b7d1014 | 2017-07-31 18:32:37 +0200 | [diff] [blame] | 37 | img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOption}") { |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 38 | |
| 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 Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 46 | if (!imageFound) { |
| 47 | sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git") |
chnyda | 77b9a97 | 2017-08-16 16:17:56 +0200 | [diff] [blame^] | 48 | sh("pip install git+https://github.com/salt-formulas/reclass.git") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 49 | } |
chnyda | e41c61c | 2017-08-09 12:49:07 +0200 | [diff] [blame] | 50 | sh("mkdir -p /srv/salt/scripts/ || true") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 51 | sh("cp -r ${testDir} /srv/salt/reclass") |
chnyda | e41c61c | 2017-08-09 12:49:07 +0200 | [diff] [blame] | 52 | sh("curl https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh -o /srv/salt/scripts/bootstrap.sh") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 53 | 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'") |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 55 | |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 56 | 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'") |
chnyda | e41c61c | 2017-08-09 12:49:07 +0200 | [diff] [blame] | 58 | sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && system_config_master'") |
| 59 | sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && saltmaster_bootstrap'") |
| 60 | sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && saltmaster_init'") |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 61 | |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 62 | if (!is_mk_ci) { |
chnyda | e41c61c | 2017-08-09 12:49:07 +0200 | [diff] [blame] | 63 | sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 64 | } |
| 65 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 66 | |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 67 | 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()) |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 73 | } |
| 74 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Test salt-minion |
| 81 | * |
| 82 | * @param minion salt minion |
| 83 | */ |
| 84 | |
| 85 | def testMinion(minionName) |
| 86 | { |
chnyda | e41c61c | 2017-08-09 12:49:07 +0200 | [diff] [blame] | 87 | 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 Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 88 | } |