Add a config option to disable Router panel

Neutron setup allows operators not to enable Router feautre
(by not using Router service plugin in neutron.conf) and
some Neutron plugin does not support Router feature.
According to bug 1350639 there is also a case where operators
want to disable Router panel from their policy.
It seems nice we have a option to control Router panel.

This commit add a new option 'enable_router' to OPENSTACK_NEUTRON_NETWORK.
The default is True since router feature is enabled in most deployments
and it is the current default behavior of Horizon.
If this option is False, Router panel will disappear.

blueprint hide-router-panel-by-config
Partial-Bug: #1292022
Closes-Bug: #1350639
Change-Id: If90517bd35c5b18173c54c14a1ba229f97ba4797
This commit is contained in:
Akihiro Motoki 2014-08-09 09:45:56 +09:00
parent 6a8ea3385c
commit 1100169130
7 changed files with 102 additions and 52 deletions

View File

@ -493,6 +493,7 @@ by cinder. Currently only the backup service is available.
Default:: Default::
{ {
'enable_router': True,
'enable_distributed_router': False, 'enable_distributed_router': False,
'enable_lb': False, 'enable_lb': False,
'enable_quotas': False, 'enable_quotas': False,
@ -507,6 +508,16 @@ A dictionary of settings which can be used to enable optional services provided
by Neutron and configure Neutron specific features. The following options are by Neutron and configure Neutron specific features. The following options are
available. available.
``enable_router``:
.. versionadded:: 2014.2(Juno)
Default: ``True``
Enable (True) or disable (False) the router panel. If your neutron
has no support for Layer-3 router features, or you do no not wish to
provide the Layer-3 features through the Dashboard, this should be set to
``False``.
``enable_distributed_router``: ``enable_distributed_router``:

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import horizon import horizon
@ -24,4 +25,6 @@ class Routers(horizon.Panel):
slug = 'routers' slug = 'routers'
permissions = ('openstack.services.network',) permissions = ('openstack.services.network',)
dashboard.Admin.register(Routers) network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
if network_config.get('enable_router', True):
dashboard.Admin.register(Routers)

View File

@ -16,6 +16,7 @@ import json
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django import http from django import http
import django.test
from mox import IsA # noqa from mox import IsA # noqa
@ -34,6 +35,17 @@ class NetworkTopologyTests(test.TestCase):
'router_list', 'router_list',
'port_list')}) 'port_list')})
def test_json_view(self): def test_json_view(self):
self._test_json_view()
@django.test.utils.override_settings(
OPENSTACK_NEUTRON_NETWORK={'enable_router': False})
@test.create_stubs({api.nova: ('server_list',),
api.neutron: ('network_list_for_tenant',
'port_list')})
def test_json_view_router_disabled(self):
self._test_json_view(router_enable=False)
def _test_json_view(self, router_enable=True):
api.nova.server_list( api.nova.server_list(
IsA(http.HttpRequest)).AndReturn([self.servers.list(), False]) IsA(http.HttpRequest)).AndReturn([self.servers.list(), False])
tenant_networks = [net for net in self.networks.list() tenant_networks = [net for net in self.networks.list()
@ -43,6 +55,7 @@ class NetworkTopologyTests(test.TestCase):
api.neutron.network_list_for_tenant( api.neutron.network_list_for_tenant(
IsA(http.HttpRequest), IsA(http.HttpRequest),
self.tenant.id).AndReturn(tenant_networks) self.tenant.id).AndReturn(tenant_networks)
if router_enable:
api.neutron.network_list( api.neutron.network_list(
IsA(http.HttpRequest), IsA(http.HttpRequest),
**{'router:external': True}).AndReturn(external_networks) **{'router:external': True}).AndReturn(external_networks)
@ -51,6 +64,7 @@ class NetworkTopologyTests(test.TestCase):
# router2 : no gateway port # router2 : no gateway port
# router3 : gateway port included in port list # router3 : gateway port included in port list
routers = self.routers.list() + self.routers_with_rules.list() routers = self.routers.list() + self.routers_with_rules.list()
if router_enable:
api.neutron.router_list( api.neutron.router_list(
IsA(http.HttpRequest), IsA(http.HttpRequest),
tenant_id=self.tenant.id).AndReturn(routers) tenant_id=self.tenant.id).AndReturn(routers)
@ -79,6 +93,7 @@ class NetworkTopologyTests(test.TestCase):
# rotuers # rotuers
# result_router_urls = [(router['id'], router['url']) # result_router_urls = [(router['id'], router['url'])
# for router in data['routers']] # for router in data['routers']]
if router_enable:
expect_router_urls = [ expect_router_urls = [
{'id': router.id, {'id': router.id,
'external_gateway_info': 'external_gateway_info':
@ -88,9 +103,13 @@ class NetworkTopologyTests(test.TestCase):
'url': '/project/routers/%s/' % router.id} 'url': '/project/routers/%s/' % router.id}
for router in routers] for router in routers]
self.assertEqual(expect_router_urls, data['routers']) self.assertEqual(expect_router_urls, data['routers'])
else:
self.assertFalse(data['routers'])
# networks # networks
expect_net_urls = [{'id': net.id, expect_net_urls = []
if router_enable:
expect_net_urls += [{'id': net.id,
'url': None, 'url': None,
'name': net.name, 'name': net.name,
'router:external': net.router__external, 'router:external': net.router__external,
@ -119,6 +138,7 @@ class NetworkTopologyTests(test.TestCase):
'status': port.status, 'status': port.status,
'url': '/project/networks/ports/%s/detail' % port.id} 'url': '/project/networks/ports/%s/detail' % port.id}
for port in self.ports.list()] for port in self.ports.list()]
if router_enable:
# fake port for router1 gateway (router1 on ext_net) # fake port for router1 gateway (router1 on ext_net)
router1 = routers[0] router1 = routers[0]
ext_net = external_networks[0] ext_net = external_networks[0]

View File

@ -103,17 +103,25 @@ class NetworkTopologyView(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(NetworkTopologyView, self).get_context_data(**kwargs) context = super(NetworkTopologyView, self).get_context_data(**kwargs)
network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
context['launch_instance_allowed'] = self._has_permission( context['launch_instance_allowed'] = self._has_permission(
(("compute", "compute:create"),)) (("compute", "compute:create"),))
context['create_network_allowed'] = self._has_permission( context['create_network_allowed'] = self._has_permission(
(("network", "create_network"),)) (("network", "create_network"),))
context['create_router_allowed'] = self._has_permission( context['create_router_allowed'] = (
(("network", "create_router"),)) network_config.get('enable_router', True) and
self._has_permission((("network", "create_router"),)))
return context return context
class JSONView(View): class JSONView(View):
@property
def is_router_enabled(self):
network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
return network_config.get('enable_router', True)
def add_resource_url(self, view, resources): def add_resource_url(self, view, resources):
tenant_id = self.request.user.tenant_id tenant_id = self.request.user.tenant_id
for resource in resources: for resource in resources:
@ -170,6 +178,7 @@ class JSONView(View):
networks) networks)
# Add public networks to the networks list # Add public networks to the networks list
if self.is_router_enabled:
try: try:
neutron_public_networks = api.neutron.network_list( neutron_public_networks = api.neutron.network_list(
request, request,
@ -196,6 +205,8 @@ class JSONView(View):
reverse=True) reverse=True)
def _get_routers(self, request): def _get_routers(self, request):
if not self.is_router_enabled:
return []
try: try:
neutron_routers = api.neutron.router_list( neutron_routers = api.neutron.router_list(
request, request,

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import horizon import horizon
@ -24,4 +25,6 @@ class Routers(horizon.Panel):
slug = 'routers' slug = 'routers'
permissions = ('openstack.services.network',) permissions = ('openstack.services.network',)
dashboard.Project.register(Routers) network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
if network_config.get('enable_router', True):
dashboard.Project.register(Routers)

View File

@ -178,6 +178,7 @@ OPENSTACK_CINDER_FEATURES = {
# services provided by neutron. Options currently available are load # services provided by neutron. Options currently available are load
# balancer service, security groups, quotas, VPN service. # balancer service, security groups, quotas, VPN service.
OPENSTACK_NEUTRON_NETWORK = { OPENSTACK_NEUTRON_NETWORK = {
'enable_router': True,
'enable_lb': False, 'enable_lb': False,
'enable_firewall': False, 'enable_firewall': False,
'enable_quotas': True, 'enable_quotas': True,

View File

@ -104,6 +104,7 @@ OPENSTACK_CINDER_FEATURES = {
} }
OPENSTACK_NEUTRON_NETWORK = { OPENSTACK_NEUTRON_NETWORK = {
'enable_router': True,
'enable_lb': True, 'enable_lb': True,
'enable_firewall': True, 'enable_firewall': True,
'enable_quotas': False, # Enabled in specific tests only 'enable_quotas': False, # Enabled in specific tests only