blob: a0d62b3e8c957c15b7915c5168aeff20953a05a9 [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
azvyagintsev1bcadc42018-10-05 20:13:15 +030011 * DISTRIB_REVISION of apt mirrror to be used (http://mirror.mirantis.com/DISTRIB_REVISION/ by default)
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
azvyagintsev1bcadc42018-10-05 20:13:15 +030025def defaultGitRef = env.DEFAULT_GIT_REF ?: null
26def defaultGitUrl = env.DEFAULT_GIT_URL ?: null
chnydad66d6fa2017-06-22 09:34:43 +020027
azvyagintsev1bcadc42018-10-05 20:13:15 +030028def distribRevision = env.DISTRIB_REVISION ?: 'nightly'
chnydad66d6fa2017-06-22 09:34:43 +020029def checkouted = false
chnyda03f3ad42017-09-19 14:41:07 +020030
Vladimir Khlyunevd77c1882022-01-31 15:57:35 +040031def nodeLabel = 'docker'
Vladimir Khlyunev81a3c902021-02-01 18:51:15 +040032
chnyda03f3ad42017-09-19 14:41:07 +020033throttle(['test-model']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010034 timeout(time: 1, unit: 'HOURS') {
Vladimir Khlyunev81a3c902021-02-01 18:51:15 +040035 node(nodeLabel) {
Jakub Josefa63f9862018-01-11 17:58:38 +010036 try{
37 stage("checkout") {
38 if(defaultGitRef != "" && defaultGitUrl != "") {
39 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
40 } else {
41 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
42 }
43 if(checkouted) {
44 if (fileExists('classes/system')) {
45 if (SYSTEM_GIT_URL == "") {
46 ssh.prepareSshAgentKey(CREDENTIALS_ID)
47 dir('classes/system') {
48 remoteUrl = git.getGitRemote()
49 ssh.ensureKnownHosts(remoteUrl)
50 }
51 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
52 } else {
53 dir('classes/system') {
54 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
55 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
56 }
chnyda03f3ad42017-09-19 14:41:07 +020057 }
chnydad66d6fa2017-06-22 09:34:43 +020058 }
59 }
60 }
61 }
chnydad66d6fa2017-06-22 09:34:43 +020062
Jakub Josefa63f9862018-01-11 17:58:38 +010063 stage("test node") {
64 if (checkouted) {
65 def workspace = common.getWorkspace()
66 common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
Denis Egorenko032b8ca2018-09-13 17:00:23 +040067
68 def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
Denis Egorenko926bc7d2019-02-19 14:27:34 +040069 def dockerHostname = NODE_TARGET.tokenize('.')[0]
70 def domain = NODE_TARGET - "${dockerHostname}."
Denis Egorenko032b8ca2018-09-13 17:00:23 +040071 def config = [
Denis Egorenko926bc7d2019-02-19 14:27:34 +040072 'dockerHostname': dockerHostname,
73 'domain': domain,
Denis Egorenko032b8ca2018-09-13 17:00:23 +040074 'clusterName': CLUSTER_NAME,
75 'reclassEnv': workspace,
azvyagintsev1bcadc42018-10-05 20:13:15 +030076 'distribRevision': distribRevision,
Denis Egorenko032b8ca2018-09-13 17:00:23 +040077 'dockerMaxCpus': MAX_CPU_PER_JOB.toInteger(),
Denis Egorenkod87490e2019-02-26 20:00:41 +040078 'dockerExtraOpts': [ '--memory=3g' ],
Denis Egorenko032b8ca2018-09-13 17:00:23 +040079 'ignoreClassNotfound': RECLASS_IGNORE_CLASS_NOTFOUND,
80 'aptRepoUrl': APT_REPOSITORY,
81 'aptRepoGPG': APT_REPOSITORY_GPG,
82 'dockerContainerName': DockerCName,
83 'testContext': 'salt-model-node'
84 ]
85 saltModelTesting.testNode(config)
chnyda3dcf0bd2017-11-30 11:49:24 +010086 }
chnyda03f3ad42017-09-19 14:41:07 +020087 }
Jakub Josefa63f9862018-01-11 17:58:38 +010088 } catch (Throwable e) {
azvyagintsev1c9801f2018-07-07 23:02:53 +030089 // If there was an error or exception thrown, the build failed
90 currentBuild.result = "FAILURE"
91 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
92 throw e
chnydad66d6fa2017-06-22 09:34:43 +020093 }
94 }
chnydad66d6fa2017-06-22 09:34:43 +020095 }
96}