diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index dcc9f11e..fe9bd3b6 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -4635,6 +4635,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): tags = [{'scope': 'a', 'tag': 'b'}] hyperbus_mode = 'DISABLE' admin_state = True + init_state = 'VIF_RESTORE' with mock.patch.object( self.policy_api, "create_or_update") as api_call, \ @@ -4648,7 +4649,8 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): allocate_addresses=allocate_addresses, hyperbus_mode=hyperbus_mode, admin_state=admin_state, tags=tags, - tenant=TEST_TENANT) + tenant=TEST_TENANT, + init_state=init_state) expected_def = core_defs.SegmentPortDef( nsx_version=nsxlib_testcase.LATEST_VERSION, @@ -4666,7 +4668,8 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): admin_state=admin_state, tags=tags, tenant=TEST_TENANT, - hyperbus_mode=hyperbus_mode) + hyperbus_mode=hyperbus_mode, + init_state=init_state) self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) @@ -4684,6 +4687,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): allocate_addresses = "BOTH" tags = [{'scope': 'a', 'tag': 'b'}] hyperbus_mode = 'DISABLE' + init_state = 'VIF_RESTORE' with mock.patch.object( self.policy_api, "create_or_update") as api_call, \ @@ -4694,7 +4698,8 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): attachment_type=attachment_type, vif_id=vif_id, app_id=app_id, context_id=context_id, traffic_tag=traffic_tag, allocate_addresses=allocate_addresses, tags=tags, - tenant=TEST_TENANT, hyperbus_mode=hyperbus_mode) + tenant=TEST_TENANT, hyperbus_mode=hyperbus_mode, + init_state=init_state) expected_def = core_defs.SegmentPortDef( nsx_version=self.policy_lib.get_version(), segment_id=segment_id, @@ -4714,6 +4719,38 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase): self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) + def test_create_with_invalid_init_state(self): + name = 'test' + description = 'desc' + segment_id = "segment" + address_bindings = [] + attachment_type = "CHILD" + vif_id = "vif" + app_id = "app" + context_id = "context" + traffic_tag = 10 + allocate_addresses = "BOTH" + tags = [{'scope': 'a', 'tag': 'b'}] + hyperbus_mode = 'DISABLE' + init_state = 'OK' + + with mock.patch.object( + self.policy_api, "create_or_update") as api_call, \ + mock.patch.object(self.resourceApi, 'version', + nsxlib_testcase.LATEST_VERSION): + with self.assertRaises(nsxlib_exc.InvalidInput): + self.resourceApi.create_or_overwrite( + name, segment_id, description=description, + address_bindings=address_bindings, + attachment_type=attachment_type, vif_id=vif_id, + app_id=app_id, + context_id=context_id, traffic_tag=traffic_tag, + allocate_addresses=allocate_addresses, tags=tags, + tenant=TEST_TENANT, hyperbus_mode=hyperbus_mode, + init_state=init_state) + actual_def = api_call.call_args_list[0][0][0] + actual_def.get_obj_dict() + def test_attach(self): segment_id = "segment" port_id = "port" diff --git a/vmware_nsxlib/v3/nsx_constants.py b/vmware_nsxlib/v3/nsx_constants.py index 4c5882b3..25a0cd80 100644 --- a/vmware_nsxlib/v3/nsx_constants.py +++ b/vmware_nsxlib/v3/nsx_constants.py @@ -33,6 +33,10 @@ VIF_TYPE_CHILD = "CHILD" ALLOCATE_ADDRESS_NONE = "None" +# SegmentPort init_state types +INIT_STATE_UNBLOCKED_VLAN = 'UNBLOCKED_VLAN' +INIT_STATE_VIF_RESTORE = 'VIF_RESTORE' + # NSXv3 L2 Gateway constants BRIDGE_ENDPOINT = "BRIDGEENDPOINT" FAILOVER_MODE_PREEMPTIVE = "PREEMPTIVE" diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 07f1c95e..91ba53a9 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -20,6 +20,7 @@ from distutils import version from oslo_log import log as logging import six +from vmware_nsxlib.v3 import exceptions from vmware_nsxlib.v3 import nsx_constants from vmware_nsxlib.v3.policy import constants from vmware_nsxlib.v3 import utils @@ -1152,12 +1153,25 @@ class SegmentPortDef(ResourceDef): self._set_attr_if_specified(body, 'admin_state', value=admin_state) + if (self.has_attr('init_state') and + self._version_dependant_attr_supported('init_state')): + valid_list = [nsx_constants.INIT_STATE_UNBLOCKED_VLAN, + nsx_constants.INIT_STATE_VIF_RESTORE] + init_state = self.get_attr('init_state') + if init_state not in valid_list: + raise exceptions.InvalidInput( + operation='create_segment_port', + arg_val=init_state, + arg_name='init_state') + self._set_attr_if_specified(body, 'init_state') + return body @property def version_dependant_attr_map(self): return {'hyperbus_mode': nsx_constants.NSX_VERSION_3_0_0, - 'admin_state': nsx_constants.NSX_VERSION_3_0_0} + 'admin_state': nsx_constants.NSX_VERSION_3_0_0, + 'init_state': nsx_constants.NSX_VERSION_3_1_0} class SegmentBindingMapDefBase(ResourceDef): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index a676e5c9..51d1ee00 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2145,6 +2145,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): allocate_addresses=IGNORE, hyperbus_mode=IGNORE, admin_state=IGNORE, + init_state=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): @@ -2162,6 +2163,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase): allocate_addresses=allocate_addresses, hyperbus_mode=hyperbus_mode, admin_state=admin_state, + init_state=init_state, tags=tags, tenant=tenant) self._create_or_store(port_def)