From 1607a9f08e054be36afb9d0884dc77aac56dc635 Mon Sep 17 00:00:00 2001 From: skovic Date: Wed, 18 Jul 2018 16:35:56 -0400 Subject: [PATCH 1/5] Add support for new physical server alert --- app/models/ext_management_system.rb | 1 + app/models/miq_alert.rb | 3 ++- app/models/mixins/assignment_mixin.rb | 2 +- app/models/physical_server.rb | 1 + app/models/zone.rb | 1 + db/fixtures/miq_alerts.yml | 15 +++++++++++++++ 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 6d97823e40e..53713330dc6 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -49,6 +49,7 @@ def self.api_allowed_attributes has_many :hardwares, :through => :vms_and_templates has_many :networks, :through => :hardwares has_many :disks, :through => :hardwares + has_many :physical_servers, :foreign_key => :ems_id, :inverse_of => :ext_management_system has_many :storages, -> { distinct }, :through => :hosts has_many :ems_events, -> { order("timestamp") }, :class_name => "EmsEvent", :foreign_key => "ems_id", diff --git a/app/models/miq_alert.rb b/app/models/miq_alert.rb index 635bbb11601..5096083a2e1 100644 --- a/app/models/miq_alert.rb +++ b/app/models/miq_alert.rb @@ -27,6 +27,7 @@ class MiqAlert < ApplicationRecord MiqServer ContainerNode ContainerProject + PhysicalServer ) def self.base_tables @@ -35,7 +36,7 @@ def self.base_tables acts_as_miq_set_member - ASSIGNMENT_PARENT_ASSOCIATIONS = [:host, :ems_cluster, :ext_management_system, :my_enterprise] + ASSIGNMENT_PARENT_ASSOCIATIONS = [:host, :ems_cluster, :ext_management_system, :my_enterprise, :physical_server] HOURLY_TIMER_EVENT = "_hourly_timer_" diff --git a/app/models/mixins/assignment_mixin.rb b/app/models/mixins/assignment_mixin.rb index a49013d5c38..91cd40375a4 100644 --- a/app/models/mixins/assignment_mixin.rb +++ b/app/models/mixins/assignment_mixin.rb @@ -16,7 +16,7 @@ def all_assignments(tag = nil) included do #:nodoc: acts_as_miq_taggable - const_set("ASSIGNMENT_PARENT_ASSOCIATIONS", [:parent_blue_folders, :parent_resource_pool, :host, :ems_cluster, :ext_management_system, :my_enterprise]) unless const_defined?("ASSIGNMENT_PARENT_ASSOCIATIONS") + const_set("ASSIGNMENT_PARENT_ASSOCIATIONS", [:parent_blue_folders, :parent_resource_pool, :host, :ems_cluster, :ext_management_system, :my_enterprise, :physical_server]) unless const_defined?("ASSIGNMENT_PARENT_ASSOCIATIONS") cache_with_timeout(:assignments_cached, 1.minute) { assignments } end diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index ccbf8f7a3bf..ce3dcfa5ffe 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -27,6 +27,7 @@ class PhysicalServer < ApplicationRecord has_one :host, :inverse_of => :physical_server has_one :asset_detail, :as => :resource, :dependent => :destroy has_many :guest_devices, :through => :hardware + has_many :miq_alert_statuses, :as => :resource, :dependent => :destroy scope :with_hosts, -> { where("physical_servers.id in (select hosts.physical_server_id from hosts)") } diff --git a/app/models/zone.rb b/app/models/zone.rb index dc370f6cfa4..3f85539314c 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -20,6 +20,7 @@ class Zone < ApplicationRecord has_many :vms, :through => :ext_management_systems has_many :miq_templates, :through => :ext_management_systems has_many :ems_clusters, :through => :ext_management_systems + has_many :physical_servers, :through => :ext_management_systems has_many :container_nodes, :through => :container_managers has_many :container_groups, :through => :container_managers has_many :container_replicators, :through => :container_managers diff --git a/db/fixtures/miq_alerts.yml b/db/fixtures/miq_alerts.yml index a71543521d1..f8ef64754c1 100644 --- a/db/fixtures/miq_alerts.yml +++ b/db/fixtures/miq_alerts.yml @@ -321,3 +321,18 @@ value: prod :db: Vm :guid: 89db0be8-c240-11de-a3be-000c290de4f9 +- description: Physical server has critical health state + options: + :notifications: + :delay_next_evaluation: 3600 + :email: + :from: '' + :to: [] + miq_expression: !ruby/object:MiqExpression + :exp: + =: + field: PhysicalServer-health_state + value: "Critical" + db: PhysicalServer + guid: 15feb65a-1f36-44db-84ee-0e71d9f497c8 + responds_to_events: _hourly_timer_ From 6abf9088484e09a0910659dd6536a5a8ff00c651 Mon Sep 17 00:00:00 2001 From: skovic Date: Fri, 20 Jul 2018 10:45:48 -0400 Subject: [PATCH 2/5] Fix spacing in miq_alerts.yml --- db/fixtures/miq_alerts.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/fixtures/miq_alerts.yml b/db/fixtures/miq_alerts.yml index f8ef64754c1..3c2080818ec 100644 --- a/db/fixtures/miq_alerts.yml +++ b/db/fixtures/miq_alerts.yml @@ -324,10 +324,10 @@ - description: Physical server has critical health state options: :notifications: - :delay_next_evaluation: 3600 + :delay_next_evaluation: 3600 :email: - :from: '' - :to: [] + :from: '' + :to: [] miq_expression: !ruby/object:MiqExpression :exp: =: From 47560cc18402af13563019ae019099709b344250 Mon Sep 17 00:00:00 2001 From: skovic Date: Fri, 20 Jul 2018 13:28:33 -0400 Subject: [PATCH 3/5] Fix formatting of physical server alert --- db/fixtures/miq_alerts.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/db/fixtures/miq_alerts.yml b/db/fixtures/miq_alerts.yml index 3c2080818ec..88bed95c367 100644 --- a/db/fixtures/miq_alerts.yml +++ b/db/fixtures/miq_alerts.yml @@ -321,18 +321,18 @@ value: prod :db: Vm :guid: 89db0be8-c240-11de-a3be-000c290de4f9 -- description: Physical server has critical health state - options: +- :description: Physical server has critical health state + :options: :notifications: :delay_next_evaluation: 3600 - :email: - :from: '' - :to: [] - miq_expression: !ruby/object:MiqExpression - :exp: + :email: + :from: '' + :to: [] + :miq_expression: !ruby/object:MiqExpression + exp: =: field: PhysicalServer-health_state value: "Critical" - db: PhysicalServer - guid: 15feb65a-1f36-44db-84ee-0e71d9f497c8 - responds_to_events: _hourly_timer_ + :db: PhysicalServer + :guid: 15feb65a-1f36-44db-84ee-0e71d9f497c8 + :responds_to_events: _hourly_timer_ From 274c3fde8b38e9ad035d0b4affa495be591da14e Mon Sep 17 00:00:00 2001 From: skovic Date: Fri, 20 Jul 2018 13:54:08 -0400 Subject: [PATCH 4/5] Fix array of symbols rubocop warnings --- app/models/miq_alert.rb | 2 +- app/models/mixins/assignment_mixin.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/miq_alert.rb b/app/models/miq_alert.rb index 5096083a2e1..c13fc746521 100644 --- a/app/models/miq_alert.rb +++ b/app/models/miq_alert.rb @@ -36,7 +36,7 @@ def self.base_tables acts_as_miq_set_member - ASSIGNMENT_PARENT_ASSOCIATIONS = [:host, :ems_cluster, :ext_management_system, :my_enterprise, :physical_server] + ASSIGNMENT_PARENT_ASSOCIATIONS = %i(host ems_cluster ext_management_system my_enterprise physical_server).freeze HOURLY_TIMER_EVENT = "_hourly_timer_" diff --git a/app/models/mixins/assignment_mixin.rb b/app/models/mixins/assignment_mixin.rb index 91cd40375a4..0fd775488d8 100644 --- a/app/models/mixins/assignment_mixin.rb +++ b/app/models/mixins/assignment_mixin.rb @@ -16,7 +16,7 @@ def all_assignments(tag = nil) included do #:nodoc: acts_as_miq_taggable - const_set("ASSIGNMENT_PARENT_ASSOCIATIONS", [:parent_blue_folders, :parent_resource_pool, :host, :ems_cluster, :ext_management_system, :my_enterprise, :physical_server]) unless const_defined?("ASSIGNMENT_PARENT_ASSOCIATIONS") + const_set("ASSIGNMENT_PARENT_ASSOCIATIONS", %i(parent_blue_folders parent_resource_pool host ems_cluster ext_management_system my_enterprise physical_server)) unless const_defined?("ASSIGNMENT_PARENT_ASSOCIATIONS") cache_with_timeout(:assignments_cached, 1.minute) { assignments } end From fefa6f185ba5a2710fae711fbf6802c7bb3cb496 Mon Sep 17 00:00:00 2001 From: skovic Date: Fri, 20 Jul 2018 14:50:56 -0400 Subject: [PATCH 5/5] Fix rails rubocop warnings --- app/models/ext_management_system.rb | 2 +- app/models/physical_server.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 53713330dc6..746a9cf5a2f 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -49,7 +49,7 @@ def self.api_allowed_attributes has_many :hardwares, :through => :vms_and_templates has_many :networks, :through => :hardwares has_many :disks, :through => :hardwares - has_many :physical_servers, :foreign_key => :ems_id, :inverse_of => :ext_management_system + has_many :physical_servers, :foreign_key => :ems_id, :inverse_of => :ext_management_system, :dependent => :destroy has_many :storages, -> { distinct }, :through => :hosts has_many :ems_events, -> { order("timestamp") }, :class_name => "EmsEvent", :foreign_key => "ems_id", diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index ce3dcfa5ffe..17edc56683d 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -27,7 +27,7 @@ class PhysicalServer < ApplicationRecord has_one :host, :inverse_of => :physical_server has_one :asset_detail, :as => :resource, :dependent => :destroy has_many :guest_devices, :through => :hardware - has_many :miq_alert_statuses, :as => :resource, :dependent => :destroy + has_many :miq_alert_statuses, :as => :resource, :dependent => :destroy, :inverse_of => :physical_server scope :with_hosts, -> { where("physical_servers.id in (select hosts.physical_server_id from hosts)") }