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

Set the initiator from the workflow/request #14070

Merged
merged 7 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion app/models/miq_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def action_audit(_action, rec, inputs)

def action_run_ansible_playbook(action, rec, _inputs)
service_template = ServiceTemplate.find(action.options[:service_template_id])
options = { :dialog_hosts => target_hosts(action, rec) }
options = { :dialog_hosts => target_hosts(action, rec),
:initiator => 'control' }
service_template.provision_request(target_user(rec), options)
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/resource_action_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(values, requester, resource_action, options = {})
@settings = {}
@requester = requester
@target = options[:target]
@initiator = options[:initiator]
@dialog = load_dialog(resource_action, values)

@settings[:resource_action_id] = resource_action.id unless resource_action.nil?
Expand Down Expand Up @@ -80,7 +81,8 @@ def load_resource_action(values = nil)
def create_values_hash
{
:dialog => @dialog.automate_values_hash,
:workflow_settings => @settings
:workflow_settings => @settings,
:initiator => @initiator
}
end

Expand Down
5 changes: 4 additions & 1 deletion app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def create_service(service_task, parent_svc = nil)
# convert template class name to service class name by naming convention
nh[:type] = self.class.name.sub('Template', '')

nh[:initiator] = service_task.options[:initiator]

# Determine service name
# target_name = self.get_option(:target_name)
# nh['name'] = target_name unless target_name.blank?
Expand Down Expand Up @@ -453,8 +455,9 @@ def update_from_options(options)

def provision_workflow(user, options = nil)
options ||= {}
ra_options = { :target => self, :initiator => options[:initiator] }
ResourceActionWorkflow.new({}, user,
provision_action, :target => self).tap do |wf|
provision_action, ra_options).tap do |wf|
options.each { |key, value| wf.set_value(key, value) }
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/miq_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def stub_csv(data)
{ :service_template_id => stap.id,
:use_event_target => true }
end
let(:options) { {:dialog_hosts => ip1 } }
let(:options) { {:dialog_hosts => ip1, :initiator => 'control' } }

it_behaves_like "#workflow check"
end
Expand All @@ -430,7 +430,7 @@ def stub_csv(data)
{ :service_template_id => stap.id,
:use_localhost => true }
end
let(:options) { {:dialog_hosts => 'localhost' } }
let(:options) { {:dialog_hosts => 'localhost', :initiator => 'control' } }

it_behaves_like "#workflow check"
end
Expand All @@ -440,7 +440,7 @@ def stub_csv(data)
{ :service_template_id => stap.id,
:hosts => "ip1, ip2" }
end
let(:options) { {:dialog_hosts => 'ip1, ip2' } }
let(:options) { {:dialog_hosts => 'ip1, ip2', :initiator => 'control' } }

it_behaves_like "#workflow check"
end
Expand Down
16 changes: 14 additions & 2 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@
end
end

context "initiator" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor Do we have any tests for when :initiator is not passed or when it is passed as nil? If the key is passed with a nil value I think it will save nil in the record instead of using the default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug Yes that was an issue, I fixed it

it 'test initiator' do
svc_template = FactoryGirl.create(:service_template, :name => 'Svc A')
svc_task = instance_double("service_task", :options => {:dialog => {},
:initiator => 'fred'})
svc = svc_template.create_service(svc_task, nil)
expect(svc.initiator).to eq('fred')
end
end

context "with multiple services" do
before(:each) do
@svc_a = FactoryGirl.create(:service_template, :name => 'Svc A')
Expand Down Expand Up @@ -606,13 +616,15 @@
resource_action = FactoryGirl.create(:resource_action, :action => "Provision")
service_template = FactoryGirl.create(:service_template,
:resource_actions => [resource_action])
hash = {:target => service_template, :initiator => 'control'}
workflow = instance_double(ResourceActionWorkflow)
expect(ResourceActionWorkflow).to(receive(:new)
.with({}, user, resource_action, :target => service_template).and_return(workflow))
.with({}, user, resource_action, hash).and_return(workflow))
expect(workflow).to receive(:submit_request)
expect(workflow).to receive(:set_value).with('ordered_by', 'fred')
expect(workflow).to receive(:set_value).with(:initiator, 'control')

service_template.provision_request(user, 'ordered_by' => 'fred')
service_template.provision_request(user, 'ordered_by' => 'fred', :initiator => 'control')
end
end
end
Expand Down