blob: 4defcd548abdba3ccf296d5373f3abe32011f16a [file] [log] [blame]
Jiri Broulikbb447ac2017-05-04 15:36:22 +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 [http://10.10.10.1:8000].
7 *
8**/
9
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
12
13
14def saltMaster
15
16timestamps {
17 node() {
18
19 stage('Connect to Salt API') {
20 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
21 }
22
23 state('Prepare upgrade') {
24 // #ignorovat no response a chyby - nene, chyby opravíme
25
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020026
27 salt.enforceState(master, 'I@salt:master', 'reclass')
28
29 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
30 // salt '*' saltutil.sync_all
31 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
32
33
34 def _pillar = salt.getPillar(master, 'I@salt:master', 'grains.item domain')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020035 def domain = _pillar['return'][0].values()[0]
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020036 println _pillar
37 println domain
Jiri Broulikbb447ac2017-05-04 15:36:22 +020038
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020039 // read backupninja variable
40 _pillar = salt.getPillar(master, 'I@backupninja:server', '_param:single_address')
41 def backupninja_backup_host = _pillar['return'][0].values()[0]
42 println _pillar
43 println backupninja_backup_host
Jiri Broulikbb447ac2017-05-04 15:36:22 +020044
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020045 _pillar = salt.getPillar(master, 'I@salt:control', 'grains.item id')
46 def kvm01 = _pillar['return'][0].values()[0]
47 def kvm02 = _pillar['return'][0].values()[1]
48 def kvm03 = _pillar['return'][0].values()[2]
49 println _pillar
50 println kvm01
51 println kvm02
52 println kvm03
53
54 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:upg01:provider')
55 def upgNodeProvider = _pillar['return'][0].values()[0]
56 println _pillar
57 println upgNodeProvider
58
59
60 salt.runSaltProcessStep(master, '${upgNodeProvider}', 'virt.destroy upg01.${domain}', [], null, true)
61 salt.runSaltProcessStep(master, '${upgNodeProvider}', 'virt.undefine upg01.${domain}', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020062
63 // salt-key -d upg01.${domain} -y
64 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', "salt-key -d upg01.${domain} -y", [], null, true)
65 // salt 'kvm02*' state.sls salt.control
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020066 salt.enforceState(saltMaster, '${upgNodeProvider}', 'salt.control')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020067
68 sleep(60)
69
70 // salt '*' saltutil.refresh_pillar
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020071 salt.runSaltProcessStep(master, 'upg*', 'saltutil.refresh_pillar', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020072 // salt '*' saltutil.sync_all
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020073 salt.runSaltProcessStep(master, 'upg*', 'saltutil.sync_all', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020074
75 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
76 salt.enforceState(master, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
77 // salt '*' state.apply salt.minion.grains
78 salt.enforceState(master, '*', 'salt.minion.grains')
79 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
80 salt.enforceState(master, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
81
Jiri Broulikbb447ac2017-05-04 15:36:22 +020082 // salt "upg*" state.sls rabbitmq
83 salt.enforceState(master, 'upg*', 'rabbitmq')
84 // salt "upg*" state.sls memcached
85 salt.enforceState(master, 'upg*', 'memcached')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020086 salt.enforceState(master, 'I@backupninja:client', 'openssh.client')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020087 // salt -C 'I@backupninja:server' state.sls backupninja
88 salt.enforceState(master, 'I@backupninja:server', 'backupninja')
89 // salt -C 'I@backupninja:client' state.sls backupninja
90 salt.enforceState(master, 'I@backupninja:client', 'backupninja')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020091 salt.runSaltProcessStep(master, 'I@backupninja:client', 'ssh.rm_known_host root ${backupninja_backup_host}', [], null, true)
92 salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "arp -d ${backupninja_backup_host}", [], null, true)
93 salt.runSaltProcessStep(master, 'I@backupninja:client', 'ssh.set_known_host root ${backupninja_backup_host}', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020094 salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/101.mysql", [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020095 salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/200.backup.rsync", [], null, true)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020096
97
98 def databases = salt.runSaltProcessStep(master, 'I@mysql:client', 'mysql.db_list | grep upgrade | awk "/-/ {print $2}"', [], null, true)
99 for (String database : databases) { System.out.println(database) }
100 for (String database : databases) { salt.runSaltProcessStep(master, 'I@mysql:client', 'mysql.db_remove ${database}', [], null, true) }
101 for (String database : databases) { salt.runSaltProcessStep(master, 'I@mysql:client', 'file.remove /root/mysql/flags/${database}-installed', [], null, true) }
102
103
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200104 salt.enforceState(master, 'I@mysql:client', 'mysql.client')
105
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200106 salt.enforceState(master, 'upg*', ['keystone.server', 'keystone.client'])
107
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200108 salt.enforceState(master, 'upg*', ['glance', 'keystone.server', 'nova', 'cinder', 'neutron', 'heat'])
109
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200110 salt.runSaltProcessStep(master, 'upg01*', 'cmd.run', '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list', null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200111 }
112
113 stage('Ask for manual confirmation') {
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200114 input message: "Do you want to continue with upgrade?"
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200115 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200116 state('Start upgrade') {
117 // # actual upgrade
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200118
119 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:ctl01:provider')
120 def ctl01NodeProvider = _pillar['return'][0].values()[0]
121
122 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:ctl02:provider')
123 def ctl02NodeProvider = _pillar['return'][0].values()[0]
124
125 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:ctl03:provider')
126 def ctl03NodeProvider = _pillar['return'][0].values()[0]
127
128 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:prx01:provider')
129 def prx01NodeProvider = _pillar['return'][0].values()[0]
130
131 _pillar = salt.getPillar(master, '${kvm01}', 'salt:control:cluster:internal:node:prx02:provider')
132 def prx02NodeProvider = _pillar['return'][0].values()[0]
133
134
135 salt.runSaltProcessStep(master, '${prx01NodeProvider}', 'virt.destroy prx01.${domain}', [], null, true)
136 salt.runSaltProcessStep(master, '${prx02NodeProvider}', 'virt.destroy prx01.${domain}', [], null, true)
137 salt.runSaltProcessStep(master, '${ctl01NodeProvider}', 'virt.destroy ctl01.${domain}', [], null, true)
138 salt.runSaltProcessStep(master, '${ctl02NodeProvider}', 'virt.destroy ctl02.${domain}', [], null, true)
139 salt.runSaltProcessStep(master, '${ctl03NodeProvider}', 'virt.destroy ctl03.${domain}', [], null, true)
140
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200141
142 // salt 'kvm01*' cmd.run '[ ! -f ./prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak'
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200143 salt.runSaltProcessStep(master, '${prx01NodeProvider}', 'cmd.run', "[ ! -f ./prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak", null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200144 // salt 'kvm03*' cmd.run '[ ! -f ./prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak'
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200145 salt.runSaltProcessStep(master, '${prx02NodeProvider}', 'cmd.run', "[ ! -f ./prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak", null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200146 // salt 'kvm01*' cmd.run '[ ! -f ./ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak'
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200147 salt.runSaltProcessStep(master, '${ctl01NodeProvider}', 'cmd.run', "[ ! -f ./ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak", null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200148 // salt 'kvm02*' cmd.run '[ ! -f ./ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak'
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200149 salt.runSaltProcessStep(master, '${ctl02NodeProvider}', 'cmd.run', "[ ! -f ./ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak", null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200150 // salt 'kvm03*' cmd.run '[ ! -f ./ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak'
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200151 salt.runSaltProcessStep(master, '${ctl03NodeProvider}', 'cmd.run', "[ ! -f ./ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak", null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200152
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200153
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200154 salt.runSaltProcessStep(master, '${prx01NodeProvider}', 'virt.undefine prx01.${domain}', [], null, true)
155 salt.runSaltProcessStep(master, '${prx02NodeProvider}', 'virt.undefine prx02.${domain}', [], null, true)
156 salt.runSaltProcessStep(master, '${ctl01NodeProvider}', 'virt.undefine ctl01.${domain}', [], null, true)
157 salt.runSaltProcessStep(master, '${ctl02NodeProvider}', 'virt.undefine ctl02.${domain}', [], null, true)
158 salt.runSaltProcessStep(master, '${ctl03NodeProvider}', 'virt.undefine ctl03.${domain}', [], null, true)
159
160
161 salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/101.mysql", [], null, true)
162 salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/200.backup.rsync", [], null, true)
163
164
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200165 salt.runSaltProcessStep(master, 'I@salt', 'cmd.run', "salt-key -d ctl01.${domain},ctl01.${domain},ctl03.${domain},prx01.${domain},prx02.${domain}", null, true)
166
167 // salt 'kvm*' state.sls salt.control
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200168 salt.enforceState(master, 'I@salt:control', 'salt.control')
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200169
170 sleep(60)
171
172 // salt '*' saltutil.refresh_pillar
173 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
174 // salt '*' saltutil.sync_all
175 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
176
177 // salt "ctl*" state.sls linux,openssh,salt.minion,ntp,rsyslog
178 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
179 // salt "ctl*" state.sls linux,openssh,salt.minion,ntp,rsyslog
180 salt.enforceState(master, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
181 // salt 'ctl*' state.sls keepalived
182 // salt 'ctl*' state.sls haproxy
183 salt.enforceState(master, 'ctl*', ['keepalived', 'haproxy'])
184 // salt 'ctl*' service.restart rsyslog
185 salt.runSaltProcessStep(master, 'ctl*', 'service.restart', ['rsyslog'], null, true)
186 // salt "ctl*" state.sls memcached
187 // salt "ctl*" state.sls keystone.server
188 salt.enforceState(master, 'ctl*', ['memcached', 'keystone.server'])
189 // salt 'ctl01*' state.sls keystone.client
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200190 salt.enforceState(master, 'I@keystone:client and ctl*', 'keystone.client')
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200191 // salt 'ctl*' state.sls glance
192 salt.enforceState(master, 'ctl*', 'glance')
193 // salt 'ctl*' state.sls glusterfs.client
194 salt.enforceState(master, 'ctl*', 'glusterfs.client')
195 // salt 'ctl*' state.sls keystone.server
196 salt.enforceState(master, 'ctl*', 'keystone.server')
197 // salt 'ctl*' state.sls nova
198 salt.enforceState(master, 'ctl*', 'nova')
199 // salt 'ctl*' state.sls cinder
200 salt.enforceState(master, 'ctl*', 'cinder')
201 // salt 'ctl*' state.sls neutron
202 salt.enforceState(master, 'ctl*', 'neutron')
203 // salt 'ctl*' state.sls heat
204 salt.enforceState(master, 'ctl*', 'heat')
205
206 // salt 'cmp*' cmd.run 'service nova-compute restart'
207 salt.runSaltProcessStep(master, 'cmp*', 'service.restart', ['nova-compute'], null, true)
208
209 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog - TODO: proč? už to jednou projelo
210 // salt 'ctl*' state.sls keepalived
211 // salt 'prx*' state.sls keepalived
212 salt.enforceState(master, 'prx*', 'keepalived')
213 // salt 'prx*' state.sls horizon
214 salt.enforceState(master, 'prx*', 'horizon')
215 // salt 'prx*' state.sls nginx
216 salt.enforceState(master, 'prx*', 'nginx')
217
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200218 salt.runSaltProcessStep(master, 'ctl01*', 'cmd.run', '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list', null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200219 }
220
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200221 stage('Verification') {
222 input message: "Please verify the control upgrade and if was not successful, in the worst scenario, you can use the openstack-control-upgrade-rollover pipeline"
223 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200224 }
225}