-
Notifications
You must be signed in to change notification settings - Fork 72
/
remove.rb
172 lines (149 loc) · 6.6 KB
/
remove.rb
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
module Procedures::Pulp
class Remove < ForemanMaintain::Procedure
metadata do
description 'Remove pulp2'
param :assumeyes, 'Do not ask for confirmation', :default => false
confine do
check_min_version('katello-common', '4.0')
end
param :assume_yes, 'Run the full removal without asking.'
end
def sys
ForemanMaintain::Utils::SystemHelpers.new
end
def pulp_data_dirs
[
'/var/lib/pulp/published',
'/var/lib/pulp/content',
'/var/lib/pulp/importers',
'/var/lib/pulp/uploads',
'/var/lib/mongodb/',
'/var/cache/pulp'
]
end
# rubocop:disable Metrics/MethodLength
def pulp_packages
possible = %w[pulp-admin-client pulp-agent pulp-consumer-client pulp-deb-admin-extensions
pulp-deb-plugins pulp-docker-admin-extensions pulp-docker-plugins
pulp-nodes-admin-extensions pulp-nodes-child pulp-nodes-common
pulp-nodes-consumer-extensions pulp-nodes-parent pulp-ostree-admin-extensions
pulp-ostree-plugins pulp-puppet-admin-extensions
pulp-puppet-consumer-extensions pulp-puppet-handlers pulp-puppet-plugins
pulp-puppet-tools pulp-python-admin-extensions pulp-python-plugins
pulp-rpm-admin-extensions pulp-rpm-consumer-extensions pulp-rpm-handlers
pulp-rpm-plugins pulp-rpm-yumplugins pulp-selinux pulp-server python-bson
python-crane python-isodate python-mongoengine python-nectar
python-pulp-agent-lib python-pulp-bindings python-pulp-client-lib
python-pulp-common python-pulp-deb-common python-pulp-devel
python-pulp-docker-common python-pulp-integrity python-pulp-manifest
python-pulp-oid_validation python-pulp-ostree-common python-pulp-puppet-common
python-pulp-python-common python-pulp-repoauth python-pulp-rpm-common
python-pulp-streamer python-pymongo python-pymongo-gridfs python2-amqp
python2-billiard python2-celery python2-debpkgr python2-django python2-kombu
python2-solv python2-vine pulp-katello pulp-maintenance
python3-pulp-2to3-migration]
@installed_pulp_packages ||= possible.select { |pkg| find_package(pkg) }
@installed_pulp_packages
end
def data_dir_removal_cmds
pulp_data_dirs.select { |dir| File.directory?(dir) }.map { |dir| "rm -rf #{dir}" }
end
def ask_to_proceed(rm_cmds)
question = "\nWARNING: All pulp2 packages will be removed with the following commands:\n"
question += "\n# rpm -e #{pulp_packages.join(' ')}" if pulp_packages.any?
question += "\n# yum remove rh-mongodb34-*"
question += "\n# yum remove squid mod_wsgi" \
"\n\nAll pulp2 data will be removed.\n"
question += rm_cmds.collect { |cmd| "\n# #{cmd}" }.join
question += "\n\nDo you want to proceed?"
answer = ask_decision(question, actions_msg: 'y(yes), q(quit)')
abort! if answer != :yes
end
def run
rm_cmds = data_dir_removal_cmds
assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
ask_to_proceed(rm_cmds) unless assumeyes_val
remove_pulp if pulp_packages.any?
remove_mongo
remove_other_packages
drop_migration_tables
drop_migrations
delete_pulp_data(rm_cmds) if rm_cmds.any?
end
def remove_pulp
with_spinner('Removing pulp2 packages') do
execute!("rpm -e #{pulp_packages.join(' ')}")
end
end
def remove_mongo
with_spinner('Removing mongo packages') do
packages_action(:remove, ['rh-mongodb34-*'], :assumeyes => true)
end
end
def remove_other_packages
with_spinner('Removing additional packages') do
packages_action(:remove, %w[squid mod_wsgi], :assumeyes => true)
end
end
def drop_migration_tables
with_spinner('Dropping migration tables') do
feature(:pulpcore_database).psql(<<-SQL)
BEGIN;
DROP TABLE IF EXISTS pulp_2to3_migration_migrationplan,
pulp_2to3_migration_pulp2blob,
pulp_2to3_migration_pulp2content,
pulp_2to3_migration_pulp2debcomponent,
pulp_2to3_migration_pulp2debcomponentpackage,
pulp_2to3_migration_pulp2debpackage,
pulp_2to3_migration_pulp2debrelease,
pulp_2to3_migration_pulp2debreleasearchitecture,
pulp_2to3_migration_pulp2distribution,
pulp_2to3_migration_pulp2distributor,
pulp_2to3_migration_pulp2distributor_pulp2_repos,
pulp_2to3_migration_pulp2erratum,
pulp_2to3_migration_pulp2importer,
pulp_2to3_migration_pulp2iso,
pulp_2to3_migration_pulp2lazycatalog,
pulp_2to3_migration_pulp2manifest,
pulp_2to3_migration_pulp2manifestlist,
pulp_2to3_migration_pulp2modulemd,
pulp_2to3_migration_pulp2modulemddefaults,
pulp_2to3_migration_pulp2packagecategory,
pulp_2to3_migration_pulp2packageenvironment,
pulp_2to3_migration_pulp2packagegroup,
pulp_2to3_migration_pulp2packagelangpacks,
pulp_2to3_migration_pulp2repocontent,
pulp_2to3_migration_pulp2repository,
pulp_2to3_migration_pulp2rpm,
pulp_2to3_migration_pulp2srpm,
pulp_2to3_migration_pulp2tag,
pulp_2to3_migration_pulp2yumrepometadatafile,
pulp_2to3_migration_reposetup CASCADE;
DROP SEQUENCE IF EXISTS pulp_2to3_migration_pulp2distributor_pulp2_repos_id_seq;
END;
SQL
end
end
def drop_migrations
with_spinner('Dropping migrations') do
feature(:pulpcore_database).psql(<<-SQL)
BEGIN;
DELETE FROM django_migrations WHERE app = 'pulp_2to3_migration';
DELETE FROM auth_permission WHERE content_type_id in (SELECT id FROM django_content_type WHERE app_label = 'pulp_2to3_migration');
DELETE FROM django_admin_log WHERE content_type_id in (SELECT id FROM django_content_type WHERE app_label = 'pulp_2to3_migration');
DELETE FROM django_content_type WHERE app_label = 'pulp_2to3_migration';
END;
SQL
end
end
# rubocop:enable Metrics/BlockLength
def delete_pulp_data(rm_cmds)
with_spinner('Deleting pulp2 data directories') do |spinner|
rm_cmds.each do |cmd|
execute!(cmd)
end
spinner.update('Done deleting pulp2 data directories')
end
end
end
end