Skip to content

Commit

Permalink
Add zone to q_options in call_automate.
Browse files Browse the repository at this point in the history
Separate Manageiq change to pass zone_name required.

https://bugzilla.redhat.com/show_bug.cgi?id=1447625
  • Loading branch information
tinaafitz committed May 8, 2017
1 parent 854ca51 commit db48545
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/miq_automation_engine/engine/miq_ae_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def self.call_automate(obj, attrs, instance_name, options = {})
raise "A user is needed to raise #{instance_name} to automate. [#{obj.class.name}] id:[#{obj.id}]" unless user

q_options = {
:zone => Zone.determine_queue_zone(options),
:miq_callback => options[:miq_callback],
:priority => MiqQueue::HIGH_PRIORITY,
:task_id => nil # Clear task_id to allow running synchronously under current worker process
Expand Down
4 changes: 3 additions & 1 deletion spec/miq_ae_discovery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

it "properly processes MiqAeEvent.raise_ems_event" do
expect(MiqAeEngine).to receive(:deliver_queue)
expect(MiqServer).to receive(:my_zone).and_return('default')
MiqAeEvent.raise_ems_event(@event)
end

Expand All @@ -39,7 +40,8 @@
:automate_message => nil}

expect(MiqAeEngine).to receive(:deliver_queue).with(args, anything)
MiqAeEvent.raise_ems_event(@event)
expect(MiqServer).to receive(:my_zone).and_return('default')
MiqAeEvent.raise_ems_event(@event)
end
end

Expand Down
52 changes: 45 additions & 7 deletions spec/miq_ae_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,46 @@
)
end

context "with user owned VM" do
let(:vm_owner) { user }
before { allow(MiqServer).to receive_messages(:my_zone => "default") }

it "has tenant" do
args = {:miq_group_id => group.id, :tenant_id => tenant.id, :user_id => user.id}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
shared_examples_for "#zone check for raise_evm_event" do
let(:vm_owner) { user }
let(:miq_server) { EvmSpecHelper.local_miq_server(:is_master => true) }
let(:args) do
{ :miq_group_id => group.id, :tenant_id => tenant.id, :user_id => user.id}
end
let(:inputs) do
{:vm => vm}
end
it "runs successfully" do
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), hash_including(:zone => zone_name))
MiqAeEvent.raise_evm_event("vm_create", vm, inputs, options)
end
end

MiqAeEvent.raise_evm_event("vm_create", vm, :vm => vm)
context "with zone" do
let(:zone) { FactoryGirl.create(:zone) }
let(:zone_name) { zone.name }
let(:options) do
{:zone => zone.name}
end
it_behaves_like "#zone check for raise_evm_event"
end

context "nil zone" do
let(:zone_name) { nil }
let(:options) do
{:zone => nil}
end
it_behaves_like "#zone check for raise_evm_event"
end

context "nil options" do
let(:zone_name) { 'default' }
let(:options) do
{}
end
it_behaves_like "#zone check for raise_evm_event"
end

context "with group owned VM" do
Expand All @@ -80,7 +111,7 @@
it "has tenant" do
args = {:user_id => admin.id, :miq_group_id => vm_group.id, :tenant_id => vm_group.tenant.id}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)

expect(MiqServer).to receive(:my_zone).and_return('default')
MiqAeEvent.raise_evm_event("vm_create", vm, :vm => vm)
end
end
Expand All @@ -95,6 +126,7 @@
:tenant_id => ems.tenant.id
}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("host_provisioned", host, :host => host)
end
Expand All @@ -108,6 +140,7 @@
:tenant_id => Tenant.root_tenant.id
}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("host_provisioned", host, :host => host)
end
Expand Down Expand Up @@ -136,6 +169,7 @@
:tenant_id => ems.tenant.id
}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("request_storage_scan", storage)
end
Expand All @@ -149,6 +183,7 @@
:tenant_id => user.current_tenant.id
}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("request_approved", request)
end
Expand All @@ -165,6 +200,7 @@
it "has tenant" do
args = {:miq_group_id => group.id, :tenant_id => tenant.id, :user_id => user.id}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("service_started", service)
end
Expand All @@ -176,6 +212,7 @@
it "has tenant" do
args = {:user_id => admin.id, :miq_group_id => service_group.id, :tenant_id => service_group.tenant.id}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')

MiqAeEvent.raise_evm_event("service_started", service)
end
Expand Down Expand Up @@ -206,6 +243,7 @@
},
}
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), anything)
expect(MiqServer).to receive(:my_zone).and_return('default')
MiqEvent.raise_evm_event(host, "host_add_to_cluster", :ems_cluster => ems_cluster, :host => host)
end
end
Expand Down

0 comments on commit db48545

Please sign in to comment.