Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 1 | /** |
| 2 | * Upgrade OpenStack packages on gateway nodes. |
| 3 | * Update packages on given nodes |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 7 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000]. |
| 8 | * OS_DIST_UPGRADE Upgrade system packages including kernel (apt-get dist-upgrade) |
| 9 | * OS_UPGRADE Upgrade all installed applications (apt-get upgrade) |
| 10 | * TARGET_SERVERS Comma separated list of salt compound definitions to upgrade. |
| 11 | * INTERACTIVE Ask interactive questions during pipeline run (bool). |
| 12 | * |
| 13 | * TODO: |
| 14 | * * Add OS_RELEASE_UPGRADE |
| 15 | **/ |
| 16 | |
| 17 | def common = new com.mirantis.mk.Common() |
| 18 | def salt = new com.mirantis.mk.Salt() |
| 19 | def python = new com.mirantis.mk.Python() |
| 20 | def openstack = new com.mirantis.mk.Openstack() |
| 21 | def debian = new com.mirantis.mk.Debian() |
| 22 | |
| 23 | def interactive = INTERACTIVE.toBoolean() |
| 24 | def LinkedHashMap upgradeStageMap = [:] |
| 25 | |
| 26 | upgradeStageMap.put('Pre upgrade', |
| 27 | [ |
| 28 | 'Description': 'Only non destructive actions will be applied during this phase. Basic api, service verification will be performed.', |
| 29 | 'Status': 'NOT_LAUNCHED', |
| 30 | 'Expected behaviors': ''' |
| 31 | * No service downtime |
| 32 | * No workload downtime''', |
| 33 | 'Launched actions': ''' |
Oleksandr Pidrepnyi | 217efc0 | 2019-07-18 16:06:57 +0300 | [diff] [blame] | 34 | * Refresh pillars on the target nodes. |
| 35 | * Apply the 'linux.system.repo' state on the target nodes. |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 36 | * Verify API, perform basic CRUD operations for services. |
| 37 | * Verify that compute/neutron agents on hosts are up. |
| 38 | * Run some service built in checkers like keystone-manage doctor or nova-status upgrade.''', |
| 39 | 'State result': 'Basic checks around services API are passed.' |
| 40 | ]) |
| 41 | upgradeStageMap.put('Upgrade pre: migrate resources', |
| 42 | [ |
| 43 | 'Description': 'In order to minimize workload downtime smooth resource migration is happening during this phase. Neutron agents on node are set to admin_disabled state, to make sure they are quickly migrated to new node (1-2 ping loss). Instances might be live-migrated from host (this stage is optional) and configured from pillar.', |
| 44 | 'Status': 'NOT_LAUNCHED', |
| 45 | 'Expected behaviors': ''' |
| 46 | * No service downtime |
| 47 | * Small workload downtime''', |
| 48 | 'Launched actions': ''' |
| 49 | * Set neutron agents to admin disabled sate |
| 50 | * Migrate instances if allowed (optional).''', |
| 51 | 'State result': ''' |
| 52 | * Hosts are being removed from scheduling to host new resources. |
| 53 | * If instance migration was performed no instances should be present.''' |
| 54 | ]) |
Ivan Udovichenko | 24f40f4 | 2018-11-29 18:14:34 +0300 | [diff] [blame] | 55 | upgradeStageMap.put('Upgrade OS', |
| 56 | [ |
| 57 | '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.', |
| 58 | 'Status': 'NOT_LAUNCHED', |
| 59 | 'Expected behaviors': ''' |
| 60 | * OpenStack services might flap |
| 61 | * No workload downtime |
| 62 | * The nodes might be rebooted''', |
| 63 | 'Launched actions': ''' |
| 64 | * Install new version of system packages |
| 65 | * If doing dist-upgrade new kernel might be installed and node rebooted |
| 66 | * System packages are updated |
| 67 | * Node might be rebooted |
| 68 | ''' |
| 69 | ]) |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 70 | upgradeStageMap.put('Upgrade OpenStack', |
| 71 | [ |
| 72 | 'Description': 'OpenStack python code will be upgraded during this stage. No workload downtime is expected.', |
| 73 | 'Status': 'NOT_LAUNCHED', |
| 74 | 'Expected behaviors': ''' |
| 75 | * OpenStack services might flap |
| 76 | * No workload downtime''', |
| 77 | 'Launched actions': ''' |
| 78 | * Install new version of OpenStack packages |
| 79 | * Render version of configs |
| 80 | * Apply offline dbsync |
| 81 | * Start OpenStack services |
| 82 | * Verify agents are alive/connected |
| 83 | * Run basic API validation''', |
| 84 | 'State result': ''' |
| 85 | * OpenStack packages are upgraded |
| 86 | * Services are running |
| 87 | * Basic checks around services API are passed |
| 88 | * Verified that agents/services on data plane nodes are connected to new control plane |
| 89 | ''' |
| 90 | ]) |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 91 | upgradeStageMap.put('Upgrade post: enable resources', |
| 92 | [ |
| 93 | 'Description': 'Verify that agents/services on node are up, add them back to scheduling.', |
| 94 | 'Status': 'NOT_LAUNCHED', |
| 95 | 'Expected behaviors': ''' |
| 96 | * No service downtime |
| 97 | * No workload downtime''', |
| 98 | 'Launched actions': ''' |
| 99 | * Set neutron agents to admin sate enabled |
| 100 | * Enable nova-compute services''', |
| 101 | 'State result': 'Hosts are being added to scheduling to host new resources', |
| 102 | ]) |
| 103 | upgradeStageMap.put('Post upgrade', |
| 104 | [ |
| 105 | 'Description': 'Only non destructive actions will be applied during this phase. Like cleanup old configs, cleanup temporary files. Online dbsyncs.', |
| 106 | 'Status': 'NOT_LAUNCHED', |
| 107 | 'Expected behaviors': ''' |
| 108 | * No service downtime |
| 109 | * No workload downtime''', |
| 110 | 'Launched actions': ''' |
| 111 | * Cleanup os client configs''', |
| 112 | 'State result': 'Temporary resources are being cleaned.' |
| 113 | ]) |
| 114 | |
| 115 | |
| 116 | def env = "env" |
| 117 | timeout(time: 24, unit: 'HOURS') { |
| 118 | node() { |
| 119 | |
| 120 | stage('Setup virtualenv for Pepper') { |
| 121 | python.setupPepperVirtualenv(env, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 122 | } |
| 123 | |
| 124 | def targetNodes = salt.getMinionsSorted(env, TARGET_SERVERS) |
| 125 | def migrateResources = true |
| 126 | |
| 127 | if (targetNodes.isEmpty()) { |
| 128 | error("No servers for upgrade matched by ${TARGET_SERVERS}") |
| 129 | } |
| 130 | if (targetNodes.size() == 1 ){ |
| 131 | migrateResources = false |
| 132 | } |
| 133 | |
| 134 | common.printStageMap(upgradeStageMap) |
| 135 | if (interactive){ |
| 136 | input message: common.getColorizedString( |
| 137 | "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") |
| 138 | } |
| 139 | |
| 140 | for (target in targetNodes){ |
| 141 | common.stageWrapper(upgradeStageMap, "Pre upgrade", target, interactive) { |
| 142 | openstack.runOpenStackUpgradePhase(env, target, 'pre') |
Oleksandr Pidrepnyi | 217efc0 | 2019-07-18 16:06:57 +0300 | [diff] [blame] | 143 | salt.runSaltProcessStep(env, target, 'saltutil.refresh_pillar', [], null, true) |
| 144 | salt.enforceState(env, target, 'linux.system.repo') |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 145 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
| 146 | } |
| 147 | |
| 148 | common.stageWrapper(upgradeStageMap, "Upgrade pre: migrate resources", target, interactive) { |
| 149 | if (migrateResources) { |
| 150 | common.infoMsg("Migrating neutron resources from ${target}") |
| 151 | openstack.runOpenStackUpgradePhase(env, target, 'upgrade.pre') |
| 152 | // Start upgrade only when resources were successfully migrated |
| 153 | } |
| 154 | } |
| 155 | |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 156 | common.stageWrapper(upgradeStageMap, "Upgrade OS", target, interactive) { |
| 157 | if (OS_DIST_UPGRADE.toBoolean() == true){ |
| 158 | upgrade_mode = 'dist-upgrade' |
| 159 | } else if (OS_UPGRADE.toBoolean() == true){ |
| 160 | upgrade_mode = 'upgrade' |
| 161 | } |
| 162 | if (OS_DIST_UPGRADE.toBoolean() == true || OS_UPGRADE.toBoolean() == true) { |
Ivan Berezovskiy | 0c16edc | 2020-01-30 20:05:22 +0400 | [diff] [blame] | 163 | debian.osUpgradeNode(env, target, upgrade_mode, false, 60, 10) |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 164 | } |
Ivan Berezovskiy | 0c16edc | 2020-01-30 20:05:22 +0400 | [diff] [blame] | 165 | salt.checkTargetMinionsReady(['saltId': env, 'target': target, wait: 60, timeout: 10]) |
Vasyl Saienko | 67d7de9 | 2019-06-24 23:44:39 +0300 | [diff] [blame] | 166 | // Workaround for PROD-31413, install python-tornado from latest release if available and |
| 167 | // restart minion to apply new code. |
| 168 | salt.upgradePackageAndRestartSaltMinion(env, target, 'python-tornado') |
Ivan Udovichenko | 24f40f4 | 2018-11-29 18:14:34 +0300 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | common.stageWrapper(upgradeStageMap, "Upgrade OpenStack", target, interactive) { |
| 172 | // Stop services on node. //Do actual step by step orch here. |
| 173 | openstack.runOpenStackUpgradePhase(env, target, 'service_stopped') |
| 174 | openstack.runOpenStackUpgradePhase(env, target, 'pkgs_latest') |
| 175 | openstack.runOpenStackUpgradePhase(env, target, 'render_config') |
| 176 | openstack.runOpenStackUpgradePhase(env, target, 'service_running') |
Vasyl Saienko | ab2a0c9 | 2018-09-05 17:24:32 +0300 | [diff] [blame] | 177 | openstack.applyOpenstackAppsStates(env, target) |
| 178 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
| 179 | } |
| 180 | |
| 181 | common.stageWrapper(upgradeStageMap, "Upgrade post: enable resources", target, interactive) { |
| 182 | openstack.runOpenStackUpgradePhase(env, target, 'upgrade.post') |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |