Skip to content

Commit

Permalink
Add option to schedule automation requests via workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed May 7, 2019
1 parent 2891bc3 commit aa1b124
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/automation_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def self.create_from_ws(version, user, uri_parts, parameters, requester)
options[:namespace] = (options.delete(:namespace) || DEFAULT_NAMESPACE).strip.gsub(/(^\/|\/$)/, "") # Strip blanks and slashes from beginning and end of string
options[:class_name] = (options.delete(:class) || DEFAULT_CLASS).strip.gsub(/(^\/|\/$)/, "")
options[:instance_name] = (options.delete(:instance) || DEFAULT_INSTANCE).strip
options[:schedule_type] = parameters['schedule_time'].present? ? "schedule" : "immediately"
options[:schedule_time] = parameters['schedule_time'] if parameters['schedule_time']

object_parameters = parse_out_objects(parameters)
attrs = MiqRequestWorkflow.parse_ws_string(parameters)
Expand Down
12 changes: 11 additions & 1 deletion spec/models/automation_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@
expect(ar.options[:attrs][:var2]).to eq(@ae_var2)
expect(ar.options[:attrs][:var3]).to eq(@ae_var3)
expect(ar.options[:attrs][:userid]).to eq(admin.userid)
expect(ar.options[:schedule_type]).to eq("immediately")
expect(ar.options[:schedule_time]).to eq(nil)
end

it "creates request with schedule" do
@parameters.merge!('schedule_time' => Time.now.utc + 2.days)
ar = AutomationRequest.create_from_ws(@version, admin, @uri_parts, @parameters, {})

expect(ar.options[:schedule_type]).to eq("schedule")
expect(ar.options[:schedule_time]).to eq(Time.now.utc + 2.days)
end

it 'doesnt downcase and stringify objects in the parameters hash' do
@object_parameters = {'VmOrTemplate::vm' => 10, 'var2' => @ae_var2.to_s, 'var3' => @ae_var3.to_s}
ar = AutomationRequest.create_from_ws(@version, admin, @uri_parts, @object_parameters, {})
ar = AutomationRequest.create_from_ws(@version, admin, @uri_parts, @object_parameters, @vm_fields)
expect(ar.options[:attrs]).to include("VmOrTemplate::vm" => 10, :var2 => @ae_var2.to_s)
end

Expand Down

0 comments on commit aa1b124

Please sign in to comment.