diff --git a/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb b/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb index eaf3f5855..42369fe70 100644 --- a/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb +++ b/app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb @@ -212,6 +212,8 @@ def host_hardware(persister_host, host, networks, nics) end def host_guest_devices(persister_hardware, host, nics, networks) + persister_host = persister_hardware.host + nics.to_miq_a.each do |nic| network = network_from_nic(nic, host, networks) ip = nic.ip.presence || nil @@ -239,7 +241,7 @@ def host_guest_devices(persister_hardware, host, nics, networks) unless network.nil? switch_uid = network.try(:id) || network.name - attributes[:switch] = persister.switches.lazy_find(switch_uid) + attributes[:switch] = persister.host_virtual_switches.lazy_find(:host => persister_host, :uid_ems => switch_uid) attributes[:network] = persister_nic end @@ -259,7 +261,10 @@ def switches(persister_host, dc, nics, networks) uid = network.try(:id) || network.name name = network.name - persister_switch = persister.switches.find_or_build(uid).assign_attributes( + persister_switch = persister.host_virtual_switches.find_or_build_by( + :host => persister_host, :uid_ems => uid + ).assign_attributes( + :host => persister_host, :uid_ems => uid, :name => name, ) @@ -306,7 +311,9 @@ def lans(network, persister_switch) return end - persister.lans.find_or_build(uid).assign_attributes( + persister.lans.find_or_build_by( + :switch => persister_switch, :uid_ems => uid + ).assign_attributes( :name => name, :uid_ems => uid, :tag => tag_value, diff --git a/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_collections.rb b/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_collections.rb index 339c4fafc..34f6066f2 100644 --- a/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_collections.rb +++ b/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_collections.rb @@ -5,7 +5,6 @@ module ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraColl include ::ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::VmsCollections include ::ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::DatacentersCollections include ::ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::StoragedomainsCollections - include ::ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::NetworksCollections include ::ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::VmsDependencyCollections def initialize_infra_inventory_collections @@ -16,9 +15,7 @@ def initialize_infra_inventory_collections add_hosts_group add_datacenters_group add_storagedomains_group - add_networks_group add_vms_dependency_collections_group - add_other_collections end # --- IC groups definitions --- @@ -59,7 +56,9 @@ def add_hosts_group host_networks host_operating_systems host_storages - host_switches).each do |name| + host_switches + host_virtual_switches + lans).each do |name| add_collection(infra, name) end @@ -68,16 +67,4 @@ def add_hosts_group def add_storagedomains_group add_storages end - - def add_networks_group - add_switches - end - - def add_other_collections - add_collection(infra, :lans) do |builder| - builder.add_properties( - :manager_ref => %i(uid_ems) - ) - end - end end diff --git a/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_group/networks_collections.rb b/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_group/networks_collections.rb deleted file mode 100644 index 579c5cebe..000000000 --- a/app/models/manageiq/providers/redhat/inventory/persister/definitions/infra_group/networks_collections.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ManageIQ::Providers::Redhat::Inventory::Persister::Definitions::InfraGroup::NetworksCollections - extend ActiveSupport::Concern - - # group :networks - def add_switches - add_collection(infra, :switches) do |builder| - if targeted? - # TODO are switches shared across emses? Seems like we weren't filling ems_id - builder.add_targeted_arel( - lambda do |_inventory_collection| - ::Switch.where(:uid_ems => references(:switches)) - end - ) - end - end - end -end diff --git a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_4_async_graph_spec.rb b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_4_async_graph_spec.rb index 5596ee90e..82c96a004 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_4_async_graph_spec.rb +++ b/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_4_async_graph_spec.rb @@ -112,8 +112,7 @@ def assert_table_counts(_lan_number) expect(Network.count).to eq(6) expect(OperatingSystem.count).to eq(20) expect(Snapshot.count).to eq(17) - # the old code expects 3 and new 2 - expect(Switch.count).to eq(2) + expect(Switch.count).to eq(3) expect(SystemService.count).to eq(0) expect(Relationship.count).to eq(45)