From: Henry Gessau Date: Sun, 3 Aug 2014 17:40:01 +0000 (-0400) Subject: Do not assume order of quotas dictionary elements X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5c93dfaf25c81576ddc664d2d30ef8297eb367e1;p=openstack-build%2Fneutron-build.git Do not assume order of quotas dictionary elements This fixes the quotas db unit test that breaks with a randomized PYTHONHASHSEED (see the bug report). The test assumed that the quotas dictionary from plugin.get_all_quotas() had elements in a particular order. Found with PYTHONHASHSEED=1235130571. The fix refactors the test case to handle an unsorted quotas dictionary. Also choose some different quota limits to make it clearer what is being verified. Partial-bug: #1348818 Note: There are several other unrelated unit tests that also break with a randomized PYTHONHASHSEED, but they are not addressed here. They will be addressed in separate patches. Change-Id: I3892b51082629e6ebce175f64f501717741baa37 --- diff --git a/neutron/tests/unit/db/test_quota_db.py b/neutron/tests/unit/db/test_quota_db.py index 813f0166a..9c6bca355 100644 --- a/neutron/tests/unit/db/test_quota_db.py +++ b/neutron/tests/unit/db/test_quota_db.py @@ -78,24 +78,31 @@ class TestDbQuotaDriver(base.BaseTestCase): resource_1 = 'res_test_1' resource_2 = 'res_test_2' - resources = {resource_1: TestResource(resource_1, 1), - resource_2: TestResource(resource_2, 1)} + resources = {resource_1: TestResource(resource_1, 3), + resource_2: TestResource(resource_2, 5)} - self.plugin.update_quota_limit(self.context, project_1, resource_1, 2) - self.plugin.update_quota_limit(self.context, project_2, resource_2, 2) + self.plugin.update_quota_limit(self.context, project_1, resource_1, 7) + self.plugin.update_quota_limit(self.context, project_2, resource_2, 9) quotas = self.plugin.get_all_quotas(self.context, resources) + # Expect two tenants' quotas self.assertEqual(2, len(quotas)) - - self.assertEqual(3, len(quotas[0])) - self.assertEqual(project_1, quotas[0]['tenant_id']) - self.assertEqual(2, quotas[0][resource_1]) - self.assertEqual(1, quotas[0][resource_2]) - - self.assertEqual(3, len(quotas[1])) - self.assertEqual(project_2, quotas[1]['tenant_id']) - self.assertEqual(1, quotas[1][resource_1]) - self.assertEqual(2, quotas[1][resource_2]) + # But not quotas for the same tenant twice + self.assertNotEqual(quotas[0]['tenant_id'], quotas[1]['tenant_id']) + + # Check the expected limits. The quotas can be in any order. + for quota in quotas: + self.assertEqual(3, len(quota)) + project = quota['tenant_id'] + self.assertIn(project, (project_1, project_2)) + if project == project_1: + expected_limit_r1 = 7 + expected_limit_r2 = 5 + if project == project_2: + expected_limit_r1 = 3 + expected_limit_r2 = 9 + self.assertEqual(expected_limit_r1, quota[resource_1]) + self.assertEqual(expected_limit_r2, quota[resource_2]) def test_limit_check(self): resources = {RESOURCE: TestResource(RESOURCE, 2)}