Merge "Handle error from neutron extension check in Overview page"
This commit is contained in:
commit
fd562ed015
@ -278,14 +278,18 @@ class UsageViewTests(test.TestCase):
|
||||
def test_usage_with_neutron_nova_security_group(self):
|
||||
self._test_usage_with_neutron(neutron_sg_enabled=False)
|
||||
|
||||
def _test_usage_with_neutron(self, neutron_sg_enabled=True):
|
||||
def _test_usage_with_neutron_prepare(self):
|
||||
now = timezone.now()
|
||||
usage_obj = api.nova.NovaUsage(self.usages.first())
|
||||
self._stub_nova_api_calls()
|
||||
self._stub_cinder_api_calls()
|
||||
api.nova.extension_supported(
|
||||
'SimpleTenantUsage', IsA(http.HttpRequest)) \
|
||||
.AndReturn(True)
|
||||
self.mox.StubOutWithMock(api.neutron, 'tenant_quota_get')
|
||||
self.mox.StubOutWithMock(api.neutron, 'is_extension_supported')
|
||||
self.mox.StubOutWithMock(api.network, 'tenant_floating_ip_list')
|
||||
self.mox.StubOutWithMock(api.network, 'security_group_list')
|
||||
start = datetime.datetime(now.year, now.month, 1, 0, 0, 0, 0)
|
||||
end = datetime.datetime(now.year, now.month, now.day, 23, 59, 59, 0)
|
||||
api.nova.usage_get(IsA(http.HttpRequest),
|
||||
@ -293,16 +297,28 @@ class UsageViewTests(test.TestCase):
|
||||
start, end).AndReturn(usage_obj)
|
||||
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
|
||||
.AndReturn(self.limits['absolute'])
|
||||
self._stub_neutron_api_calls(neutron_sg_enabled)
|
||||
# NOTE: api.neutron.is_extension_supported is stubbed out in
|
||||
# _stub_neutron_api_calls.
|
||||
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
|
||||
.AndReturn(True)
|
||||
|
||||
def _test_usage_with_neutron(self, neutron_sg_enabled=True):
|
||||
self._test_usage_with_neutron_prepare()
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'quotas').AndReturn(True)
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest),
|
||||
'security-group').AndReturn(neutron_sg_enabled)
|
||||
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.floating_ips.list())
|
||||
if neutron_sg_enabled:
|
||||
api.network.security_group_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.q_secgroups.list())
|
||||
api.neutron.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \
|
||||
.AndReturn(self.neutron_quotas.first())
|
||||
self._stub_cinder_api_calls()
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self._test_usage_with_neutron_check(neutron_sg_enabled)
|
||||
|
||||
def _test_usage_with_neutron_check(self, neutron_sg_enabled=True,
|
||||
max_fip_expected=50,
|
||||
max_sg_expected=20):
|
||||
res = self.client.get(reverse('horizon:project:overview:index'))
|
||||
self.assertContains(res, 'Floating IPs')
|
||||
self.assertContains(res, 'Security Groups')
|
||||
@ -310,11 +326,32 @@ class UsageViewTests(test.TestCase):
|
||||
res_limits = res.context['usage'].limits
|
||||
# Make sure the floating IPs comes from Neutron (50 vs. 10)
|
||||
max_floating_ips = res_limits['maxTotalFloatingIps']
|
||||
self.assertEqual(max_floating_ips, 50)
|
||||
self.assertEqual(max_floating_ips, max_fip_expected)
|
||||
if neutron_sg_enabled:
|
||||
# Make sure the security group limit comes from Neutron (20 vs. 10)
|
||||
max_security_groups = res_limits['maxSecurityGroups']
|
||||
self.assertEqual(max_security_groups, 20)
|
||||
self.assertEqual(max_security_groups, max_sg_expected)
|
||||
|
||||
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
def test_usage_with_neutron_quotas_ext_error(self):
|
||||
self._test_usage_with_neutron_prepare()
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'quotas').AndRaise(self.exceptions.neutron)
|
||||
self.mox.ReplayAll()
|
||||
self._test_usage_with_neutron_check(max_fip_expected=float("inf"),
|
||||
max_sg_expected=float("inf"))
|
||||
|
||||
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
def test_usage_with_neutron_sg_ext_error(self):
|
||||
self._test_usage_with_neutron_prepare()
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'quotas').AndReturn(True)
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest),
|
||||
'security-group').AndRaise(self.exceptions.neutron)
|
||||
self.mox.ReplayAll()
|
||||
self._test_usage_with_neutron_check(max_fip_expected=float("inf"),
|
||||
max_sg_expected=float("inf"))
|
||||
|
||||
def test_usage_with_cinder(self):
|
||||
self._test_usage_cinder(cinder_enabled=True)
|
||||
|
@ -139,26 +139,28 @@ class BaseUsage(object):
|
||||
def get_neutron_limits(self):
|
||||
if not api.base.is_service_enabled(self.request, 'network'):
|
||||
return
|
||||
|
||||
neutron_sg_used = \
|
||||
api.neutron.is_security_group_extension_supported(self.request)
|
||||
|
||||
self._get_neutron_usage(self.limits, 'floatingip')
|
||||
if neutron_sg_used:
|
||||
self._get_neutron_usage(self.limits, 'security_group')
|
||||
|
||||
# Quotas are an optional extension in Neutron. If it isn't
|
||||
# enabled, assume the floating IP limit is infinite.
|
||||
if api.neutron.is_quotas_extension_supported(self.request):
|
||||
try:
|
||||
try:
|
||||
neutron_quotas_supported = \
|
||||
api.neutron.is_quotas_extension_supported(self.request)
|
||||
neutron_sg_used = \
|
||||
api.neutron.is_security_group_extension_supported(self.request)
|
||||
self._get_neutron_usage(self.limits, 'floatingip')
|
||||
if neutron_sg_used:
|
||||
self._get_neutron_usage(self.limits, 'security_group')
|
||||
# Quotas are an optional extension in Neutron. If it isn't
|
||||
# enabled, assume the floating IP limit is infinite.
|
||||
if neutron_quotas_supported:
|
||||
neutron_quotas = api.neutron.tenant_quota_get(self.request,
|
||||
self.project_id)
|
||||
except Exception:
|
||||
else:
|
||||
neutron_quotas = None
|
||||
msg = _('Unable to retrieve network quota information.')
|
||||
exceptions.handle(self.request, msg)
|
||||
else:
|
||||
except Exception:
|
||||
# Assume neutron security group and quotas are enabled
|
||||
# because they are enabled in most Neutron plugins.
|
||||
neutron_sg_used = True
|
||||
neutron_quotas = None
|
||||
msg = _('Unable to retrieve network quota information.')
|
||||
exceptions.handle(self.request, msg)
|
||||
|
||||
self._set_neutron_limit(self.limits, neutron_quotas, 'floatingip')
|
||||
if neutron_sg_used:
|
||||
|
Loading…
Reference in New Issue
Block a user