diff --git a/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb b/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb index da6be923f9..e06a4eb0b3 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb @@ -8,6 +8,7 @@ def initialize_inventory_collections(ems) :builder_params => {:ems_id => ems.id}, :association => :container_projects, :secondary_refs => {:by_name => [:name]}, + :delete_method => :disconnect_inv, ) initialize_custom_attributes_collections(ems.container_projects, %w(labels additional_attributes)) @@ -88,6 +89,7 @@ def initialize_inventory_collections(ems) # TODO: old save matches on [:image_ref, :container_image_registry_id] # TODO: should match on digest when available :manager_ref => [:image_ref], + :delete_method => :disconnect_inv, ) initialize_custom_attributes_collections(ems.container_images, %w(labels docker_labels)) @@ -99,6 +101,7 @@ def initialize_inventory_collections(ems) :association => :container_groups, :secondary_refs => {:by_namespace_and_name => [:namespace, :name]}, :attributes_blacklist => [:namespace], + :delete_method => :disconnect_inv, ) initialize_container_conditions_collection(ems.container_groups) initialize_custom_attributes_collections(ems.container_groups, %w(labels node_selectors)) @@ -109,6 +112,7 @@ def initialize_inventory_collections(ems) :builder_params => {:ems_id => ems.id}, :association => :container_definitions, # parser sets :ems_ref => "#{pod_id}_#{container_def.name}_#{container_def.image}" + :delete_method => :disconnect_inv, ) @inv_collections[:container_volumes] = ::ManagerRefresh::InventoryCollection.new( @@ -124,6 +128,7 @@ def initialize_inventory_collections(ems) :builder_params => {:ems_id => ems.id}, :association => :containers, # parser sets :ems_ref => "#{pod_id}_#{container.name}_#{container.image}" + :delete_method => :disconnect_inv, ) @inv_collections[:container_port_configs] = ::ManagerRefresh::InventoryCollection.new( diff --git a/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb index dcf7c947f8..2b3dbc6b95 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb @@ -1,4 +1,7 @@ -describe ManageIQ::Providers::Kubernetes::ContainerManager::Refresher do +# instantiated at the end, for both classical and graph refresh +shared_examples "kubernetes refresher VCR tests" do |check_tag_mapping: true| + let(:check_tag_mapping) { check_tag_mapping } + before(:each) do allow(MiqServer).to receive(:my_zone).and_return("default") auth = AuthToken.new(:name => "test", :auth_key => "valid-token") @@ -28,8 +31,6 @@ ) end - let(:check_tag_mapping) { true } - def full_refresh_test 3.times do # Run three times to verify that second & third runs with existing data do not change anything VCR.use_cassette(described_class.name.underscore) do # , :record => :new_episodes) do @@ -61,22 +62,6 @@ def full_refresh_test full_refresh_test end - describe "graph refresh" do - let(:check_tag_mapping) { false } # TODO: pending implementation - - it "will perform a full refresh with inventory_objects on k8s" do - stub_settings_merge( - :ems_refresh => { - :kubernetes => { - :inventory_object_refresh => true - } - } - ) - - full_refresh_test - end - end - def assert_table_counts expect(ContainerGroup.count).to eq(2) expect(ContainerNode.count).to eq(2) @@ -528,3 +513,30 @@ def assert_disconnected(object) expect(object.archived?).to be true end end + +describe ManageIQ::Providers::Kubernetes::ContainerManager::Refresher do + context "classical refresh" do + before(:each) do + stub_settings_merge( + :ems_refresh => {:kubernetes => {:inventory_object_refresh => false}} + ) + + expect(ManageIQ::Providers::Kubernetes::ContainerManager::RefreshParser).not_to receive(:ems_inv_to_inv_collections) + end + + include_examples "kubernetes refresher VCR tests" + end + + context "graph refresh" do + before(:each) do + stub_settings_merge( + :ems_refresh => {:kubernetes => {:inventory_object_refresh => true}} + ) + + expect(ManageIQ::Providers::Kubernetes::ContainerManager::RefreshParser).not_to receive(:ems_inv_to_hashes) + end + + # TODO: pending graph tag mapping implementation + include_examples "kubernetes refresher VCR tests", :check_tag_mapping => false + end +end