blob: e22bcbe0f69dc38be5382edfd8eb6b912237887a [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
chnydad66d6fa2017-06-22 09:34:43 +020014 */
15
16def common = new com.mirantis.mk.Common()
17def gerrit = new com.mirantis.mk.Gerrit()
chnyda4ed3c272017-06-22 14:50:09 +020018def git = new com.mirantis.mk.Git()
chnydac6092a22017-06-22 14:47:10 +020019def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020020def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
21
22def defaultGitRef = DEFAULT_GIT_REF
23def defaultGitUrl = DEFAULT_GIT_URL
24
25def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020026
27throttle(['test-model']) {
28 node("python") {
29 try{
30 stage("checkout") {
31 if(defaultGitRef != "" && defaultGitUrl != "") {
32 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
33 } else {
34 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
35 }
36 if(checkouted) {
37 if (fileExists('classes/system')) {
38 if (SYSTEM_GIT_URL == "") {
39 ssh.prepareSshAgentKey(CREDENTIALS_ID)
40 dir('classes/system') {
41 remoteUrl = git.getGitRemote()
42 ssh.ensureKnownHosts(remoteUrl)
43 }
44 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
45 } else {
46 dir('classes/system') {
47 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
48 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
49 }
chnydad66d6fa2017-06-22 09:34:43 +020050 }
51 }
52 }
53 }
54 }
chnydad66d6fa2017-06-22 09:34:43 +020055
chnyda03f3ad42017-09-19 14:41:07 +020056 stage("test node") {
57 if (checkouted) {
58 def workspace = common.getWorkspace()
Jakub Josef70fd76e2017-09-25 14:48:44 +020059 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
chnyda03f3ad42017-09-19 14:41:07 +020060 saltModelTesting.setupAndTestNode(NODE_TARGET, CLUSTER_NAME, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE, FORMULAS_REVISION, MAX_CPU_PER_JOB.toInteger())
61 }
chnydad66d6fa2017-06-22 09:34:43 +020062 }
chnyda03f3ad42017-09-19 14:41:07 +020063 } catch (Throwable e) {
64 // If there was an error or exception thrown, the build failed
65 currentBuild.result = "FAILURE"
66 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
67 throw e
chnydad66d6fa2017-06-22 09:34:43 +020068 }
chnydad66d6fa2017-06-22 09:34:43 +020069 }
70}