Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 1 | |
| 2 | /** |
| 3 | * Test salt models pipeline |
| 4 | * DEFAULT_GIT_REF |
| 5 | * DEFAULT_GIT_URL |
| 6 | * CREDENTIALS_ID |
| 7 | */ |
| 8 | |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 9 | def common = new com.mirantis.mk.Common() |
| 10 | def gerrit = new com.mirantis.mk.Gerrit() |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 11 | def ssh = new com.mirantis.mk.Ssh() |
| 12 | def git = new com.mirantis.mk.Git() |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 13 | |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 14 | def gerritRef |
| 15 | try { |
| 16 | gerritRef = GERRIT_REFSPEC |
| 17 | } catch (MissingPropertyException e) { |
| 18 | gerritRef = null |
| 19 | } |
| 20 | |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 21 | def defaultGitRef, defaultGitUrl |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 22 | try { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 23 | defaultGitRef = DEFAULT_GIT_REF |
| 24 | defaultGitUrl = DEFAULT_GIT_URL |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 25 | } catch (MissingPropertyException e) { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 26 | defaultGitRef = null |
| 27 | defaultGitUrl = null |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 28 | } |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 29 | def checkouted = false |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 30 | def merged = false |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 31 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 32 | def testMinion(minion) |
chnyda | 51b0314 | 2017-05-10 17:15:27 +0200 | [diff] [blame] | 33 | { |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 34 | return sh(script: "reclass-salt -p ${minion}", returnStatus:true) |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 35 | } |
| 36 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 37 | |
| 38 | |
chnyda | 51b0314 | 2017-05-10 17:15:27 +0200 | [diff] [blame] | 39 | def setupandtest(master) { |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 40 | def img = docker.image("ubuntu:latest") |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 41 | def saltOpts = "--retcode-passthrough --force-color" |
chnyda | 6c509b8 | 2017-05-11 08:41:12 +0200 | [diff] [blame] | 42 | def common = new com.mirantis.mk.Common() |
| 43 | def workspace = common.getWorkspace() |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 44 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 45 | // -v ${workspace}:/srv/salt/reclass |
| 46 | img.inside("-u root:root --hostname=${master}") { |
chnyda | 6c509b8 | 2017-05-11 08:41:12 +0200 | [diff] [blame] | 47 | wrap([$class: 'AnsiColorBuildWrapper']) { |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 48 | |
| 49 | sh("mkdir -p /srv/salt/ || true") |
| 50 | sh("cp -r ${workspace} /srv/salt/reclass") |
Tomáš Kukrál | 500c018 | 2017-05-11 13:46:19 +0200 | [diff] [blame] | 51 | sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev reclass git") |
chnyda | ce3b0d7 | 2017-05-11 17:01:09 +0200 | [diff] [blame] | 52 | sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts") |
chnyda | 6c509b8 | 2017-05-11 08:41:12 +0200 | [diff] [blame] | 53 | sh("git config --global user.email || git config --global user.email 'ci@ci.local'") |
Tomáš Kukrál | 500c018 | 2017-05-11 13:46:19 +0200 | [diff] [blame] | 54 | sh("git config --global user.name || git config --global user.name 'CI'") |
chnyda | c0016dc | 2017-05-11 11:08:37 +0200 | [diff] [blame] | 55 | sh("ls -lRa /srv/salt/reclass") |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 56 | |
chnyda | 6c509b8 | 2017-05-11 08:41:12 +0200 | [diff] [blame] | 57 | // setup iniot and verify salt master and minions |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 58 | withEnv(["FORMULAS_SOURCE=pkg", "DEBUG=1", "MASTER_HOSTNAME=${master}", "MINION_ID=${master}", "HOSTNAME=cfg01","DOMAIN=mk-ci.local"]){ |
| 59 | sh("bash -c 'echo $MASTER_HOSTNAME'") |
| 60 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && system_config'") |
| 61 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_bootstrap'") |
| 62 | sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; cd /srv/salt/scripts && saltmaster_init'") |
chnyda | 6c509b8 | 2017-05-11 08:41:12 +0200 | [diff] [blame] | 63 | } |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 64 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 65 | def nodes |
| 66 | if (DEFAULT_GIT_URL.contains("mk-ci")) { |
| 67 | nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true |
| 68 | } else { |
| 69 | nodes = sh script:"find /srv/salt/reclass/nodes/_generated -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true |
| 70 | } |
| 71 | for (minion in nodes.tokenize()) { |
| 72 | def basename = sh script: "basename ${minion} .yml", returnStdout: true |
| 73 | testMinion(basename.trim()) |
| 74 | } |
| 75 | |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 76 | } |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 77 | |
| 78 | } |
| 79 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 80 | return 0 |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 81 | } |
| 82 | |
chnyda | fa4b0ec | 2017-05-05 15:49:27 +0200 | [diff] [blame] | 83 | node("python&&docker") { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 84 | try{ |
| 85 | stage("checkout") { |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 86 | if (gerritRef) { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 87 | // job is triggered by Gerrit |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 88 | // test if change aren't already merged |
| 89 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID) |
| 90 | merged = gerritChange.status == "MERGED" |
| 91 | if(!merged){ |
| 92 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 93 | credentialsId : CREDENTIALS_ID |
| 94 | ]) |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 95 | } else{ |
| 96 | common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them") |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 97 | } |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 98 | } else if(defaultGitRef && defaultGitUrl) { |
Jakub Josef | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 99 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 100 | } |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 101 | if(checkouted){ |
| 102 | if (fileExists('classes/system')) { |
| 103 | ssh.prepareSshAgentKey(CREDENTIALS_ID) |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 104 | dir('classes/system') { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 105 | remoteUrl = git.getGitRemote() |
| 106 | ssh.ensureKnownHosts(remoteUrl) |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 107 | } |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 108 | ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive") |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 109 | } |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 110 | }else if(!merged){ |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 111 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 112 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 113 | } |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 114 | |
| 115 | def nodes |
| 116 | dir ('nodes') { |
Tomáš Kukrál | 500c018 | 2017-05-11 13:46:19 +0200 | [diff] [blame] | 117 | nodes = sh script: "find ./ -type f -name 'cfg*.yml'", returnStdout: true |
chnyda | a9c8870 | 2017-05-09 16:51:07 +0200 | [diff] [blame] | 118 | } |
| 119 | |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 120 | stage("test-nodes") { |
| 121 | def buildSteps = [:] |
chnyda | 51b0314 | 2017-05-10 17:15:27 +0200 | [diff] [blame] | 122 | for (masterNode in nodes.tokenize()) { |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 123 | def basename = sh script: "basename ${masterNode} .yml", returnStdout: true |
| 124 | buildSteps[basename.trim()] = { setupandtest(basename.trim()) } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 125 | } |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 126 | parallel buildSteps |
chnyda | 51b0314 | 2017-05-10 17:15:27 +0200 | [diff] [blame] | 127 | } |
chnyda | 14e4429 | 2017-05-13 19:00:06 +0200 | [diff] [blame^] | 128 | |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 129 | } catch (Throwable e) { |
| 130 | // If there was an error or exception thrown, the build failed |
| 131 | currentBuild.result = "FAILURE" |
| 132 | throw e |
| 133 | } finally { |
| 134 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 135 | } |
Tomáš Kukrál | 500c018 | 2017-05-11 13:46:19 +0200 | [diff] [blame] | 136 | } |