Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 1 | /** |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 2 | * Upgrade OpenStack packages on control plane nodes. |
| 3 | * There are no silver boollet in uprading cloud. |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 4 | * Update packages on given nodes |
| 5 | * |
| 6 | * Expected parameters: |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 8 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000]. |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 9 | * OS_DIST_UPGRADE Upgrade system packages including kernel (apt-get dist-upgrade) |
| 10 | * OS_UPGRADE Upgrade all installed applications (apt-get upgrade) |
| 11 | * TARGET_SERVERS Comma separated list of salt compound definitions to upgrade. |
Vasyl Saienko | 1a034dd | 2018-06-22 15:33:37 +0300 | [diff] [blame] | 12 | * INTERACTIVE Ask interactive questions during pipeline run (bool). |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 13 | * |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 14 | * TODO: |
| 15 | * * Add OS_RELEASE_UPGRADE |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 16 | **/ |
| 17 | |
| 18 | def common = new com.mirantis.mk.Common() |
| 19 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 20 | def python = new com.mirantis.mk.Python() |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 21 | def debian = new com.mirantis.mk.Debian() |
| 22 | def openstack = new com.mirantis.mk.Openstack() |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 23 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 24 | def interactive = INTERACTIVE.toBoolean() |
| 25 | def LinkedHashMap upgradeStageMap = [:] |
| 26 | |
| 27 | upgradeStageMap.put('Pre upgrade', |
| 28 | [ |
| 29 | 'Description': 'Only non destructive actions will be applied during this phase. Basic api, service verification will be performed.', |
| 30 | 'Status': 'NOT_LAUNCHED', |
| 31 | 'Expected behaviors': ''' |
| 32 | * No service downtime |
| 33 | * No workload downtime''', |
| 34 | 'Launched actions': ''' |
Oleksandr Pidrepnyi | d662e5c | 2019-07-18 16:06:57 +0300 | [diff] [blame] | 35 | * Refresh pillars on the target nodes. |
| 36 | * Apply the 'linux.system.repo' state on the target nodes. |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 37 | * Verify API, perform basic CRUD operations for services. |
| 38 | * Verify that compute/neutron agents on hosts are up. |
| 39 | * Run some service built in checkers like keystone-manage doctor or nova-status upgrade.''', |
| 40 | 'State result': 'Basic checks around services API are passed.' |
| 41 | ]) |
| 42 | upgradeStageMap.put('Stop OpenStack services', |
| 43 | [ |
| 44 | 'Description': 'All OpenStack python services will be stopped on All control nodes. This does not affect data plane services such as openvswitch or qemu.', |
| 45 | 'Status': 'NOT_LAUNCHED', |
| 46 | 'Expected behaviors': ''' |
| 47 | * OpenStack python services are stopped. |
| 48 | * OpenStack API are not accessible from this point. |
| 49 | * No workload downtime''', |
| 50 | 'Launched actions': ''' |
| 51 | * Stop OpenStack python services''', |
| 52 | 'State result': 'OpenStack python services are stopped', |
| 53 | ]) |
Ivan Udovichenko | 24f40f4 | 2018-11-29 18:14:34 +0300 | [diff] [blame] | 54 | upgradeStageMap.put('Upgrade OS', |
| 55 | [ |
| 56 | 'Description': 'Optional step. OS packages will be upgraded during this phase, depending on the job parameters dist-upgrade might be called. And reboot of node executed.', |
| 57 | 'Status': 'NOT_LAUNCHED', |
| 58 | 'Expected behaviors': ''' |
| 59 | * OpenStack services might flap |
| 60 | * No workload downtime |
| 61 | * The nodes might be rebooted''', |
| 62 | 'Launched actions': ''' |
| 63 | * Install new version of system packages |
| 64 | * If doing dist-upgrade new kernel might be installed and node rebooted |
| 65 | * System packages are updated |
| 66 | * Node might be rebooted |
| 67 | ''' |
| 68 | ]) |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 69 | upgradeStageMap.put('Upgrade OpenStack', |
| 70 | [ |
| 71 | 'Description': 'OpenStack python code will be upgraded during this stage. No workload downtime is expected.', |
| 72 | 'Status': 'NOT_LAUNCHED', |
| 73 | 'Expected behaviors': ''' |
| 74 | * OpenStack services might flap |
| 75 | * No workload downtime''', |
| 76 | 'Launched actions': ''' |
| 77 | * Install new version of OpenStack packages |
| 78 | * Render version of configs |
| 79 | * Apply offline dbsync |
| 80 | * Start OpenStack services |
| 81 | * Verify agents are alive/connected |
| 82 | * Run basic API validation''', |
| 83 | 'State result': ''' |
| 84 | * OpenStack packages are upgraded |
| 85 | * Services are running |
| 86 | * Basic checks around services API are passed |
| 87 | * Verified that agents/services on data plane nodes are connected to new control plane |
| 88 | ''' |
| 89 | ]) |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 90 | |
| 91 | def stopOpenStackServices(env, target) { |
Jiri Broulik | 0d111e9 | 2018-04-25 21:30:42 +0200 | [diff] [blame] | 92 | def salt = new com.mirantis.mk.Salt() |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 93 | def openstack = new com.mirantis.mk.Openstack() |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 94 | def common = new com.mirantis.mk.Common() |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 95 | |
| 96 | def services = openstack.getOpenStackUpgradeServices(env, target) |
| 97 | def st |
| 98 | for (service in services){ |
| 99 | st = "${service}.upgrade.service_stopped".trim() |
| 100 | common.infoMsg("Stopping ${st} services on ${target}") |
| 101 | salt.enforceState(env, target, st) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 105 | def snapshotVM(env, domain, snapshotName) { |
| 106 | def common = new com.mirantis.mk.Common() |
| 107 | def salt = new com.mirantis.mk.Salt() |
| 108 | |
| 109 | def target = salt.getNodeProvider(env, domain) |
| 110 | |
| 111 | // TODO: gracefully migrate all workloads from VM, and stop it |
| 112 | salt.runSaltProcessStep(env, target, 'virt.shutdown', [domain], null, true, 3600) |
| 113 | |
| 114 | //TODO: wait while VM is powered off |
| 115 | |
| 116 | common.infoMsg("Creating snapshot ${snapshotName} for VM ${domain} on node ${target}") |
| 117 | salt.runSaltProcessStep(env, target, 'virt.snapshot', [domain, snapshotName], null, true, 3600) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 120 | def revertSnapshotVM(env, domain, snapshotName, ensureUp=true) { |
| 121 | def common = new com.mirantis.mk.Common() |
| 122 | def salt = new com.mirantis.mk.Salt() |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 123 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 124 | def target = salt.getNodeProvider(env, domain) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 125 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 126 | common.infoMsg("Reverting snapshot ${snapshotName} for VM ${domain} on node ${target}") |
| 127 | salt.runSaltProcessStep(env, target, 'virt.revert_snapshot', [snapshotName, domain], null, true, 3600) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 128 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 129 | if (ensureUp){ |
| 130 | salt.runSaltProcessStep(env, target, 'virt.start', [domain], null, true, 300) |
| 131 | } |
| 132 | } |
| 133 | |
Valeriy Sakharov | 01f1654 | 2023-03-23 20:50:09 +0400 | [diff] [blame] | 134 | def restartDesignate(env, target) { |
Valeriy Sakharov | f264ade | 2023-02-17 15:49:32 +0400 | [diff] [blame] | 135 | def common = new com.mirantis.mk.Common() |
| 136 | def salt = new com.mirantis.mk.Salt() |
| 137 | // Workaround for PROD-33592, restart designate-central services if enabled |
Valeriy Sakharov | 01f1654 | 2023-03-23 20:50:09 +0400 | [diff] [blame] | 138 | designate_enabled = salt.getPillar(env, target, "designate:server:enabled").get("return")[0].values()[0] |
Valeriy Sakharov | f264ade | 2023-02-17 15:49:32 +0400 | [diff] [blame] | 139 | if (designate_enabled == '' || designate_enabled == 'false' || designate_enabled == null) { |
| 140 | common.infoMsg('Designate is disabled, nothing to do') |
| 141 | } else { |
| 142 | try { |
Valeriy Sakharov | 01f1654 | 2023-03-23 20:50:09 +0400 | [diff] [blame] | 143 | salt.runSaltProcessStep(env, target, "service.restart", "designate-central", null, true) |
Valeriy Sakharov | f264ade | 2023-02-17 15:49:32 +0400 | [diff] [blame] | 144 | } |
| 145 | catch (Exception ex) { |
| 146 | common.infoMsg(ex) |
| 147 | error('Designate service is broken, please check logs') |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 152 | def env = "env" |
| 153 | timeout(time: 12, unit: 'HOURS') { |
| 154 | node() { |
| 155 | |
| 156 | stage('Setup virtualenv for Pepper') { |
| 157 | python.setupPepperVirtualenv(env, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 160 | def upgradeTargets = salt.getMinionsSorted(env, TARGET_SERVERS) |
| 161 | |
| 162 | if (upgradeTargets.isEmpty()) { |
| 163 | error("No servers for upgrade matched by ${TARGET_SERVERS}") |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 166 | common.printStageMap(upgradeStageMap) |
| 167 | if (interactive){ |
| 168 | input message: common.getColorizedString( |
| 169 | "Above you can find detailed info this pipeline will execute.\nThe info provides brief description of each stage, actions that will be performed and service/workload impact during each stage.\nPlease read it carefully.", "yellow") |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Vladimir Khlyunev | f1a6533 | 2021-08-30 13:28:08 +0400 | [diff] [blame] | 172 | common.infoMsg("Refreshing haproxy config for mysql proxies") |
| 173 | salt.enforceState(env, 'I@haproxy:proxy:listen:mysql_cluster', ['haproxy.proxy']) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 174 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 175 | for (target in upgradeTargets){ |
| 176 | common.stageWrapper(upgradeStageMap, "Pre upgrade", target, interactive) { |
| 177 | openstack.runOpenStackUpgradePhase(env, target, 'pre') |
Oleksandr Pidrepnyi | d662e5c | 2019-07-18 16:06:57 +0300 | [diff] [blame] | 178 | salt.runSaltProcessStep(env, target, 'saltutil.refresh_pillar', [], null, true) |
| 179 | salt.enforceState(env, target, 'linux.system.repo') |
Valeriy Sakharov | 01f1654 | 2023-03-23 20:50:09 +0400 | [diff] [blame] | 180 | restartDesignate(env, target) |
Vasyl Saienko | b286f6c | 2018-10-03 14:35:40 +0300 | [diff] [blame] | 181 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
Vasyl Saienko | 1a034dd | 2018-06-22 15:33:37 +0300 | [diff] [blame] | 182 | } |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 183 | } |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 184 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 185 | for (target in upgradeTargets) { |
| 186 | common.stageWrapper(upgradeStageMap, "Stop OpenStack services", target, interactive) { |
| 187 | stopOpenStackServices(env, target) |
| 188 | } |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 191 | for (target in upgradeTargets) { |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 192 | common.stageWrapper(upgradeStageMap, "Upgrade OS", target, interactive) { |
| 193 | if (OS_DIST_UPGRADE.toBoolean() == true){ |
| 194 | upgrade_mode = 'dist-upgrade' |
| 195 | } else if (OS_UPGRADE.toBoolean() == true){ |
| 196 | upgrade_mode = 'upgrade' |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 197 | } |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 198 | if (OS_DIST_UPGRADE.toBoolean() == true || OS_UPGRADE.toBoolean() == true) { |
| 199 | debian.osUpgradeNode(env, target, upgrade_mode, false) |
| 200 | } |
Vasyl Saienko | 278179b | 2019-06-24 23:44:39 +0300 | [diff] [blame] | 201 | // Workaround for PROD-31413, install python-tornado from latest release if available and |
| 202 | // restart minion to apply new code. |
| 203 | salt.upgradePackageAndRestartSaltMinion(env, target, 'python-tornado') |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 204 | } |
Ivan Udovichenko | 24f40f4 | 2018-11-29 18:14:34 +0300 | [diff] [blame] | 205 | |
| 206 | common.stageWrapper(upgradeStageMap, "Upgrade OpenStack", target, interactive) { |
| 207 | openstack.runOpenStackUpgradePhase(env, target, 'upgrade') |
| 208 | openstack.applyOpenstackAppsStates(env, target) |
| 209 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
| 210 | } |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 211 | } |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 212 | } |
Vasyl Saienko | 1a034dd | 2018-06-22 15:33:37 +0300 | [diff] [blame] | 213 | } |