blob: f0921c4118d9714664f0c53c69c93c47d803e398 [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)
Jakub Joseff5b7e082018-03-22 14:40:57 +010010 * @param reclassVersion Version of used reclass (branch, tag, ...) (optional, default master)
chnydaf4e5eb42017-05-26 15:34:38 +020011 * @param testDir directory of model
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040012 * @param formulasSource Salt formulas source type (optional, default pkg)
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020013 * @param formulasRevision APT revision for formulas (optional default stable)
Petr Michalec6414aa52017-08-17 14:32:52 +020014 * @param ignoreClassNotfound Ignore missing classes for reclass model
Jakub Josef90d8e572017-10-03 18:44:44 +020015 * @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 Ukov630b9e12017-10-23 12:00:19 +040017 * @param aptRepoUrl package repository with salt formulas
18 * @param aptRepoGPG GPG key for apt repository with formulas
chnydaf14ea2a2017-05-26 15:07:47 +020019 */
20
Jakub Joseff5b7e082018-03-22 14:40:57 +010021def setupAndTestNode(masterName, clusterName, extraFormulas, testDir, formulasSource = 'pkg', formulasRevision = 'stable', reclassVersion = "master", dockerMaxCpus = 0, ignoreClassNotfound = false, legacyTestingMode = false, aptRepoUrl='', aptRepoGPG='') {
Jakub Josef8fc0fd12018-01-15 18:36:48 +010022 // timeout for test execution (40min)
23 def testTimeout = 40 * 60
chnydaf14ea2a2017-05-26 15:07:47 +020024 def saltOpts = "--retcode-passthrough --force-color"
25 def common = new com.mirantis.mk.Common()
26 def workspace = common.getWorkspace()
Jakub Josefecf8b302018-05-11 14:33:08 +000027 def img = docker.image("mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7")
Jakub Joseff5b7e082018-03-22 14:40:57 +010028 img.pull()
chnydaf14ea2a2017-05-26 15:07:47 +020029
chnydaf6a0c952017-05-29 10:34:45 +020030 if (!extraFormulas || extraFormulas == "") {
chnyda77e46972017-05-26 16:14:27 +020031 extraFormulas = "linux"
chnyda66bfc582017-05-26 16:24:21 +020032 }
chnyda77e46972017-05-26 16:14:27 +020033
Dennis Dmitriev3c3ee6d2017-07-25 20:02:44 +030034 def dockerMaxCpusOption = ""
35 if (dockerMaxCpus > 0) {
36 dockerMaxCpusOption = "--cpus=${dockerMaxCpus}"
37 }
38
Jakub Josefb7d10142017-07-31 18:32:37 +020039 img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOption}") {
chnydaeebab582017-11-13 15:33:48 +010040 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "DISTRIB_REVISION=${formulasRevision}",
41 "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}",
Jakub Joseff5b7e082018-03-22 14:40:57 +010042 "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "APT_REPOSITORY=${aptRepoUrl}",
chnydaeebab582017-11-13 15:33:48 +010043 "APT_REPOSITORY_GPG=${aptRepoGPG}"]){
Jakub Josefecf8b302018-05-11 14:33:08 +000044 sh("git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts")
Jakub Josef68f46d22018-05-11 21:34:55 +020045 sh("""rsync -ah ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts
Jakub Joseff5b7e082018-03-22 14:40:57 +010046 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'""")
chnyda45892802017-12-20 15:49:00 +010054 sh("timeout ${testTimeout} bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'")
chnyda3c6680a2017-05-29 16:55:34 +020055
Jakub Josef9923de22018-05-11 20:18:22 +020056 if (!legacyTestingMode.toBoolean()) {
chnydae41c61c2017-08-09 12:49:07 +020057 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040058 }
59 }
chnydaf14ea2a2017-05-26 15:07:47 +020060
Jakub Josef9923de22018-05-11 20:18:22 +020061 if (legacyTestingMode.toBoolean()) {
Jakub Josef90d8e572017-10-03 18:44:44 +020062 common.infoMsg("Running legacy mode test for master hostname ${masterName}")
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040063 def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
64 for (minion in nodes.tokenize()) {
Jakub Josef2ccb69b2018-02-19 18:14:22 +010065 def basename = sh script: "set +x;basename ${minion} .yml", returnStdout: true
Ruslan Kamaldinov00c1ea42017-08-07 18:45:27 +040066 if (!basename.trim().contains(masterName)) {
67 testMinion(basename.trim())
chnydaf14ea2a2017-05-26 15:07:47 +020068 }
69 }
chnydaf14ea2a2017-05-26 15:07:47 +020070 }
71 }
72}
73
74/**
75 * Test salt-minion
76 *
77 * @param minion salt minion
78 */
79
80def testMinion(minionName)
81{
chnyda532239d2017-10-05 13:36:01 +020082 sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'")
Jakub Joseffa6ad8d2017-06-26 18:29:55 +020083}