blob: 9bbd782bd11e0447c3c8cf869c5b207eb2cff96a [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
Jakub Josef107769c2017-08-17 13:38:15 +02007 * CLUSTER_NAME
chnydad66d6fa2017-06-22 09:34:43 +02008 * NODE_TARGET
9 * SYSTEM_GIT_URL
10 * SYSTEM_GIT_REF
Jakub Josefe40bbf92018-03-22 15:02:46 +010011 * RECLASS_VERSION
chnydabb6d2a62017-07-31 14:09:16 +020012 * MAX_CPU_PER_JOB
Jakub Josef6e4a09d2017-10-05 16:53:02 +020013 * LEGACY_TEST_MODE
Jakub Josefb1c81632017-10-05 17:19:53 +020014 * RECLASS_IGNORE_CLASS_NOTFOUND
Dmitry Ukovb2aa6db2017-10-23 12:30:31 +040015 * APT_REPOSITORY
16 * APT_REPOSITORY_GPG
chnydad66d6fa2017-06-22 09:34:43 +020017 */
18
19def common = new com.mirantis.mk.Common()
20def gerrit = new com.mirantis.mk.Gerrit()
chnyda4ed3c272017-06-22 14:50:09 +020021def git = new com.mirantis.mk.Git()
chnydac6092a22017-06-22 14:47:10 +020022def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020023def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
24
25def defaultGitRef = DEFAULT_GIT_REF
26def defaultGitUrl = DEFAULT_GIT_URL
27
28def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020029
Vasyl Saienko682043d2018-07-23 16:04:10 +030030def reclassVersion = 'v1.5.4'
Vasyl Saienko772e1232018-07-23 14:42:24 +030031if (common.validInputParam('RECLASS_VERSION')) {
32 reclassVersion = RECLASS_VERSION
33}
34
chnyda03f3ad42017-09-19 14:41:07 +020035throttle(['test-model']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010036 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010037 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010038 try{
39 stage("checkout") {
40 if(defaultGitRef != "" && defaultGitUrl != "") {
41 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
42 } else {
43 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
44 }
45 if(checkouted) {
46 if (fileExists('classes/system')) {
47 if (SYSTEM_GIT_URL == "") {
48 ssh.prepareSshAgentKey(CREDENTIALS_ID)
49 dir('classes/system') {
50 remoteUrl = git.getGitRemote()
51 ssh.ensureKnownHosts(remoteUrl)
52 }
53 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
54 } else {
55 dir('classes/system') {
56 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
57 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
58 }
chnyda03f3ad42017-09-19 14:41:07 +020059 }
chnydad66d6fa2017-06-22 09:34:43 +020060 }
61 }
62 }
63 }
chnydad66d6fa2017-06-22 09:34:43 +020064
Jakub Josefa63f9862018-01-11 17:58:38 +010065 stage("test node") {
66 if (checkouted) {
67 def workspace = common.getWorkspace()
68 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
Denis Egorenko032b8ca2018-09-13 17:00:23 +040069
70 def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
71 def config = [
72 'dockerHostname': NODE_TARGET,
73 'clusterName': CLUSTER_NAME,
74 'reclassEnv': workspace,
75 'formulasRevision': FORMULAS_REVISION,
76 'reclassVersion': reclassVersion,
77 'dockerMaxCpus': MAX_CPU_PER_JOB.toInteger(),
78 'ignoreClassNotfound': RECLASS_IGNORE_CLASS_NOTFOUND,
79 'aptRepoUrl': APT_REPOSITORY,
80 'aptRepoGPG': APT_REPOSITORY_GPG,
81 'dockerContainerName': DockerCName,
82 'testContext': 'salt-model-node'
83 ]
84 saltModelTesting.testNode(config)
chnyda3dcf0bd2017-11-30 11:49:24 +010085 }
chnyda03f3ad42017-09-19 14:41:07 +020086 }
Jakub Josefa63f9862018-01-11 17:58:38 +010087 } catch (Throwable e) {
azvyagintsev1c9801f2018-07-07 23:02:53 +030088 // If there was an error or exception thrown, the build failed
89 currentBuild.result = "FAILURE"
90 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
91 throw e
chnydad66d6fa2017-06-22 09:34:43 +020092 }
93 }
chnydad66d6fa2017-06-22 09:34:43 +020094 }
95}