From 6635a30c32f3320e8d9c3239178ae03ccc72868f Mon Sep 17 00:00:00 2001 From: Amelia Cordwell Date: Tue, 30 Jan 2018 14:40:02 +1300 Subject: [PATCH] Lower quota sizes always in preapproved list * Adds a test to check this as well * Also modifies the large_cinder_only quota size to ensure that it is not matching the same amount as the actual large amount Change-Id: Idd66560d27b0867c2532b8ecbfe5268bee76da8c Fixes-Bug: 1746137 --- .../actions/v1/tests/test_resource_actions.py | 2 +- adjutant/api/v1/tests/test_api_openstack.py | 47 +++++++++++++++++++ adjutant/common/quota.py | 5 +- adjutant/test_settings.py | 2 +- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/adjutant/actions/v1/tests/test_resource_actions.py b/adjutant/actions/v1/tests/test_resource_actions.py index 2c90b18..7d768a2 100644 --- a/adjutant/actions/v1/tests/test_resource_actions.py +++ b/adjutant/actions/v1/tests/test_resource_actions.py @@ -458,7 +458,7 @@ class ProjectSetupActionTests(TestCase): self.assertFalse('RegionThree' in nova_cache) r2_cinderquota = cinder_cache['RegionThree'][ 'test_project_id']['quota'] - self.assertEqual(r2_cinderquota['gigabytes'], 50000) + self.assertEqual(r2_cinderquota['gigabytes'], 50001) self.assertEqual(r2_cinderquota['snapshots'], 600) self.assertEqual(r2_cinderquota['volumes'], 200) diff --git a/adjutant/api/v1/tests/test_api_openstack.py b/adjutant/api/v1/tests/test_api_openstack.py index c51b16b..e9f3e2a 100644 --- a/adjutant/api/v1/tests/test_api_openstack.py +++ b/adjutant/api/v1/tests/test_api_openstack.py @@ -1195,3 +1195,50 @@ class QuotaAPITests(APITestCase): self.check_quota_cache('RegionOne', 'test_project_id', 'small') self.check_quota_cache('RegionTwo', 'test_project_id', 'small') + + def test_view_correct_sizes(self): + """ + Calculates the best 'fit' quota size from a custom quota. + """ + + project = fake_clients.FakeProject( + name="test_project", id='test_project_id') + + user = fake_clients.FakeUser( + name="test@example.com", password="123", email="test@example.com") + + setup_identity_cache(projects=[project], users=[user]) + + admin_headers = { + 'project_name': "test_project", + 'project_id': project.id, + 'roles': "project_admin,_member_,project_mod", + 'username': "test@example.com", + 'user_id': user.id, + 'authenticated': True + } + url = "/v1/openstack/quotas/?regions=RegionOne" + + response = self.client.get(url, headers=admin_headers) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + response.data['regions'][0]['current_quota_size'], 'small') + self.assertEqual( + response.data['regions'][0]['quota_change_options'], ['medium']) + + cinder_cache['RegionOne'][project.id][ + 'quota'] = settings.PROJECT_QUOTA_SIZES['large']['cinder'] + + nova_cache['RegionOne'][project.id][ + 'quota'] = settings.PROJECT_QUOTA_SIZES['large']['nova'] + + neutron_cache['RegionOne'][project.id][ + 'quota'] = settings.PROJECT_QUOTA_SIZES['large']['neutron'] + + response = self.client.get(url, headers=admin_headers) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + response.data['regions'][0]['current_quota_size'], 'large') + self.assertEqual( + response.data['regions'][0]['quota_change_options'], + ['small', 'medium']) diff --git a/adjutant/common/quota.py b/adjutant/common/quota.py index f5a4679..3280653 100644 --- a/adjutant/common/quota.py +++ b/adjutant/common/quota.py @@ -83,9 +83,8 @@ class QuotaManager(object): except ValueError: return [] - quota_change_list = [] - if list_position - 1 >= 0: - quota_change_list.append(quota_list[list_position - 1]) + quota_change_list = quota_list[:list_position] + if list_position + 1 < len(quota_list): quota_change_list.append(quota_list[list_position + 1]) diff --git a/adjutant/test_settings.py b/adjutant/test_settings.py index 805ff35..ce491d5 100644 --- a/adjutant/test_settings.py +++ b/adjutant/test_settings.py @@ -374,7 +374,7 @@ PROJECT_QUOTA_SIZES = { }, "large_cinder_only": { "cinder": { - "gigabytes": 50000, + "gigabytes": 50001, "volumes": 200, "snapshots": 600 },