Merge "Remove hardcoded check for subnet actions of a shared network"
This commit is contained in:
commit
80643ca53f
|
@ -31,33 +31,30 @@ from openstack_dashboard.usage import quotas
|
||||||
LOG = logging.getLogger(__name__)
|
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):
|
class SubnetPolicyTargetMixin(policy.PolicyTargetMixin):
|
||||||
|
|
||||||
def get_policy_target(self, request, datum=None):
|
def get_policy_target(self, request, datum=None):
|
||||||
policy_target = super(SubnetPolicyTargetMixin, self)\
|
policy_target = super(SubnetPolicyTargetMixin, self)\
|
||||||
.get_policy_target(request, datum)
|
.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
|
# neutron switched policy target values, we'll support both
|
||||||
policy_target["network:tenant_id"] = network.tenant_id
|
policy_target["network:tenant_id"] = network.tenant_id
|
||||||
policy_target["network:project_id"] = network.tenant_id
|
policy_target["network:project_id"] = network.tenant_id
|
||||||
return policy_target
|
return policy_target
|
||||||
|
|
||||||
|
|
||||||
class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
class DeleteSubnet(SubnetPolicyTargetMixin, tables.DeleteAction):
|
||||||
tables.DeleteAction):
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def action_present(count):
|
def action_present(count):
|
||||||
return ungettext_lazy(
|
return ungettext_lazy(
|
||||||
|
@ -89,8 +86,7 @@ class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
|
||||||
class CreateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
class CreateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
|
||||||
tables.LinkAction):
|
|
||||||
name = "create"
|
name = "create"
|
||||||
verbose_name = _("Create Subnet")
|
verbose_name = _("Create Subnet")
|
||||||
url = "horizon:project:networks:createsubnet"
|
url = "horizon:project:networks:createsubnet"
|
||||||
|
@ -118,8 +114,7 @@ class CreateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class UpdateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
class UpdateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
|
||||||
tables.LinkAction):
|
|
||||||
name = "update"
|
name = "update"
|
||||||
verbose_name = _("Edit Subnet")
|
verbose_name = _("Edit Subnet")
|
||||||
url = "horizon:project:networks:editsubnet"
|
url = "horizon:project:networks:editsubnet"
|
||||||
|
|
|
@ -1110,7 +1110,6 @@ class NetworkSubnetTests(test.TestCase):
|
||||||
|
|
||||||
@test.create_stubs({api.neutron: ('subnet_delete',
|
@test.create_stubs({api.neutron: ('subnet_delete',
|
||||||
'subnet_list',
|
'subnet_list',
|
||||||
'network_get',
|
|
||||||
'port_list',
|
'port_list',
|
||||||
'is_extension_supported',)})
|
'is_extension_supported',)})
|
||||||
def test_subnet_delete_with_mac_learning(self):
|
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_delete(IsA(http.HttpRequest), subnet.id)
|
||||||
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
||||||
.AndReturn([self.subnets.first()])
|
.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),
|
api.neutron.is_extension_supported(IsA(http.HttpRequest),
|
||||||
'mac-learning')\
|
'mac-learning')\
|
||||||
.AndReturn(mac_learning)
|
.AndReturn(mac_learning)
|
||||||
|
@ -1145,7 +1142,6 @@ class NetworkSubnetTests(test.TestCase):
|
||||||
|
|
||||||
@test.create_stubs({api.neutron: ('subnet_delete',
|
@test.create_stubs({api.neutron: ('subnet_delete',
|
||||||
'subnet_list',
|
'subnet_list',
|
||||||
'network_get',
|
|
||||||
'port_list',
|
'port_list',
|
||||||
'is_extension_supported',)})
|
'is_extension_supported',)})
|
||||||
def test_subnet_delete_exception_with_mac_learning(self):
|
def test_subnet_delete_exception_with_mac_learning(self):
|
||||||
|
@ -1158,8 +1154,6 @@ class NetworkSubnetTests(test.TestCase):
|
||||||
.AndRaise(self.exceptions.neutron)
|
.AndRaise(self.exceptions.neutron)
|
||||||
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
||||||
.AndReturn([self.subnets.first()])
|
.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),
|
api.neutron.is_extension_supported(IsA(http.HttpRequest),
|
||||||
'mac-learning')\
|
'mac-learning')\
|
||||||
.AndReturn(mac_learning)
|
.AndReturn(mac_learning)
|
||||||
|
|
|
@ -24,6 +24,8 @@ from horizon import exceptions
|
||||||
from horizon import tables
|
from horizon import tables
|
||||||
|
|
||||||
from openstack_dashboard import api
|
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 import policy
|
||||||
from openstack_dashboard.usage import quotas
|
from openstack_dashboard.usage import quotas
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ class EditNetwork(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
policy_rules = (("network", "update_network"),)
|
policy_rules = (("network", "update_network"),)
|
||||||
|
|
||||||
|
|
||||||
class CreateSubnet(policy.PolicyTargetMixin, tables.LinkAction):
|
class CreateSubnet(subnet_tables.SubnetPolicyTargetMixin, tables.LinkAction):
|
||||||
name = "subnet"
|
name = "subnet"
|
||||||
verbose_name = _("Create Subnet")
|
verbose_name = _("Create Subnet")
|
||||||
url = "horizon:project:networks:createsubnet"
|
url = "horizon:project:networks:createsubnet"
|
||||||
|
|
|
@ -213,8 +213,6 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
|
||||||
.AndReturn(self.networks.first())
|
.AndReturn(self.networks.first())
|
||||||
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\
|
||||||
.AndReturn([self.subnets.first()])
|
.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),
|
api.neutron.is_extension_supported(IsA(http.HttpRequest),
|
||||||
'mac-learning')\
|
'mac-learning')\
|
||||||
.AndReturn(mac_learning)
|
.AndReturn(mac_learning)
|
||||||
|
@ -326,8 +324,6 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
|
||||||
AndReturn(self.networks.first())
|
AndReturn(self.networks.first())
|
||||||
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
|
api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
|
||||||
AndReturn([self.subnets.first()])
|
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),
|
api.neutron.is_extension_supported(IsA(http.HttpRequest),
|
||||||
'mac-learning')\
|
'mac-learning')\
|
||||||
.AndReturn(mac_learning)
|
.AndReturn(mac_learning)
|
||||||
|
|
Loading…
Reference in New Issue