diff --git a/app/models/manageiq/providers/nuage/inventory/collector.rb b/app/models/manageiq/providers/nuage/inventory/collector.rb index c7f3bf0212..09063b98f3 100644 --- a/app/models/manageiq/providers/nuage/inventory/collector.rb +++ b/app/models/manageiq/providers/nuage/inventory/collector.rb @@ -9,9 +9,9 @@ def initialize(_manager, _target) end def initialize_inventory_sources + @cloud_tenants = {} @cloud_subnets = [] @security_groups = [] - @network_groups = [] @zones = {} @domains = {} end diff --git a/app/models/manageiq/providers/nuage/inventory/collector/network_manager.rb b/app/models/manageiq/providers/nuage/inventory/collector/network_manager.rb index 6da9a105a0..f20deff6bf 100644 --- a/app/models/manageiq/providers/nuage/inventory/collector/network_manager.rb +++ b/app/models/manageiq/providers/nuage/inventory/collector/network_manager.rb @@ -1,4 +1,8 @@ class ManageIQ::Providers::Nuage::Inventory::Collector::NetworkManager < ManageIQ::Providers::Nuage::Inventory::Collector + def cloud_tenants + _cloud_tenants.values + end + def cloud_subnets return @cloud_subnets if @cloud_subnets.any? @cloud_subnets = vsd_client.get_subnets @@ -9,34 +13,48 @@ def security_groups @security_groups = vsd_client.get_policy_groups end - def network_groups - return @network_groups if @network_groups.any? - @network_groups = vsd_client.get_enterprises - end - def zones - return @zones if @zones.any? - @zones = vsd_client.get_zones.map { |zone| [zone['ID'], zone] } .to_h + _zones.values end def domains - return @domains if @domains.any? - @domains = vsd_client.get_domains.map { |domain| [domain['ID'], domain] } .to_h + _domains.values end def security_group(ems_ref) security_groups.find { |sg| sg['ID'] == ems_ref } end - def network_group(ems_ref) - network_groups.find { |ng| ng['ID'] == ems_ref } + def cloud_tenant(ems_ref) + _cloud_tenants[ems_ref] end def zone(ems_ref) - zones[ems_ref] + _zones[ems_ref] end def domain(ems_ref) - domains[ems_ref] + _domains[ems_ref] + end + + private + + def _cloud_tenants + return @cloud_tenants if @cloud_tenants.any? + @cloud_tenants = hash_by_id(vsd_client.get_enterprises) + end + + def _zones + return @zones if @zones.any? + @zones = hash_by_id(vsd_client.get_zones) + end + + def _domains + return @domains if @domains.any? + @domains = hash_by_id(vsd_client.get_domains) + end + + def hash_by_id(list) + list.map { |el| [el['ID'], el] }.to_h end end diff --git a/app/models/manageiq/providers/nuage/inventory/collector/target_collection.rb b/app/models/manageiq/providers/nuage/inventory/collector/target_collection.rb index 5616b0cd9d..0f1e87ab9c 100644 --- a/app/models/manageiq/providers/nuage/inventory/collector/target_collection.rb +++ b/app/models/manageiq/providers/nuage/inventory/collector/target_collection.rb @@ -21,10 +21,10 @@ def security_groups @security_groups_map.values.compact end - def network_groups - return [] if references(:network_groups).blank? - references(:network_groups).collect { |ems_ref| network_group(ems_ref) } - @network_groups_map.values.compact + def cloud_tenants + return [] if references(:cloud_tenants).blank? + references(:cloud_tenants).collect { |ems_ref| cloud_tenant(ems_ref) } + @cloud_tenant_map.values.compact end def cloud_subnet(ems_ref) @@ -37,9 +37,9 @@ def security_group(ems_ref) @security_groups_map[ems_ref] = safe_call { vsd_client.get_policy_group(ems_ref) } end - def network_group(ems_ref) - return @network_groups_map[ems_ref] if @network_groups_map.key?(ems_ref) - @network_groups_map[ems_ref] = safe_call { vsd_client.get_enterprise(ems_ref) } + def cloud_tenant(ems_ref) + return @cloud_tenant_map[ems_ref] if @cloud_tenant_map.key?(ems_ref) + @cloud_tenant_map[ems_ref] = safe_call { vsd_client.get_enterprise(ems_ref) } end def zone(ems_ref) @@ -55,41 +55,41 @@ def domain(ems_ref) private def initialize_cache - @cloud_subnets_map = {} - @security_groups_map = {} - @network_groups_map = {} - @zones_map = {} - @domains_map = {} - @domains_per_network_group = {} + @cloud_subnets_map = {} + @security_groups_map = {} + @cloud_tenant_map = {} + @zones_map = {} + @domains_map = {} + @domains_per_tenant = {} end - def domains_for_network_group(network_group_ems_ref) - ems_ref = network_group_ems_ref - @domains_per_network_group[ems_ref] ||= safe_list { vsd_client.get_domains_for_enterprise(ems_ref) } - @domains_per_network_group[ems_ref].each { |d| @domains_map[d['ID']] = d } - @domains_per_network_group[ems_ref] + def domains_for_tenant(tenant_ems_ref) + ems_ref = tenant_ems_ref + @domains_per_tenant[ems_ref] ||= safe_list { vsd_client.get_domains_for_enterprise(ems_ref) } + @domains_per_tenant[ems_ref].each { |d| @domains_map[d['ID']] = d } + @domains_per_tenant[ems_ref] end - def cloud_subnets_for_network_group(network_group_ems_ref) - domains_for_network_group(network_group_ems_ref).each_with_object([]) do |d, arr| + def cloud_subnets_for_tenant(tenant_ems_ref) + domains_for_tenant(tenant_ems_ref).each_with_object([]) do |d, arr| arr.push(safe_list { vsd_client.get_subnets_for_domain(d['ID']) }) end.flatten(1) end - def security_groups_for_network_group(network_group_ems_ref) - domains_for_network_group(network_group_ems_ref).each_with_object([]) do |d, arr| + def security_groups_for_tenant(tenant_ems_ref) + domains_for_tenant(tenant_ems_ref).each_with_object([]) do |d, arr| arr.push(safe_list { vsd_client.get_policy_groups_for_domain(d['ID']) }) end.flatten(1) end - def network_group_ems_ref_for_cloud_subnet(cloud_subnet_ems_ref) + def tenant_ems_ref_for_cloud_subnet(cloud_subnet_ems_ref) cloud_subnet = cloud_subnet(cloud_subnet_ems_ref) return nil if cloud_subnet.nil? domain_ems_ref = zone(cloud_subnet['parentID'])['parentID'] domain(domain_ems_ref)['parentID'] end - def network_group_ems_ref_for_security_group(security_group_ems_ref) + def tenant_ems_ref_for_security_group(security_group_ems_ref) security_group = security_group(security_group_ems_ref) return nil if security_group.nil? domain(security_group['parentID'])['parentID'] @@ -106,8 +106,8 @@ def parse_targets! add_simple_target!(:cloud_subnets, t.ems_ref) when SecurityGroup add_simple_target!(:security_groups, t.ems_ref) - when NetworkGroup - add_simple_target!(:network_groups, t.ems_ref) + when CloudTenant + add_simple_target!(:cloud_tenants, t.ems_ref) end end end @@ -124,21 +124,21 @@ def infer_related_ems_refs! end def infer_related_ems_refs_db! - if references(:network_groups).any? - network_groups = manager.network_groups.where(:ems_ref => references(:network_groups)) + if references(:cloud_tenants).any? + tenants = manager.cloud_tenants.where(:ems_ref => references(:cloud_tenants)) .includes(:cloud_subnets, :security_groups) - network_groups.each do |ng| - ng.cloud_subnets.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:cloud_subnets, ems_ref) } - ng.security_groups.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:security_groups, ems_ref) } + tenants.each do |tenant| + tenant.cloud_subnets.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:cloud_subnets, ems_ref) } + tenant.security_groups.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:security_groups, ems_ref) } end end if references(:cloud_subnets).any? cloud_subnets = manager.cloud_subnets.where(:ems_ref => references(:cloud_subnets)) cloud_subnets.each do |cloud_subnet| - next if cloud_subnet.network_group.nil? - add_simple_target!(:network_groups, cloud_subnet.network_group.ems_ref) - cloud_subnet.network_group.security_groups.each do |security_group| + next if cloud_subnet.cloud_tenant.nil? + add_simple_target!(:cloud_tenants, cloud_subnet.cloud_tenant.ems_ref) + cloud_subnet.cloud_tenant.security_groups.each do |security_group| add_simple_target!(:security_groups, security_group.ems_ref) end end @@ -147,33 +147,33 @@ def infer_related_ems_refs_db! if references(:security_groups).any? security_groups = manager.security_groups.where(:ems_ref => references(:security_groups)) security_groups.each do |security_group| - add_simple_target!(:network_groups, security_group.network_group.ems_ref) unless security_group.network_group.nil? + add_simple_target!(:cloud_tenants, security_group.cloud_tenant.ems_ref) unless security_group.cloud_tenant.nil? end end end def infer_related_ems_refs_api! - references(:network_groups).each do |ng_ems_ref| - cloud_subnets_for_network_group(ng_ems_ref).each do |cloud_subnet| + references(:cloud_tenants).each do |tenant_ems_ref| + cloud_subnets_for_tenant(tenant_ems_ref).each do |cloud_subnet| add_simple_target!(:cloud_subnets, cloud_subnet['ID']) end - security_groups_for_network_group(ng_ems_ref).each do |policy_group| + security_groups_for_tenant(tenant_ems_ref).each do |policy_group| add_simple_target!(:security_groups, policy_group['ID']) end end references(:cloud_subnets).each do |cs_ems_ref| - ng_ems_ref = network_group_ems_ref_for_cloud_subnet(cs_ems_ref) - next if ng_ems_ref.nil? - add_simple_target!(:network_groups, ng_ems_ref) - security_groups_for_network_group(ng_ems_ref).each do |policy_group| + tenant_ems_ref = tenant_ems_ref_for_cloud_subnet(cs_ems_ref) + next if tenant_ems_ref.nil? + add_simple_target!(:cloud_tenants, tenant_ems_ref) + security_groups_for_tenant(tenant_ems_ref).each do |policy_group| add_simple_target!(:security_groups, policy_group['ID']) end end references(:security_groups).each do |sg_ems_ref| - add_simple_target!(:network_groups, network_group_ems_ref_for_security_group(sg_ems_ref)) + add_simple_target!(:cloud_tenants, tenant_ems_ref_for_security_group(sg_ems_ref)) end end diff --git a/app/models/manageiq/providers/nuage/inventory/parser/network_manager.rb b/app/models/manageiq/providers/nuage/inventory/parser/network_manager.rb index 271225e670..a5e7804b99 100644 --- a/app/models/manageiq/providers/nuage/inventory/parser/network_manager.rb +++ b/app/models/manageiq/providers/nuage/inventory/parser/network_manager.rb @@ -1,12 +1,21 @@ class ManageIQ::Providers::Nuage::Inventory::Parser::NetworkManager < ManageIQ::Providers::Nuage::Inventory::Parser def parse + cloud_tenants cloud_subnets security_groups - network_groups end private + def cloud_tenants + collector.cloud_tenants.each do |enterprise| + persister.cloud_tenants.find_or_build(enterprise['ID']).assign_attributes( + :name => enterprise['name'], + :description => enterprise['description'] + ) + end + end + def cloud_subnets collector.cloud_subnets.each do |subnet| extra = map_extra_attributes(subnet['parentID']) || {} @@ -17,7 +26,7 @@ def cloud_subnets :gateway => subnet['gateway'], :dhcp_enabled => false, :extra_attributes => extra, - :network_group => persister.network_groups.lazy_find(extra["enterprise_id"]) + :cloud_tenant => persister.cloud_tenants.lazy_find(extra["enterprise_id"]) ) end end @@ -28,17 +37,8 @@ def security_groups domain = collector.domain(domain_id) || {} persister.security_groups.find_or_build(sg['ID']).assign_attributes( - :name => sg['name'], - :network_group => persister.network_groups.lazy_find(domain['parentID']) - ) - end - end - - def network_groups - collector.network_groups.each do |ng| - persister.network_groups.find_or_build(ng['ID']).assign_attributes( - :name => ng['name'], - :status => 'active' + :name => sg['name'], + :cloud_tenant => persister.cloud_tenants.lazy_find(domain['parentID']) ) end end @@ -49,12 +49,12 @@ def map_extra_attributes(zone_id) domain_id = zone['parentID'] domain = collector.domain(domain_id) return unless domain - network_group_id = domain['parentID'] - network_group = collector.network_group(network_group_id) - return unless network_group + tenant_id = domain['parentID'] + tenant = collector.cloud_tenant(tenant_id) + return unless tenant { - "enterprise_name" => network_group['name'], + "enterprise_name" => tenant['name'], "enterprise_id" => domain['parentID'], "domain_name" => domain['name'], "domain_id" => domain_id, diff --git a/app/models/manageiq/providers/nuage/inventory/persister/network_manager.rb b/app/models/manageiq/providers/nuage/inventory/persister/network_manager.rb index beb13243dd..0d849c418e 100644 --- a/app/models/manageiq/providers/nuage/inventory/persister/network_manager.rb +++ b/app/models/manageiq/providers/nuage/inventory/persister/network_manager.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Nuage::Inventory::Persister::NetworkManager < ManageI def initialize_inventory_collections add_inventory_collections( network, - %i(cloud_subnets security_groups network_groups) + %i(cloud_tenants cloud_subnets security_groups) ) end end diff --git a/app/models/manageiq/providers/nuage/inventory/persister/target_collection.rb b/app/models/manageiq/providers/nuage/inventory/persister/target_collection.rb index a9b6105757..7425b8db5f 100644 --- a/app/models/manageiq/providers/nuage/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/nuage/inventory/persister/target_collection.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Nuage::Inventory::Persister::TargetCollection < Manag def initialize_inventory_collections add_inventory_collections_with_references( network, - %i(cloud_subnets security_groups network_groups), + %i(cloud_tenants cloud_subnets security_groups), :parent => manager ) end diff --git a/app/models/manageiq/providers/nuage/inventory_collection_default/network_manager.rb b/app/models/manageiq/providers/nuage/inventory_collection_default/network_manager.rb index 0e061e6560..99ce7a0f4a 100644 --- a/app/models/manageiq/providers/nuage/inventory_collection_default/network_manager.rb +++ b/app/models/manageiq/providers/nuage/inventory_collection_default/network_manager.rb @@ -13,7 +13,7 @@ def cloud_subnets(extra_attributes = {}) :gateway, :dhcp_enabled, :extra_attributes, - :network_group + :cloud_tenant ] } @@ -28,26 +28,30 @@ def security_groups(extra_attributes = {}) :ems_id, :ems_ref, :name, - :network_group + :cloud_tenant ] } super(attributes.merge!(extra_attributes)) end - def network_groups(extra_attributes = {}) + def cloud_tenants(extra_attributes = {}) attributes = { - :model_class => ::ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup, + :model_class => ::ManageIQ::Providers::Nuage::NetworkManager::CloudTenant, + :association => :cloud_tenants, + :builder_params => { + :ems_id => ->(persister) { persister.manager.id }, + }, :inventory_object_attributes => [ :type, :ems_id, :ems_ref, :name, - :status + :description ] } - super(attributes.merge!(extra_attributes)) + attributes.merge!(extra_attributes) end end end diff --git a/app/models/manageiq/providers/nuage/network_manager.rb b/app/models/manageiq/providers/nuage/network_manager.rb index cf29e9453d..975ecbb9b9 100644 --- a/app/models/manageiq/providers/nuage/network_manager.rb +++ b/app/models/manageiq/providers/nuage/network_manager.rb @@ -6,9 +6,9 @@ class ManageIQ::Providers::Nuage::NetworkManager < ManageIQ::Providers::NetworkM require_nested :RefreshWorker require_nested :Refresher require_nested :VsdClient + require_nested :CloudTenant require_nested :CloudSubnet require_nested :SecurityGroup - require_nested :NetworkGroup supports :ems_network_new @@ -44,4 +44,8 @@ def self.event_monitor_class def name self[:name] end + + def cloud_tenants + ::CloudTenant.where(:ems_id => id) + end end diff --git a/app/models/manageiq/providers/nuage/network_manager/cloud_tenant.rb b/app/models/manageiq/providers/nuage/network_manager/cloud_tenant.rb new file mode 100644 index 0000000000..0f17e4129e --- /dev/null +++ b/app/models/manageiq/providers/nuage/network_manager/cloud_tenant.rb @@ -0,0 +1,2 @@ +class ManageIQ::Providers::Nuage::NetworkManager::CloudTenant < ::CloudTenant +end diff --git a/app/models/manageiq/providers/nuage/network_manager/event_target_parser.rb b/app/models/manageiq/providers/nuage/network_manager/event_target_parser.rb index d81230f5d3..9f779f2f8b 100644 --- a/app/models/manageiq/providers/nuage/network_manager/event_target_parser.rb +++ b/app/models/manageiq/providers/nuage/network_manager/event_target_parser.rb @@ -24,13 +24,13 @@ def parse_ems_event_targets(event) case event.full_data["entityType"] when 'enterprise' - add_targets(target_collection, :network_groups, event.full_data['entities']) + add_targets(target_collection, :cloud_tenants, event.full_data['entities']) when 'subnet' add_targets(target_collection, :cloud_subnets, event.full_data['entities']) when 'policygroup' add_targets(target_collection, :security_groups, event.full_data['entities']) when 'domain' - add_targets(target_collection, :network_groups, event.full_data['entities'], :key => 'enterpriseID') + add_targets(target_collection, :cloud_tenants, event.full_data['entities'], :key => 'enterpriseID') end target_collection.targets diff --git a/app/models/manageiq/providers/nuage/network_manager/network_group.rb b/app/models/manageiq/providers/nuage/network_manager/network_group.rb deleted file mode 100644 index b74b73dcf3..0000000000 --- a/app/models/manageiq/providers/nuage/network_manager/network_group.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup < ::NetworkGroup -end diff --git a/spec/factories/cloud_tenant.rb b/spec/factories/cloud_tenant.rb new file mode 100644 index 0000000000..9f6873e194 --- /dev/null +++ b/spec/factories/cloud_tenant.rb @@ -0,0 +1,3 @@ +FactoryGirl.define do + factory :cloud_tenant_nuage, :class => "ManageIQ::Providers::Nuage::NetworkManager::CloudTenant" +end diff --git a/spec/factories/network_group.rb b/spec/factories/network_group.rb deleted file mode 100644 index a17010945d..0000000000 --- a/spec/factories/network_group.rb +++ /dev/null @@ -1,3 +0,0 @@ -FactoryGirl.define do - factory :network_group_nuage, :class => "ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup" -end diff --git a/spec/models/manageiq/providers/nuage/network_manager/event_target_parser_spec.rb b/spec/models/manageiq/providers/nuage/network_manager/event_target_parser_spec.rb index 6b3c17d285..9c9b07c6b7 100644 --- a/spec/models/manageiq/providers/nuage/network_manager/event_target_parser_spec.rb +++ b/spec/models/manageiq/providers/nuage/network_manager/event_target_parser_spec.rb @@ -11,7 +11,7 @@ it "entityType: enterprise" do assert_event_triggers_target( 'enterprise_create.json', - [[:network_groups, {:ems_ref => 'fda58efc-7f7c-4a51-b6b4-24b32d755785'}]] + [[:cloud_tenants, {:ems_ref => 'fda58efc-7f7c-4a51-b6b4-24b32d755785'}]] ) end @@ -32,7 +32,7 @@ it "entityType: domain" do assert_event_triggers_target( 'domain_create.json', - [[:network_groups, {:ems_ref => 'fda58efc-7f7c-4a51-b6b4-24b32d755785'}]] + [[:cloud_tenants, {:ems_ref => 'fda58efc-7f7c-4a51-b6b4-24b32d755785'}]] ) end end diff --git a/spec/models/manageiq/providers/nuage/network_manager/inventory_parser_spec.rb b/spec/models/manageiq/providers/nuage/network_manager/inventory_parser_spec.rb index f0eeaf43ab..47082a20ce 100644 --- a/spec/models/manageiq/providers/nuage/network_manager/inventory_parser_spec.rb +++ b/spec/models/manageiq/providers/nuage/network_manager/inventory_parser_spec.rb @@ -14,10 +14,10 @@ allow(subject).to receive(:collector).and_return(collector) end - let(:collector) { double('collector', :zone => zone, :domain => domain, :network_group => network_group) } - let(:zone) { {} } - let(:domain) { {} } - let(:network_group) { {} } + let(:collector) { double('collector', :zone => zone, :domain => domain, :cloud_tenant => cloud_tenant) } + let(:zone) { {} } + let(:domain) { {} } + let(:cloud_tenant) { {} } context 'when zone not found' do let(:zone) { nil } @@ -34,19 +34,19 @@ end context 'when network group not found' do - let(:network_group) { nil } + let(:cloud_tenant) { nil } it 'invoke' do expect(subject.send(:map_extra_attributes, 'the-zone')).to eq(nil) end end context 'regular case' do - let(:zone) { { 'name' => 'Zone Name', 'parentID' => 'domain-id' } } - let(:domain) { { 'name' => 'Domain Name', 'parentID' => 'network-group-id' } } - let(:network_group) { { 'name' => 'Network Group Name' } } + let(:zone) { { 'name' => 'Zone Name', 'parentID' => 'domain-id' } } + let(:domain) { { 'name' => 'Domain Name', 'parentID' => 'network-group-id' } } + let(:cloud_tenant) { { 'name' => 'Tenant Name' } } it 'invoke' do expect(subject.send(:map_extra_attributes, 'the-zone')).to eq( - 'enterprise_name' => 'Network Group Name', + 'enterprise_name' => 'Tenant Name', 'enterprise_id' => 'network-group-id', 'domain_name' => 'Domain Name', 'domain_id' => 'domain-id', @@ -69,7 +69,7 @@ it 'map_extra_attributes returns nothing' do expect(persister).to receive_message_chain(:cloud_subnets, :find_or_build, :assign_attributes).with(hash_including(:extra_attributes => {})) - expect(persister).to receive_message_chain(:network_groups, :lazy_find).with(nil) + expect(persister).to receive_message_chain(:cloud_tenants, :lazy_find).with(nil) subject.send(:cloud_subnets) end end @@ -84,8 +84,8 @@ let(:collector) { double('collector', :domain => nil, :security_groups => [{}]) } it 'domain not found' do - expect(persister).to receive_message_chain(:security_groups, :find_or_build, :assign_attributes).with(hash_including(:network_group => nil)) - expect(persister).to receive_message_chain(:network_groups, :lazy_find).with(nil) + expect(persister).to receive_message_chain(:security_groups, :find_or_build, :assign_attributes).with(hash_including(:cloud_tenant => nil)) + expect(persister).to receive_message_chain(:cloud_tenants, :lazy_find).with(nil) subject.send(:security_groups) end end diff --git a/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/refresher_spec.rb b/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/refresher_spec.rb index 7d14561dfb..7bbc843368 100644 --- a/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/refresher_spec.rb +++ b/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/refresher_spec.rb @@ -1,26 +1,26 @@ describe ManageIQ::Providers::Nuage::NetworkManager::Refresher do ALL_REFRESH_SETTINGS = [ - { - :inventory_object_refresh => false - }, { :inventory_object_refresh => true, :inventory_collections => { :saver_strategy => :default, }, - }, { + }, + { :inventory_object_refresh => true, :inventory_collections => { :saver_strategy => :batch, :use_ar_object => true, }, - }, { + }, + { :inventory_object_refresh => true, :inventory_collections => { :saver_strategy => :batch, :use_ar_object => false, }, - }, { + }, + { :inventory_object_saving_strategy => :recursive, :inventory_object_refresh => true } @@ -51,8 +51,8 @@ end describe "refresh" do - let(:network_group_ref1) { "713d0ba0-dea8-44b4-8ac7-6cab9dc321a7" } - let(:network_group_ref2) { "e0819464-e7fc-4a37-b29a-e72da7b5956c" } + let(:tenant_ref1) { "713d0ba0-dea8-44b4-8ac7-6cab9dc321a7" } + let(:tenant_ref2) { "e0819464-e7fc-4a37-b29a-e72da7b5956c" } let(:security_group_ref) { "02e072ef-ca95-4164-856d-3ff177b9c13c" } let(:cloud_subnet_ref1) { "d60d316a-c1ac-4412-813c-9652bdbc4e41" } let(:cloud_subnet_ref2) { "debb9f88-f252-4c30-9a17-d6ae3865e365" } @@ -78,7 +78,7 @@ @ems.reload assert_table_counts assert_ems - assert_network_groups + assert_cloud_tenants assert_security_groups assert_cloud_subnets end @@ -89,7 +89,7 @@ def assert_table_counts expect(ExtManagementSystem.count).to eq(1) - expect(NetworkGroup.count).to eq(2) + expect(CloudTenant.count).to eq(2) expect(SecurityGroup.count).to eq(1) expect(CloudSubnet.count).to eq(2) expect(FloatingIp.count).to eq(0) @@ -98,41 +98,35 @@ def assert_table_counts end def assert_ems - expect(@ems.network_groups.count).to eq(2) + expect(@ems.cloud_tenants.count).to eq(2) expect(@ems.security_groups.count).to eq(1) expect(@ems.cloud_subnets.count).to eq(2) - expect(@ems.network_groups.map(&:ems_ref)) - .to match_array([network_group_ref1, network_group_ref2]) + expect(@ems.cloud_tenants.map(&:ems_ref)) + .to match_array([tenant_ref1, tenant_ref2]) expect(@ems.security_groups.map(&:ems_ref)) .to match_array([security_group_ref]) expect(@ems.cloud_subnets.map(&:ems_ref)) .to match_array([cloud_subnet_ref1, cloud_subnet_ref2]) end - def assert_network_groups - g1 = NetworkGroup.find_by(:ems_ref => network_group_ref1) + def assert_cloud_tenants + g1 = CloudTenant.find_by(:ems_ref => tenant_ref1) expect(g1).to have_attributes( - :name => "Ansible-Test", - :cidr => nil, - :status => "active", - :enabled => nil, - :ems_id => @ems.id, - :orchestration_stack_id => nil, - :type => "ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup" + :name => "Ansible-Test", + :enabled => nil, + :ems_id => @ems.id, + :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudTenant" ) expect(g1.cloud_subnets.count).to eq(0) expect(g1.security_groups.count).to eq(0) - g2 = NetworkGroup.find_by(:ems_ref => network_group_ref2) + g2 = CloudTenant.find_by(:ems_ref => tenant_ref2) expect(g2).to have_attributes( - :name => "XLAB", - :cidr => nil, - :status => "active", - :enabled => nil, - :ems_id => @ems.id, - :orchestration_stack_id => nil, - :type => "ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup" + :name => "XLAB", + :enabled => nil, + :ems_id => @ems.id, + :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudTenant" ) expect(g2.cloud_subnets.count).to eq(2) expect(g2.security_groups.count).to eq(1) @@ -151,10 +145,9 @@ def assert_security_groups :type => "ManageIQ::Providers::Nuage::NetworkManager::SecurityGroup", :ems_id => @ems.id, :cloud_network_id => nil, - :cloud_tenant_id => nil, + :cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref2).id, :orchestration_stack_id => nil ) - expect(g1.network_group.ems_ref).to eq(network_group_ref2) end def assert_cloud_subnets @@ -169,17 +162,16 @@ def assert_cloud_subnets :dhcp_enabled => false, :gateway => "10.10.20.1", :network_protocol => "ipv4", - :cloud_tenant_id => nil, + :cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref2).id, :dns_nameservers => nil, :ipv6_router_advertisement_mode => nil, :ipv6_address_mode => nil, :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet", :network_router_id => nil, - :network_group_id => NetworkGroup.find_by(:ems_ref => network_group_ref2).id, :parent_cloud_subnet_id => nil, :extra_attributes => { "enterprise_name" => "XLAB", - "enterprise_id" => network_group_ref2, + "enterprise_id" => tenant_ref2, "domain_name" => "BaseL3", "domain_id" => "75ad8ee8-726c-4950-94bc-6a5aab64631d", "zone_name" => "Zone 1", @@ -198,17 +190,16 @@ def assert_cloud_subnets :dhcp_enabled => false, :gateway => "10.10.10.1", :network_protocol => "ipv4", - :cloud_tenant_id => nil, + :cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref2).id, :dns_nameservers => nil, :ipv6_router_advertisement_mode => nil, :ipv6_address_mode => nil, :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet", :network_router_id => nil, - :network_group_id => NetworkGroup.find_by(:ems_ref => network_group_ref2).id, :parent_cloud_subnet_id => nil, :extra_attributes => { "enterprise_name" => "XLAB", - "enterprise_id" => network_group_ref2, + "enterprise_id" => tenant_ref2, "domain_name" => "BaseL3", "domain_id" => "75ad8ee8-726c-4950-94bc-6a5aab64631d", "zone_name" => "Zone 0", diff --git a/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/targeted_refresh_spec.rb b/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/targeted_refresh_spec.rb index 64d2a01ef0..9819dc8ce5 100644 --- a/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/targeted_refresh_spec.rb +++ b/spec/models/manageiq/providers/nuage/network_manager/vcr_specs/targeted_refresh_spec.rb @@ -51,7 +51,7 @@ end describe "targeted refresh" do - let(:network_group_ref) { "e0819464-e7fc-4a37-b29a-e72da7b5956c" } + let(:tenant_ref) { "e0819464-e7fc-4a37-b29a-e72da7b5956c" } let(:security_group_ref) { "02e072ef-ca95-4164-856d-3ff177b9c13c" } let(:cloud_subnet_ref1) { "d60d316a-c1ac-4412-813c-9652bdbc4e41" } let(:cloud_subnet_ref2) { "debb9f88-f252-4c30-9a17-d6ae3865e365" } @@ -76,11 +76,11 @@ end end - it "will refresh network_group" do - network_group = FactoryGirl.build(:network_group_nuage, :ems_ref => network_group_ref) - test_targeted_refresh([network_group], 'network_group') do - assert_network_group_counts - assert_specific_network_group + it "will refresh cloud tenant" do + tenant = FactoryGirl.build(:cloud_tenant_nuage, :ems_ref => tenant_ref) + test_targeted_refresh([tenant], 'cloud_tenant') do + assert_cloud_tenant_counts + assert_specific_cloud_tenant end end @@ -95,23 +95,23 @@ describe "on populated database" do context "object updated on remote server" do - let!(:network_group) do - FactoryGirl.create(:network_group_nuage, :ems_id => @ems.id, :ems_ref => network_group_ref, :name => nil) + let!(:cloud_tenant) do + FactoryGirl.create(:cloud_tenant_nuage, :ems_id => @ems.id, :ems_ref => tenant_ref, :name => nil) end let!(:cloud_subnet) do FactoryGirl.create(:cloud_subnet_nuage, :ems_id => @ems.id, :ems_ref => cloud_subnet_ref1, - :network_group => network_group, :name => nil) + :cloud_tenant => cloud_tenant, :name => nil) end let!(:security_group) do FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => security_group_ref, - :network_group => network_group, :name => nil) + :cloud_tenant => cloud_tenant, :name => nil) end - it "network_group is updated" do - test_targeted_refresh([network_group], 'network_group_is_updated') do - assert_fetched(network_group) + it "cloud_tenant is updated" do + test_targeted_refresh([cloud_tenant], 'cloud_tenant_is_updated') do + assert_fetched(cloud_tenant) assert_fetched(cloud_subnet) assert_fetched(security_group) end @@ -119,7 +119,7 @@ it "cloud_subnet is updated" do test_targeted_refresh([cloud_subnet], 'cloud_subnet_is_updated') do - assert_fetched(network_group) + assert_fetched(cloud_tenant) assert_fetched(cloud_subnet) assert_fetched(security_group) end @@ -127,7 +127,7 @@ it "security_group is updated" do test_targeted_refresh([security_group], 'security_group_is_updated') do - assert_fetched(network_group) + assert_fetched(cloud_tenant) assert_not_fetched(cloud_subnet) assert_fetched(security_group) end @@ -135,33 +135,33 @@ end context "object no longer exists on remote server" do - it "unexisting network_group is deleted" do - network_group = FactoryGirl.create(:network_group_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref) - cloud_subnet = FactoryGirl.create(:cloud_subnet_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :network_group => network_group) - security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :network_group => network_group) - test_targeted_refresh([network_group], 'network_group_is_deleted', :repeat => 1) do - assert_deleted(network_group) + it "unexisting cloud_tenant is deleted" do + cloud_tenant = FactoryGirl.create(:cloud_tenant_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref) + cloud_subnet = FactoryGirl.create(:cloud_subnet_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :cloud_tenant => cloud_tenant) + security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :cloud_tenant => cloud_tenant) + test_targeted_refresh([cloud_tenant], 'cloud_tenant_is_deleted', :repeat => 1) do + assert_deleted(cloud_tenant) assert_deleted(cloud_subnet) assert_deleted(security_group) end end - it "unexisting cloud_subnet is deleted, but related network_group and security_group updated" do - network_group = FactoryGirl.create(:network_group_nuage, :ems_id => @ems.id, :ems_ref => network_group_ref) - cloud_subnet = FactoryGirl.create(:cloud_subnet_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :network_group => network_group) - security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => security_group_ref, :network_group => network_group) + it "unexisting cloud_subnet is deleted, but related cloud_tenant and security_group updated" do + cloud_tenant = FactoryGirl.create(:cloud_tenant_nuage, :ems_id => @ems.id, :ems_ref => tenant_ref) + cloud_subnet = FactoryGirl.create(:cloud_subnet_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :cloud_tenant => cloud_tenant) + security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => security_group_ref, :cloud_tenant => cloud_tenant) test_targeted_refresh([cloud_subnet], 'cloud_subnet_is_deleted', :repeat => 1) do - assert_fetched(network_group) + assert_fetched(cloud_tenant) assert_deleted(cloud_subnet) assert_fetched(security_group) end end - it "unexisting security_group is deleted, but related network_group updated" do - network_group = FactoryGirl.create(:network_group_nuage, :ems_id => @ems.id, :ems_ref => network_group_ref) - security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :network_group => network_group) + it "unexisting security_group is deleted, but related cloud_tenant updated" do + cloud_tenant = FactoryGirl.create(:cloud_tenant_nuage, :ems_id => @ems.id, :ems_ref => tenant_ref) + security_group = FactoryGirl.create(:security_group_nuage, :ems_id => @ems.id, :ems_ref => unexisting_ref, :cloud_tenant => cloud_tenant) test_targeted_refresh([security_group], 'security_group_is_deleted', :repeat => 1) do - assert_fetched(network_group) + assert_fetched(cloud_tenant) assert_deleted(security_group) end end @@ -190,8 +190,8 @@ def active_records_to_targets(targets) case target when ManagerRefresh::Target return target - when NetworkGroup - association = :network_groups + when CloudTenant + association = :cloud_tenants when CloudSubnet association = :cloud_subnets when SecurityGroup @@ -207,7 +207,7 @@ def active_records_to_targets(targets) def assert_cloud_subnet_counts expect(ExtManagementSystem.count).to eq(1) - expect(NetworkGroup.count).to eq(1) + expect(CloudTenant.count).to eq(1) expect(SecurityGroup.count).to eq(1) expect(CloudSubnet.count).to eq(1) expect(FloatingIp.count).to eq(0) @@ -227,17 +227,16 @@ def assert_specific_cloud_subnet :dhcp_enabled => false, :gateway => "10.10.20.1", :network_protocol => "ipv4", - :cloud_tenant_id => nil, + :cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref).id, :dns_nameservers => nil, :ipv6_router_advertisement_mode => nil, :ipv6_address_mode => nil, :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudSubnet", :network_router_id => nil, - :network_group_id => NetworkGroup.find_by(:ems_ref => network_group_ref).id, :parent_cloud_subnet_id => nil, :extra_attributes => { "enterprise_name" => "XLAB", - "enterprise_id" => network_group_ref, + "enterprise_id" => tenant_ref, "domain_name" => "BaseL3", "domain_id" => "75ad8ee8-726c-4950-94bc-6a5aab64631d", "zone_name" => "Zone 1", @@ -246,9 +245,9 @@ def assert_specific_cloud_subnet ) end - def assert_network_group_counts + def assert_cloud_tenant_counts expect(ExtManagementSystem.count).to eq(1) - expect(NetworkGroup.count).to eq(1) + expect(CloudTenant.count).to eq(1) expect(SecurityGroup.count).to eq(1) expect(CloudSubnet.count).to eq(2) expect(FloatingIp.count).to eq(0) @@ -256,16 +255,12 @@ def assert_network_group_counts expect(NetworkRouter.count).to eq(0) end - def assert_specific_network_group - g = NetworkGroup.find_by(:ems_ref => network_group_ref) + def assert_specific_cloud_tenant + g = CloudTenant.find_by(:ems_ref => tenant_ref) expect(g).to have_attributes( - :name => "XLAB", - :cidr => nil, - :status => "active", - :enabled => nil, - :ems_id => @ems.id, - :orchestration_stack_id => nil, - :type => "ManageIQ::Providers::Nuage::NetworkManager::NetworkGroup" + :name => "XLAB", + :ems_id => @ems.id, + :type => "ManageIQ::Providers::Nuage::NetworkManager::CloudTenant" ) expect(g.cloud_subnets.count).to eq(2) expect(g.security_groups.count).to eq(1) @@ -278,7 +273,7 @@ def assert_specific_network_group def assert_security_group_counts expect(ExtManagementSystem.count).to eq(1) - expect(NetworkGroup.count).to eq(1) + expect(CloudTenant.count).to eq(1) expect(SecurityGroup.count).to eq(1) expect(CloudSubnet.count).to eq(0) expect(FloatingIp.count).to eq(0) @@ -294,10 +289,9 @@ def assert_specific_security_group :type => "ManageIQ::Providers::Nuage::NetworkManager::SecurityGroup", :ems_id => @ems.id, :cloud_network_id => nil, - :cloud_tenant_id => nil, + :cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref).id, :orchestration_stack_id => nil ) - expect(g1.network_group.ems_ref).to eq(network_group_ref) end def assert_fetched(instance) diff --git a/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group.yml b/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant.yml similarity index 100% rename from spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group.yml rename to spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant.yml diff --git a/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group_is_deleted.yml b/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant_is_deleted.yml similarity index 100% rename from spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group_is_deleted.yml rename to spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant_is_deleted.yml diff --git a/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group_is_updated.yml b/spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant_is_updated.yml similarity index 100% rename from spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/network_group_is_updated.yml rename to spec/vcr_cassettes/manageiq/providers/nuage/network_manager/refresher_targeted/cloud_tenant_is_updated.yml