foreman_maintain 1.7.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22d0abf16f40a1448c08bbcc3841e1347d27ffe2e7da598e05dd27a3c565de49
4
- data.tar.gz: b3b19431311ac39014e8679653bcb61c055cf46f4cc867158cc1222485986ebd
3
+ metadata.gz: 076bba551da26888de415a1f67a2b1950493db5cbcc8ace83b3efd0498ffa96d
4
+ data.tar.gz: b39e663f0109565f11303ce1cd02740e8b937dbd554ff3d8123446b63d09e073
5
5
  SHA512:
6
- metadata.gz: 6534adf54060798589ef949490e03d43ef58525b6cf6818a0b55c9f1c909bd29b6cd8db3909e0961efaf3357b6148ef868b75713c15bd1b85ab7729c7b2331c9
7
- data.tar.gz: 53173b1621d5ced84e12eeffb80a03fb5d808dd92ed2f29585439506312e382600cfc25a53c799a692344513de27fe313c5bda1717b17304ef27068909627664
6
+ metadata.gz: 636a6a7fde3ba794afd5080133c38ec4f77533190659b901fc796daa6c0130f7b213c2e9572b1c149e6a6a55911423c5431606b7e119cbe5613b7f91543bface
7
+ data.tar.gz: c7361d2bc970e0d58b6e4a2f4fb32550720ceb3565759447305c36339015ad96cc19722e53f9a21130834f3a582b29614de5848d04c7ea1a950b83ed5b2693f8
@@ -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
@@ -8,7 +8,7 @@ class Features::Installer < ForemanMaintain::Feature
8
8
  end
9
9
 
10
10
  def answers
11
- load_answers(configuration)
11
+ YAML.load_file(answer_file)
12
12
  end
13
13
 
14
14
  def configuration
@@ -28,11 +28,13 @@ class Features::Installer < ForemanMaintain::Feature
28
28
  end
29
29
 
30
30
  def config_files
31
- Dir.glob(File.join(config_directory, '**/*')) +
32
- [
33
- '/opt/puppetlabs/puppet/cache/foreman_cache_data',
34
- '/opt/puppetlabs/puppet/cache/pulpcore_cache_data',
35
- ]
31
+ paths = [
32
+ config_directory,
33
+ '/opt/puppetlabs/puppet/cache/foreman_cache_data',
34
+ '/opt/puppetlabs/puppet/cache/pulpcore_cache_data',
35
+ ]
36
+ paths << answer_file unless answer_file.start_with?("#{config_directory}/")
37
+ paths
36
38
  end
37
39
 
38
40
  def last_scenario
@@ -80,8 +82,8 @@ class Features::Installer < ForemanMaintain::Feature
80
82
 
81
83
  private
82
84
 
83
- def load_answers(config)
84
- YAML.load_file(config[:answer_file])
85
+ def answer_file
86
+ configuration[:answer_file]
85
87
  end
86
88
 
87
89
  def last_scenario_config
@@ -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
- full_config = File.read(PULPCORE_DB_CONFIG).split(/[\s,'":]/).reject(&:empty?)
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'] = full_config[full_config.index('HOST') + 1]
36
- @configuration['port'] = full_config[full_config.index('PORT') + 1]
37
- @configuration['database'] = full_config[full_config.index('NAME') + 1]
38
- @configuration['username'] = full_config[full_config.index('USER') + 1]
39
- @configuration['password'] = full_config[full_config.index('PASSWORD') + 1]
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
@@ -11,11 +11,11 @@ class Features::Satellite < ForemanMaintain::Feature
11
11
  end
12
12
 
13
13
  def target_version
14
- '6.16'
14
+ satellite_maintain_target_version
15
15
  end
16
16
 
17
17
  def current_version
18
- @current_version ||= package_version(package_name) || version_from_source
18
+ @current_version ||= package_version(package_name)
19
19
  end
20
20
 
21
21
  def package_name
@@ -25,10 +25,4 @@ class Features::Satellite < ForemanMaintain::Feature
25
25
  def module_name
26
26
  'satellite'
27
27
  end
28
-
29
- private
30
-
31
- def version_from_source
32
- version(File.read('/usr/share/foreman/lib/satellite/version.rb')[/6\.\d\.\d/])
33
- end
34
28
  end
@@ -4,15 +4,14 @@ module Scenarios::Satellite
4
4
  metadata do
5
5
  tags :upgrade_scenario
6
6
  confine do
7
- (feature(:instance).downstream&.current_minor_version == '6.15' || \
8
- ForemanMaintain.upgrade_in_progress == '6.16')
7
+ feature(:instance).downstream&.satellite_upgrade_allowed?
9
8
  end
10
9
  instance_eval(&block)
11
10
  end
12
11
  end
13
12
 
14
13
  def target_version
15
- '6.16'
14
+ feature(:instance).downstream&.satellite_maintain_target_version
16
15
  end
17
16
  end
18
17
 
@@ -16,11 +16,12 @@ module ForemanMaintain
16
16
  end
17
17
 
18
18
  def deb_postgresql_versions
19
- installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
20
- @deb_postgresql_versions ||= installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
21
- name.split('-').last
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?(config = configuration)
45
- ['localhost', '127.0.0.1', `hostname`.strip].include?(config['host'])
45
+ def local?
46
+ ['localhost', '127.0.0.1', `hostname`.strip].include?(configuration['host'])
46
47
  end
47
48
 
48
- def query(sql, config = configuration)
49
- parse_csv(query_csv(sql, config))
49
+ def query(sql)
50
+ parse_csv(query_csv(sql))
50
51
  end
51
52
 
52
- def query_csv(sql, config = configuration)
53
- psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER}, config)
53
+ def query_csv(sql)
54
+ psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER})
54
55
  end
