Exclude security group related quotas when the extension disabled

When using neutron as network service and security group extension
disabled, the quotas update workflow will hit some error, because
'security_group' and 'security_group_rule' are passed to the quotas
update method for neutron.
This patch fixes the problem by excluding these two quotas when
neutron security group extension is disabled.

Change-Id: I0011e1c0956d3248b748f109d5ab5e93ec55f7d3
Closes-bug: 1330632
(cherry picked from commit 1246cd32e3)
This commit is contained in:
liyingjun 2014-06-17 23:48:50 +08:00 committed by Dirk Mueller
parent fb429f4978
commit 91098122fc
2 changed files with 20 additions and 8 deletions

View File

@ -272,7 +272,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
'get_disabled_quotas'),
api.cinder: ('tenant_quota_update',),
api.nova: ('tenant_quota_update',)})
def test_add_project_post(self):
def test_add_project_post(self, neutron=False):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
@ -285,6 +285,9 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
# init
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
if neutron:
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
@ -363,7 +366,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
self.tenant.id,
**neutron_updated_quota)
self.test_add_project_post()
self.test_add_project_post(neutron=True)
@test.create_stubs({api.keystone: ('user_list',
'role_list',
@ -817,7 +820,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
api.cinder: ('tenant_quota_update',),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas')})
def test_update_project_save(self):
def test_update_project_save(self, neutron=False):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
@ -836,6 +839,9 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
if neutron:
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
@ -1017,7 +1023,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
self.tenant.id,
**neutron_updated_quota)
self.test_update_project_save()
self.test_update_project_save(neutron=True)
@test.create_stubs({api.keystone: ('tenant_get',)})
def test_update_project_get_error(self):

View File

@ -461,8 +461,11 @@ class CreateProject(workflows.Workflow):
if api.base.is_service_enabled(request, 'network') and \
api.neutron.is_quotas_extension_supported(request):
neutron_data = dict([(key, data[key]) for key in
quotas.NEUTRON_QUOTA_FIELDS])
neutron_data = {}
disabled_quotas = quotas.get_disabled_quotas(request)
for key in quotas.NEUTRON_QUOTA_FIELDS:
if key not in disabled_quotas:
neutron_data[key] = data[key]
api.neutron.tenant_quota_update(request,
project_id,
**neutron_data)
@ -723,8 +726,11 @@ class UpdateProject(workflows.Workflow):
if api.base.is_service_enabled(request, 'network') and \
api.neutron.is_quotas_extension_supported(request):
neutron_data = dict([(key, data[key]) for key in
quotas.NEUTRON_QUOTA_FIELDS])
neutron_data = {}
disabled_quotas = quotas.get_disabled_quotas(request)
for key in quotas.NEUTRON_QUOTA_FIELDS:
if key not in disabled_quotas:
neutron_data[key] = data[key]
api.neutron.tenant_quota_update(request,
project_id,
**neutron_data)