blob: d6a1b82f01783ebfab800e29b43073595201f939 [file] [log] [blame]
chnydaf14ea2a2017-05-26 15:07:47 +02001package com.mirantis.mk
2
3/**
Denis Egorenko6fd79ac2018-09-12 13:28:21 +04004 * Setup Docker to run some tests. Returns true/false based on
5 were tests successful or not.
6 * @param config - LinkedHashMap with configuration params:
7 * dockerHostname - (required) Hostname to use for Docker container.
Denis Egorenkob090a762018-09-12 19:25:41 +04008 * formulasRevision - (optional) Revision of packages to use (default proposed).
Denis Egorenko6fd79ac2018-09-12 13:28:21 +04009 * runCommands - (optional) Dict with closure structure of body required tests. For example:
10 * [ '001_Test': { sh("./run-some-test") }, '002_Test': { sh("./run-another-test") } ]
11 * Before execution runCommands will be sorted by key names. Alpabetical order is preferred.
12 * runFinally - (optional) Dict with closure structure of body required commands, which should be
13 * executed in any case of test results. Same format as for runCommands
14 * updateRepo - (optional) Whether to run common repo update step.
15 * dockerContainerName - (optional) Docker container name.
16 * dockerImageName - (optional) Docker image name
17 * dockerMaxCpus - (optional) Number of CPUS to use in Docker.
18 * dockerExtraOpts - (optional) Array of Docker extra opts for container
19 * envOpts - (optional) Array of variables that should be passed as ENV vars to Docker container.
20 * Return true | false
21 */
22
23def setupDockerAndTest(LinkedHashMap config) {
24 def common = new com.mirantis.mk.Common()
25 def TestMarkerResult = false
26 // setup options
27 def defaultContainerName = 'test-' + UUID.randomUUID().toString()
28 def dockerHostname = config.get('dockerHostname', defaultContainerName)
29 def formulasRevision = config.get('formulasRevision', 'proposed')
30 def runCommands = config.get('runCommands', [:])
31 def runFinally = config.get('runFinally', [:])
32 def baseRepoPreConfig = config.get('baseRepoPreConfig', true)
33 def dockerContainerName = config.get('dockerContainerName', defaultContainerName)
34 def dockerImageName = config.get('image', "mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7")
35 def dockerMaxCpus = config.get('dockerMaxCpus', 4)
36 def dockerExtraOpts = config.get('dockerExtraOpts', [])
37 def envOpts = config.get('envOpts', [])
38 envOpts.add("DISTRIB_REVISION=${formulasRevision}")
39 def dockerBaseOpts = [
40 '-u root:root',
41 "--hostname=${dockerHostname}",
42 '--ulimit nofile=4096:8192',
43 "--name=${dockerContainerName}",
44 "--cpus=${dockerMaxCpus}"
45 ]
46
47 def dockerOptsFinal = (dockerBaseOpts + dockerExtraOpts).join(' ')
48 def img = docker.image(dockerImageName)
49 img.pull()
50
51 try {
52 img.inside(dockerOptsFinal) {
53 withEnv(envOpts) {
54 try {
55 // Currently, we don't have any other point to install
56 // runtime dependencies for tests.
57 if (baseRepoPreConfig) {
58 sh("""#!/bin/bash -xe
59 echo "Installing extra-deb dependencies inside docker:"
60 echo "APT::Get::AllowUnauthenticated 'true';" > /etc/apt/apt.conf.d/99setupAndTestNode
61 echo "APT::Get::Install-Suggests 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode
62 echo "APT::Get::Install-Recommends 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode
63 rm -vf /etc/apt/sources.list.d/* || true
64 echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial main restricted universe' > /etc/apt/sources.list
65 echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial-updates main restricted universe' >> /etc/apt/sources.list
66 apt-get update
67 apt-get install -y python-netaddr
68 """)
69 }
70 runCommands.sort().each { command, body ->
71 common.warningMsg("Running command: ${command}")
72 // doCall is the closure implementation in groovy, allow to pass arguments to closure
73 body.call()
74 }
75 // If we didn't dropped for now - test has been passed.
76 TestMarkerResult = true
77 }
78 finally {
79 runFinally.sort().each { command, body ->
80 common.warningMsg("Running ${command} command.")
81 // doCall is the closure implementation in groovy, allow to pass arguments to closure
82 body.call()
83 }
84 }
85 }
86 }
87 }
88 catch (Exception er) {
89 common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString())
90 }
91
92 try {
93 common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors")
94 timeout(time: 10, unit: 'SECONDS') {
95 sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true)
96 }
97 timeout(time: 10, unit: 'SECONDS') {
98 sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true)
99 }
100 }
101 catch (Exception er) {
102 common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString())
103 }
104
105 if (TestMarkerResult) {
106 common.infoMsg("Test finished: SUCCESS")
107 } else {
108 common.warningMsg("Test finished: FAILURE")
109 }
110 return TestMarkerResult
111}
112
113/**
Denis Egorenkob090a762018-09-12 19:25:41 +0400114 * Wrapper around setupDockerAndTest, to run checks against new Reclass version
115 * that current model is compatible with new Reclass.
116 *
117 * @param config - LinkedHashMap with configuration params:
118 * dockerHostname - (required) Hostname to use for Docker container.
119 * distribRevision - (optional) Revision of packages to use (default proposed).
120 * extraRepo - (optional) Extra repo to use to install new Reclass version. Has
121 * high priority on distribRevision
122 * targetNodes - (required) List nodes to check pillar data.
123 */
124def compareReclassVersions(config) {
125 def common = new com.mirantis.mk.Common()
126 def salt = new com.mirantis.mk.Salt()
127 common.infoMsg("Going to test new reclass for CFG node")
128 def distribRevision = config.get('distribRevision', 'proposed')
129 def venv = config.get('venv')
130 def extraRepo = config.get('extraRepo', '')
131 def extraRepoKey = config.get('extraRepoKey', '')
132 def targetNodes = config.get('targetNodes')
133 sh "rm -rf ${env.WORKSPACE}/old ${env.WORKSPACE}/new"
134 sh "mkdir -p ${env.WORKSPACE}/old ${env.WORKSPACE}/new"
135 def configRun = [
136 'formulasRevision': distribRevision,
137 'dockerExtraOpts': [
138 "-v /srv/salt/reclass:/srv/salt/reclass:ro",
139 "-v /etc/salt:/etc/salt:ro",
140 "-v /usr/share/salt-formulas/:/usr/share/salt-formulas/:ro"
141 ],
142 'envOpts': [
143 "WORKSPACE=${env.WORKSPACE}",
144 "NODES_LIST=${targetNodes.join(' ')}"
145 ],
146 'runCommands': [
147 '001_Update_Reclass_package': {
148 sh('apt-get update && apt-get install -y reclass')
149 },
150 '002_Test_Reclass_Compatibility': {
151 sh('''
152 reclass-salt -b /srv/salt/reclass -t > ${WORKSPACE}/new/inventory || exit 1
153 for node in $NODES_LIST; do
154 reclass-salt -b /srv/salt/reclass -p $node > ${WORKSPACE}/new/$node || exit 1
155 done
156 ''')
157 }
158 ]
159 ]
160 if (extraRepo) {
161 configRun['runCommands']['0001_Additional_Extra_Repo_Passed'] = {
162 sh("""
163 echo "${extraRepo}" > /etc/apt/sources.list.d/mcp_extra.list
164 [ "${extraRepoKey}" ] && wget -O - ${extraRepoKey} | apt-key add -
165 """)
166 }
167 } else {
168 configRun['runCommands']['0001_Additional_Extra_Repo_Default'] = {
169 sh("""
170 echo "deb [arch=amd64] http://apt.mirantis.com/xenial ${distribRevision} extra" > /etc/apt/sources.list.d/mcp_extra.list
171 wget -O - http://apt.mirantis.com/public.gpg | apt-key add -
172 """)
173 }
174 }
175 if (setupDockerAndTest(configRun)) {
176 common.infoMsg("New reclass version is compatible with current model: SUCCESS")
177 def inventoryOld = salt.cmdRun(venv, "I@salt:master", "reclass-salt -b /srv/salt/reclass -t", true, null, true).get("return")[0].values()[0]
178 // [0..-31] to exclude 'echo Salt command execution success' from output
179 writeFile(file: "${env.WORKSPACE}/old/inventory", text: inventoryOld[0..-31])
180 for(String node in targetNodes) {
181 def nodeOut = salt.cmdRun(venv, "I@salt:master", "reclass-salt -b /srv/salt/reclass -p ${node}", true, null, true).get("return")[0].values()[0]
182 writeFile(file: "${env.WORKSPACE}/old/${node}", text: nodeOut[0..-31])
183 }
184 def reclassDiff = common.comparePillars(env.WORKSPACE, env.BUILD_URL, '')
185 currentBuild.description = reclassDiff
186 if (reclassDiff != '<b>No job changes</b>') {
187 throw new RuntimeException("Pillars with new reclass version has been changed: FAILED")
188 } else {
189 common.infoMsg("Pillars not changed with new reclass version: SUCCESS")
190 }
191 } else {
192 throw new RuntimeException("New reclass version is not compatible with current model: FAILED")
193 }
194}
195
196/**
Denis Egorenko6fd79ac2018-09-12 13:28:21 +0400197 * Wrapper over setupDockerAndTest, to test CC model.
198 *
199 * @param config - dict with params:
200 * dockerHostname - (required) salt master's name
201 * clusterName - (optional) model cluster name
202 * extraFormulas - (optional) extraFormulas to install. DEPRECATED
203 * formulasSource - (optional) formulas source (git or pkg, default pkg)
204 * reclassVersion - (optional) Version of used reclass (branch, tag, ...) (optional, default master)
205 * reclassEnv - (require) directory of model
206 * ignoreClassNotfound - (optional) Ignore missing classes for reclass model (default false)
207 * aptRepoUrl - (optional) package repository with salt formulas
208 * aptRepoGPG - (optional) GPG key for apt repository with formulas
209 * testContext - (optional) Description of test
210 Return: true\exception
211 */
212
213def testNode(LinkedHashMap config) {
214 def common = new com.mirantis.mk.Common()
215 def result = ''
216 def dockerHostname = config.get('dockerHostname')
217 def reclassEnv = config.get('reclassEnv')
218 def clusterName = config.get('clusterName', "")
219 def formulasSource = config.get('formulasSource', 'pkg')
220 def extraFormulas = config.get('extraFormulas', 'linux')
221 def reclassVersion = config.get('reclassVersion', 'master')
222 def ignoreClassNotfound = config.get('ignoreClassNotfound', false)
223 def aptRepoUrl = config.get('aptRepoUrl', "")
224 def aptRepoGPG = config.get('aptRepoGPG', "")
225 def testContext = config.get('testContext', 'test')
226 config['envOpts'] = [
227 "RECLASS_ENV=${reclassEnv}", "SALT_STOPSTART_WAIT=5",
228 "MASTER_HOSTNAME=${dockerHostname}", "CLUSTER_NAME=${clusterName}",
229 "MINION_ID=${dockerHostname}", "FORMULAS_SOURCE=${formulasSource}",
230 "EXTRA_FORMULAS=${extraFormulas}", "RECLASS_VERSION=${reclassVersion}",
231 "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "DEBUG=1",
232 "APT_REPOSITORY=${aptRepoUrl}", "APT_REPOSITORY_GPG=${aptRepoGPG}",
233 "EXTRA_FORMULAS_PKG_ALL=true"
234 ]
235
236 config['runCommands'] = [
237 '001_Clone_salt_formulas_scripts': {
238 sh(script: 'git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts', returnStdout: true)
239 },
240
241 '002_Prepare_something': {
242 sh('''rsync -ah ${RECLASS_ENV}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts
243 cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;
244 cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;
245 ''')
246 },
247
248 // should be switched on packages later
249 '003_Install_reclass': {
250 sh('''for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do
251 sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \
252 -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${RECLASS_VERSION};
253 done
254 ''')
255 },
256
257 '004_Run_tests': {
258 def testTimeout = 40 * 60
259 timeout(time: testTimeout, unit: 'SECONDS') {
260 sh('''#!/bin/bash
261 source /srv/salt/scripts/bootstrap.sh
262 cd /srv/salt/scripts
263 source_local_envs
264 configure_salt_master
265 configure_salt_minion
266 install_salt_formula_pkg
267 source /srv/salt/scripts/bootstrap.sh
268 cd /srv/salt/scripts
269 saltservice_restart''')
270
271 sh('''#!/bin/bash
272 source /srv/salt/scripts/bootstrap.sh
273 cd /srv/salt/scripts
274 source_local_envs
275 saltmaster_init''')
276
277 sh('''#!/bin/bash
278 source /srv/salt/scripts/bootstrap.sh
279 cd /srv/salt/scripts
280 verify_salt_minions''')
281 }
282 }
283 ]
284 config['runFinally'] = [
285 '001_Archive_artefacts': {
286 sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true)
287 archiveArtifacts artifacts: "nodesinfo.tar.gz"
288 }
289 ]
290 testResult = setupDockerAndTest(config)
291 if (testResult) {
292 common.infoMsg("Node test for context: ${testContext} model: ${reclassEnv} finished: SUCCESS")
293 } else {
294 throw new RuntimeException("Node test for context: ${testContext} model: ${reclassEnv} finished: FAILURE")
295 }
296 return testResult
297}
298
299/**
chnydaf14ea2a2017-05-26 15:07:47 +0200300 * setup and test salt-master
301 *
azvyagintsevb4e0c442018-09-12 17:00:04 +0300302 * @param masterName salt master's name
303 * @param clusterName model cluster name
304 * @param extraFormulas extraFormulas to install. DEPRECATED
305 * @param formulasSource formulas source (git or pkg)
306 * @param reclassVersion Version of used reclass (branch, tag, ...) (optional, default master)
307 * @param testDir directory of model
308 * @param formulasSource Salt formulas source type (optional, default pkg)
309 * @param formulasRevision APT revision for formulas (optional default stable)
Petr Michalec6414aa52017-08-17 14:32:52 +0200310 * @param ignoreClassNotfound Ignore missing classes for reclass model
azvyagintsevb4e0c442018-09-12 17:00:04 +0300311 * @param dockerMaxCpus max cpus passed to docker (default 0, disabled)
312 * @param legacyTestingMode do you want to enable legacy testing mode (iterating through the nodes directory definitions instead of reading cluster models)
313 * @param aptRepoUrl package repository with salt formulas
314 * @param aptRepoGPG GPG key for apt repository with formulas
azvyagintsev28fa9d92018-06-26 14:31:49 +0300315 * Return true | false
chnydaf14ea2a2017-05-26 15:07:47 +0200316 */
317
azvyagintsevb4e0c442018-09-12 17:00:04 +0300318def setupAndTestNode(masterName, clusterName, extraFormulas = '*', testDir, formulasSource = 'pkg',
Vasyl Saienko369ed902018-07-23 11:49:32 +0000319 formulasRevision = 'stable', reclassVersion = "master", dockerMaxCpus = 0,
azvyagintsev28fa9d92018-06-26 14:31:49 +0300320 ignoreClassNotfound = false, legacyTestingMode = false, aptRepoUrl = '', aptRepoGPG = '', dockerContainerName = false) {
azvyagintsevb4e0c442018-09-12 17:00:04 +0300321 def common = new com.mirantis.mk.Common()
azvyagintsev1cecc092018-09-14 13:19:16 +0300322 // TODO
323 common.errorMsg('You are using deprecated function!Please migrate to "setupDockerAndTest".' +
324 'It would be removed after 2018.q4 release!Pushing forced 60s sleep..')
325 sh('sleep 60')
azvyagintsevb4e0c442018-09-12 17:00:04 +0300326 // timeout for test execution (40min)
327 def testTimeout = 40 * 60
328 def TestMarkerResult = false
329 def saltOpts = "--retcode-passthrough --force-color"
330 def workspace = common.getWorkspace()
331 def img = docker.image("mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7")
332 img.pull()
chnydaf14ea2a2017-05-26 15:07:47 +0200333
azvyagintsev635affb2018-09-13 13:02:54 +0300334 if (formulasSource == 'pkg') {
335 if (extraFormulas) {
336 common.warningMsg("You have passed deprecated variable:extraFormulas=${extraFormulas}. " +
337 "\n It would be ignored, and all formulas would be installed anyway")
338 }
azvyagintsevb4e0c442018-09-12 17:00:04 +0300339 }
340 if (!dockerContainerName) {
341 dockerContainerName = 'setupAndTestNode' + UUID.randomUUID().toString()
342 }
343 def dockerMaxCpusOpt = "--cpus=4"
344 if (dockerMaxCpus > 0) {
345 dockerMaxCpusOpt = "--cpus=${dockerMaxCpus}"
346 }
347 try {
348 img.inside("-u root:root --hostname=${masterName} --ulimit nofile=4096:8192 ${dockerMaxCpusOpt} --name=${dockerContainerName}") {
azvyagintsev635affb2018-09-13 13:02:54 +0300349 withEnv(["FORMULAS_SOURCE=${formulasSource}", "EXTRA_FORMULAS=${extraFormulas}", "EXTRA_FORMULAS_PKG_ALL=true",
azvyagintsevb4e0c442018-09-12 17:00:04 +0300350 "DISTRIB_REVISION=${formulasRevision}",
351 "DEBUG=1", "MASTER_HOSTNAME=${masterName}",
352 "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}",
353 "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}",
354 "APT_REPOSITORY=${aptRepoUrl}", "SALT_STOPSTART_WAIT=5",
355 "APT_REPOSITORY_GPG=${aptRepoGPG}"]) {
356 try {
357 // Currently, we don't have any other point to install
358 // runtime dependencies for tests.
359 sh("""#!/bin/bash -xe
azvyagintsev1bfe6842018-08-09 18:40:17 +0200360 echo "Installing extra-deb dependencies inside docker:"
361 echo "APT::Get::AllowUnauthenticated 'true';" > /etc/apt/apt.conf.d/99setupAndTestNode
362 echo "APT::Get::Install-Suggests 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode
363 echo "APT::Get::Install-Recommends 'false';" >> /etc/apt/apt.conf.d/99setupAndTestNode
364 rm -vf /etc/apt/sources.list.d/* || true
365 echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial main restricted universe' > /etc/apt/sources.list
366 echo 'deb [arch=amd64] http://mirror.mirantis.com/$DISTRIB_REVISION/ubuntu xenial-updates main restricted universe' >> /etc/apt/sources.list
367 apt-get update
368 apt-get install -y python-netaddr
369 """)
azvyagintsevb4e0c442018-09-12 17:00:04 +0300370 sh(script: "git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts", returnStdout: true)
371 sh("""rsync -ah ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts
azvyagintsev1bfe6842018-08-09 18:40:17 +0200372 cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;
373 cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;
374 """)
azvyagintsevb4e0c442018-09-12 17:00:04 +0300375 // FIXME: should be changed to use reclass from mcp_extra_nigtly?
376 sh("""for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do
azvyagintsev1bfe6842018-08-09 18:40:17 +0200377 sudo -H pip install --install-option=\"--prefix=\" --upgrade --force-reinstall -I \
378 -t \"\$s\" git+https://github.com/salt-formulas/reclass.git@${reclassVersion};
379 done""")
azvyagintsevb4e0c442018-09-12 17:00:04 +0300380 timeout(time: testTimeout, unit: 'SECONDS') {
381 sh('''#!/bin/bash
azvyagintsev1bfe6842018-08-09 18:40:17 +0200382 source /srv/salt/scripts/bootstrap.sh
383 cd /srv/salt/scripts
384 source_local_envs
385 configure_salt_master
386 configure_salt_minion
387 install_salt_formula_pkg
388 source /srv/salt/scripts/bootstrap.sh
389 cd /srv/salt/scripts
390 saltservice_restart''')
azvyagintsevb4e0c442018-09-12 17:00:04 +0300391 sh('''#!/bin/bash
azvyagintsev1bfe6842018-08-09 18:40:17 +0200392 source /srv/salt/scripts/bootstrap.sh
393 cd /srv/salt/scripts
394 source_local_envs
395 saltmaster_init''')
396
azvyagintsevb4e0c442018-09-12 17:00:04 +0300397 if (!legacyTestingMode.toBoolean()) {
398 sh('''#!/bin/bash
azvyagintsev1bfe6842018-08-09 18:40:17 +0200399 source /srv/salt/scripts/bootstrap.sh
400 cd /srv/salt/scripts
401 verify_salt_minions
402 ''')
azvyagintsevb4e0c442018-09-12 17:00:04 +0300403 }
404 }
405 // If we didn't dropped for now - test has been passed.
406 TestMarkerResult = true
407 }
408
409 finally {
410 // Collect rendered per-node data.Those info could be simply used
411 // for diff processing. Data was generated via reclass.cli --nodeinfo,
412 /// during verify_salt_minions.
413 sh(script: "cd /tmp; tar -czf ${env.WORKSPACE}/nodesinfo.tar.gz *reclass*", returnStatus: true)
414 archiveArtifacts artifacts: "nodesinfo.tar.gz"
415 }
azvyagintsev1bfe6842018-08-09 18:40:17 +0200416 }
azvyagintsev1bfe6842018-08-09 18:40:17 +0200417 }
chnydaf14ea2a2017-05-26 15:07:47 +0200418 }
azvyagintsevb4e0c442018-09-12 17:00:04 +0300419 catch (Exception er) {
420 common.warningMsg("IgnoreMe:Something wrong with img.Message:\n" + er.toString())
421 }
azvyagintsev28fa9d92018-06-26 14:31:49 +0300422
azvyagintsevb4e0c442018-09-12 17:00:04 +0300423 if (legacyTestingMode.toBoolean()) {
424 common.infoMsg("Running legacy mode test for master hostname ${masterName}")
425 def nodes = sh(script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true)
426 for (minion in nodes.tokenize()) {
427 def basename = sh(script: "set +x;basename ${minion} .yml", returnStdout: true)
428 if (!basename.trim().contains(masterName)) {
429 testMinion(basename.trim())
430 }
431 }
azvyagintsev28fa9d92018-06-26 14:31:49 +0300432 }
azvyagintsev28fa9d92018-06-26 14:31:49 +0300433
azvyagintsevb4e0c442018-09-12 17:00:04 +0300434 try {
435 common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors")
436 timeout(time: 10, unit: 'SECONDS') {
437 sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true)
438 }
439 timeout(time: 10, unit: 'SECONDS') {
440 sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true)
441 }
azvyagintsev28fa9d92018-06-26 14:31:49 +0300442 }
azvyagintsevb4e0c442018-09-12 17:00:04 +0300443 catch (Exception er) {
444 common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString())
azvyagintsev28fa9d92018-06-26 14:31:49 +0300445 }
azvyagintsev28fa9d92018-06-26 14:31:49 +0300446
azvyagintsevb4e0c442018-09-12 17:00:04 +0300447 if (TestMarkerResult) {
448 common.infoMsg("Test finished: SUCCESS")
449 } else {
450 common.warningMsg("Test finished: FAILURE")
451 }
452 return TestMarkerResult
azvyagintsev28fa9d92018-06-26 14:31:49 +0300453
chnydaf14ea2a2017-05-26 15:07:47 +0200454}
455
456/**
457 * Test salt-minion
458 *
azvyagintsev28fa9d92018-06-26 14:31:49 +0300459 * @param minion salt minion
chnydaf14ea2a2017-05-26 15:07:47 +0200460 */
461
azvyagintsev28fa9d92018-06-26 14:31:49 +0300462def testMinion(minionName) {
azvyagintsevb4e0c442018-09-12 17:00:04 +0300463 sh(script: "bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minion ${minionName}'", returnStdout: true)
Jakub Joseffa6ad8d2017-06-26 18:29:55 +0200464}
azvyagintsev2b279d82018-08-07 17:22:54 +0200465
azvyagintsev2b279d82018-08-07 17:22:54 +0200466/**
467 * Wrapper over setupAndTestNode, to test exactly one CC model.
azvyagintsevb4e0c442018-09-12 17:00:04 +0300468 Whole workspace and model - should be pre-rendered and passed via MODELS_TARGZ
469 Flow: grab all data, and pass to setupAndTestNode function
470 under-modell will be directly mirrored to `model/{cfg.testReclassEnv}/* /srv/salt/reclass/*`
azvyagintsev2b279d82018-08-07 17:22:54 +0200471 *
472 * @param cfg - dict with params:
azvyagintsevb4e0c442018-09-12 17:00:04 +0300473 MODELS_TARGZ http link to arch with (models|contexts|global_reclass)
474 modelFile
475 DockerCName directly passed to setupAndTestNode
476 EXTRA_FORMULAS directly passed to setupAndTestNode
477 DISTRIB_REVISION directly passed to setupAndTestNode
478 reclassVersion directly passed to setupAndTestNode
azvyagintsev2b279d82018-08-07 17:22:54 +0200479
azvyagintsevb4e0c442018-09-12 17:00:04 +0300480 Return: true\exception
azvyagintsev2b279d82018-08-07 17:22:54 +0200481 */
482
483def testCCModel(cfg) {
azvyagintsevb4e0c442018-09-12 17:00:04 +0300484 def common = new com.mirantis.mk.Common()
azvyagintsev1cecc092018-09-14 13:19:16 +0300485 common.errorMsg('You are using deprecated function!Please migrate to "testNode".' +
486 'It would be removed after 2018.q4 release!Pushing forced 60s sleep..')
487 sh('sleep 60')
azvyagintsevb4e0c442018-09-12 17:00:04 +0300488 sh(script: 'find . -mindepth 1 -delete || true', returnStatus: true)
489 sh(script: "wget --progress=dot:mega --auth-no-challenge -O models.tar.gz ${cfg.MODELS_TARGZ}")
490 // unpack data
491 sh(script: "tar -xzf models.tar.gz ")
492 common.infoMsg("Going to test exactly one context: ${cfg.modelFile}\n, with params: ${cfg}")
493 content = readFile(file: cfg.modelFile)
494 templateContext = readYaml text: content
495 clusterName = templateContext.default_context.cluster_name
496 clusterDomain = templateContext.default_context.cluster_domain
azvyagintsev2b279d82018-08-07 17:22:54 +0200497
azvyagintsevb4e0c442018-09-12 17:00:04 +0300498 def testResult = false
499 testResult = setupAndTestNode(
500 "cfg01.${clusterDomain}",
501 clusterName,
502 '',
503 cfg.testReclassEnv, // Sync into image exactly one env
504 'pkg',
505 cfg.DISTRIB_REVISION,
506 cfg.reclassVersion,
507 0,
508 false,
509 false,
510 '',
511 '',
512 cfg.DockerCName)
513 if (testResult) {
514 common.infoMsg("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: SUCCESS")
515 } else {
516 throw new RuntimeException("testCCModel for context: ${cfg.modelFile} model: ${cfg.testReclassEnv} finished: FAILURE")
517 }
518 return testResult
azvyagintsev2b279d82018-08-07 17:22:54 +0200519}