Skip to content

Commit

Permalink
Merge pull request ManageIQ#22716 from agrare/add_shared_examples_ext…
Browse files Browse the repository at this point in the history
…_management_system_pause_resume

Add shared examples for EMS#pause! and #resume!
  • Loading branch information
Fryguy authored Sep 28, 2023
2 parents 909b5de + fca621e commit 9e4b2e3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 139 deletions.
139 changes: 0 additions & 139 deletions spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,145 +501,6 @@
end
end

context "#pause!" do
before do
Zone.seed
end

it 'disables an ems with child managers and moves them to maintenance zone' do
zone = FactoryBot.create(:zone)
ems = FactoryBot.create(:ext_management_system, :zone => zone)
child = FactoryBot.create(:ext_management_system, :zone => zone)
ems.child_managers << child

2.times do
ems.pause!

expect(ems.enabled).to eq(false)
expect(ems.zone).to eq(Zone.maintenance_zone)
expect(ems.zone_before_pause).to eq(zone)

child.reload
expect(child.enabled).to eq(false)
expect(child.zone).to eq(Zone.maintenance_zone)
expect(child.zone_before_pause).to eq(zone)
end
end

it 'disables an ems and moves child managers created by ensure_managers() to maintenance zone' do
zone = FactoryBot.create(:zone)
emses = {
:amazon_cloud => FactoryBot.create(:ems_amazon, :zone => zone),
:azure_cloud => FactoryBot.create(:ems_azure, :zone => zone),
:google_cloud => FactoryBot.create(:ems_google, :zone => zone),
:openstack_cloud => FactoryBot.create(:ems_openstack, :zone => zone),
:openstack_infra => FactoryBot.create(:ems_openstack_infra, :zone => zone),
:vmware_cloud => FactoryBot.create(:ems_vmware_cloud, :zone => zone),
:vpc_cloud => FactoryBot.create(:ems_ibm_cloud_vpc, :zone => zone)
}

2.times do
# managers with child managers created with ensure_managers() callback has own callback to change zone
# so it should be tested separately
emses.each_value do |manager|
manager.pause!

manager.reload
expect(manager.network_manager.enabled).to be_falsey
expect(manager.network_manager.zone_before_pause).to eq(zone)
expect(manager.network_manager.zone).to eq(Zone.maintenance_zone)
end

# The same for storage managers, i.e. amazon
%i[amazon_cloud openstack_cloud].each do |manager_type|
emses[manager_type].storage_managers.each do |storage_manager|
expect(storage_manager.enabled).to be_falsey
expect(storage_manager.zone_before_pause).to eq(zone)
expect(storage_manager.zone).to eq(Zone.maintenance_zone)
end
end
end
end
end

context "#resume" do
before do
Zone.seed
end

it "enables an ems with child managers and move them from maintenance zone" do
zone = FactoryBot.create(:zone)
ems = FactoryBot.create(:ext_management_system,
:zone_before_pause => zone,
:zone => Zone.maintenance_zone,
:enabled => false)

child = FactoryBot.create(:ext_management_system,
:zone_before_pause => zone,
:zone => Zone.maintenance_zone,
:enabled => false)
ems.child_managers << child

ems.resume!

expect(ems.enabled).to eq(true)
expect(ems.zone).to eq(zone)
expect(ems.zone_before_pause).to be_nil

child.reload
expect(child.enabled).to eq(true)
expect(child.zone).to eq(zone)
expect(child.zone_before_pause).to be_nil
end

it "doesn't change zone when ems was disabled before" do
zone = FactoryBot.create(:zone)
ems = FactoryBot.create(:ext_management_system,
:zone_before_pause => nil,
:zone => zone,
:enabled => false)

ems.resume!

expect(ems.enabled).to eq(true)
expect(ems.zone).to eq(zone)
end

it 'enables an ems and moves child managers created by ensure_managers() to original zone' do
zone = FactoryBot.create(:zone)
# Cannot create paused child managers this way, so we first pause! (tested yet) and then resume!
emses = {
:amazon_cloud => FactoryBot.create(:ems_amazon, :zone => zone),
:azure_cloud => FactoryBot.create(:ems_azure, :zone => zone),
:google_cloud => FactoryBot.create(:ems_google, :zone => zone),
:openstack_cloud => FactoryBot.create(:ems_openstack, :zone => zone),
:openstack_infra => FactoryBot.create(:ems_openstack_infra, :zone => zone),
:vmware_cloud => FactoryBot.create(:ems_vmware_cloud, :zone => zone),
}

# managers with child managers created with ensure_managers() callback has own callback to change zone
# so it should be tested separately
emses.each_value do |manager|
manager.pause!
manager.reload

manager.resume!
manager.reload

expect(manager.network_manager.zone_before_pause).to be_nil
expect(manager.network_manager.zone).to eq(zone)
end

# The same for storage managers, i.e. amazon
%i(amazon_cloud openstack_cloud).each do |manager_type|
emses[manager_type].storage_managers.each do |storage_manager|
expect(storage_manager.zone_before_pause).to be_nil
expect(storage_manager.zone).to eq(zone)
end
end
end
end

describe "#class_by_ems" do
it 'returns a concrete target subclass for a concrete EMS' do
ems = FactoryBot.create(:ems_openstack)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
shared_examples_for "ExtManagementSystem#pause!" do
before { Zone.seed }

it "disables the manager and moves it to the maintenance zone" do
ems.pause!

ems.reload

expect(ems.enabled).to eq(false)
expect(ems.zone).to eq(Zone.maintenance_zone)
expect(ems.zone_before_pause).to eq(zone)
end

it "disables all child managers and moves them to the maintenance zone" do
ems.pause!

ems.reload

ems.child_managers.each do |child_manager|
expect(child_manager.enabled).to eq(false)
expect(child_manager.zone).to eq(Zone.maintenance_zone)
expect(child_manager.zone_before_pause).to eq(zone)
end
end
end

shared_examples_for "ExtManagementSystem#resume!" do
before { Zone.seed }

it "resumes the manager and moves it to the original zone" do
ems.pause!
ems.reload
ems.resume!
ems.reload

expect(ems.enabled).to eq(true)
expect(ems.zone).to eq(zone)
expect(ems.zone_before_pause).to be_nil
end
end

0 comments on commit 9e4b2e3

Please sign in to comment.