blob: 3b6ee0938d1585753717bbf043dcaa0017fb2f4f [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
Jakub Josefe40bbf92018-03-22 15:02:46 +010013 * RECLASS_VERSION
chnydabb6d2a62017-07-31 14:09:16 +020014 * MAX_CPU_PER_JOB
Jakub Josef6e4a09d2017-10-05 16:53:02 +020015 * LEGACY_TEST_MODE
Jakub Josefb1c81632017-10-05 17:19:53 +020016 * RECLASS_IGNORE_CLASS_NOTFOUND
Dmitry Ukovb2aa6db2017-10-23 12:30:31 +040017 * APT_REPOSITORY
18 * APT_REPOSITORY_GPG
chnydad66d6fa2017-06-22 09:34:43 +020019 */
20
21def common = new com.mirantis.mk.Common()
22def gerrit = new com.mirantis.mk.Gerrit()
chnyda4ed3c272017-06-22 14:50:09 +020023def git = new com.mirantis.mk.Git()
chnydac6092a22017-06-22 14:47:10 +020024def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020025def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
26
27def defaultGitRef = DEFAULT_GIT_REF
28def defaultGitUrl = DEFAULT_GIT_URL
29
30def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020031
32throttle(['test-model']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010033 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010034 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010035 try{
36 stage("checkout") {
37 if(defaultGitRef != "" && defaultGitUrl != "") {
38 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
39 } else {
40 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
41 }
42 if(checkouted) {
43 if (fileExists('classes/system')) {
44 if (SYSTEM_GIT_URL == "") {
45 ssh.prepareSshAgentKey(CREDENTIALS_ID)
46 dir('classes/system') {
47 remoteUrl = git.getGitRemote()
48 ssh.ensureKnownHosts(remoteUrl)
49 }
50 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
51 } else {
52 dir('classes/system') {
53 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
54 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
55 }
chnyda03f3ad42017-09-19 14:41:07 +020056 }
chnydad66d6fa2017-06-22 09:34:43 +020057 }
58 }
59 }
60 }
chnydad66d6fa2017-06-22 09:34:43 +020061
Jakub Josefa63f9862018-01-11 17:58:38 +010062 stage("test node") {
63 if (checkouted) {
64 def workspace = common.getWorkspace()
65 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
66 try {
Kirill Mashchenko18071f62018-06-29 12:42:16 +030067 def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
Kirill Mashchenkoa71cc702018-06-29 15:58:11 +030068
69 saltModelTesting.setupAndTestNode(
70 NODE_TARGET,
71 CLUSTER_NAME,
72 EXTRA_FORMULAS,
73 workspace,
74 FORMULAS_SOURCE,
75 FORMULAS_REVISION,
76 RECLASS_VERSION,
77 MAX_CPU_PER_JOB.toInteger(),
78 RECLASS_IGNORE_CLASS_NOTFOUND,
79 LEGACY_TEST_MODE,
80 APT_REPOSITORY,
81 APT_REPOSITORY_GPG,
82 DockerCName)
Jakub Josefa63f9862018-01-11 17:58:38 +010083 } catch (Exception e) {
84 if (e.getMessage() == "script returned exit code 124") {
85 common.errorMsg("Impossible to test node due to timeout of salt-master, ABORTING BUILD")
86 currentBuild.result = "ABORTED"
87 } else {
88 throw e
89 }
chnyda3dcf0bd2017-11-30 11:49:24 +010090 }
91 }
chnyda03f3ad42017-09-19 14:41:07 +020092 }
Jakub Josefa63f9862018-01-11 17:58:38 +010093 } catch (Throwable e) {
94 // If there was an error or exception thrown, the build failed
95 currentBuild.result = "FAILURE"
96 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
97 throw e
chnydad66d6fa2017-06-22 09:34:43 +020098 }
99 }
chnydad66d6fa2017-06-22 09:34:43 +0200100 }
101}