Skip to content

Commit

Permalink
Merge pull request ManageIQ#15760 from lfu/service_user_in_groups_146…
Browse files Browse the repository at this point in the history
…7364_2

miq_group_id is required by automate.
(cherry picked from commit 2fe7cd5)

https://bugzilla.redhat.com/show_bug.cgi?id=1480007
  • Loading branch information
gmcculloug authored and d-m-u committed Jun 6, 2018
1 parent 6bf6c4e commit d6a6395
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/models/automation_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def do_request
args[:class_name] = options[:class_name]
args[:instance_name] = options[:instance_name]
args[:user_id] = options[:user_id]
args[:miq_group_id] = options[:miq_group_id] || User.find(options[:user_id]).current_group.id
args[:tenant_id] = options[:tenant_id] || User.find(options[:user_id]).current_tenant.id
args[:automate_message] = options[:message]

MiqAeEngine.deliver(args)
Expand Down
15 changes: 10 additions & 5 deletions spec/models/automation_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
describe AutomationTask do
before(:each) do
allow(MiqServer).to receive(:my_zone).and_return("default")
admin = FactoryGirl.create(:user_admin)
@admin = FactoryGirl.create(:user_admin)

@ae_instance = "IIII"
@ae_message = "MMMM"
@ae_var1 = "vvvv"
@ae_var2 = "wwww"
@ae_var3 = "xxxx"

@attrs = {:var1 => @ae_var1, :var2 => @ae_var2, :var3 => @ae_var3, :userid => admin.userid}
@options = {:attrs => @attrs, :instance => @instance, :message => @message, :user_id => admin.id, :delivered_on => Time.now.utc.to_s}
@at = FactoryGirl.create(:automation_task, :state => 'pending', :status => 'Ok', :userid => admin.userid, :options => @options)
@attrs = {:var1 => @ae_var1, :var2 => @ae_var2, :var3 => @ae_var3, :userid => @admin.userid}
@options = {:attrs => @attrs, :instance => @instance, :message => @message, :user_id => @admin.id, :delivered_on => Time.now.utc.to_s}
@at = FactoryGirl.create(:automation_task, :state => 'pending', :status => 'Ok', :userid => @admin.userid, :options => @options)
@ar = FactoryGirl.create(:automation_request)
@ar.automation_tasks << @at
@ar.save!
end

it "#execute" do
expect(MiqAeEngine).to receive(:deliver).once
options = {
:user_id => @admin.id,
:miq_group_id => @admin.current_group.id,
:tenant_id => @admin.current_tenant.id
}
expect(MiqAeEngine).to receive(:deliver).with(hash_including(options)).once
@at.execute
expect(@ar.reload.message).to eq("#{AutomationRequest::TASK_DESCRIPTION} initiated")
end
Expand Down

0 comments on commit d6a6395

Please sign in to comment.