Skip to content

Commit

Permalink
Test quotas (and other counts) against new VCR
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Jan 28, 2018
1 parent a73f053 commit f5ecabb
Showing 1 changed file with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
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,
)
expect(container_quota.container_project.name).to eq("default")
end

def assert_specific_container_limit
Expand Down Expand Up @@ -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 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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit f5ecabb

Please sign in to comment.