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 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
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 = 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) { MiqAeMethodService::MiqAeService.new(workspace) }

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