chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 1 | |
| 2 | /** |
| 3 | * Test salt models pipeline |
| 4 | * DEFAULT_GIT_REF |
| 5 | * DEFAULT_GIT_URL |
| 6 | * CREDENTIALS_ID |
Jakub Josef | 107769c | 2017-08-17 13:38:15 +0200 | [diff] [blame] | 7 | * CLUSTER_NAME |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 8 | * NODE_TARGET |
| 9 | * SYSTEM_GIT_URL |
| 10 | * SYSTEM_GIT_REF |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 11 | * DISTRIB_REVISION of apt mirrror to be used (http://mirror.mirantis.com/DISTRIB_REVISION/ by default) |
chnyda | bb6d2a6 | 2017-07-31 14:09:16 +0200 | [diff] [blame] | 12 | * MAX_CPU_PER_JOB |
Jakub Josef | 6e4a09d | 2017-10-05 16:53:02 +0200 | [diff] [blame] | 13 | * LEGACY_TEST_MODE |
Jakub Josef | b1c8163 | 2017-10-05 17:19:53 +0200 | [diff] [blame] | 14 | * RECLASS_IGNORE_CLASS_NOTFOUND |
Dmitry Ukov | b2aa6db | 2017-10-23 12:30:31 +0400 | [diff] [blame] | 15 | * APT_REPOSITORY |
| 16 | * APT_REPOSITORY_GPG |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | def common = new com.mirantis.mk.Common() |
| 20 | def gerrit = new com.mirantis.mk.Gerrit() |
chnyda | 4ed3c27 | 2017-06-22 14:50:09 +0200 | [diff] [blame] | 21 | def git = new com.mirantis.mk.Git() |
chnyda | c6092a2 | 2017-06-22 14:47:10 +0200 | [diff] [blame] | 22 | def ssh = new com.mirantis.mk.Ssh() |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 23 | def saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
| 24 | |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 25 | def defaultGitRef = env.DEFAULT_GIT_REF ?: null |
| 26 | def defaultGitUrl = env.DEFAULT_GIT_URL ?: null |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 27 | |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 28 | def distribRevision = env.DISTRIB_REVISION ?: 'nightly' |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 29 | def checkouted = false |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 30 | |
Vladimir Khlyunev | d77c188 | 2022-01-31 15:57:35 +0400 | [diff] [blame^] | 31 | def nodeLabel = 'docker' |
Vladimir Khlyunev | 81a3c90 | 2021-02-01 18:51:15 +0400 | [diff] [blame] | 32 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 33 | throttle(['test-model']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 34 | timeout(time: 1, unit: 'HOURS') { |
Vladimir Khlyunev | 81a3c90 | 2021-02-01 18:51:15 +0400 | [diff] [blame] | 35 | node(nodeLabel) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 36 | 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 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 57 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 62 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 63 | 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 Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 67 | |
| 68 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
Denis Egorenko | 926bc7d | 2019-02-19 14:27:34 +0400 | [diff] [blame] | 69 | def dockerHostname = NODE_TARGET.tokenize('.')[0] |
| 70 | def domain = NODE_TARGET - "${dockerHostname}." |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 71 | def config = [ |
Denis Egorenko | 926bc7d | 2019-02-19 14:27:34 +0400 | [diff] [blame] | 72 | 'dockerHostname': dockerHostname, |
| 73 | 'domain': domain, |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 74 | 'clusterName': CLUSTER_NAME, |
| 75 | 'reclassEnv': workspace, |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 76 | 'distribRevision': distribRevision, |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 77 | 'dockerMaxCpus': MAX_CPU_PER_JOB.toInteger(), |
Denis Egorenko | d87490e | 2019-02-26 20:00:41 +0400 | [diff] [blame] | 78 | 'dockerExtraOpts': [ '--memory=3g' ], |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 79 | '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) |
chnyda | 3dcf0bd | 2017-11-30 11:49:24 +0100 | [diff] [blame] | 86 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 87 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 88 | } catch (Throwable e) { |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 89 | // 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 |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 93 | } |
| 94 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 95 | } |
| 96 | } |