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 13, 2019
1 parent 2891bc3 commit e086131
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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
11 changes: 11 additions & 0 deletions spec/models/automation_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
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
scheduling_time = (Time.now.utc + 2.days).change(:usec => 0)
@parameters['schedule_time'] = scheduling_time
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(scheduling_time)
end

it 'doesnt downcase and stringify objects in the parameters hash' do
Expand Down

0 comments on commit e086131

Please sign in to comment.