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
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ def instantiate(uri)
return nil
end

def create_service_provision_request(svc_template, options = nil)
result = ar_object(svc_template).provision_request(@workspace.ae_user, options)
MiqAeServiceModelBase.wrap_results(result)
end

def object(path = nil)
obj = @workspace.get_obj_from_path(path)
return nil if obj.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def self.create_automation_request(options, userid = "admin", auto_approve = fal
MiqAeServiceModelBase.wrap_results(AutomationRequest.create_request(options, user, auto_approve))
end

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


def self.drb_undumped(klass)
_log.info "Entered: klass=#{klass.name}"
klass.include(DRbUndumped) unless klass.ancestors.include?(DRbUndumped)
Expand Down
27 changes: 27 additions & 0 deletions spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,32 @@ def category_create_script
ct.reload
expect(ct.entries.collect(&:name).include?('fred')).to be_truthy
end

context "#create_service_provision_request" do
let(:options) { {:fred => :flintstone} }
let(:svc_options) { {:dialog_style => "medium"} }
let(:user) { FactoryGirl.create(:user_with_group) }
let(:template) { FactoryGirl.create(:service_template_ansible_playbook) }
let(:miq_request) { FactoryGirl.create(:service_template_provision_request) }
let(:svc_template) do
MiqAeMethodService::MiqAeServiceServiceTemplate.find(template.id)
end
let(:workspace) do
double("MiqAeEngine::MiqAeWorkspaceRuntime",
:root => options,
: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) }


it "create service request" do
allow(workspace).to receive(:disable_rbac)
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

expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest)
end
end
end
end
27 changes: 0 additions & 27 deletions spec/miq_ae_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,32 +208,5 @@ module MiqAeServiceSpec
end
end
end

context "#create_service_provision_request" do
let(:options) { {:fred => :flintstone} }
let(:svc_options) { {:dialog_style => "medium"} }
let(:user) { FactoryGirl.create(:user_with_group) }
let(:template) { FactoryGirl.create(:service_template_ansible_playbook) }
let(:miq_request) { FactoryGirl.create(:service_template_provision_request) }
let(:svc_template) do
MiqAeMethodService::MiqAeServiceServiceTemplate.find(template.id)
end
let(:workspace) do
double("MiqAeEngine::MiqAeWorkspaceRuntime",
:root => options,
:persist_state_hash => {},
:ae_user => user)
end
let(:miq_ae_service) { MiqAeService.new(workspace) }

it "create service request" do
allow(workspace).to receive(:disable_rbac)
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.create_service_provision_request(svc_template, svc_options)
expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest)
end
end
end
end