Skip to content

Commit

Permalink
Merge pull request #155 from slemrmartin/edit-suspended-provider
Browse files Browse the repository at this point in the history
Changed provider zone when EMS paused/resumed
  • Loading branch information
agrare authored Feb 19, 2019
2 parents c6b0b46 + 329999d commit 6fb2cc1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
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

0 comments on commit 6fb2cc1

Please sign in to comment.