foreman_maintain 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/definitions/features/candlepin_database.rb +0 -9
- data/definitions/features/pulpcore_database.rb +11 -8
- data/lib/foreman_maintain/concerns/base_database.rb +49 -54
- data/lib/foreman_maintain/upgrade_runner.rb +0 -1
- data/lib/foreman_maintain/utils/command_runner.rb +9 -15
- data/lib/foreman_maintain/version.rb +1 -1
- data/lib/foreman_maintain.rb +8 -6
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 076bba551da26888de415a1f67a2b1950493db5cbcc8ace83b3efd0498ffa96d
|
4
|
+
data.tar.gz: b39e663f0109565f11303ce1cd02740e8b937dbd554ff3d8123446b63d09e073
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636a6a7fde3ba794afd5080133c38ec4f77533190659b901fc796daa6c0130f7b213c2e9572b1c149e6a6a55911423c5431606b7e119cbe5613b7f91543bface
|
7
|
+
data.tar.gz: c7361d2bc970e0d58b6e4a2f4fb32550720ceb3565759447305c36339015ad96cc19722e53f9a21130834f3a582b29614de5848d04c7ea1a950b83ed5b2693f8
|
data/README.md
CHANGED
@@ -20,7 +20,6 @@ Subcommands:
|
|
20
20
|
check --target-version TARGET_VERSION Run pre-upgrade checks for upgrading to specified version
|
21
21
|
--disable-self-upgrade Disable automatic self upgrade (default: false)
|
22
22
|
run --target-version TARGET_VERSION Run the full upgrade
|
23
|
-
[--phase=phase TARGET_VERSION] Run just a specific phase of the upgrade
|
24
23
|
--disable-self-upgrade Disable automatic self upgrade (default: false)
|
25
24
|
|
26
25
|
advanced Advanced tools for server maintenance
|
@@ -28,15 +28,6 @@ class Features::CandlepinDatabase < ForemanMaintain::Feature
|
|
28
28
|
execute?(help_cmd)
|
29
29
|
end
|
30
30
|
|
31
|
-
def env_content_ids_with_null_content
|
32
|
-
sql = <<-SQL
|
33
|
-
SELECT ec.id
|
34
|
-
FROM cp_env_content ec
|
35
|
-
LEFT JOIN cp_content c ON ec.contentid = c.id WHERE c.id IS NULL
|
36
|
-
SQL
|
37
|
-
query(sql).map { |r| r['id'] }
|
38
|
-
end
|
39
|
-
|
40
31
|
private
|
41
32
|
|
42
33
|
def load_configuration
|
@@ -26,18 +26,21 @@ class Features::PulpcoreDatabase < ForemanMaintain::Feature
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
# rubocop:disable Metrics/AbcSize
|
30
29
|
def load_configuration
|
31
|
-
|
30
|
+
python_command = <<~PYTHON.strip
|
31
|
+
from django.conf import settings; import json; print(json.dumps(settings.DATABASES["default"]))
|
32
|
+
PYTHON
|
33
|
+
manager_command = pulpcore_manager("shell --command '#{python_command}'")
|
34
|
+
manager_result = execute!(manager_command)
|
35
|
+
db_config = JSON.parse(manager_result)
|
32
36
|
|
33
37
|
@configuration = {}
|
34
38
|
@configuration['adapter'] = 'postgresql'
|
35
|
-
@configuration['host'] =
|
36
|
-
@configuration['port'] =
|
37
|
-
@configuration['database'] =
|
38
|
-
@configuration['username'] =
|
39
|
-
@configuration['password'] =
|
39
|
+
@configuration['host'] = db_config['HOST']
|
40
|
+
@configuration['port'] = db_config['PORT']
|
41
|
+
@configuration['database'] = db_config['NAME']
|
42
|
+
@configuration['username'] = db_config['USER']
|
43
|
+
@configuration['password'] = db_config['PASSWORD']
|
40
44
|
@configuration
|
41
45
|
end
|
42
|
-
# rubocop:enable Metrics/AbcSize
|
43
46
|
end
|
@@ -16,11 +16,12 @@ module ForemanMaintain
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def deb_postgresql_versions
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
@deb_postgresql_versions ||= begin
|
20
|
+
installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
|
21
|
+
installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
|
22
|
+
name.split('-').last
|
23
|
+
end
|
22
24
|
end
|
23
|
-
@deb_postgresql_versions
|
24
25
|
end
|
25
26
|
|
26
27
|
def postgresql_conf
|
@@ -41,49 +42,47 @@ module ForemanMaintain
|
|
41
42
|
raise NotImplementedError
|
42
43
|
end
|
43
44
|
|
44
|
-
def local?
|
45
|
-
['localhost', '127.0.0.1', `hostname`.strip].include?(
|
45
|
+
def local?
|
46
|
+
['localhost', '127.0.0.1', `hostname`.strip].include?(configuration['host'])
|
46
47
|
end
|
47
48
|
|
48
|
-
def query(sql
|
49
|
-
parse_csv(query_csv(sql
|
49
|
+
def query(sql)
|
50
|
+
parse_csv(query_csv(sql))
|
50
51
|
end
|
51
52
|
|
52
|
-
def query_csv(sql
|
53
|
-
psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER}
|
53
|
+
def query_csv(sql)
|
54
|
+
psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER})
|
54
55
|
end
|
55
56
|
|
56
|
-
def psql(query
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
raise_service_error
|
63
|
-
end
|
57
|
+
def psql(query)
|
58
|
+
ping!
|
59
|
+
|
60
|
+
execute('psql',
|
61
|
+
:stdin => query,
|
62
|
+
:env => base_env)
|
64
63
|
end
|
65
64
|
|
66
|
-
def ping
|
67
|
-
execute?(
|
65
|
+
def ping
|
66
|
+
execute?('psql',
|
68
67
|
:stdin => 'SELECT 1 as ping',
|
69
|
-
:
|
68
|
+
:env => base_env)
|
70
69
|
end
|
71
70
|
|
72
|
-
def dump_db(file
|
73
|
-
|
71
|
+
def dump_db(file)
|
72
|
+
dump_command = "pg_dump -Fc -f #{file}"
|
73
|
+
execute!(dump_command, :env => base_env)
|
74
74
|
end
|
75
75
|
|
76
|
-
def restore_dump(file, localdb
|
76
|
+
def restore_dump(file, localdb)
|
77
77
|
if localdb
|
78
78
|
dump_cmd = "runuser - postgres -c 'pg_restore -C -d postgres #{file}'"
|
79
79
|
execute!(dump_cmd)
|
80
80
|
else
|
81
81
|
# TODO: figure out how to completely ignore errors. Currently this
|
82
82
|
# sometimes exits with 1 even though errors are ignored by pg_restore
|
83
|
-
dump_cmd =
|
84
|
-
|
85
|
-
|
86
|
-
execute!(dump_cmd, :hidden_patterns => [config['password']],
|
83
|
+
dump_cmd = 'pg_restore --no-privileges --clean --disable-triggers -n public ' \
|
84
|
+
"-d #{configuration['database']} #{file}"
|
85
|
+
execute!(dump_cmd, :env => base_env,
|
87
86
|
:valid_exit_statuses => [0, 1])
|
88
87
|
end
|
89
88
|
end
|
@@ -109,11 +108,11 @@ module ForemanMaintain
|
|
109
108
|
@backup_dir ||= File.expand_path(ForemanMaintain.config.db_backup_dir)
|
110
109
|
end
|
111
110
|
|
112
|
-
def dropdb
|
111
|
+
def dropdb
|
113
112
|
if local?
|
114
|
-
execute!("runuser - postgres -c 'dropdb #{
|
113
|
+
execute!("runuser - postgres -c 'dropdb #{configuration['database']}'")
|
115
114
|
else
|
116
|
-
delete_statement = psql(
|
115
|
+
delete_statement = psql(<<~SQL)
|
117
116
|
select string_agg('drop table if exists \"' || tablename || '\" cascade;', '')
|
118
117
|
from pg_tables
|
119
118
|
where schemaname = 'public';
|
@@ -122,15 +121,13 @@ module ForemanMaintain
|
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
125
|
-
def db_version
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
raise_service_error
|
133
|
-
end
|
124
|
+
def db_version
|
125
|
+
ping!
|
126
|
+
|
127
|
+
query = 'SHOW server_version'
|
128
|
+
server_version_cmd = 'psql --tuples-only --no-align'
|
129
|
+
version_string = execute!(server_version_cmd, :stdin => query, :env => base_env)
|
130
|
+
version(version_string)
|
134
131
|
end
|
135
132
|
|
136
133
|
def psql_cmd_available?
|
@@ -145,22 +142,20 @@ module ForemanMaintain
|
|
145
142
|
|
146
143
|
private
|
147
144
|
|
148
|
-
def
|
149
|
-
|
150
|
-
|
151
|
-
|
145
|
+
def base_env
|
146
|
+
{
|
147
|
+
'PGHOST' => configuration.fetch('host', 'localhost'),
|
148
|
+
'PGPORT' => configuration['port']&.to_s,
|
149
|
+
'PGUSER' => configuration['username'],
|
150
|
+
'PGPASSWORD' => configuration['password'],
|
151
|
+
'PGDATABASE' => configuration['database'],
|
152
|
+
}
|
152
153
|
end
|
153
154
|
|
154
|
-
def
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
def dump_command(config)
|
159
|
-
base_command(config, 'pg_dump') + " -Fc #{config['database']}"
|
160
|
-
end
|
161
|
-
|
162
|
-
def raise_service_error
|
163
|
-
raise Error::Fail, 'Please check whether database service is up & running state.'
|
155
|
+
def ping!
|
156
|
+
unless ping
|
157
|
+
raise Error::Fail, 'Please check whether database service is up & running state.'
|
158
|
+
end
|
164
159
|
end
|
165
160
|
end
|
166
161
|
end
|
@@ -137,7 +137,6 @@ module ForemanMaintain
|
|
137
137
|
@reporter.before_scenario_starts(scenario)
|
138
138
|
@reporter.puts <<~MESSAGE
|
139
139
|
Skipping #{skipped_phase} phase as it was already run before.
|
140
|
-
To enforce to run the phase, use `upgrade run --phase #{skipped_phase}`
|
141
140
|
MESSAGE
|
142
141
|
@reporter.after_scenario_finishes(scenario)
|
143
142
|
end
|
@@ -8,26 +8,27 @@ module ForemanMaintain
|
|
8
8
|
attr_reader :logger, :command
|
9
9
|
|
10
10
|
def initialize(logger, command, options)
|
11
|
-
options.validate_options!(:stdin, :
|
11
|
+
options.validate_options!(:stdin, :interactive, :valid_exit_statuses, :env)
|
12
12
|
options[:valid_exit_statuses] ||= [0]
|
13
|
+
options[:env] ||= {}
|
13
14
|
@logger = logger
|
14
15
|
@command = command
|
15
16
|
@stdin = options[:stdin]
|
16
|
-
@hidden_patterns = Array(options[:hidden_patterns]).compact
|
17
17
|
@interactive = options[:interactive]
|
18
18
|
@options = options
|
19
19
|
@valid_exit_statuses = options[:valid_exit_statuses]
|
20
|
+
@env = options[:env]
|
20
21
|
raise ArgumentError, 'Can not pass stdin for interactive command' if @interactive && @stdin
|
21
22
|
end
|
22
23
|
|
23
24
|
def run
|
24
|
-
logger&.debug(
|
25
|
+
logger&.debug("Running command #{@command} with stdin #{@stdin.inspect}")
|
25
26
|
if @interactive
|
26
27
|
run_interactively
|
27
28
|
else
|
28
29
|
run_non_interactively
|
29
30
|
end
|
30
|
-
logger&.debug("output of the command:\n #{
|
31
|
+
logger&.debug("output of the command:\n #{output}")
|
31
32
|
end
|
32
33
|
|
33
34
|
def interactive?
|
@@ -49,10 +50,10 @@ module ForemanMaintain
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def execution_error
|
52
|
-
raise Error::ExecutionError.new(
|
53
|
+
raise Error::ExecutionError.new(@command,
|
53
54
|
exit_status,
|
54
|
-
|
55
|
-
@interactive ? nil :
|
55
|
+
@stdin,
|
56
|
+
@interactive ? nil : @output)
|
56
57
|
end
|
57
58
|
|
58
59
|
private
|
@@ -81,7 +82,7 @@ module ForemanMaintain
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def run_non_interactively
|
84
|
-
IO.popen(full_command, 'r+') do |f|
|
85
|
+
IO.popen(@env, full_command, 'r+') do |f|
|
85
86
|
if @stdin
|
86
87
|
f.puts(@stdin)
|
87
88
|
f.close_write
|
@@ -94,13 +95,6 @@ module ForemanMaintain
|
|
94
95
|
def full_command
|
95
96
|
"#{@command} 2>&1"
|
96
97
|
end
|
97
|
-
|
98
|
-
def hide_strings(string)
|
99
|
-
return unless string
|
100
|
-
@hidden_patterns.reduce(string) do |result, hidden_pattern|
|
101
|
-
result.gsub(hidden_pattern, '[FILTERED]')
|
102
|
-
end
|
103
|
-
end
|
104
98
|
end
|
105
99
|
end
|
106
100
|
end
|
data/lib/foreman_maintain.rb
CHANGED
@@ -181,20 +181,22 @@ module ForemanMaintain
|
|
181
181
|
|
182
182
|
def perform_self_upgrade
|
183
183
|
package_name, command = pkg_and_cmd_name
|
184
|
+
packages_to_update = [package_name, main_package_name].uniq
|
185
|
+
packages_to_update_str = packages_to_update.join(', ')
|
184
186
|
|
185
|
-
puts "Checking for new version of #{
|
187
|
+
puts "Checking for new version of #{packages_to_update_str}..."
|
186
188
|
|
187
189
|
enable_maintenance_module
|
188
190
|
package_manager = ForemanMaintain.package_manager
|
189
191
|
|
190
|
-
if package_manager.update_available?(
|
191
|
-
puts "\nUpdating #{
|
192
|
-
package_manager.update(
|
193
|
-
puts "\
|
192
|
+
if package_manager.update_available?(packages_to_update)
|
193
|
+
puts "\nUpdating #{packages_to_update_str}."
|
194
|
+
package_manager.update(packages_to_update, :assumeyes => true)
|
195
|
+
puts "\nSuccessfully updated #{packages_to_update_str}."\
|
194
196
|
"\nRe-run #{command} with required options!"
|
195
197
|
exit 75
|
196
198
|
end
|
197
|
-
puts "Nothing to update, can't find new version of #{
|
199
|
+
puts "Nothing to update, can't find new version of #{packages_to_update_str}."
|
198
200
|
end
|
199
201
|
|
200
202
|
def enable_maintenance_module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_maintain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|
@@ -410,7 +410,7 @@ homepage: https://github.com/theforeman/foreman_maintain
|
|
410
410
|
licenses:
|
411
411
|
- GPL-3.0
|
412
412
|
metadata: {}
|
413
|
-
post_install_message:
|
413
|
+
post_install_message:
|
414
414
|
rdoc_options: []
|
415
415
|
require_paths:
|
416
416
|
- lib
|
@@ -429,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
429
429
|
version: '0'
|
430
430
|
requirements: []
|
431
431
|
rubygems_version: 3.3.27
|
432
|
-
signing_key:
|
432
|
+
signing_key:
|
433
433
|
specification_version: 4
|
434
434
|
summary: Foreman maintenance tool belt
|
435
435
|
test_files: []
|