diff --git a/neutron_lib/api/definitions/trunk.py b/neutron_lib/api/definitions/trunk.py index 1fdb12743..4ef61db03 100644 --- a/neutron_lib/api/definitions/trunk.py +++ b/neutron_lib/api/definitions/trunk.py @@ -95,6 +95,8 @@ REQUIRED_EXTENSIONS = [ ] # The list of optional extensions. -OPTIONAL_EXTENSIONS = None +OPTIONAL_EXTENSIONS = [ + "provider", # needed to learn about network segmentation details. +] # TODO(armax): add support for modeling custom queries diff --git a/neutron_lib/api/validators.py b/neutron_lib/api/validators.py index a37990e53..9f2cecc7b 100644 --- a/neutron_lib/api/validators.py +++ b/neutron_lib/api/validators.py @@ -924,12 +924,15 @@ def validate_subports(data, valid_values=None): return msg subport_ids.add(subport["port_id"]) - # Validate that both segmentation id and segmentation type are + # 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") + # IDs (unless it is explicitly asked to inherit segmentation + # details from the underlying subport's network). segmentation_type = subport.get("segmentation_type") - if (not segmentation_id or not segmentation_type) and len(subport) > 1: + if segmentation_type == 'inherit': + return + segmentation_id = subport.get("segmentation_id") + if (not segmentation_type or not segmentation_id) and len(subport) > 1: msg = _("Invalid subport details '%s': missing segmentation " "information. Must specify both segmentation_id and " "segmentation_type") % subport diff --git a/neutron_lib/tests/unit/api/test_validators.py b/neutron_lib/tests/unit/api/test_validators.py index 57eca716f..55b9926ea 100644 --- a/neutron_lib/tests/unit/api/test_validators.py +++ b/neutron_lib/tests/unit/api/test_validators.py @@ -1013,6 +1013,13 @@ class TestAttributeValidation(base.BaseTestCase): ] self.assertIsNotNone(validators.validate_subports(body)) + def test_validate_subports_inherit_segmentation_details(self): + body = [ + {'port_id': '00000000-ffff-ffff-ffff-000000000000', + 'segmentation_type': 'inherit'} + ] + self.assertIsNone(validators.validate_subports(body)) + def test_validate_subports_valid_unique_segmentation_id(self): body = [ {'port_id': '00000000-ffff-ffff-ffff-000000000000',