foreman_maintain 0.8.22 → 0.8.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 197a1b9603612e47c37ae3a24fec9362d70eb50447144ea599b612571565ea3b
4
- data.tar.gz: d100893294ab1e960e3e7f93cdca402ffbfc5f64c0f51d19f7aa074ee0b18b1a
3
+ metadata.gz: 5fd64b664ab2e4651af4f4c42f19e4418a7e2890537fceac8dd5cd15acdef8fe
4
+ data.tar.gz: 906efdc85144a0cc9a62ff45351e8be0f24268337fe42ec4251796ce19031268
5
5
  SHA512:
6
- metadata.gz: 72d0e0a9f785ea86cb69e7ef2b12c26d7e9ae3777347ec29780395bd32539e08e8c8344242a3c6974518a5ed4df03585b6817b0e08d9491aa8d0f87076ceb8aa
7
- data.tar.gz: d7bcef48c7493525577c010f40079d33b3bcd834d370bbba2e298592562eff57acc79e8c0bb6eb80925bd15a28d13c39e827195fc1cd1a8a08a4f28c7d02a6df
6
+ metadata.gz: dbe5d5ac12761231471d1779aa5f6e0cfc28b204340775b54c7843b888d2f1eb7b2fd10d1eacbc5c31c50aaa320e2e707759601166c9611659f4db7b1d3b52a0
7
+ data.tar.gz: 622b67bfef11facd70f05ddb620183c94dc3edd840863a22220956982da2efe33d9982a40ee159809a49a54d0cfcd2371d74b7cb31b56b4350c7a51888f3f4ab
@@ -82,15 +82,22 @@ class Features::ForemanTasks < ForemanMaintain::Feature
82
82
  def delete(state)
83
83
  tasks_condition = condition(state)
84
84
 
85
- feature(:foreman_database).psql(<<-SQL)
86
- BEGIN;
87
- DELETE FROM dynflow_steps USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_steps.execution_plan_uuid::varchar) AND #{tasks_condition};
88
- DELETE FROM dynflow_actions USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_actions.execution_plan_uuid::varchar) AND #{tasks_condition};
89
- DELETE FROM dynflow_execution_plans USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_execution_plans.uuid::varchar) AND #{tasks_condition};
90
- DELETE FROM foreman_tasks_tasks WHERE #{tasks_condition};
91
- COMMIT;
85
+ sql = <<-SQL
86
+ DELETE FROM dynflow_steps USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_steps.execution_plan_uuid::varchar) AND #{tasks_condition};
87
+ DELETE FROM dynflow_actions USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_actions.execution_plan_uuid::varchar) AND #{tasks_condition};
88
+ DELETE FROM dynflow_execution_plans USING foreman_tasks_tasks WHERE (foreman_tasks_tasks.external_id = dynflow_execution_plans.uuid::varchar) AND #{tasks_condition};
89
+ DELETE FROM foreman_tasks_tasks WHERE #{tasks_condition};
90
+ -- Delete locks and links which may now be orphaned
91
+ DELETE FROM foreman_tasks_locks as ftl where ftl.task_id NOT IN (SELECT id FROM foreman_tasks_tasks);
92
92
  SQL
93
93
 
94
+ if check_min_version(foreman_plugin_name('foreman-tasks'), '4.0.0')
95
+ sql += 'DELETE FROM foreman_tasks_links as ftl ' \
96
+ 'where ftl.task_id NOT IN (SELECT id FROM foreman_tasks_tasks);'
97
+ end
98
+
99
+ feature(:foreman_database).psql("BEGIN; #{sql}; COMMIT;")
100
+
94
101
  count(state)
95
102
  end
96
103
 
@@ -21,6 +21,10 @@ class Features::SystemRepos < ForemanMaintain::Feature
21
21
  Hash[*repos.delete!(' ').split("\n")]
22
22
  end
23
23
 
24
+ def enabled_repos_ids
25
+ trim_repoids(enabled_repos_hash.keys)
26
+ end
27
+
24
28
  def upstream_repos_ids
25
29
  trim_repoids(upstream_repos.keys)
26
30
  end
@@ -29,6 +33,10 @@ class Features::SystemRepos < ForemanMaintain::Feature
29
33
  execute!("yum-config-manager --disable #{repo_ids.join(',')}")
30
34
  end
31
35
 
