blob: 8a5d26b61ff639a7c37c3b5a1702844af5dd4e93 [file] [log] [blame]
Jiri Broulik9b73d6c2017-06-02 12:27:05 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
7 * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
Jiri Broulik9b73d6c2017-06-02 12:27:05 +02008 * TARGET_SUBSET_TEST Number of nodes to list package updates, empty string means all targetted nodes.
9 * TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update.
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020010 *
11**/
12
13def common = new com.mirantis.mk.Common()
14def salt = new com.mirantis.mk.Salt()
15
16def saltMaster
17def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
18def targetTestSubset
19def targetLiveSubset
20def targetLiveAll
21def minions
22def result
Jiri Broulik52a6b832017-06-16 13:05:08 +020023def args
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020024def command
25def commandKwargs
Jiri Broulik52a6b832017-06-16 13:05:08 +020026def probe = 1
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020027
28node() {
29 try {
30
31 stage('Connect to Salt master') {
32 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
33 }
34
35 stage('List target servers') {
36 minions = salt.getMinions(saltMaster, targetAll)
37
38 if (minions.isEmpty()) {
39 throw new Exception("No minion was targeted")
40 }
41
42 if (TARGET_SUBSET_TEST != "") {
43 targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
44 } else {
45 targetTestSubset = minions.join(' or ')
46 }
47 targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
Jiri Broulik52a6b832017-06-16 13:05:08 +020048 targetTestSubsetProbe = minions.subList(0, probe).join(' or ')
49 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020050
51 targetLiveAll = minions.join(' or ')
52 common.infoMsg("Found nodes: ${targetLiveAll}")
53 common.infoMsg("Selected test nodes: ${targetTestSubset}")
54 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
55 }
56
Jiri Broulik52a6b832017-06-16 13:05:08 +020057
58 stage("Add new repos on test nodes") {
59 salt.enforceState(saltMaster, targetTestSubset, 'linux.system.repo')
60 }
61
62
63 opencontrail = null
64
65 try {
66 opencontrail = salt.cmdRun(saltMaster, targetTestSubsetProbe, "salt-call grains.item roles | grep opencontrail.compute")
67 print(opencontrail)
68 } catch (Exception er) {
69 common.infoMsg("opencontrail is not used")
70 }
71
72 if(opencontrail != null) {
73 stage('Remove OC component from repos on test nodes') {
74 salt.cmdRun(saltMaster, targetTestSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g'")
75 salt.runSaltProcessStep(saltMaster, targetTestSubset, 'pkg.refresh_db', [], null, true)
76 }
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020077 }
78
79 stage("List package upgrades") {
80 salt.runSaltProcessStep(saltMaster, targetTestSubset, 'pkg.list_upgrades', [], null, true)
81 }
82
Jiri Broulik52a6b832017-06-16 13:05:08 +020083 stage('Confirm upgrade on sample nodes') {
84 input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?"
85 }
86
87 stage("Add new repos on sample nodes") {
88 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
89 }
90
91 if(opencontrail != null) {
92 stage('Remove OC component from repos on sample nodes') {
93 salt.cmdRun(saltMaster, targetLiveSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g'")
94 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'pkg.refresh_db', [], null, true)
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020095 }
96 }
97
Jiri Broulik52a6b832017-06-16 13:05:08 +020098 args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade"
99
100 stage('Test upgrade on sample') {
101 try {
102 salt.cmdRun(saltMaster, targetLiveSubset, args)
103 } catch (Exception er) {
104 print(er)
105 }
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200106 }
107
Jiri Broulik52a6b832017-06-16 13:05:08 +0200108 stage('Confirm upgrade on sample') {
109 input message: "Please verify if there are packages that it wants to downgrade. If so, execute apt-cache policy on them and verify if everything is fine. Do you want to continue with upgrade?"
110 }
111
112 command = "cmd.run"
Jiri Broulikf555b1f2017-06-20 23:04:08 +0200113 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
Jiri Broulik52a6b832017-06-16 13:05:08 +0200114
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200115 stage('Apply package upgrades on sample') {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200116 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200117 salt.printSaltCommandResult(out)
118 }
119
Jiri Broulik52a6b832017-06-16 13:05:08 +0200120 openvswitch = null
121
122 try {
123 openvswitch = salt.cmdRun(saltMaster, targetLiveSubsetProbe, "salt-call grains.item roles | grep neutron.compute")
124 } catch (Exception er) {
125 common.infoMsg("openvswitch is not used")
126 }
127
128 if(openvswitch != null) {
129 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
130
131 stage('Start ovs on sample nodes') {
132 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
133 salt.printSaltCommandResult(out)
134 }
Jiri Broulikf20c7672017-06-19 21:20:52 +0200135 stage("Run salt states on sample nodes") {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200136 salt.enforceState(saltMaster, targetLiveSubset, ['nova', 'neutron'])
Jiri Broulikf20c7672017-06-19 21:20:52 +0200137 //salt.enforceHighstate(saltMaster, targetLiveAll)
Jiri Broulik52a6b832017-06-16 13:05:08 +0200138 }
139 } else {
140 stage("Run salt states on sample nodes") {
Jiri Broulikf20c7672017-06-19 21:20:52 +0200141 salt.enforceState(saltMaster, targetLiveSubset, ['nova', 'linux.system.repo'])
142 //salt.enforceHighstate(saltMaster, targetLiveAll)
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200143 }
144 }
145
Jiri Broulikf20c7672017-06-19 21:20:52 +0200146 stage('Confirm upgrade on all targeted nodes') {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200147 timeout(time: 2, unit: 'HOURS') {
148 input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
149 }
150 }
151
152 if(opencontrail != null) {
Jiri Broulikf20c7672017-06-19 21:20:52 +0200153 stage('Remove OC component from repos on all targeted nodes') {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200154 salt.cmdRun(saltMaster, targetLiveAll, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g'")
155 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.refresh_db', [], null, true)
156 }
157 }
158
Jiri Broulikf555b1f2017-06-20 23:04:08 +0200159 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
Jiri Broulik52a6b832017-06-16 13:05:08 +0200160
Jiri Broulikf20c7672017-06-19 21:20:52 +0200161 stage('Apply package upgrades on all targeted nodes') {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200162 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200163 salt.printSaltCommandResult(out)
164 }
165
Jiri Broulik52a6b832017-06-16 13:05:08 +0200166 if(openvswitch != null) {
167 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
168
Jiri Broulikf20c7672017-06-19 21:20:52 +0200169 stage('Start ovs on all targeted nodes') {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200170 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
171 salt.printSaltCommandResult(out)
172 }
Jiri Broulikf20c7672017-06-19 21:20:52 +0200173 stage("Run salt states on all targeted nodes") {
Jiri Broulik52a6b832017-06-16 13:05:08 +0200174 salt.enforceState(saltMaster, targetLiveAll, ['nova', 'neutron'])
Jiri Broulikf20c7672017-06-19 21:20:52 +0200175 //salt.enforceHighstate(saltMaster, targetLiveAll)
Jiri Broulik52a6b832017-06-16 13:05:08 +0200176 }
177 } else {
Jiri Broulikf20c7672017-06-19 21:20:52 +0200178 stage("Run salt states on all targeted nodes") {
179 salt.enforceState(saltMaster, targetLiveAll, ['nova', 'linux.system.repo'])
180 //salt.enforceHighstate(saltMaster, targetLiveAll)
Jiri Broulik52a6b832017-06-16 13:05:08 +0200181 }
182 }
183
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200184 } catch (Throwable e) {
185 // If there was an error or exception thrown, the build failed
186 currentBuild.result = "FAILURE"
187 throw e
188 }
189}
Jiri Broulik52a6b832017-06-16 13:05:08 +0200190