Merge "Remove local subports validator"

This commit is contained in:
Jenkins 2016-08-04 12:56:22 +00:00 committed by Gerrit Code Review
commit 6fef9c7909
2 changed files with 2 additions and 65 deletions

View File

@ -13,75 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
from oslo_log import log as logging
from neutron_lib.api import converters
from neutron_lib.api import validators
from neutron._i18n import _
from neutron.api import extensions
from neutron.api.v2 import attributes as attr
from neutron.api.v2 import resource_helper
LOG = logging.getLogger(__name__)
# TODO(armax): this validator was introduced in neutron-lib in
# https://review.openstack.org/#/c/319386/; remove it as soon
# as there is a new release.
def validate_subports(data, valid_values=None):
if not isinstance(data, list):
msg = _("Invalid data format for subports: '%s' is not a list") % data
LOG.debug(msg)
return msg
subport_ids = set()
segmentations = collections.defaultdict(set)
for subport in data:
if not isinstance(subport, dict):
msg = _("Invalid data format for subport: "
"'%s' is not a dict") % subport
LOG.debug(msg)
return msg
# Expect a non duplicated and valid port_id for the subport
if 'port_id' not in subport:
msg = _("A valid port UUID must be specified")
LOG.debug(msg)
return msg
elif validators.validate_uuid(subport["port_id"]):
msg = _("Invalid UUID for subport: '%s'") % subport["port_id"]
return msg
elif subport["port_id"] in subport_ids:
msg = _("Non unique UUID for subport: '%s'") % subport["port_id"]
return msg
subport_ids.add(subport["port_id"])
# Validate that both segmentation id and segmentation type are
# specified, and that the client does not duplicate segmentation
# ids
segmentation_id = subport.get("segmentation_id")
segmentation_type = subport.get("segmentation_type")
if (not segmentation_id or not segmentation_type) and len(subport) > 1:
msg = _("Invalid subport details '%s': missing segmentation "
"information. Must specify both segmentation_id and "
"segmentation_type") % subport
LOG.debug(msg)
return msg
if segmentation_id in segmentations.get(segmentation_type, []):
msg = _("Segmentation ID '%(seg_id)s' for '%(subport)s' is not "
"unique") % {"seg_id": segmentation_id,
"subport": subport["port_id"]}
LOG.debug(msg)
return msg
if segmentation_id:
segmentations[segmentation_type].add(segmentation_id)
validators.validators['type:subports'] = validate_subports
RESOURCE_ATTRIBUTE_MAP = {
'trunks': {

View File

@ -13,12 +13,12 @@
# under the License.
from neutron_lib.api import converters
from neutron_lib.api import validators
from neutron_lib import constants as n_const
from neutron_lib import exceptions as n_exc
from neutron._i18n import _
from neutron.extensions import portbindings
from neutron.extensions import trunk
from neutron import manager
from neutron.objects import trunk as trunk_objects
from neutron.services.trunk import exceptions as trunk_exc
@ -102,7 +102,7 @@ class SubPortsValidator(object):
# Perform basic validation on subports, in case subports
# are not automatically screened by the API layer.
if basic_validation:
msg = trunk.validate_subports(self.subports)
msg = validators.validate_subports(self.subports)
if msg:
raise n_exc.InvalidInput(error_message=msg)
if trunk_validation: