-
Notifications
You must be signed in to change notification settings - Fork 74
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
Move create_service_provision_request into MiqAeServiceMethods for consistency #34
Conversation
…n_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb
@fdupont-redhat Thanks for the PR and for referencing the BZ. A few quick comments.
In this case I would say the description you provided in the git issue should really be the description of this PR. Again, I updated the description to reflect that.
I still need to look into failing tests. |
@gmcculloug Thanks for these advices. |
Create a PR in the content repo and in the title and description you should include the dependency. Here is an example of the title: ManageIQ/manageiq#13049 Once the new PR is created I also like to update the description in this PR for easy reference. |
expect(svc_template).to receive(:instance_variable_get).with('@object').and_return(template) | ||
expect(template).to receive(:provision_request).with(user, svc_options).and_return(miq_request) | ||
|
||
result = miq_ae_service.execute(:create_service_provision_reques, svc_template, svc_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat
Is this missing a 't' create_service_provision_request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @mkanoor. Any thoughts on why the test is failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor, aka. Hawk Eye ;)
I corrected it. It seems the problem comes from the fact that MiqAeMethodService class is not know in this context. I also tried to change the test to:
it "#create_service_provision_request" do
options = {:fred => :flinstone}
svc_options = {:dialog_style => "medium"}
template = FactoryGirl.create(:service_template_ansible_playbook)
miq_request = FactoryGirl.create(:service_template_provision_request)
svc_template = MiqAeMethodService::MiqAeServiceServiceTemplate.find(template.id)
workspace = double("MiqAeEngine::MiqAeWorkspaceRuntime", :root => options, :persist_state_hash => {}, :ae_user => @user)
#miq_ae_service = MiqAeMethodService.new(workspace)
allow(workspace).to receive(:disable_rbac)
expect(svc_template).to receive(:instance_variable_get).with('@object').and_return(template)
expect(template).to receive(:service_provision_request).with(@user, svc_options).and_return(miq_request)
result = invoke_ae.execute(:create_service_provision_request, svc_template.inspect, svc_options.inspect)
expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest)
end
But invoke_ae doesn't really give $evm
object and tells me
undefined method `execute' for #<MiqAeEngine::MiqAeWorkspaceRuntime:0x0000000e3db518>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is probably why there is no test for create_automation_request
and create_provision_request
. Should we move these methods to lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb
? That would also be consistent with $evm.create_notification
. And it would be easier to write tests. The drawback is that it would probably require more changes to manageiq-content
repository.
What do you think @gmcculloug, @mkanoor ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should get things moving for the test:
it "create service request" do
allow(workspace).to receive(:disable_rbac)
expect_any_instance_of(ServiceTemplate).to receive(:provision_request).with(user, svc_options).and_return(miq_request)
result = miq_ae_service.execute(:create_service_provision_request, svc_template, svc_options)
expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat A few updates to get the code working. I did not get time to spend on the test yet. Hopefully can get there in the next day or two.
:persist_state_hash => {}, | ||
:ae_user => user) | ||
end | ||
let(:miq_ae_service) { MiqAeService.new(workspace) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add the namespace to the class:
let(:miq_ae_service) { MiqAeMethodService::MiqAeService.new(workspace) }
def self.create_service_provision_request(svc_template, options = nil) | ||
result = ar_object(svc_template).provision_request(@workspace.ae_user, options) | ||
MiqAeServiceModelBase.wrap_results(result) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method has to change a bit more now that it is running under a different class. Since we do not have access to @workspace
we can get the user from the User.current_user
set but the calling method execute
here.
def self.create_service_provision_request(svc_template, options = nil)
result = svc_template.object_send(:provision_request, User.current_user, options)
MiqAeServiceModelBase.wrap_results(result)
end
…der_ansible_playbook.rb and associated spec to match ManageIQ/manageiq-automation_engine#34
@gmcculloug you rock! |
@fdupont-redhat Let's make one last change to avoid the rubocop warning about using I used that call initially because the service model loads it's own copy of the To avoid using Here is my diff that changes the test to use the same instance of service_template: - expect_any_instance_of(ServiceTemplate).to receive(:provision_request).with(user, svc_options).and_return(miq_request)
+ allow(ServiceTemplate).to receive(:find).with(template.id).and_return(template)
+ expect(template).to receive(:provision_request).with(user, svc_options).and_return(miq_request) |
Checked commits fabiendupont/manageiq-automation_engine@f81a347~...2fd5605 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor Can you give this a final review. Thanks.
@gmcculloug @fdupont-redhat 👍 |
Fine backport (to manageiq repo) details:
|
Fixes #33
https://bugzilla.redhat.com/show_bug.cgi?id=1457754
Related to:
ManageIQ/manageiq-content#126