From e08613154c3ef9758cf4b86e34b292451df74edb Mon Sep 17 00:00:00 2001 From: d-m-u Date: Tue, 7 May 2019 08:15:31 -0400 Subject: [PATCH] Add option to schedule automation requests via workflow --- app/models/automation_request.rb | 2 ++ spec/models/automation_request_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/automation_request.rb b/app/models/automation_request.rb index d7622c748f8..ccdce07ec7a 100644 --- a/app/models/automation_request.rb +++ b/app/models/automation_request.rb @@ -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) diff --git a/spec/models/automation_request_spec.rb b/spec/models/automation_request_spec.rb index c0e9f16a0f9..9d0ea556cc3 100644 --- a/spec/models/automation_request_spec.rb +++ b/spec/models/automation_request_spec.rb @@ -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