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

Add option to schedule automation requests via workflow #18741

Merged
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
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