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 |
Jakub Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 10 | * @param formulasSource Salt formulas source type (optional, default pkg) |
| 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 | |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 46 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 47 | if (!imageFound) { |
| 48 | sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev git") |
| 49 | sh("pip install git+https://github.com/epcim/reclass.git@pr/fix/fix_raise_UndefinedVariableError") |
| 50 | } |
| 51 | sh("mkdir -p /srv/salt/ || true") |
chnyda | f4e5eb4 | 2017-05-26 15:34:38 +0200 | [diff] [blame] | 52 | sh("cp -r ${testDir} /srv/salt/reclass") |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 53 | sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts") |
| 54 | sh("git config --global user.email || git config --global user.email 'ci@ci.local'") |
| 55 | sh("git config --global user.name || git config --global user.name 'CI'") |
| 56 | |
Jakub Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 57 | withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}", "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "MINION_ID=${masterName}", "HOSTNAME=cfg01", "DOMAIN=mk-ci.local"]){ |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 58 | sh("bash -c 'echo $MASTER_HOSTNAME'") |
| 59 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'") |
| 60 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'") |
| 61 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'") |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 62 | |
| 63 | if (!is_mk_ci) { |
| 64 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && verify_salt_minions'") |
| 65 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 66 | } |
| 67 | |
chnyda | 4967e4d | 2017-05-29 16:07:53 +0200 | [diff] [blame] | 68 | if (is_mk_ci) { |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 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()) |
| 74 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 77 | |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Test salt-minion |
| 84 | * |
| 85 | * @param minion salt minion |
| 86 | */ |
| 87 | |
| 88 | def testMinion(minionName) |
| 89 | { |
| 90 | 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 Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 91 | } |