From ebc9ee920eab20f19eb3ea353d48a9ace82475a7 Mon Sep 17 00:00:00 2001 From: Marek Date: Wed, 30 Oct 2019 09:38:29 +0100 Subject: Fixes a series of bugs related to Floating IPs. - Fixes KeyErrors when accessing 'floatingip' values in usages, which broken Floating IP allocation. - The quota display in the bottom right of the Allocation dialog are only displayed if 'enabled_quotas' is True - Adds security group rule tallying for the usages overview page, which fixes a KeyError crash for installations where Horizon 'enable_quotas' is set to true, but the 'quota_details' extension is not installed on in Neutron - Adds a policy check to show and hide The plus/add button in Instances->Associate Floating IP to match the Allocate IP To Project button in Floating IPs - Fixed the page title not being set for the non-modal version of the modal allocation dialog/form - Added an 'allowed' functionality for network usage overview charts to allow for them to be dynamically disabled - Added tests and mocks for the above - Added tests for non-legacy quota tallying for networks - Added test for disabled network quotas in overview Change-Id: I47f73ff94664d315a2400feb8ce8a25f4e6beced closes-bug: #1838522 (cherry picked from commit 161b4ae5d4a7a29f9e5c91d9b391dee49e075993) --- .../dashboards/project/floating_ips/forms.py | 3 +- .../dashboards/project/floating_ips/tables.py | 2 +- .../templates/floating_ips/_allocate.html | 40 ++++---- .../templates/floating_ips/allocate.html | 2 + .../dashboards/project/floating_ips/views.py | 3 +- .../dashboards/project/floating_ips/workflows.py | 10 +- .../dashboards/project/overview/tests.py | 27 ++++-- openstack_dashboard/test/unit/usage/test_quotas.py | 106 ++++++++++++++++++--- openstack_dashboard/usage/quotas.py | 25 ++++- openstack_dashboard/usage/views.py | 33 +++++-- 10 files changed, 196 insertions(+), 55 deletions(-) diff --git a/openstack_dashboard/dashboards/project/floating_ips/forms.py b/openstack_dashboard/dashboards/project/floating_ips/forms.py index 7b9964583..e838bf71c 100644 --- a/openstack_dashboard/dashboards/project/floating_ips/forms.py +++ b/openstack_dashboard/dashboards/project/floating_ips/forms.py @@ -56,7 +56,8 @@ class FloatingIpAllocate(forms.SelfHandlingForm): # Prevent allocating more IP than the quota allows usages = quotas.tenant_quota_usages(request, targets=('floatingip', )) - if usages['floatingip']['available'] <= 0: + if ('floatingip' in usages and + usages['floatingip']['available'] <= 0): error_message = _('You are already using all of your available' ' floating IPs.') self.api_error(error_message) diff --git a/openstack_dashboard/dashboards/project/floating_ips/tables.py b/openstack_dashboard/dashboards/project/floating_ips/tables.py index fe0984491..de7b0fb58 100644 --- a/openstack_dashboard/dashboards/project/floating_ips/tables.py +++ b/openstack_dashboard/dashboards/project/floating_ips/tables.py @@ -49,7 +49,7 @@ class AllocateIP(tables.LinkAction): def allowed(self, request, fip=None): usages = quotas.tenant_quota_usages(request, targets=('floatingip', )) - if usages['floatingip']['available'] <= 0: + if 'floatingip' in usages and usages['floatingip']['available'] <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = format_lazy( diff --git a/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html b/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html index 6bd9e48ac..8dd180100 100644 --- a/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html +++ b/openstack_dashboard/dashboards/project/floating_ips/templates/floating_ips/_allocate.html @@ -5,26 +5,30 @@

{% trans "Description:" %}

{% trans "Allocate a floating IP from a given floating IP pool." %}

+ {% if usages %} +

{% trans "Project Quotas" %}

-

{% trans "Project Quotas" %}

-
-
- {% trans "Floating IP" %} -
- - {% blocktrans with used=usages.floatingip.used quota=usages.floatingip.quota|quotainf %}{{ used }} of {{ quota }} Used{% endblocktrans %} - -
-
- {% widthratio usages.floatingip.used usages.floatingip.quota 100 as ip_percent %} - {% widthratio 100 usages.floatingip.quota 1 as single_step %} - {% bs_progress_bar ip_percent single_step %} -
-
+ {% if usages.floatingip %} +
+
+ {% trans "Floating IP" %} +
+ + {% blocktrans with used=usages.floatingip.used quota=usages.floatingip.quota|quotainf %}{{ used }} of {{ quota }} Used{% endblocktrans %} + +
+
+ {% widthratio usages.floatingip.used usages.floatingip.quota 100 as ip_percent %} + {% widthratio 100 usages.floatingip.quota 1 as single_step %} + {% bs_progress_bar ip_percent single_step %} +
+ {% endif %} + {% endif %} +