Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
| 12 | |
| 13 | |
| 14 | def saltMaster |
| 15 | |
| 16 | timestamps { |
| 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 26 | |
| 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 35 | def domain = _pillar['return'][0].values()[0] |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 36 | println _pillar |
| 37 | println domain |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 38 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 39 | // 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 44 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 45 | _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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 62 | |
| 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 66 | salt.enforceState(saltMaster, '${upgNodeProvider}', 'salt.control') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 67 | |
| 68 | sleep(60) |
| 69 | |
| 70 | // salt '*' saltutil.refresh_pillar |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 71 | salt.runSaltProcessStep(master, 'upg*', 'saltutil.refresh_pillar', [], null, true) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 72 | // salt '*' saltutil.sync_all |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 73 | salt.runSaltProcessStep(master, 'upg*', 'saltutil.sync_all', [], null, true) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 74 | |
| 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 82 | // salt "upg*" state.sls rabbitmq |
| 83 | salt.enforceState(master, 'upg*', 'rabbitmq') |
| 84 | // salt "upg*" state.sls memcached |
| 85 | salt.enforceState(master, 'upg*', 'memcached') |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 86 | salt.enforceState(master, 'I@backupninja:client', 'openssh.client') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 87 | // 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 91 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 94 | salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/101.mysql", [], null, true) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 95 | salt.runSaltProcessStep(master, 'I@backupninja:client', 'cmd.run', "backupninja -n --run /etc/backup.d/200.backup.rsync", [], null, true) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 96 | |
| 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 104 | salt.enforceState(master, 'I@mysql:client', 'mysql.client') |
| 105 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 106 | salt.enforceState(master, 'upg*', ['keystone.server', 'keystone.client']) |
| 107 | |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 108 | salt.enforceState(master, 'upg*', ['glance', 'keystone.server', 'nova', 'cinder', 'neutron', 'heat']) |
| 109 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 110 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | stage('Ask for manual confirmation') { |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 114 | input message: "Do you want to continue with upgrade?" |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 115 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 116 | state('Start upgrade') { |
| 117 | // # actual upgrade |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 118 | |
| 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 141 | |
| 142 | // salt 'kvm01*' cmd.run '[ ! -f ./prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak' |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 143 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 144 | // salt 'kvm03*' cmd.run '[ ! -f ./prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak' |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 145 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 146 | // salt 'kvm01*' cmd.run '[ ! -f ./ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak' |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 147 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 148 | // salt 'kvm02*' cmd.run '[ ! -f ./ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak' |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 149 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 150 | // salt 'kvm03*' cmd.run '[ ! -f ./ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak' |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 151 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 152 | |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 153 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 154 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 165 | 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 168 | salt.enforceState(master, 'I@salt:control', 'salt.control') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 169 | |
| 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 190 | salt.enforceState(master, 'I@keystone:client and ctl*', 'keystone.client') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 191 | // 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 218 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 221 | 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 224 | } |
| 225 | } |