55
56
 
56
- def psql(query, config = configuration)
57
- if ping(config)
58
- execute(psql_command(config),
59
- :stdin => query,
60
- :hidden_patterns => [config['password']])
61
- else
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(config = configuration)
67
- execute?(psql_command(config),
65
+ def ping
66
+ execute?('psql',
68
67
  :stdin => 'SELECT 1 as ping',
69
- :hidden_patterns => [config['password']])
68
+ :env => base_env)
70
69
  end
71
70
 
72
- def dump_db(file, config = configuration)
73
- execute!(dump_command(config) + " > #{file}", :hidden_patterns => [config['password']])
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, config = configuration)
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 = base_command(config, 'pg_restore') +
84
- ' --no-privileges --clean --disable-triggers -n public ' \
85
- "-d #{config['database']} #{file}"
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(config = configuration)
111
+ def dropdb
113
112
  if local?
114
- execute!("runuser - postgres -c 'dropdb #{config['database']}'")
113
+ execute!("runuser - postgres -c 'dropdb #{configuration['database']}'")
115
114
  else
116
- delete_statement = psql(<<-SQL)
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(config = configuration)
126
- if ping(config)
127
- # Note - t removes headers, -A removes alignment whitespace
128
- server_version_cmd = psql_command(config) + ' -c "SHOW server_version" -t -A'
129
- version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']])
130
- version(version_string)
131
- else
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 base_command(config, command = 'psql')
149
- "PGPASSWORD='#{config[%(password)]}' "\
150
- "#{command} -h #{config['host'] || 'localhost'} "\
151
- " -p #{config['port'] || '5432'} -U #{config['username']}"
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 psql_command(config)
155
- base_command(config, 'psql') + " -d #{config['database']}"
156
- end
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
@@ -1,6 +1,8 @@
1
1
  module ForemanMaintain
2
2
  module Concerns
3
3
  module Downstream
4
+ SATELLITE_MAINTAIN_CONFIG = '/usr/share/satellite-maintain/config.yml'.freeze
5
+
4
6
  def current_version
5
7
  raise NotImplementedError
6
8
  end
@@ -46,8 +48,25 @@ module ForemanMaintain
46
48
  %w[satellite-maintain satellite-maintain]
47
49
  end
48
50
 
51
+ def satellite_maintain_target_version
52
+ satellite_maintain_config['current_satellite_version']
53
+ end
54
+
55
+ def satellite_upgrade_allowed?
56
+ current_minor_version == satellite_maintain_config['previous_satellite_version'] ||
57
+ ForemanMaintain.upgrade_in_progress == satellite_maintain_target_version
58
+ end
59
+
49
60
  private
50
61
 
62
+ def satellite_maintain_config
63
+ if File.exist?(SATELLITE_MAINTAIN_CONFIG)
64
+ YAML.load_file(SATELLITE_MAINTAIN_CONFIG)
65
+ else
66
+ raise "Could not load satellite-maintain configuration file #{SATELLITE_MAINTAIN_CONFIG}."
67
+ end
68
+ end
69
+
51
70
  def rh_repos(server_version)
52
71
  server_version = version(server_version)
53
72
  rh_repos = main_rh_repos
@@ -71,10 +90,6 @@ module ForemanMaintain
71
90
  "rhel-#{el_major_version}-for-x86_64-appstream-rpms",
72
91
  ]
73
92
  end
74
-
75
- def version_from_source
76
- raise NotImplementedError
77
- end
78
93
  end
79
94
  end
80
95
  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, :hidden_patterns, :interactive, :valid_exit_statuses)
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(hide_strings("Running command #{@command} with stdin #{@stdin.inspect}"))
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 #{hide_strings(output)}")
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(hide_strings(@command),
53
+ raise Error::ExecutionError.new(@command,
53
54
  exit_status,
54
- hide_strings(@stdin),
55
- @interactive ? nil : hide_strings(@output))
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
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.7.6'.freeze
2
+ VERSION = '1.8.1'.freeze
3
3
  end
@@ -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 #{package_name}..."
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?(main_package_name)
191
- puts "\nUpdating #{package_name} package."
192
- package_manager.update(main_package_name, :assumeyes => true)
193
- puts "\nThe #{package_name} package successfully updated."\
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 #{package_name}."
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.7.6
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-16 00:00:00.000000000 Z
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: []