blob: b95c3dd5f8f84bb9ea8da4c65d41a642d584bc86 [file] [log] [blame]
Jakub Josef83379312017-03-29 18:12:34 +02001
2/**
3 * Test salt models pipeline
4 * DEFAULT_GIT_REF
5 * DEFAULT_GIT_URL
6 * CREDENTIALS_ID
7 */
8
Jakub Josefc5a223a2017-03-01 14:40:08 +01009def common = new com.mirantis.mk.Common()
10def gerrit = new com.mirantis.mk.Gerrit()
Filip Pytloun38005aa2017-03-06 10:26:38 +010011def ssh = new com.mirantis.mk.Ssh()
12def git = new com.mirantis.mk.Git()
Jakub Josefc5a223a2017-03-01 14:40:08 +010013
Filip Pytloun19376a82017-03-07 12:29:00 +010014def gerritRef
15try {
16 gerritRef = GERRIT_REFSPEC
17} catch (MissingPropertyException e) {
18 gerritRef = null
19}
20
Jakub Josef83379312017-03-29 18:12:34 +020021def defaultGitRef, defaultGitUrl
Filip Pytloun19376a82017-03-07 12:29:00 +010022try {
Jakub Josef83379312017-03-29 18:12:34 +020023 defaultGitRef = DEFAULT_GIT_REF
24 defaultGitUrl = DEFAULT_GIT_URL
Filip Pytloun19376a82017-03-07 12:29:00 +010025} catch (MissingPropertyException e) {
Jakub Josef83379312017-03-29 18:12:34 +020026 defaultGitRef = null
27 defaultGitUrl = null
Filip Pytloun19376a82017-03-07 12:29:00 +010028}
Jakub Josef83379312017-03-29 18:12:34 +020029def checkouted = false
Jakub Joseffcb615e2017-04-10 14:34:40 +020030def merged = false
Filip Pytloun19376a82017-03-07 12:29:00 +010031
chnyda51b03142017-05-10 17:15:27 +020032def testMinion(minion, saltOpts)
33{
chnydace3b0d72017-05-11 17:01:09 +020034 sh("reclass-salt -p ${minion} > /tmp/${minion}.pillar_verify")
chnydaa9c88702017-05-09 16:51:07 +020035}
36
chnyda51b03142017-05-10 17:15:27 +020037def setupandtest(master) {
38 def img = docker.image("ubuntu:trusty")
chnydaa9c88702017-05-09 16:51:07 +020039 def saltOpts = "--retcode-passthrough --force-color"
chnyda6c509b82017-05-11 08:41:12 +020040 def common = new com.mirantis.mk.Common()
41 def workspace = common.getWorkspace()
chnydaa9c88702017-05-09 16:51:07 +020042
chnyda6c509b82017-05-11 08:41:12 +020043 img.inside("-u root:root -v ${workspace}:/srv/salt/reclass") {
44 wrap([$class: 'AnsiColorBuildWrapper']) {
Tomáš Kukrál500c0182017-05-11 13:46:19 +020045 sh("apt-get update && apt-get install -y curl subversion git python-pip sudo python-pip python-dev zlib1g-dev reclass git")
chnydace3b0d72017-05-11 17:01:09 +020046 sh("svn export --force https://github.com/salt-formulas/salt-formulas/trunk/deploy/scripts /srv/salt/scripts")
chnyda6c509b82017-05-11 08:41:12 +020047 sh("git config --global user.email || git config --global user.email 'ci@ci.local'")
Tomáš Kukrál500c0182017-05-11 13:46:19 +020048 sh("git config --global user.name || git config --global user.name 'CI'")
chnyda6c509b82017-05-11 08:41:12 +020049 sh("cd /srv/salt/reclass; test ! -e .gitmodules || git submodule update --init --recursive")
50 sh("cd /srv/salt/reclass; git commit -am 'Fake branch update' || true")
chnydac0016dc2017-05-11 11:08:37 +020051 sh("ls -lRa /srv/salt/reclass")
chnydaa9c88702017-05-09 16:51:07 +020052
chnyda6c509b82017-05-11 08:41:12 +020053 // setup iniot and verify salt master and minions
chnydace3b0d72017-05-11 17:01:09 +020054 withEnv(["SUDO=sudo", "FORMULAS_SOURCE=pkg", "DEBUG=1", "MASTER_HOSTNAME=${master}"]){
chnyda17d877c2017-05-11 09:49:45 +020055 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; system_config'")
56 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; saltmaster_bootstrap'")
chnydac0016dc2017-05-11 11:08:37 +020057 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; saltmaster_init'")
chnyda17d877c2017-05-11 09:49:45 +020058 sh("bash -c 'source /srv/salt/scripts/salt-master-init.sh; verify_salt_master'")
chnyda6c509b82017-05-11 08:41:12 +020059 }
chnydaa9c88702017-05-09 16:51:07 +020060
chnyda6c509b82017-05-11 08:41:12 +020061 testSteps = [:]
chnydace3b0d72017-05-11 17:01:09 +020062 def nodes = sh script:"find /srv/salt/reclass/nodes/_generated -name '*.yml' | grep -v 'cfg*.yml", returnStdout: true
63 if (DEFAULT_GIT_URL.contains("mk-ci")) {
64 nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml", returnStdout: true
65 }
chnyda6c509b82017-05-11 08:41:12 +020066 for (minion in nodes.tokenize()) {
67 def basename = sh script: "basename ${minion} .yml", returnStdout: true
68 testSteps = { testMinion(basename.trim())}
69 }
70 parallel testSteps
chnydaa9c88702017-05-09 16:51:07 +020071 }
chnydaa9c88702017-05-09 16:51:07 +020072
73 }
74
75}
76
chnydafa4b0ec2017-05-05 15:49:27 +020077node("python&&docker") {
Jakub Josefc5a223a2017-03-01 14:40:08 +010078 try{
79 stage("checkout") {
Filip Pytloun19376a82017-03-07 12:29:00 +010080 if (gerritRef) {
Jakub Josef83379312017-03-29 18:12:34 +020081 // job is triggered by Gerrit
Jakub Joseffcb615e2017-04-10 14:34:40 +020082 // test if change aren't already merged
83 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID)
84 merged = gerritChange.status == "MERGED"
85 if(!merged){
86 checkouted = gerrit.gerritPatchsetCheckout ([
87 credentialsId : CREDENTIALS_ID
88 ])
chnydaa9c88702017-05-09 16:51:07 +020089 } else{
90 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them")
Jakub Joseffcb615e2017-04-10 14:34:40 +020091 }
Jakub Josef83379312017-03-29 18:12:34 +020092 } else if(defaultGitRef && defaultGitUrl) {
Jakub Josefe1407ac2017-03-30 14:10:19 +020093 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Filip Pytloun19376a82017-03-07 12:29:00 +010094 }
Jakub Josef83379312017-03-29 18:12:34 +020095 if(checkouted){
96 if (fileExists('classes/system')) {
97 ssh.prepareSshAgentKey(CREDENTIALS_ID)
Filip Pytloun19376a82017-03-07 12:29:00 +010098 dir('classes/system') {
Jakub Josef83379312017-03-29 18:12:34 +020099 remoteUrl = git.getGitRemote()
100 ssh.ensureKnownHosts(remoteUrl)
Filip Pytloun19376a82017-03-07 12:29:00 +0100101 }
Jakub Josef83379312017-03-29 18:12:34 +0200102 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
Filip Pytloun19376a82017-03-07 12:29:00 +0100103 }
Jakub Joseffcb615e2017-04-10 14:34:40 +0200104 }else if(!merged){
Jakub Josef5ce6a362017-03-31 13:41:17 +0200105 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Filip Pytloun38005aa2017-03-06 10:26:38 +0100106 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100107 }
chnydaa9c88702017-05-09 16:51:07 +0200108
109 def nodes
110 dir ('nodes') {
Tomáš Kukrál500c0182017-05-11 13:46:19 +0200111 nodes = sh script: "find ./ -type f -name 'cfg*.yml'", returnStdout: true
chnydaa9c88702017-05-09 16:51:07 +0200112 }
113
Jakub Josef62218bb2017-05-09 18:31:00 +0200114 stage("test") {
chnyda51b03142017-05-10 17:15:27 +0200115 for (masterNode in nodes.tokenize()) {
116 basename = sh script: "basename ${masterNode} .yml", returnStdout: true
chnyda6c509b82017-05-11 08:41:12 +0200117 setupandtest(basename.trim())
Jakub Josefc5a223a2017-03-01 14:40:08 +0100118 }
chnydaa9c88702017-05-09 16:51:07 +0200119
chnyda51b03142017-05-10 17:15:27 +0200120 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100121 } catch (Throwable e) {
122 // If there was an error or exception thrown, the build failed
123 currentBuild.result = "FAILURE"
124 throw e
125 } finally {
126 common.sendNotification(currentBuild.result,"",["slack"])
127 }
Tomáš Kukrál500c0182017-05-11 13:46:19 +0200128}