diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 6234c7c00e3..ae19b213421 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -193,12 +193,12 @@ def edit_with_params(params, endpoints, authentications) endpoints_changed ||= ems.endpoints.any?(&:changed?) authentications_changed ||= ems.authentications.any?(&:changed?) + after_update_endpoints if endpoints_changed + after_update_authentication if authentications_changed + ems.provider.save! if ems.provider.present? && ems.provider.changed? ems.save! end - - after_update_endpoints if endpoints_changed - after_update_authentication if authentications_changed end end @@ -920,14 +920,14 @@ def stop_event_monitor_queue end def stop_event_monitor_queue_on_change - if event_monitor_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress") + if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress") _log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.") stop_event_monitor_queue end end def stop_event_monitor_queue_on_credential_change - if event_monitor_class && !self.new_record? && self.credentials_changed? + if event_monitor_class && !new_record? && default_authentication.changed? _log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.") stop_event_monitor_queue end @@ -984,14 +984,14 @@ def stop_refresh_worker_queue end def stop_refresh_worker_queue_on_change - if refresh_worker_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress") + if refresh_worker_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress") _log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.") stop_refresh_worker_queue end end def stop_refresh_worker_queue_on_credential_change - if refresh_worker_class && !self.new_record? && self.credentials_changed? + if refresh_worker_class && !new_record? && default_authentication.changed? _log.info("EMS: [#{name}], Credentials have changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.") stop_refresh_worker_queue end diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index e6ac8966285..dc9d1198227 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -931,6 +931,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) ems.edit_with_params(params, endpoints, authentications) end + + it "stops the event monitor" do + expect(ems).to receive(:stop_event_monitor_queue) + + ems.edit_with_params(params, endpoints, authentications) + end end context "adding an authentication" do @@ -985,6 +991,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) ems.edit_with_params(params, endpoints, authentications) end + + it "stops the event monitor" do + expect(ems).to receive(:stop_event_monitor_queue) + + ems.edit_with_params(params, endpoints, authentications) + end end end