36
+ def enable_repos(repo_ids)
37
+ execute!("yum-config-manager --enable #{repo_ids.join(',')}")
38
+ end
39
+
32
40
  private
33
41
 
34
42
  def trim_repoids(repos)
@@ -0,0 +1,16 @@
1
+ module Procedures::Repositories
2
+ class BackupEnabledRepos < ForemanMaintain::Procedure
3
+ metadata do
4
+ label :backup_enabled_repos
5
+ description 'Stores enabled repositories in yaml file'
6
+ end
7
+
8
+ def run
9
+ enabled_repos_ids = feature(:system_repos).enabled_repos_ids
10
+ unless enabled_repos_ids.empty?
11
+ backup_dir = File.expand_path(ForemanMaintain.config.backup_dir)
12
+ File.write(File.join(backup_dir, 'enabled_repos.yml'), enabled_repos_ids.to_yaml)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Procedures::Repositories
2
+ class Enable < ForemanMaintain::Procedure
3
+ metadata do
4
+ param :repos, 'List of repositories to enable'
5
+ description 'Enable repositories'
6
+ end
7
+ def run
8
+ with_spinner('Enabling repositories') do
9
+ feature(:system_repos).enable_repos(@repos)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,102 @@
1
+ module ForemanMaintain::Scenarios
2
+ class SelfUpgradeBase < ForemanMaintain::Scenario
3
+ def enabled_system_repos_id
4
+ feature(:system_repos).enabled_repos_ids
5
+ end
6
+
7
+ def enable_repos(repo_ids = stored_enabled_repos_ids)
8
+ add_step(Procedures::Repositories::Enable.new(repos: repo_ids))
9
+ end
10
+
11
+ def disable_repos(repo_ids = stored_enabled_repos_ids)
12
+ add_step(Procedures::Repositories::Disable.new(repos: repo_ids))
13
+ end
14
+
15
+ def target_version
16
+ @target_version ||= context.get(:target_version)
17
+ end
18
+
19
+ def current_version
20
+ feature(:instance).downstream.current_minor_version
21
+ end
22
+
23
+ def maintenance_repo_id(version)
24
+ if (repo = ENV['maintenance_repo'])
25
+ return repo unless repo.empty?
26
+ end
27
+
28
+ maintenance_repo(version)
29
+ end
30
+
31
+ def maintenance_repo(version)
32
+ if el7?
33
+ "rhel-#{el_major_version}-server-satellite-maintenance-#{version}-rpms"
34
+ else
35
+ "satellite-maintenance-#{version}-for-rhel-#{el_major_version}-x86_64-rpms"
36
+ end
37
+ end
38
+
39
+ def maintenance_repo_version
40
+ return '6' if current_version == '6.10'
41
+
42
+ current_version
43
+ end
44
+
45
+ def stored_enabled_repos_ids
46
+ @stored_enabled_repos_ids ||= begin
47
+ path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir)
48
+ @stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : []
49
+ end
50
+ end
51
+
52
+ def all_maintenance_repos
53
+ repo_regex = if el7?
54
+ /rhel-\d-server-satellite-maintenance-\d.\d-rpms/
55
+ else
56
+ /satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/
57
+ end
58
+ stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? }
59
+ end
60
+
61
+ def repos_ids_to_reenable
62
+ repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos
63
+ repos_ids_to_reenable << maintenance_repo(maintenance_repo_version)
64
+ end
65
+ end
66
+
67
+ class SelfUpgrade < SelfUpgradeBase
68
+ metadata do
69
+ label :self_upgrade_foreman_maintain
70
+ description "Enables the specified version's maintenance repository and,"\
71
+ "\nupdates the satellite-maintain packages"
72
+ manual_detection
73
+ end
74
+
75
+ def compose
76
+ if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
77
+ pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain]
78
+ add_step(Procedures::Repositories::BackupEnabledRepos.new)
79
+ disable_repos
80
+ add_step(Procedures::Repositories::Enable.new(repos: [maintenance_repo_id(target_version)]))
81
+ add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true))
82
+ enable_repos(repos_ids_to_reenable)
83
+ end
84
+ end
85
+ end
86
+
87
+ class SelfUpgradeRescue < SelfUpgradeBase
88
+ metadata do
89
+ label :rescue_self_upgrade
90
+ description 'Disables all version specific maintenance repositories and,'\
91
+ "\nenables the repositories which were configured prior to self upgrade"
92
+ manual_detection
93
+ run_strategy :fail_slow
94
+ end
95
+
96
+ def compose
97
+ if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
98
+ enable_repos(repos_ids_to_reenable)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,39 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ class SelfUpgradeCommand < Base
4
+ option ['--target-version'], 'TARGET_VERSION',\
5
+ 'Major version of the Satellite or Capsule'\
6
+ ', e.g 7.0', :required => true
7
+ def execute
8
+ allow_major_version_upgrade_only
9
+ run_scenario(upgrade_scenario, upgrade_rescue_scenario)
10
+ end
11
+
12
+ def upgrade_scenario
13
+ Scenarios::SelfUpgrade.new(target_version: target_version)
14
+ end
15
+
16
+ def upgrade_rescue_scenario
17
+ Scenarios::SelfUpgradeRescue.new(target_version: target_version)
18
+ end
19
+
20
+ def current_downstream_version
21
+ ForemanMaintain.detector.feature(:instance).downstream.current_version
22
+ end
23
+
24
+ def allow_major_version_upgrade_only
25
+ begin
26
+ next_version = Gem::Version.new(target_version)
27
+ rescue ArgumentError => err
28
+ raise Error::UsageError, "Invalid version! #{err}"
29
+ end
30
+ if current_downstream_version >= next_version
31
+ message = "The target-version #{target_version} should be "\
32
+ "greater than existing version #{current_downstream_version},"\
33
+ "\nand self-upgrade should be used for major version upgrades only!"
34
+ raise Error::UsageError, message
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,6 +11,7 @@ require 'foreman_maintain/cli/restore_command'
11
11
  require 'foreman_maintain/cli/maintenance_mode_command'
