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 9, 2017
1 parent 854ca51 commit 19ddbd6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 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 @@ -125,6 +125,7 @@ def self.call_automate(obj, attrs, instance_name, options = {})
:priority => MiqQueue::HIGH_PRIORITY,
:task_id => nil # Clear task_id to allow running synchronously under current worker process
}
q_options[:zone] = options[:zone] if options[:zone].present?

args = {
:object_type => obj.class.name,
Expand Down
2 changes: 1 addition & 1 deletion spec/miq_ae_discovery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
:automate_message => nil}

expect(MiqAeEngine).to receive(:deliver_queue).with(args, anything)
MiqAeEvent.raise_ems_event(@event)
MiqAeEvent.raise_ems_event(@event)
end
end

Expand Down
56 changes: 48 additions & 8 deletions spec/miq_ae_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
:vm_or_template_id => vm.id
)
end
before { allow(MiqServer).to receive_messages(:my_zone => "zone test") }

context "with user owned VM" do
let(:vm_owner) { user }
Expand Down Expand Up @@ -63,24 +62,65 @@
)
end

context "with user owned VM" do
let(:vm_owner) { user }
shared_context "variables" 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
end

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 "#pass zone to raise_evm_event" do
include_context "variables"

MiqAeEvent.raise_evm_event("vm_create", vm, :vm => vm)
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

shared_examples_for "#zone not passed to raise_evm_event" do
include_context "variables"

it "runs successfully" do
expect(MiqAeEngine).to receive(:deliver_queue).with(hash_including(args), hash_excluding(:zone))
MiqAeEvent.raise_evm_event("vm_create", vm, inputs, options)
end
end

context "with zone" do
let(:zone) { FactoryGirl.create(:zone) }
let(:zone_name) { zone.name }
let(:options) do
{:zone => zone.name}
end
it_behaves_like "#pass zone to raise_evm_event"
end

context "nil zone" do
let(:zone_name) { nil }
let(:options) do
{:zone => nil}
end
end

context "nil options" do
let(:zone_name) { 'default' }
let(:options) do
{}
end
it_behaves_like "#zone not passed to raise_evm_event"
end

context "with group owned VM" do
let(:vm_group) { FactoryGirl.create(:miq_group, :tenant => FactoryGirl.create(:tenant)) }

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)

MiqAeEvent.raise_evm_event("vm_create", vm, :vm => vm)
end
end
Expand Down

0 comments on commit 19ddbd6

Please sign in to comment.