From d80a96a6bcb2615830223c4eac2625dc69795aef Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Wed, 24 Jan 2018 21:40:15 +0200 Subject: [PATCH] Test quotas (and other counts) against new VCR --- .../container_manager/refresher_spec.rb | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) 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 61fbd481b3..f6ecc47b92 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager/refresher_spec.rb @@ -45,10 +45,9 @@ def full_refresh_test(expected_extra_tags: []) assert_specific_container_service assert_specific_container_replicator(:expected_extra_tags => expected_extra_tags) assert_specific_container_project - assert_specific_container_quota assert_specific_container_limit assert_specific_container_image_and_registry - # Volumes, PVs, and PVCs are tested in _before_deletions VCR. + # Quotas, Volumes, PVs, and PVCs are tested in _before_deletions VCR. end it "will perform a full refresh on k8s" do @@ -323,17 +322,36 @@ def assert_specific_container_project end def assert_specific_container_quota - container_quota = ContainerQuota.find_by(:name => "quota") + expect(ContainerQuota.where(:name => "my-resource-quota-scopes2-2").pluck(:deleted_on)).to eq([nil]) # exactly one, active. + container_quota = ContainerQuota.find_by(:name => "my-resource-quota-scopes2-2") expect(container_quota.ems_created_on).to be_a(ActiveSupport::TimeWithZone) - expect(container_quota.container_quota_scopes.count).to eq(0) - expect(container_quota.container_quota_items.count).to eq(8) - cpu_quota = container_quota.container_quota_items.select { |x| x[:resource] == 'cpu' }[0] + expect(container_quota.container_quota_scopes).to contain_exactly( + an_object_having_attributes(:scope => "Terminating"), + an_object_having_attributes(:scope => "NotBestEffort"), + ) + expect(container_quota.container_project.name).to eq("my-project-2") + end + + def assert_specific_container_quota_item + container_quota = ContainerQuota.find_by(:name => "my-resource-quota-scopes2-2") + expect(container_quota.container_quota_items.count).to eq(3) + cpu_quota = container_quota.container_quota_items.find_by(:resource => 'requests.cpu') expect(cpu_quota).to have_attributes( - :quota_desired => 20, - :quota_enforced => 20, - :quota_observed => 0.1, + :quota_desired => 5.7, + :quota_enforced => 5.7, + :quota_observed => 0.0, ) - expect(container_quota.container_project.name).to eq("default") + end + + def assert_modified_container_quota_item + container_quota = ContainerQuota.find_by(:name => "my-resource-quota-scopes2-2") + expect(container_quota.container_quota_items.count).to eq(3) + cpu_quota = container_quota.container_quota_items.find_by(:resource => 'requests.cpu') + expect(cpu_quota).to have_attributes( + :quota_desired => 5.701, + :quota_enforced => 5.701, + :quota_observed => 0.0, + ) end def assert_specific_container_limit @@ -403,11 +421,12 @@ def tag_in_category_with_description(category, description) # using strings instead of actual model classes for compact rspec diffs { 'ContainerNode' => 2, # including the fake @archived_node - 'ContainerGroup' => 10, - 'Container' => 10, - 'ContainerService' => 11, - 'ContainerQuota' => 3, - 'ContainerQuotaItem' => 15, + 'ContainerGroup' => 9, + 'Container' => 9, + 'ContainerService' => 6, + 'ContainerQuota' => 9, + 'ContainerQuotaScope' => 9, + 'ContainerQuotaItem' => 30, 'ContainerLimit' => 3, 'ContainerLimitItem' => 12, 'PersistentVolume' => persintent_volumes_count, @@ -425,6 +444,8 @@ def tag_in_category_with_description(category, description) assert_specific_container_volume assert_specific_persistent_volume assert_specific_persistent_volume_claim + assert_specific_container_quota + assert_specific_container_quota_item end def assert_specific_container_volume @@ -505,8 +526,9 @@ def assert_specific_persistent_volume_claim it "removes the deleted objects from the DB" do deleted = { 'ContainerService' => 2, - 'ContainerQuota' => 2, - 'ContainerQuotaItem' => 10, + 'ContainerQuota' => 6, + 'ContainerQuotaScope' => 6, + 'ContainerQuotaItem' => 2 * 10 + 1, 'ContainerLimit' => 2, 'ContainerLimitItem' => 8, 'PersistentVolume' => 0, @@ -532,8 +554,8 @@ def assert_specific_persistent_volume_claim it "archives & disconnects objects" do archived = { 'ContainerNode' => 1, # the fake @archived_node - 'ContainerGroup' => 3, - 'Container' => 3, + 'ContainerGroup' => 2 * 2 + 1, + 'Container' => 2 * 2 + 1, } actual_archived = archived.collect { |k, _| [k, k.constantize.archived.count] }.to_h expect(actual_archived).to eq(archived) @@ -554,11 +576,11 @@ def assert_specific_persistent_volume_claim assert_disconnected(pod) expect(pod.container_project).not_to be_nil expect(pod.containers.count).to eq(1) - expect(pod.container_volumes.count).to eq(1) + expect(pod.container_volumes.count).to eq(2) # default-token-*, my-pvc-pod-volume-2. TODO: test before deletions end # ContainerVolume records don't get archived themselves, but some belong to archived pods. expect(ContainerVolume.where(:type => 'ContainerVolume').count).to eq(container_volumes_count) - expect(@ems.container_volumes.count).to eq(container_volumes_count - 3) + expect(@ems.container_volumes.count).to eq(container_volumes_count - 12) container0 = Container.find_by(:name => "my-container", :container_group => pod0) container1 = Container.find_by(:name => "my-container", :container_group => pod1) @@ -570,6 +592,11 @@ def assert_specific_persistent_volume_claim expect(container.container_project).not_to be_nil end end + + it "updates quotas" do + assert_specific_container_quota + assert_modified_container_quota_item + end end end