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 |
Mykyta Karpin | c0758f3 | 2017-06-23 18:10:24 +0300 | [diff] [blame] | 11 | * FORMULAS_SOURCE |
Jakub Josef | e40bbf9 | 2018-03-22 15:02:46 +0100 | [diff] [blame] | 12 | * RECLASS_VERSION |
chnyda | bb6d2a6 | 2017-07-31 14:09:16 +0200 | [diff] [blame] | 13 | * MAX_CPU_PER_JOB |
Jakub Josef | 6e4a09d | 2017-10-05 16:53:02 +0200 | [diff] [blame] | 14 | * LEGACY_TEST_MODE |
Jakub Josef | b1c8163 | 2017-10-05 17:19:53 +0200 | [diff] [blame] | 15 | * RECLASS_IGNORE_CLASS_NOTFOUND |
Dmitry Ukov | b2aa6db | 2017-10-23 12:30:31 +0400 | [diff] [blame] | 16 | * APT_REPOSITORY |
| 17 | * APT_REPOSITORY_GPG |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | def common = new com.mirantis.mk.Common() |
| 21 | def gerrit = new com.mirantis.mk.Gerrit() |
chnyda | 4ed3c27 | 2017-06-22 14:50:09 +0200 | [diff] [blame] | 22 | def git = new com.mirantis.mk.Git() |
chnyda | c6092a2 | 2017-06-22 14:47:10 +0200 | [diff] [blame] | 23 | def ssh = new com.mirantis.mk.Ssh() |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 24 | def saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
| 25 | |
| 26 | def defaultGitRef = DEFAULT_GIT_REF |
| 27 | def defaultGitUrl = DEFAULT_GIT_URL |
| 28 | |
| 29 | def checkouted = false |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 30 | |
Vasyl Saienko | 682043d | 2018-07-23 16:04:10 +0300 | [diff] [blame] | 31 | def reclassVersion = 'v1.5.4' |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 32 | if (common.validInputParam('RECLASS_VERSION')) { |
| 33 | reclassVersion = RECLASS_VERSION |
| 34 | } |
| 35 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 36 | throttle(['test-model']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 37 | timeout(time: 1, unit: 'HOURS') { |
Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 38 | node("python&&docker") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 39 | try{ |
| 40 | stage("checkout") { |
| 41 | if(defaultGitRef != "" && defaultGitUrl != "") { |
| 42 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
| 43 | } else { |
| 44 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null") |
| 45 | } |
| 46 | if(checkouted) { |
| 47 | if (fileExists('classes/system')) { |
| 48 | if (SYSTEM_GIT_URL == "") { |
| 49 | ssh.prepareSshAgentKey(CREDENTIALS_ID) |
| 50 | dir('classes/system') { |
| 51 | remoteUrl = git.getGitRemote() |
| 52 | ssh.ensureKnownHosts(remoteUrl) |
| 53 | } |
| 54 | ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive") |
| 55 | } else { |
| 56 | dir('classes/system') { |
| 57 | if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) { |
| 58 | common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}") |
| 59 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 60 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 65 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 66 | stage("test node") { |
| 67 | if (checkouted) { |
| 68 | def workspace = common.getWorkspace() |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 69 | def testResult = false |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}") |
| 71 | try { |
Kirill Mashchenko | 18071f6 | 2018-06-29 12:42:16 +0300 | [diff] [blame] | 72 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 73 | testResult = saltModelTesting.setupAndTestNode( |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 74 | NODE_TARGET, |
| 75 | CLUSTER_NAME, |
azvyagintsev | b8ddb49 | 2018-09-12 14:59:45 +0300 | [diff] [blame^] | 76 | '', |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 77 | workspace, |
| 78 | FORMULAS_SOURCE, |
| 79 | FORMULAS_REVISION, |
Vasyl Saienko | c777bb8 | 2018-07-23 14:56:01 +0300 | [diff] [blame] | 80 | reclassVersion, |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 81 | MAX_CPU_PER_JOB.toInteger(), |
| 82 | RECLASS_IGNORE_CLASS_NOTFOUND, |
| 83 | LEGACY_TEST_MODE, |
| 84 | APT_REPOSITORY, |
| 85 | APT_REPOSITORY_GPG, |
| 86 | DockerCName) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 87 | } catch (Exception e) { |
| 88 | if (e.getMessage() == "script returned exit code 124") { |
| 89 | common.errorMsg("Impossible to test node due to timeout of salt-master, ABORTING BUILD") |
| 90 | currentBuild.result = "ABORTED" |
| 91 | } else { |
| 92 | throw e |
| 93 | } |
chnyda | 3dcf0bd | 2017-11-30 11:49:24 +0100 | [diff] [blame] | 94 | } |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 95 | if (testResult) { |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 96 | common.infoMsg("Test finished: SUCCESS") |
| 97 | } else { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 98 | error('Test node finished: FAILURE') |
| 99 | throw new RuntimeException('Test node stage finished: FAILURE') |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 100 | } |
chnyda | 3dcf0bd | 2017-11-30 11:49:24 +0100 | [diff] [blame] | 101 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 102 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 103 | } catch (Throwable e) { |
azvyagintsev | 1c9801f | 2018-07-07 23:02:53 +0300 | [diff] [blame] | 104 | // If there was an error or exception thrown, the build failed |
| 105 | currentBuild.result = "FAILURE" |
| 106 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 107 | throw e |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 108 | } |
| 109 | } |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 110 | } |
| 111 | } |