/
uninstall.py
444 lines (400 loc) · 16.2 KB
/
uninstall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import os
import re
import copy
import tempfile
from fabfile.config import *
from fabfile.utils.fabos import *
from fabfile.utils.host import get_openstack_internal_vip, get_from_testbed_dict
from fabfile.utils.analytics import is_ceilometer_install_supported,\
is_ceilometer_compute_install_supported
from fabfile.utils.install import get_compute_ceilometer_pkgs,\
get_compute_pkgs, get_ceilometer_plugin_pkgs,\
get_openstack_ceilometer_pkgs
from fabfile.tasks.helpers import *
def get_pkg_list():
output = sudo('yum list installed | grep @contrail_install_repo | cut -d" " -f1')
pkgs = output.split("\r\n")
def filter_condition(pkg):
dont_remove_list = [
'contrail-install-packages',
'contrail-fabric-utils',
'contrail-interface-name',
'glib2',
'glibc',
'glibc-common',
'libgcc',
'make',
'pkgconfig',
'python',
'python-libs',
]
if any(dont_rm_pkg in pkg for dont_rm_pkg in dont_remove_list):
return False
return True
pkgs = filter(filter_condition, pkgs)
return pkgs
@task
@EXECUTE_TASK
@roles('all')
def uninstall_rpm_all(rpm):
"""Uninstalls any rpm in all nodes."""
execute('uninstall_pkg_node', rpm, env.host_string)
@task
@EXECUTE_TASK
@roles('all')
def uninstall_deb_all(deb):
"""Uninstalls any deb in all nodes."""
execute('uninstall_pkg_node', deb, env.host_string)
@task
@EXECUTE_TASK
@roles('all')
def uninstall_pkg_all(pkg):
"""Uninstalls any rpm/deb package in all nodes."""
execute('uninstall_pkg_node', pkg, env.host_string)
@task
@roles('build')
def uninstall_pkg_all_without_openstack(pkg):
"""Uninstalls any rpm/deb package in all nodes excluding openstack node."""
host_strings = copy.deepcopy(env.roledefs['all'])
dummy = [host_strings.remove(openstack_node)
for openstack_node in env.roledefs['openstack']]
execute('uninstall_pkg_node', pkg, *host_strings)
@task
def uninstall_pkg_node(pkg, *args):
"""Uninstalls any rpm/deb in one node."""
for host_string in args:
with settings(host_string=host_string, warn_only=True):
build = get_build()
if not build:
print "Package %s already uninstalled in the node(%s)." % (pkg, host_string)
continue
if detect_ostype() == 'ubuntu':
apt_uninstall([pkg])
else:
yum_uninstall([pkg])
def yum_uninstall(rpms):
cmd = "rpm -e --nodeps "
if detect_ostype() in ['centos', 'fedora', 'redhat', 'centoslinux']:
with settings(warn_only=True):
sudo(cmd + ' '.join(rpms))
def apt_uninstall(debs):
cmd = "DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes autoremove --purge "
if detect_ostype() in ['ubuntu']:
with settings(warn_only=True):
sudo(cmd + ' '.join(debs))
@task
@EXECUTE_TASK
@roles('all')
def cleanup_opt_contrail():
sudo("sudo rm -rf /opt/contrail")
@task
@EXECUTE_TASK
@roles('compute')
def uninstall_interface_name():
"""Uninstalls interface name package in all nodes defined in compute role."""
if not env.roledefs['compute']:
return
if detect_ostype() == 'ubuntu':
print "[%s]: uninstalling interface rename package not required for Ubuntu..Skipping it" %env.host_string
else:
execute("uninstall_interface_name_node", env.host_string)
@task
def uninstall_interface_name_node(*args):
"""Uninstalls interface name package in one or list of nodes. USAGE:fab uninstall_interface_name_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
rpm = ['contrail-interface-name']
yum_uninstall(rpm)
sudo('rm -f /etc/sysconfig/network-scripts/ifcfg-p*p*p*')
@task
@EXECUTE_TASK
@roles('database')
def uninstall_database():
"""Uninstalls database pkgs in all nodes defined in database."""
if env.roledefs['database']:
execute("uninstall_database_node", env.host_string)
@task
def uninstall_database_node(*args):
"""Uninstalls database pkgs in one or list of nodes. USAGE:fab uninstall_database_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-openstack-database']
if detect_ostype() == 'ubuntu':
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/etc/'):
sudo('sudo rm -rf zookeeper')
with cd('/var/lib/'):
sudo('sudo rm -rf /usr/share/cassandra /var/cassandra_log /var/crashes /home/cassandra')
sudo('sudo rm -rf /var/log/cassandra /var/log/zookeeper')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
@task
@EXECUTE_TASK
@roles('openstack')
def uninstall_openstack():
"""Uninstalls openstack pkgs in all nodes defined in openstack role."""
if env.roledefs['openstack']:
execute("uninstall_openstack_node", env.host_string)
@task
def uninstall_openstack_node(*args):
"""Uninstalls openstack pkgs in one or list of nodes. USAGE:fab uninstall_openstack_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-openstack']
if len(env.roledefs['openstack']) > 1 and get_openstack_internal_vip():
pkg.append('contrail-openstack-ha')
if is_ceilometer_install_supported():
pkg += get_openstack_ceilometer_pkgs()
pkg += get_ceilometer_plugin_pkgs()
if detect_ostype() == 'ubuntu':
with settings(warn_only=True):
sudo("umount /var/lib/glance/images")
sudo("sed -i '/.*glance.*/d' /etc/fstab")
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/etc/'):
sudo('sudo rm -rf glance/ cinder/ openstack_dashboard/ keystone/ quantum/ nova/ haproxy/ keepalived/')
with cd('/var/lib/'):
sudo('sudo rm -rf nova quantum glance quantum keystone mysql haproxy')
with cd('/var/run'):
sudo('sudo rm -rf cinder glance quantum nova keystone')
with cd('/var/log'):
sudo('sudo rm -rf contrail/* nova quantum glance cinder ~/keystone-signing /tmp/keystone-signing /tmp/keystone-signing-nova')
@task
@EXECUTE_TASK
@roles('cfgm')
def uninstall_cfgm():
"""Uninstalls config pkgs in all nodes defined in cfgm role."""
if env.roledefs['cfgm']:
execute("uninstall_cfgm_node", env.host_string)
@task
def uninstall_cfgm_node(*args):
"""Uninstalls config pkgs in one or list of nodes. USAGE:fab uninstall_cfgm_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-openstack-config']
if detect_ostype() == 'ubuntu':
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/etc/'):
sudo('sudo rm -rf irond haproxy keepalived')
with cd('/var/lib/'):
sudo('sudo rm -rf haproxy')
sudo('sudo rm -rf /var/crashes')
with cd('/usr/share'):
sudo('sudo rm -rf irond')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
@task
@EXECUTE_TASK
@roles('control')
def uninstall_control():
"""Uninstalls control pkgs in all nodes defined in control role."""
if env.roledefs['control']:
execute("uninstall_control_node", env.host_string)
@task
def uninstall_control_node(*args):
"""Uninstalls control pkgs in one or list of nodes. USAGE:fab uninstall_control_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-openstack-control']
if detect_ostype() == 'ubuntu':
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/var/'):
sudo('sudo rm -rf crashes')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
@task
@EXECUTE_TASK
@roles('collector')
def uninstall_collector():
"""Uninstalls analytics pkgs in all nodes defined in collector role."""
if env.roledefs['collector']:
execute("uninstall_collector_node", env.host_string)
@task
def uninstall_collector_node(*args):
"""Uninstalls analytics pkgs in one or list of nodes. USAGE:fab uninstall_collector_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-openstack-analytics', 'contrail-docs']
if detect_ostype() == 'ubuntu':
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/var/lib/'):
sudo('sudo rm -rf redis')
sudo('sudo rm -rf /var/crashes')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
@task
@EXECUTE_TASK
@roles('webui')
def uninstall_webui():
"""Uninstalls webui pkgs in all nodes defined in webui role."""
if env.roledefs['webui']:
execute("uninstall_webui_node", env.host_string)
@task
def uninstall_webui_node(*args):
"""Uninstalls webui pkgs in one or list of nodes. USAGE:fab uninstall_webui_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
with settings(warn_only=True):
sudo("stop_webui")
sudo("kill -9 $(pidof redis-server)")
pkg = ['contrail-openstack-webui']
if detect_ostype() == 'ubuntu':
apt_uninstall(pkg)
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/var/'):
sudo('sudo rm -rf crashes')
with cd('/opt/contrail'):
sudo('sudo rm -rf nodejs*')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
@task
@EXECUTE_TASK
@roles('compute')
def uninstall_vrouter(manage_nova_compute='yes'):
"""Uninstalls vrouter pkgs in all nodes defined in vrouter role."""
if env.roledefs['compute']:
execute("uninstall_only_vrouter_node", manage_nova_compute, env.host_string)
@task
def uninstall_vrouter_node(*args):
"""Uninstalls nova compute and vrouter pkgs in one or list of nodes. USAGE:fab uninstall_vrouter_node:user@1.1.1.1,user@2.2.2.2"""
execute('uninstall_only_vrouter_node', 'yes', *args)
@task
def uninstall_only_vrouter_node(manage_nova_compute='yes', *args):
"""Uninstalls only vrouter pkgs in one or list of nodes. USAGE:fab uninstall_vrouter_node:user@1.1.1.1,user@2.2.2.2
If manage_nova_compute = no, User has to uninstall nova-compute in the compute node.
"""
for host_string in args:
ostype = detect_ostype()
with settings(host_string=host_string):
manage_nova_compute = 'no'
if is_package_installed('contrail-openstack-vrouter'):
manage_nova_compute = 'yes'
pkgs = get_compute_pkgs(manage_nova_compute)
if ostype == 'ubuntu':
if is_ceilometer_compute_install_supported():
pkgs.append('ceilometer-agent-compute')
apt_uninstall(pkgs)
sudo("sed -i 's/inet manual/inet dhcp/g' /etc/network/interfaces")
# Delete vhost0 interface
sudo("""sed -ri.bak '
/^auto vhost0/ d
/^iface vhost0/,/^(\w|$)/ {
/iface vhost0/ d
/^\s/ d
}
' /etc/network/interfaces""")
# Remove SR-IOV configuration
sudo("sed -i.bak '/sriov_numvfs/ d' /etc/rc.local")
else:
pkgs = get_pkg_list()
yum_uninstall(pkgs)
with cd('/etc/'):
sudo('sudo rm -rf libvirt')
with settings(warn_only=True):
cmds = ['find ./contrail/*'
'! -iname "contrail_ifrename.sh"',
'! -iname "debs_list.txt"',
'! -iname "rpm_list.txt"',
'-delete',
]
sudo(' '.join(cmds))
with cd('/var/'):
sudo('sudo rm -rf crashes')
sudo('sudo rm -rf tmp')
with cd('/var/log'):
sudo('sudo rm -rf contrail/*')
undo_setup_hugepages()
@roles('build')
@task
def uninstall_contrail(full='no'):
"""Uninstalls required contrail packages in all nodes as per the role definition.
Note that contrail-install-packages package is still
retained so that a new uninstall/setup can be run using :
fab install_contrail
fab setup_all
To force a full cleanup, set full=True as argument.
This will remove contrail-install-packages as well
"""
execute(uninstall_database)
execute(uninstall_openstack)
execute(uninstall_cfgm)
execute(uninstall_control)
execute(uninstall_collector)
execute(uninstall_webui)
execute(uninstall_vrouter)
if getattr(env, 'interface_rename', True):
execute(uninstall_interface_name)
if full == 'yes':
pkgs = ['contrail-install-packages', 'contrail-fabric-utils', 'contrail-setup']
for pkg in pkgs:
execute('uninstall_pkg_all', pkg)
execute('cleanup_opt_contrail')
execute('reboot_all_build_atlast')
@roles('build')
@task
def uninstall_without_openstack(manage_nova_compute='yes', full='no'):
"""Uninstalls required contrail packages in all nodes as per the role definition except the openstack.
User has to uninstall the openstack node with their custom openstack pakckages.
If subset of contrail-openstack-vrouter package is installed, pass manage_nova_compute = no
Note that contrail-install-packages package is still
retained so that a new uninstall/setup can be run using :
fab install_contrail
fab setup_all
To force a full cleanup, set full=True as argument.
This will remove contrail-install-packages as well
"""
execute(uninstall_database)
execute(uninstall_cfgm)
execute(uninstall_control)
execute(uninstall_collector)
execute(uninstall_webui)
execute('uninstall_vrouter', manage_nova_compute)
if getattr(env, 'interface_rename', True):
execute(uninstall_interface_name)
if full == 'yes':
pkgs = ['contrail-install-packages', 'contrail-fabric-utils', 'contrail-setup']
for pkg in pkgs:
execute('uninstall_pkg_all', pkg)
execute('cleanup_opt_contrail')
execute('reboot_all_build_atlast')
@task
@roles('build')
def reboot_all_build_atlast():
"""Reboot all nodes, will reboot the node from where fab command is trrigered at last"""
if env.host_string in env.roledefs['all']:
#Trrigered from one of the node in cluster
node_list_except_build = copy.deepcopy(env.roledefs['all'])
node_list_except_build.remove(env.host_string)
execute("reboot_nodes_atlast", *node_list_except_build)
execute("reboot_nodes_atlast", env.host_string)
else:
#Trrigered from external machine
nodes = copy.deepcopy(env.roledefs['all'])
execute("reboot_nodes_atlast", *nodes)
@task
def reboot_nodes_atlast(*args):
"""reboots the given nodes"""
for host_string in args:
with settings(host_string=host_string):
print "Rebooting (%s)..." % host_string
try:
sudo('reboot --force', timeout=3)
except CommandTimeout:
pass