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 |
Jakub Josef | 2d01c84 | 2017-08-17 13:37:26 +0200 | [diff] [blame] | 7 | * @param clusterName model cluster name |
chnyda | 85f72e6 | 2017-05-26 15:43:27 +0200 | [diff] [blame] | 8 | * @param extraFormulas extraFormulas to install |
Mykyta Karpin | 1cb8d3f | 2017-06-23 15:42:17 +0300 | [diff] [blame] | 9 | * @param formulasSource formulas source (git or pkg) |
Jakub Josef | f5b7e08 | 2018-03-22 14:40:57 +0100 | [diff] [blame] | 10 | * @param reclassVersion Version of used reclass (branch, tag, ...) (optional, default master) |
chnyda | f4e5eb4 | 2017-05-26 15:34:38 +0200 | [diff] [blame] | 11 | * @param testDir directory of model |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 12 | * @param formulasSource Salt formulas source type (optional, default pkg) |
Jakub Josef | fa6ad8d | 2017-06-26 18:29:55 +0200 | [diff] [blame] | 13 | * @param formulasRevision APT revision for formulas (optional default stable) |
Petr Michalec | 6414aa5 | 2017-08-17 14:32:52 +0200 | [diff] [blame] | 14 | * @param ignoreClassNotfound Ignore missing classes for reclass model |
Jakub Josef | 90d8e57 | 2017-10-03 18:44:44 +0200 | [diff] [blame] | 15 | * @param dockerMaxCpus max cpus passed to docker (default 0, disabled) |
| 16 | * @param legacyTestingMode do you want to enable legacy testing mode (iterating through the nodes directory definitions instead of reading cluster models) |
Dmitry Ukov | 630b9e1 | 2017-10-23 12:00:19 +0400 | [diff] [blame] | 17 | * @param aptRepoUrl package repository with salt formulas |
| 18 | * @param aptRepoGPG GPG key for apt repository with formulas |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Jakub Josef | f5b7e08 | 2018-03-22 14:40:57 +0100 | [diff] [blame] | 21 | def setupAndTestNode(masterName, clusterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable', reclassVersion = "master", dockerMaxCpus = 0, ignoreClassNotfound = false, legacyTestingMode = false, aptRepoUrl='', aptRepoGPG='') { |
Jakub Josef | 8fc0fd1 | 2018-01-15 18:36:48 +0100 | [diff] [blame] | 22 | // timeout for test execution (40min) |
| 23 | def testTimeout = 40 * 60 |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 24 | def saltOpts = "--retcode-passthrough --force-color" |
| 25 | def common = new com.mirantis.mk.Common() |
| 26 | def workspace = common.getWorkspace() |
Jakub Josef | c6e0310 | 2018-03-27 18:44:37 +0200 | [diff] [blame] | 27 | def img = docker.image("tcpcloud/salt-models-testing:latest") |
Jakub Josef | f5b7e08 | 2018-03-22 14:40:57 +0100 | [diff] [blame] | 28 | img.pull() |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 29 | |
chnyda | f6a0c95 | 2017-05-29 10:34:45 +0200 | [diff] [blame] | 30 | if (!extraFormulas || extraFormulas == "") { |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame] | 31 | extraFormulas = "linux" |
chnyda | 66bfc58 | 2017-05-26 16:24:21 +0200 | [diff] [blame] | 32 | } |
chnyda | 77e4697 | 2017-05-26 16:14:27 +0200 | [diff] [blame] | 33 | |
Dennis Dmitriev | 3c3ee6d | 2017-07-25 20:02:44 +0300 | [diff] [blame] | 34 | def dockerMaxCpusOption = "" |
| 35 | if (dockerMaxCpus > 0) { |
| 36 | dockerMaxCpusOption = "--cpus=${dockerMaxCpus}" |
| 37 | } |
| 38 | |
Jakub Josef | b7d1014 | 2017-07-31 18:32:37 +0200 | [diff] [blame] | 39 | img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOption}") { |
chnyda | eebab58 | 2017-11-13 15:33:48 +0100 | [diff] [blame] | 40 | withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}", |
| 41 | "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}", |
Jakub Josef | f5b7e08 | 2018-03-22 14:40:57 +0100 | [diff] [blame] | 42 | "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "APT_REPOSITORY=${aptRepoUrl}", |
chnyda | eebab58 | 2017-11-13 15:33:48 +0100 | [diff] [blame] | 43 | "APT_REPOSITORY_GPG=${aptRepoGPG}"]){ |
| 44 | |
Jakub Josef | f5b7e08 | 2018-03-22 14:40:57 +0100 | [diff] [blame] | 45 | sh("""cp -r ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts |
| 46 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\; |
| 47 | cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;""") |
| 48 | sh("""for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do |
| 49 | sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \ |
| 50 | -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${reclassVersion}; |
| 51 | done""") |
| 52 | sh("""timeout ${testTimeout} bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && configure_salt_master && configure_salt_minion && install_salt_formula_pkg' |
| 53 | bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && saltservice_restart'""") |
Jakub Josef | bd518f2 | 2017-12-19 16:42:55 +0000 | [diff] [blame] | 54 | |
chnyda | 4589280 | 2017-12-20 15:49:00 +0100 | [diff] [blame] | 55 | sh("timeout ${testTimeout} bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'") |
chnyda | 3c6680a | 2017-05-29 16:55:34 +0200 | [diff] [blame] | 56 | |
Jakub Josef | 90d8e57 | 2017-10-03 18:44:44 +0200 | [diff] [blame] | 57 | if (!legacyTestingMode) { |
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 && verify_salt_minions'") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 59 | } |
| 60 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 61 | |
Jakub Josef | 90d8e57 | 2017-10-03 18:44:44 +0200 | [diff] [blame] | 62 | if (legacyTestingMode) { |
| 63 | common.infoMsg("Running legacy mode test for master hostname ${masterName}") |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 64 | def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true |
| 65 | for (minion in nodes.tokenize()) { |
Jakub Josef | 2ccb69b | 2018-02-19 18:14:22 +0100 | [diff] [blame] | 66 | def basename = sh script: "set +x;basename ${minion} .yml", returnStdout: true |
Ruslan Kamaldinov | 00c1ea4 | 2017-08-07 18:45:27 +0400 | [diff] [blame] | 67 | if (!basename.trim().contains(masterName)) { |
| 68 | testMinion(basename.trim()) |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 69 | } |
| 70 | } |
chnyda | f14ea2a | 2017-05-26 15:07:47 +0200 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Test salt-minion |
| 77 | * |
| 78 | * @param minion salt minion |
| 79 | */ |
| 80 | |
| 81 | def testMinion(minionName) |
| 82 | { |
chnyda | 532239d | 2017-10-05 13:36:01 +0200 | [diff] [blame] | 83 | sh("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] | 84 | } |