12
12
  require 'foreman_maintain/cli/packages_command'
13
13
  require 'foreman_maintain/cli/content_command'
14
+ require 'foreman_maintain/cli/self_upgrade_command'
14
15
 
15
16
  module ForemanMaintain
16
17
  module Cli
@@ -25,6 +26,7 @@ module ForemanMaintain
25
26
  subcommand 'packages', 'Lock/Unlock package protection, install, update', PackagesCommand
26
27
  subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
27
28
  subcommand 'content', 'Content related commands', ContentCommand
29
+ subcommand 'self-upgrade', 'Perform major version self upgrade', SelfUpgradeCommand
28
30
  subcommand 'maintenance-mode', 'Control maintenance-mode for application',
29
31
  MaintenanceModeCommand
30
32
  if ForemanMaintain.detector.feature(:satellite) &&
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.8.22'.freeze
2
+ VERSION = '0.8.25'.freeze
3
3
  end
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: 0.8.22
4
+ version: 0.8.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2022-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -274,7 +274,9 @@ files:
274
274
  - definitions/procedures/puppet/delete_empty_ca_cert_request_files.rb
275
275
  - definitions/procedures/refresh_features.rb
276
276
  - definitions/procedures/remote_execution/remove_existing_settingsd.rb
277
+ - definitions/procedures/repositories/backup_enabled_repos.rb
277
278
  - definitions/procedures/repositories/disable.rb
279
+ - definitions/procedures/repositories/enable.rb
278
280
  - definitions/procedures/repositories/setup.rb
279
281
  - definitions/procedures/restore/candlepin_dump.rb
280
282
  - definitions/procedures/restore/configs.rb
@@ -307,6 +309,7 @@ files:
307
309
  - definitions/scenarios/packages.rb
308
310
  - definitions/scenarios/prep_6_10_upgrade.rb
309
311
  - definitions/scenarios/restore.rb
312
+ - definitions/scenarios/self_upgrade.rb
310
313
  - definitions/scenarios/services.rb
311
314
  - definitions/scenarios/upgrade_to_capsule_6_10.rb
312
315
  - definitions/scenarios/upgrade_to_capsule_6_10_z.rb
@@ -354,6 +357,7 @@ files:
354
357
  - lib/foreman_maintain/cli/maintenance_mode_command.rb
355
358
  - lib/foreman_maintain/cli/packages_command.rb
356
359
  - lib/foreman_maintain/cli/restore_command.rb
360
+ - lib/foreman_maintain/cli/self_upgrade_command.rb
357
361
  - lib/foreman_maintain/cli/service_command.rb
358
362
  - lib/foreman_maintain/cli/transform_clamp_options.rb
359
363
  - lib/foreman_maintain/cli/upgrade_command.rb