blob: 38930660f0cca44c251d4e8614424cf706387261 [file] [log] [blame]
chnydad66d6fa2017-06-22 09:34:43 +02001
2/**
3 * Test salt models pipeline
4 * DEFAULT_GIT_REF
5 * DEFAULT_GIT_URL
6 * CREDENTIALS_ID
7 * EXTRA_FORMULAS
Jakub Josef107769c2017-08-17 13:38:15 +02008 * CLUSTER_NAME
chnydad66d6fa2017-06-22 09:34:43 +02009 * NODE_TARGET
10 * SYSTEM_GIT_URL
11 * SYSTEM_GIT_REF
Mykyta Karpinc0758f32017-06-23 18:10:24 +030012 * FORMULAS_SOURCE
chnydabb6d2a62017-07-31 14:09:16 +020013 * MAX_CPU_PER_JOB
Jakub Josef6e4a09d2017-10-05 16:53:02 +020014 * LEGACY_TEST_MODE
Jakub Josefb1c81632017-10-05 17:19:53 +020015 * RECLASS_IGNORE_CLASS_NOTFOUND
Dmitry Ukovb2aa6db2017-10-23 12:30:31 +040016 * APT_REPOSITORY
17 * APT_REPOSITORY_GPG
chnydad66d6fa2017-06-22 09:34:43 +020018 */
19
20def common = new com.mirantis.mk.Common()
21def gerrit = new com.mirantis.mk.Gerrit()
chnyda4ed3c272017-06-22 14:50:09 +020022def git = new com.mirantis.mk.Git()
chnydac6092a22017-06-22 14:47:10 +020023def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020024def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
25
26def defaultGitRef = DEFAULT_GIT_REF
27def defaultGitUrl = DEFAULT_GIT_URL
28
29def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020030
31throttle(['test-model']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010032 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010033 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010034 try{
35 stage("checkout") {
36 if(defaultGitRef != "" && defaultGitUrl != "") {
37 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
38 } else {
39 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
40 }
41 if(checkouted) {
42 if (fileExists('classes/system')) {
43 if (SYSTEM_GIT_URL == "") {
44 ssh.prepareSshAgentKey(CREDENTIALS_ID)
45 dir('classes/system') {
46 remoteUrl = git.getGitRemote()
47 ssh.ensureKnownHosts(remoteUrl)
48 }
49 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
50 } else {
51 dir('classes/system') {
52 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
53 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
54 }
chnyda03f3ad42017-09-19 14:41:07 +020055 }
chnydad66d6fa2017-06-22 09:34:43 +020056 }
57 }
58 }
59 }
chnydad66d6fa2017-06-22 09:34:43 +020060
Jakub Josefa63f9862018-01-11 17:58:38 +010061 stage("test node") {
62 if (checkouted) {
63 def workspace = common.getWorkspace()
64 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
65 try {
66 saltModelTesting.setupAndTestNode(NODE_TARGET, CLUSTER_NAME, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE, FORMULAS_REVISION, MAX_CPU_PER_JOB.toInteger(), RECLASS_IGNORE_CLASS_NOTFOUND, LEGACY_TEST_MODE, APT_REPOSITORY, APT_REPOSITORY_GPG)
67 } catch (Exception e) {
68 if (e.getMessage() == "script returned exit code 124") {
69 common.errorMsg("Impossible to test node due to timeout of salt-master, ABORTING BUILD")
70 currentBuild.result = "ABORTED"
71 } else {
72 throw e
73 }
chnyda3dcf0bd2017-11-30 11:49:24 +010074 }
75 }
chnyda03f3ad42017-09-19 14:41:07 +020076 }
Jakub Josefa63f9862018-01-11 17:58:38 +010077 } catch (Throwable e) {
78 // If there was an error or exception thrown, the build failed
79 currentBuild.result = "FAILURE"
80 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
81 throw e
chnydad66d6fa2017-06-22 09:34:43 +020082 }
83 }
chnydad66d6fa2017-06-22 09:34:43 +020084 }
85}