diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index 6e85d2a898a..f063c05d574 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -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) diff --git a/spec/support/examples_group/shared_examples_for_ext_management_system.rb b/spec/support/examples_group/shared_examples_for_ext_management_system.rb new file mode 100644 index 00000000000..326dfe28104 --- /dev/null +++ b/spec/support/examples_group/shared_examples_for_ext_management_system.rb @@ -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