Merge "Prepare trunk rules module to deal with the Ironic use case"
This commit is contained in:
commit
9b4e22bd64
|
@ -162,6 +162,7 @@ class SubPortsValidator(object):
|
||||||
msg = validators.validate_subports(self.subports)
|
msg = validators.validate_subports(self.subports)
|
||||||
if msg:
|
if msg:
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
if trunk_validation:
|
if trunk_validation:
|
||||||
trunk_port_mtu = self._get_port_mtu(context, self.trunk_port_id)
|
trunk_port_mtu = self._get_port_mtu(context, self.trunk_port_id)
|
||||||
return [self._validate(context, s, trunk_port_mtu)
|
return [self._validate(context, s, trunk_port_mtu)
|
||||||
|
@ -182,7 +183,8 @@ class SubPortsValidator(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
port = core_plugin.get_port(context, port_id)
|
port = core_plugin.get_port(context, port_id)
|
||||||
net = core_plugin.get_network(context, port['network_id'])
|
return core_plugin.get_network(
|
||||||
|
context, port['network_id'])[api.MTU]
|
||||||
except (n_exc.PortNotFound, n_exc.NetworkNotFound):
|
except (n_exc.PortNotFound, n_exc.NetworkNotFound):
|
||||||
# A concurrent request might have made the port or network
|
# A concurrent request might have made the port or network
|
||||||
# disappear; though during DB insertion, the subport request
|
# disappear; though during DB insertion, the subport request
|
||||||
|
@ -190,15 +192,11 @@ class SubPortsValidator(object):
|
||||||
# a None MTU here.
|
# a None MTU here.
|
||||||
return
|
return
|
||||||
|
|
||||||
return net[api.MTU]
|
def _raise_subport_is_parent_port(self, context, subport):
|
||||||
|
|
||||||
def _validate(self, context, subport, trunk_port_mtu):
|
|
||||||
# Check that the subport doesn't reference the same port_id as a
|
|
||||||
# trunk we may be in the middle of trying to create, in other words
|
|
||||||
# make the validation idiot proof.
|
|
||||||
if subport['port_id'] == self.trunk_port_id:
|
if subport['port_id'] == self.trunk_port_id:
|
||||||
raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])
|
raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])
|
||||||
|
|
||||||
|
def _raise_subport_invalid_mtu(self, context, subport, trunk_port_mtu):
|
||||||
# Check MTU sanity - subport MTU must not exceed trunk MTU.
|
# Check MTU sanity - subport MTU must not exceed trunk MTU.
|
||||||
# If for whatever reason trunk_port_mtu is not available,
|
# If for whatever reason trunk_port_mtu is not available,
|
||||||
# the MTU sanity check cannot be enforced.
|
# the MTU sanity check cannot be enforced.
|
||||||
|
@ -212,14 +210,12 @@ class SubPortsValidator(object):
|
||||||
trunk_mtu=trunk_port_mtu
|
trunk_mtu=trunk_port_mtu
|
||||||
)
|
)
|
||||||
|
|
||||||
# If the segmentation details are missing, we will need to
|
def _raise_if_segmentation_details_missing(self, subport):
|
||||||
# figure out defaults when the time comes to support Ironic.
|
|
||||||
# We can reasonably expect segmentation details to be provided
|
|
||||||
# in all other cases for now.
|
|
||||||
try:
|
try:
|
||||||
segmentation_type = subport["segmentation_type"]
|
segmentation_type = subport["segmentation_type"]
|
||||||
segmentation_id = (
|
segmentation_id = (
|
||||||
converters.convert_to_int(subport["segmentation_id"]))
|
converters.convert_to_int(subport["segmentation_id"]))
|
||||||
|
return (segmentation_type, segmentation_id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
msg = _("Invalid subport details '%s': missing segmentation "
|
msg = _("Invalid subport details '%s': missing segmentation "
|
||||||
"information. Must specify both segmentation_id and "
|
"information. Must specify both segmentation_id and "
|
||||||
|
@ -230,6 +226,9 @@ class SubPortsValidator(object):
|
||||||
"not an integer") % subport["segmentation_id"]
|
"not an integer") % subport["segmentation_id"]
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
|
def _raise_if_segmentation_details_invalid(self,
|
||||||
|
segmentation_type,
|
||||||
|
segmentation_id):
|
||||||
if segmentation_type not in self._segmentation_types:
|
if segmentation_type not in self._segmentation_types:
|
||||||
msg = _("Unknown segmentation_type '%s'") % segmentation_type
|
msg = _("Unknown segmentation_type '%s'") % segmentation_type
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
@ -238,7 +237,20 @@ class SubPortsValidator(object):
|
||||||
msg = _("Segmentation ID '%s' is not in range") % segmentation_id
|
msg = _("Segmentation ID '%s' is not in range") % segmentation_id
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
# Check if the subport is already participating in an active trunk
|
def _raise_if_subport_is_used_in_other_trunk(self, context, subport):
|
||||||
trunk_validator = TrunkPortValidator(subport['port_id'])
|
trunk_validator = TrunkPortValidator(subport['port_id'])
|
||||||
trunk_validator.validate(context, parent_port=False)
|
trunk_validator.validate(context, parent_port=False)
|
||||||
|
|
||||||
|
def _validate(self, context, subport, trunk_port_mtu):
|
||||||
|
self._raise_subport_is_parent_port(context, subport)
|
||||||
|
|
||||||
|
self._raise_subport_invalid_mtu(context, subport, trunk_port_mtu)
|
||||||
|
|
||||||
|
segmentation_type, segmentation_id = (
|
||||||
|
self._raise_if_segmentation_details_missing(subport))
|
||||||
|
|
||||||
|
self._raise_if_segmentation_details_invalid(
|
||||||
|
segmentation_type, segmentation_id)
|
||||||
|
|
||||||
|
self._raise_if_subport_is_used_in_other_trunk(context, subport)
|
||||||
return subport
|
return subport
|
||||||
|
|
Loading…
Reference in New Issue