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

Change the role for Service provisioning create_request_tasks MiqQueue.put. #17297

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
2 changes: 1 addition & 1 deletion app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def execute
:instance_id => id,
:method_name => "create_request_tasks",
:zone => options.fetch(:miq_zone, my_zone),
:role => my_role,
:role => kind_of?(ServiceTemplateProvisionRequest) ? 'automate' : my_role,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The my_role method is used so sub-classes can override it, like you point out in the description for AutomationRequest. This value should be changed in the my_role method in the ServiceTemplateProvisionRequest model here app/models/service_template_provision_request.rb#L36-L38

Then you do not need this change to the base miq_request model.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug I specifically changed it that way because I want to limit the change to only the create_request_tasks call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be clearer if the my_role method took a parameter and the model could then determine the proper response. The refactoring would effect several files so I am ok with doing that as a follow to this PR to this.

@tinaafitz @mkanoor Any thoughts on this approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug I'll look into it and we could discuss. I would prefer we do work as a follow up.

:tracking_label => tracking_label_id,
:msg_timeout => 3600,
:deliver_on => deliver_on
Expand Down
32 changes: 32 additions & 0 deletions spec/models/miq_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,38 @@ def approvals
end
end

context '#execute' do
shared_examples_for "#calls create_request_tasks with the proper role" do
it "runs successfully" do
expect(request).to receive(:approved?).and_return(true)
expect(MiqQueue.count).to eq(0)

request.execute
expect(MiqQueue.count).to eq(1)
expect(MiqQueue.first.role).to eq(role)
end
end

context 'Service provisioning' do
let(:request) { FactoryGirl.create(:service_template_provision_request, :approval_state => 'approved', :requester => fred) }
let(:role) { 'automate' }

context "uses the automate role" do
it_behaves_like "#calls create_request_tasks with the proper role"
end
end

context 'VM provisioning' do
let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication)) }
let(:request) { FactoryGirl.build(:miq_provision_request, :requester => fred, :src_vm_id => template.id).tap(&:valid?) }
let(:role) { 'ems_operations' }

context "uses the ems_operations role" do
it_behaves_like "#calls create_request_tasks with the proper role"
end
end
end

context '#post_create_request_tasks' do
context 'VM provisioning' do
before do
Expand Down