blob: 88bbf571d46456598fde1dcc224315edbb38729f [file] [log] [blame]
Vasyl Saienkoab2a0c92018-09-05 17:24:32 +03001/**
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
17def common = new com.mirantis.mk.Common()
18def salt = new com.mirantis.mk.Salt()
19def python = new com.mirantis.mk.Python()
20def openstack = new com.mirantis.mk.Openstack()
21def debian = new com.mirantis.mk.Debian()
22
23def interactive = INTERACTIVE.toBoolean()
24def LinkedHashMap upgradeStageMap = [:]
25
26upgradeStageMap.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': '''
34 * Verify API, perform basic CRUD operations for services.
35 * Verify that compute/neutron agents on hosts are up.
36 * Run some service built in checkers like keystone-manage doctor or nova-status upgrade.''',
37 'State result': 'Basic checks around services API are passed.'
38 ])
39upgradeStageMap.put('Upgrade pre: migrate resources',
40 [
41 '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.',
42 'Status': 'NOT_LAUNCHED',
43 'Expected behaviors': '''
44 * No service downtime
45 * Small workload downtime''',
46 'Launched actions': '''
47 * Set neutron agents to admin disabled sate
48 * Migrate instances if allowed (optional).''',
49 'State result': '''
50 * Hosts are being removed from scheduling to host new resources.
51 * If instance migration was performed no instances should be present.'''
52 ])
53upgradeStageMap.put('Upgrade OpenStack',
54 [
55 'Description': 'OpenStack python code will be upgraded during this stage. No workload downtime is expected.',
56 'Status': 'NOT_LAUNCHED',
57 'Expected behaviors': '''
58 * OpenStack services might flap
59 * No workload downtime''',
60 'Launched actions': '''
61 * Install new version of OpenStack packages
62 * Render version of configs
63 * Apply offline dbsync
64 * Start OpenStack services
65 * Verify agents are alive/connected
66 * Run basic API validation''',
67 'State result': '''
68 * OpenStack packages are upgraded
69 * Services are running
70 * Basic checks around services API are passed
71 * Verified that agents/services on data plane nodes are connected to new control plane
72'''
73 ])
74upgradeStageMap.put('Upgrade OS',
75 [
76 '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.',
77 'Status': 'NOT_LAUNCHED',
78 'Expected behaviors': '''
79 * OpenStack services might flap
80 * No workload downtime
81 * The nodes might be rebooted''',
82 'Launched actions': '''
83 * Install new version of system packages
84 * If doing dist-upgrade new kernel might be installed and node rebooted
85 * Verify agents are alive/connected
86 * Run basic API validation''',
87 'State result': '''
88 * System packages are updated
89 * Services are running
90 * Basic checks around services API are passed
91 * Verified that agents/services on data plane nodes are connected
92 * Node might be rebooted
93'''
94 ])
95upgradeStageMap.put('Upgrade post: enable resources',
96 [
97 'Description': 'Verify that agents/services on node are up, add them back to scheduling.',
98 'Status': 'NOT_LAUNCHED',
99 'Expected behaviors': '''
100 * No service downtime
101 * No workload downtime''',
102 'Launched actions': '''
103 * Set neutron agents to admin sate enabled
104 * Enable nova-compute services''',
105 'State result': 'Hosts are being added to scheduling to host new resources',
106 ])
107upgradeStageMap.put('Post upgrade',
108 [
109 'Description': 'Only non destructive actions will be applied during this phase. Like cleanup old configs, cleanup temporary files. Online dbsyncs.',
110 'Status': 'NOT_LAUNCHED',
111 'Expected behaviors': '''
112 * No service downtime
113 * No workload downtime''',
114 'Launched actions': '''
115 * Cleanup os client configs''',
116 'State result': 'Temporary resources are being cleaned.'
117 ])
118
119
120def env = "env"
121timeout(time: 24, unit: 'HOURS') {
122 node() {
123
124 stage('Setup virtualenv for Pepper') {
125 python.setupPepperVirtualenv(env, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
126 }
127
128 def targetNodes = salt.getMinionsSorted(env, TARGET_SERVERS)
129 def migrateResources = true
130
131 if (targetNodes.isEmpty()) {
132 error("No servers for upgrade matched by ${TARGET_SERVERS}")
133 }
134 if (targetNodes.size() == 1 ){
135 migrateResources = false
136 }
137
138 common.printStageMap(upgradeStageMap)
139 if (interactive){
140 input message: common.getColorizedString(
141 "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")
142 }
143
144 for (target in targetNodes){
145 common.stageWrapper(upgradeStageMap, "Pre upgrade", target, interactive) {
146 openstack.runOpenStackUpgradePhase(env, target, 'pre')
147 openstack.runOpenStackUpgradePhase(env, target, 'verify')
148 }
149
150 common.stageWrapper(upgradeStageMap, "Upgrade pre: migrate resources", target, interactive) {
151 if (migrateResources) {
152 common.infoMsg("Migrating neutron resources from ${target}")
153 openstack.runOpenStackUpgradePhase(env, target, 'upgrade.pre')
154 // Start upgrade only when resources were successfully migrated
155 }
156 }
157
158 common.stageWrapper(upgradeStageMap, "Upgrade OpenStack", target, interactive) {
159 // Stop services on node. //Do actual step by step orch here.
160 openstack.runOpenStackUpgradePhase(env, target, 'service_stopped')
161 openstack.runOpenStackUpgradePhase(env, target, 'pkgs_latest')
162 openstack.runOpenStackUpgradePhase(env, target, 'render_config')
163 openstack.runOpenStackUpgradePhase(env, target, 'service_running')
164 openstack.applyOpenstackAppsStates(env, target)
165 openstack.runOpenStackUpgradePhase(env, target, 'verify')
166 }
167 common.stageWrapper(upgradeStageMap, "Upgrade OS", target, interactive) {
168 if (OS_DIST_UPGRADE.toBoolean() == true){
169 upgrade_mode = 'dist-upgrade'
170 } else if (OS_UPGRADE.toBoolean() == true){
171 upgrade_mode = 'upgrade'
172 }
173 if (OS_DIST_UPGRADE.toBoolean() == true || OS_UPGRADE.toBoolean() == true) {
174 debian.osUpgradeNode(env, target, upgrade_mode, false)
175 }
176 openstack.applyOpenstackAppsStates(env, target)
177 openstack.runOpenStackUpgradePhase(env, target, 'verify')
178 }
179
180 common.stageWrapper(upgradeStageMap, "Upgrade post: enable resources", target, interactive) {
181 openstack.runOpenStackUpgradePhase(env, target, 'upgrade.post')
182 }
183 }
184 }
185}