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

Move create_service_provision_request into MiqAeServiceMethods for consistency #34

Merged
merged 3 commits into from Jun 12, 2017
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jun 2, 2017

…n_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb
@miq-bot miq-bot added the wip label Jun 2, 2017
@gmcculloug gmcculloug requested a review from mkanoor June 2, 2017 12:25
@gmcculloug gmcculloug self-assigned this Jun 2, 2017
@gmcculloug
Copy link
Member

@fdupont-redhat Thanks for the PR and for referencing the BZ.

A few quick comments.

  • There is no need to create a git issue to link the PR to, a PR is essentially a git issue so you are just duplicating your efforts.
  • If you do have a git issue using Fixes #nn will automatically close the issue when the PR is merged. (I updated the description.)

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.

@ghost
Copy link
Author

ghost commented Jun 2, 2017

@gmcculloug Thanks for these advices.
For the file to modify in manageiq-content, how do you handle this cross linkage?

@gmcculloug
Copy link
Member

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
And description: ManageIQ/manageiq#15251

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)
Copy link
Contributor

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

Copy link
Member

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?

Copy link
Author

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>

Copy link
Author

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 ?

Copy link
Member

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

Copy link
Member

@gmcculloug gmcculloug left a 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) }
Copy link
Member

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
Copy link
Member

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

ghost pushed a commit to fabiendupont/manageiq-content that referenced this pull request Jun 6, 2017
@ghost
Copy link
Author

ghost commented Jun 6, 2017

@gmcculloug you rock!

@gmcculloug
Copy link
Member

@fdupont-redhat Let's make one last change to avoid the rubocop warning about using expect_any_instance_of.

I used that call initially because the service model loads it's own copy of the service_template and the expect(template).to receive(:provision_request) would be called on the wrong copy.

To avoid using expect_any_instance_of we just need to return the same template instance when the service model for ServiceTemplate performs a find to look up the instance.

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)

@miq-bot
Copy link
Member

miq-bot commented Jun 12, 2017

Checked commits fabiendupont/manageiq-automation_engine@f81a347~...2fd5605 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks fine. ⭐

@gmcculloug gmcculloug changed the title [WIP] Move create_service_provision_request into MiqAeServiceMethods for consistency Move create_service_provision_request into MiqAeServiceMethods for consistency Jun 12, 2017
Copy link
Member

@gmcculloug gmcculloug left a 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.

@mkanoor
Copy link
Contributor

mkanoor commented Jun 12, 2017

@gmcculloug @fdupont-redhat 👍

@gmcculloug gmcculloug merged commit f650a66 into ManageIQ:master Jun 12, 2017
@gmcculloug gmcculloug added this to the Sprint 63 Ending Jun 19, 2017 milestone Jun 12, 2017
@simaishi
Copy link
Contributor

Fine backport (to manageiq repo) details:

$ git log -1
commit ebd69905757ba17d786876ebc18c93fd8df6cda4
Author: Greg McCullough <[email protected]>
Date:   Mon Jun 12 09:44:46 2017 -0400

    Merge pull request #34 from fdupont-redhat/bz1447754
    
    Move create_service_provision_request into MiqAeServiceMethods for consistency
    (cherry picked from commit f650a66f1241de078ffdca508b0e77afb8eb5460)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1461144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants