From 0e66f9f8490cb957ff8c487a8e8563942cf4b43b Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Tue, 10 Mar 2020 09:38:41 -0400 Subject: [PATCH 1/3] Add initial specs for ensure_manager. --- .../manageiq/providers/embedded_ansible/provider_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 65b0a5333e9..2db5b516f14 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -68,4 +68,11 @@ expect(Hardware.count).to eq(0) end end + + context "ensure_managers callback" do + it "automatically creates an automation manager if none is provided" do + provider = FactoryBot.create(:provider_embedded_ansible) + expect(provider.automation_manager).to be_kind_of(ManageIQ::Providers::EmbeddedAnsible::AutomationManager) + end + end end From 5c9be160f538f1ac60547b38eabb59a8355e6189 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Tue, 10 Mar 2020 09:57:10 -0400 Subject: [PATCH 2/3] Allow embedded ansible to be created in maintenance zone. --- .../providers/embedded_ansible/provider.rb | 5 ++++- .../providers/embedded_ansible/provider_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/embedded_ansible/provider.rb b/app/models/manageiq/providers/embedded_ansible/provider.rb index 6c90c40f6ca..4380ef768e3 100644 --- a/app/models/manageiq/providers/embedded_ansible/provider.rb +++ b/app/models/manageiq/providers/embedded_ansible/provider.rb @@ -14,6 +14,9 @@ class ManageIQ::Providers::EmbeddedAnsible::Provider < ::Provider def ensure_managers build_automation_manager unless automation_manager automation_manager.name = _("%{name} Automation Manager") % {:name => name} - automation_manager.zone_id = zone_id if zone_id_changed? + if zone_id_changed? + automation_manager.enabled = Zone.maintenance_zone&.id != zone_id + automation_manager.zone_id = zone_id + end end end diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 2db5b516f14..9f4fba9fd10 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -70,9 +70,25 @@ end context "ensure_managers callback" do + before do + EvmSpecHelper.local_miq_server(:is_master => true, :zone => Zone.seed) + end + it "automatically creates an automation manager if none is provided" do provider = FactoryBot.create(:provider_embedded_ansible) expect(provider.automation_manager).to be_kind_of(ManageIQ::Providers::EmbeddedAnsible::AutomationManager) end + + it "sets the automation manager to disabled if created in the maintenance zone" do + provider = FactoryBot.create(:provider_embedded_ansible, :zone => Zone.maintenance_zone) + expect(provider.automation_manager.enabled).to eql(false) + expect(provider.automation_manager.zone).to eql(Zone.maintenance_zone) + end + + it "sets the automation manager to enabled if not created in the maintenance zone" do + provider = FactoryBot.create(:provider_embedded_ansible, :zone => Zone.default_zone) + expect(provider.automation_manager.enabled).to eql(true) + expect(provider.automation_manager.zone).to eql(Zone.default_zone) + end end end From 092e45510da4f602531182c0e56b2b8d0d74f613 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Tue, 10 Mar 2020 12:16:15 -0400 Subject: [PATCH 3/3] Seed zones properly. --- .../manageiq/providers/embedded_ansible/provider_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 9f4fba9fd10..42db9d32db8 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -4,6 +4,8 @@ let(:miq_server) { FactoryBot.create(:miq_server) } before do + MiqRegion.seed + Zone.seed EvmSpecHelper.assign_embedded_ansible_role(miq_server) end @@ -70,10 +72,6 @@ end context "ensure_managers callback" do - before do - EvmSpecHelper.local_miq_server(:is_master => true, :zone => Zone.seed) - end - it "automatically creates an automation manager if none is provided" do provider = FactoryBot.create(:provider_embedded_ansible) expect(provider.automation_manager).to be_kind_of(ManageIQ::Providers::EmbeddedAnsible::AutomationManager)