blob: 17b8fffa39bac339445c344b1c0b67290df3ce61 [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
chnydad66d6fa2017-06-22 09:34:43 +020016 */
17
18def common = new com.mirantis.mk.Common()
19def gerrit = new com.mirantis.mk.Gerrit()
chnyda4ed3c272017-06-22 14:50:09 +020020def git = new com.mirantis.mk.Git()
chnydac6092a22017-06-22 14:47:10 +020021def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020022def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
23
24def defaultGitRef = DEFAULT_GIT_REF
25def defaultGitUrl = DEFAULT_GIT_URL
26
27def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020028
29throttle(['test-model']) {
30 node("python") {
31 try{
32 stage("checkout") {
33 if(defaultGitRef != "" && defaultGitUrl != "") {
34 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
35 } else {
36 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
37 }
38 if(checkouted) {
39 if (fileExists('classes/system')) {
40 if (SYSTEM_GIT_URL == "") {
41 ssh.prepareSshAgentKey(CREDENTIALS_ID)
42 dir('classes/system') {
43 remoteUrl = git.getGitRemote()
44 ssh.ensureKnownHosts(remoteUrl)
45 }
46 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
47 } else {
48 dir('classes/system') {
49 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
50 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
51 }
chnydad66d6fa2017-06-22 09:34:43 +020052 }
53 }
54 }
55 }
56 }
chnydad66d6fa2017-06-22 09:34:43 +020057
chnyda03f3ad42017-09-19 14:41:07 +020058 stage("test node") {
59 if (checkouted) {
60 def workspace = common.getWorkspace()
Jakub Josef70fd76e2017-09-25 14:48:44 +020061 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
Jakub Josefb1c81632017-10-05 17:19:53 +020062 saltModelTesting.setupAndTestNode(NODE_TARGET, CLUSTER_NAME, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE, FORMULAS_REVISION, MAX_CPU_PER_JOB.toInteger(), LEGACY_TEST_MODE, RECLASS_IGNORE_CLASS_NOTFOUND)
chnyda03f3ad42017-09-19 14:41:07 +020063 }
chnydad66d6fa2017-06-22 09:34:43 +020064 }
chnyda03f3ad42017-09-19 14:41:07 +020065 } catch (Throwable e) {
66 // If there was an error or exception thrown, the build failed
67 currentBuild.result = "FAILURE"
68 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
69 throw e
chnydad66d6fa2017-06-22 09:34:43 +020070 }
chnydad66d6fa2017-06-22 09:34:43 +020071 }
72}