Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed provider zone when EMS paused/resumed #155

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager
:with_provider_connection,
:to => :provider

def self.included(klass)
klass.after_save :change_maintenance_for_provider, :if => proc { |ems| ems.enabled_changed? }
end

module ClassMethods
private

Expand All @@ -22,4 +26,11 @@ def connection_source(options = {})
def image_name
"ansible"
end

def change_maintenance_for_provider
if provider.present? && zone_id_changed?
provider.zone_id = zone_id
provider.save
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def default_api_path
def ensure_managers
build_automation_manager unless automation_manager
automation_manager.name = _("%{name} Automation Manager") % {:name => name}
automation_manager.zone_id = zone_id
automation_manager.zone_id = zone_id if zone_id_changed?
end
end
37 changes: 37 additions & 0 deletions spec/support/ansible_shared/automation_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,41 @@
ansible_automation_manager.connect
end
end

context "#pause!, #resume!" do
before do
MiqRegion.seed
Zone.seed
end

it "moves provider to maintenance_zone when paused" do
provider = FactoryBot.create(:provider, :zone => Zone.default_zone)
ems = FactoryBot.create(:automation_manager_ansible_tower,
:provider => provider,
:zone => Zone.default_zone)

ems.pause!
provider.reload

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

it "moves provider from maintenance_zone when resumed" do
provider = FactoryBot.create(:provider, :zone => Zone.maintenance_zone)
ems = FactoryBot.create(:automation_manager_ansible_tower,
:enabled => false,
:provider => provider,
:zone => Zone.maintenance_zone,
:zone_before_pause => Zone.default_zone)

ems.resume!
provider.reload

expect(ems.enabled).to eq(true)
expect(ems.zone).to eq(Zone.default_zone)
expect(provider.zone).to eq(Zone.default_zone)
end
end
end