From e28c0e217700dc1184f43527c10f5b46c9a2a06b Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 22 Feb 2024 13:52:09 +0100 Subject: [PATCH] only run module stuff on el8 --- definitions/scenarios/upgrade_to_capsule_6_16.rb | 6 ++++-- definitions/scenarios/upgrade_to_capsule_6_16_z.rb | 6 ++++-- .../scenarios/upgrade_to_foreman_nightly.rb | 2 +- .../scenarios/upgrade_to_katello_nightly.rb | 6 ++++-- definitions/scenarios/upgrade_to_satellite_6_16.rb | 6 ++++-- .../scenarios/upgrade_to_satellite_6_16_z.rb | 6 ++++-- lib/foreman_maintain.rb | 2 +- lib/foreman_maintain/concerns/os_facts.rb | 4 ++++ test/lib/foreman_maintain_test.rb | 14 +++++++++++++- 9 files changed, 39 insertions(+), 13 deletions(-) diff --git a/definitions/scenarios/upgrade_to_capsule_6_16.rb b/definitions/scenarios/upgrade_to_capsule_6_16.rb index d5e4fc494..025f167d1 100644 --- a/definitions/scenarios/upgrade_to_capsule_6_16.rb +++ b/definitions/scenarios/upgrade_to_capsule_6_16.rb @@ -39,8 +39,10 @@ class PreMigrations < Abstract def compose add_step(Procedures::Repositories::Setup.new(:version => '6.16')) - modules_to_enable = ["satellite-capsule:#{el_short_name}"] - add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + if el8? + modules_to_enable = ["satellite-capsule:#{el_short_name}"] + add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + end add_step(Procedures::Packages::Update.new( :assumeyes => true, :dnf_options => ['--downloadonly'] diff --git a/definitions/scenarios/upgrade_to_capsule_6_16_z.rb b/definitions/scenarios/upgrade_to_capsule_6_16_z.rb index 7eed5ff7f..41ea9b8ec 100644 --- a/definitions/scenarios/upgrade_to_capsule_6_16_z.rb +++ b/definitions/scenarios/upgrade_to_capsule_6_16_z.rb @@ -39,8 +39,10 @@ class PreMigrations < Abstract def compose add_step(Procedures::Repositories::Setup.new(:version => '6.16')) - modules_to_enable = ["satellite-capsule:#{el_short_name}"] - add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + if el8? + modules_to_enable = ["satellite-capsule:#{el_short_name}"] + add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + end add_step(Procedures::Packages::Update.new( :assumeyes => true, :dnf_options => ['--downloadonly'] diff --git a/definitions/scenarios/upgrade_to_foreman_nightly.rb b/definitions/scenarios/upgrade_to_foreman_nightly.rb index 7d30aaf5c..7942768b7 100644 --- a/definitions/scenarios/upgrade_to_foreman_nightly.rb +++ b/definitions/scenarios/upgrade_to_foreman_nightly.rb @@ -52,7 +52,7 @@ def set_context_mapping def compose add_step(Procedures::Repositories::Setup.new(:version => 'nightly')) - if el? + if el8? modules_to_enable = ["foreman:#{el_short_name}"] add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) end diff --git a/definitions/scenarios/upgrade_to_katello_nightly.rb b/definitions/scenarios/upgrade_to_katello_nightly.rb index 594a48b17..5c8d7c6f3 100644 --- a/definitions/scenarios/upgrade_to_katello_nightly.rb +++ b/definitions/scenarios/upgrade_to_katello_nightly.rb @@ -52,8 +52,10 @@ def set_context_mapping def compose add_step(Procedures::Repositories::Setup.new(:version => 'nightly')) - modules_to_enable = ["katello:#{el_short_name}", "pulpcore:#{el_short_name}"] - add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + if el8? + modules_to_enable = ["katello:#{el_short_name}", "pulpcore:#{el_short_name}"] + add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + end add_step(Procedures::Packages::Update.new( :assumeyes => true, :dnf_options => ['--downloadonly'] diff --git a/definitions/scenarios/upgrade_to_satellite_6_16.rb b/definitions/scenarios/upgrade_to_satellite_6_16.rb index 879d91e9f..fbf2b3487 100644 --- a/definitions/scenarios/upgrade_to_satellite_6_16.rb +++ b/definitions/scenarios/upgrade_to_satellite_6_16.rb @@ -39,8 +39,10 @@ class PreMigrations < Abstract def compose add_step(Procedures::Repositories::Setup.new(:version => '6.16')) - modules_to_enable = ["satellite:#{el_short_name}"] - add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + if el8? + modules_to_enable = ["satellite:#{el_short_name}"] + add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + end add_step(Procedures::Packages::Update.new( :assumeyes => true, :dnf_options => ['--downloadonly'] diff --git a/definitions/scenarios/upgrade_to_satellite_6_16_z.rb b/definitions/scenarios/upgrade_to_satellite_6_16_z.rb index 9c8e060f2..42fdb6306 100644 --- a/definitions/scenarios/upgrade_to_satellite_6_16_z.rb +++ b/definitions/scenarios/upgrade_to_satellite_6_16_z.rb @@ -39,8 +39,10 @@ class PreMigrations < Abstract def compose add_step(Procedures::Repositories::Setup.new(:version => '6.16')) - modules_to_enable = ["satellite:#{el_short_name}"] - add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + if el8? + modules_to_enable = ["satellite:#{el_short_name}"] + add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable)) + end add_step(Procedures::Packages::Update.new( :assumeyes => true, :dnf_options => ['--downloadonly'] diff --git a/lib/foreman_maintain.rb b/lib/foreman_maintain.rb index 779f7679e..f941b2c0e 100644 --- a/lib/foreman_maintain.rb +++ b/lib/foreman_maintain.rb @@ -193,7 +193,7 @@ def perform_self_upgrade end def enable_maintenance_module - return unless el? + return unless el8? maintenance_module = 'satellite-maintenance:el8' package_manager = ForemanMaintain.package_manager diff --git a/lib/foreman_maintain/concerns/os_facts.rb b/lib/foreman_maintain/concerns/os_facts.rb index 17ea462da..0e2106c60 100644 --- a/lib/foreman_maintain/concerns/os_facts.rb +++ b/lib/foreman_maintain/concerns/os_facts.rb @@ -54,6 +54,10 @@ def el? File.exist?('/etc/redhat-release') end + def el8? + el_major_version == 8 + end + def debian? os_id == 'debian' end diff --git a/test/lib/foreman_maintain_test.rb b/test/lib/foreman_maintain_test.rb index b36a7cced..01e7eb2d5 100644 --- a/test/lib/foreman_maintain_test.rb +++ b/test/lib/foreman_maintain_test.rb @@ -30,7 +30,7 @@ describe 'enable_maintenance_module' do before do - subject.stubs(:el?).returns(true) + subject.stubs(:el8?).returns(true) end let(:package_manager) { ForemanMaintain::PackageManager::Dnf } @@ -66,6 +66,18 @@ subject.enable_maintenance_module end end + + it 'should not enable the maintenance module on el9' do + subject.stubs(:el8?).returns(false) + package_manager.any_instance.stubs(:module_exists?).returns(false) + package_manager.any_instance.stubs(:module_enabled?).returns(false) + + package_manager.any_instance.expects(:enable_module).with('satellite-maintenance:el8').never + + assert_output('') do + subject.enable_maintenance_module + end + end end describe '#main_package_name' do