From f81a3479626a173d9996e8e2de74989517b6e6cb Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Fri, 2 Jun 2017 11:35:37 +0200 Subject: [PATCH 1/3] Move the create_service_provision_request method to lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb --- .../miq_ae_method_service/miq_ae_service.rb | 5 ---- .../miq_ae_service_methods.rb | 5 ++++ .../miq_ae_service_methods_spec.rb | 27 +++++++++++++++++++ spec/miq_ae_service_spec.rb | 27 ------------------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb index 742cde313..bd38be43c 100644 --- a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb +++ b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb @@ -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? diff --git a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb index 7adee3870..1c43641c8 100644 --- a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb +++ b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb @@ -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 + def self.drb_undumped(klass) _log.info "Entered: klass=#{klass.name}" klass.include(DRbUndumped) unless klass.ancestors.include?(DRbUndumped) diff --git a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb index 5c3cc0264..b1019cb62 100644 --- a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb +++ b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb @@ -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) } + + 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) + expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest) + end + end end end diff --git a/spec/miq_ae_service_spec.rb b/spec/miq_ae_service_spec.rb index d27accdc6..a34bd00c1 100644 --- a/spec/miq_ae_service_spec.rb +++ b/spec/miq_ae_service_spec.rb @@ -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 From 18e4d1dfdc8f0bd79306dfd440f860d7e12d0125 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Tue, 6 Jun 2017 23:13:43 +0200 Subject: [PATCH 2/3] Updated following @gmcculloug recommendations --- .../engine/miq_ae_method_service/miq_ae_service_methods.rb | 2 +- .../miq_ae_method_service/miq_ae_service_methods_spec.rb | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb index 1c43641c8..06b0bf6e1 100644 --- a/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb +++ b/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_methods.rb @@ -111,7 +111,7 @@ def self.create_automation_request(options, userid = "admin", auto_approve = fal end def self.create_service_provision_request(svc_template, options = nil) - result = ar_object(svc_template).provision_request(@workspace.ae_user, options) + result = svc_template.object_send(:provision_request, User.current_user, options) MiqAeServiceModelBase.wrap_results(result) end diff --git a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb index b1019cb62..5de315791 100644 --- a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb +++ b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb @@ -178,14 +178,13 @@ def category_create_script :persist_state_hash => {}, :ae_user => user) end - let(:miq_ae_service) { MiqAeService.new(workspace) } + 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) + 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_reques, svc_template, svc_options) + result = miq_ae_service.execute(:create_service_provision_request, svc_template, svc_options) expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest) end end From 2fd5605a62c0ca8234f16dc208c7d2bc5d5d5e8c Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 12 Jun 2017 09:49:53 +0200 Subject: [PATCH 3/3] Updated spec to get rid of rubocop complains --- .../miq_ae_method_service/miq_ae_service_methods_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb index 5de315791..795f37f51 100644 --- a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb +++ b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb @@ -182,7 +182,8 @@ def category_create_script 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) + 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) result = miq_ae_service.execute(:create_service_provision_request, svc_template, svc_options) expect(result).to be_kind_of(MiqAeMethodService::MiqAeServiceMiqRequest)