Merge "Remove hardcoded check for subnet actions of a shared network"

This commit is contained in:
Jenkins 2017-10-14 11:58:22 +00:00 committed by Gerrit Code Review
commit 80643ca53f
4 changed files with 18 additions and 31 deletions

View File

@ -31,33 +31,30 @@ from openstack_dashboard.usage import quotas
LOG = logging.getLogger(__name__)
class CheckNetworkEditable(object):
"""Mixin class to determine the specified network is editable."""
def allowed(self, request, datum=None):
# Only administrator is allowed to create and manage subnets
# on shared networks.
network = self.table._get_network()
if network.shared:
return False
return True
class SubnetPolicyTargetMixin(policy.PolicyTargetMixin):
def get_policy_target(self, request, datum=None):
policy_target = super(SubnetPolicyTargetMixin, self)\
.get_policy_target(request, datum)
network = self.table._get_network()
# Use the network information if it is passed in with datum.
if datum and "tenant_id" in datum:
network = datum
else:
# This is called by the table actions of the subnets table on the
# network details panel and some information is not available.
# 1. Network information is not passed in so need to make a neutron
# API call to get it.
# 2. tenant_id and project_id are missing from policy_target.
network = self.table._get_network()
policy_target["tenant_id"] = network.tenant_id
policy_target["project_id"] = network.tenant_id
# neutron switched policy target values, we'll support both
policy_target["network:tenant_id"] = network.tenant_id
policy_target["network:project_id"] = network.tenant_id
return policy_target
class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
tables.DeleteAction):
class DeleteSubnet(SubnetPolicyTargetMixin, tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
@ -89,8 +86,7 @@ class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
exceptions.handle(request, msg, redirect=redirect)
class CreateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
tables.LinkAction):
class CreateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
name = "create"
verbose_name = _("Create Subnet")
url = "horizon:project:networks:createsubnet"
@ -118,8 +114,7 @@ class CreateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
return True
class UpdateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
tables.LinkAction):
class UpdateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
name = "update"
verbose_name = _("Edit Subnet")
url = "horizon:project:networks:editsubnet"

View File

@ -1110,7 +1110,6 @@ class NetworkSubnetTests(test.TestCase):
@test.create_stubs({api.neutron: ('subnet_delete',
'subnet_list',
'network_get',
'port_list',
'is_extension_supported',)})
def test_subnet_delete_with_mac_learning(self):
@ -1122,8 +1121,6 @@ class NetworkSubnetTests(test.TestCase):
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet.id)
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
.AndReturn([self.subnets.first()])
api.neutron.network_get(IsA(http.HttpRequest), network_id)\
.AndReturn(self.networks.first())
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'mac-learning')\
.AndReturn(mac_learning)
@ -1145,7 +1142,6 @@ class NetworkSubnetTests(test.TestCase):
@test.create_stubs({api.neutron: ('subnet_delete',
'subnet_list',
'network_get',
'port_list',
'is_extension_supported',)})
def test_subnet_delete_exception_with_mac_learning(self):
@ -1158,8 +1154,6 @@ class NetworkSubnetTests(test.TestCase):
.AndRaise(self.exceptions.neutron)
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
.AndReturn([self.subnets.first()])
api.neutron.network_get(IsA(http.HttpRequest), network_id)\
.AndReturn(self.networks.first())
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'mac-learning')\
.AndReturn(mac_learning)

View File

@ -24,6 +24,8 @@ from horizon import exceptions
from horizon import tables
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.networks.subnets import tables \
as subnet_tables
from openstack_dashboard import policy
from openstack_dashboard.usage import quotas
@ -104,7 +106,7 @@ class EditNetwork(policy.PolicyTargetMixin, tables.LinkAction):
policy_rules = (("network", "update_network"),)
class CreateSubnet(policy.PolicyTargetMixin, tables.LinkAction):
class CreateSubnet(subnet_tables.SubnetPolicyTargetMixin, tables.LinkAction):
name = "subnet"
verbose_name = _("Create Subnet")
url = "horizon:project:networks:createsubnet"

View File

@ -213,8 +213,6 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
.AndReturn(self.networks.first())
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
.AndReturn([self.subnets.first()])
api.neutron.network_get(IsA(http.HttpRequest), network_id)\
.AndReturn(self.networks.first())
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'mac-learning')\
.AndReturn(mac_learning)
@ -326,8 +324,6 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
AndReturn(self.networks.first())
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
AndReturn([self.subnets.first()])
api.neutron.network_get(IsA(http.HttpRequest), network_id).\
AndReturn(self.networks.first())
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'mac-learning')\
.AndReturn(mac_learning)