Support policy segment & port admin state
Change-Id: I1254d4bccec44c1b7fa65c106a1261e00c57f2f2
This commit is contained in:
parent
3aca031d96
commit
015f493fd1
@ -3850,7 +3850,7 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
|||||||
self.resourceApi = self.policy_lib.segment
|
self.resourceApi = self.policy_lib.segment
|
||||||
|
|
||||||
def _test_create(self, tier1_id=None, tier0_id=None, mdproxy=None,
|
def _test_create(self, tier1_id=None, tier0_id=None, mdproxy=None,
|
||||||
dhcp_server=None):
|
dhcp_server=None, admin_state=None):
|
||||||
name = 'test'
|
name = 'test'
|
||||||
description = 'desc'
|
description = 'desc'
|
||||||
subnets = [core_defs.Subnet(gateway_address="2.2.2.0/24")]
|
subnets = [core_defs.Subnet(gateway_address="2.2.2.0/24")]
|
||||||
@ -3869,11 +3869,15 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
|||||||
|
|
||||||
if dhcp_server:
|
if dhcp_server:
|
||||||
kwargs['dhcp_server_config_id'] = dhcp_server
|
kwargs['dhcp_server_config_id'] = dhcp_server
|
||||||
|
if admin_state:
|
||||||
|
kwargs['admin_state'] = admin_state
|
||||||
|
|
||||||
with mock.patch.object(self.policy_api,
|
with mock.patch.object(self.policy_api,
|
||||||
"create_or_update") as api_call:
|
"create_or_update") as api_call:
|
||||||
result = self.resourceApi.create_or_overwrite(name, **kwargs)
|
result = self.resourceApi.create_or_overwrite(name, **kwargs)
|
||||||
|
|
||||||
|
if admin_state:
|
||||||
|
kwargs['admin_state'] = admin_state if 'UP' else 'DOWN'
|
||||||
expected_def = core_defs.SegmentDef(
|
expected_def = core_defs.SegmentDef(
|
||||||
nsx_version='3.0.0',
|
nsx_version='3.0.0',
|
||||||
segment_id=mock.ANY,
|
segment_id=mock.ANY,
|
||||||
@ -3900,6 +3904,12 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
|||||||
def test_create_with_dhcp_server_config(self):
|
def test_create_with_dhcp_server_config(self):
|
||||||
self._test_create(dhcp_server='dhcp1')
|
self._test_create(dhcp_server='dhcp1')
|
||||||
|
|
||||||
|
def test_create_with_admin_state_up(self):
|
||||||
|
self._test_create(admin_state=True)
|
||||||
|
|
||||||
|
def test_create_with_admin_state_down(self):
|
||||||
|
self._test_create(admin_state=False)
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
segment_id = '111'
|
segment_id = '111'
|
||||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||||
@ -3929,14 +3939,18 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
|||||||
def test_update(self):
|
def test_update(self):
|
||||||
segment_id = '111'
|
segment_id = '111'
|
||||||
name = 'new name'
|
name = 'new name'
|
||||||
|
admin_state = False
|
||||||
with self.mock_get(segment_id, name), \
|
with self.mock_get(segment_id, name), \
|
||||||
self.mock_create_update() as update_call:
|
self.mock_create_update() as update_call:
|
||||||
|
|
||||||
self.resourceApi.update(segment_id,
|
self.resourceApi.update(segment_id,
|
||||||
name=name,
|
name=name,
|
||||||
|
admin_state=admin_state,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
expected_def = core_defs.SegmentDef(segment_id=segment_id,
|
expected_def = core_defs.SegmentDef(nsx_version='3.0.0',
|
||||||
|
segment_id=segment_id,
|
||||||
name=name,
|
name=name,
|
||||||
|
admin_state=admin_state,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
self.assert_called_with_def(update_call, expected_def)
|
self.assert_called_with_def(update_call, expected_def)
|
||||||
|
|
||||||
@ -4376,6 +4390,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
|||||||
allocate_addresses = "BOTH"
|
allocate_addresses = "BOTH"
|
||||||
tags = [{'scope': 'a', 'tag': 'b'}]
|
tags = [{'scope': 'a', 'tag': 'b'}]
|
||||||
hyperbus_mode = 'DISABLE'
|
hyperbus_mode = 'DISABLE'
|
||||||
|
admin_state = True
|
||||||
|
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.policy_api, "create_or_update") as api_call, \
|
self.policy_api, "create_or_update") as api_call, \
|
||||||
@ -4386,7 +4401,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
|||||||
attachment_type=attachment_type, vif_id=vif_id, app_id=app_id,
|
attachment_type=attachment_type, vif_id=vif_id, app_id=app_id,
|
||||||
context_id=context_id, traffic_tag=traffic_tag,
|
context_id=context_id, traffic_tag=traffic_tag,
|
||||||
allocate_addresses=allocate_addresses,
|
allocate_addresses=allocate_addresses,
|
||||||
hyperbus_mode=hyperbus_mode,
|
hyperbus_mode=hyperbus_mode, admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
|
||||||
@ -4403,6 +4418,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
|||||||
context_id=context_id,
|
context_id=context_id,
|
||||||
traffic_tag=traffic_tag,
|
traffic_tag=traffic_tag,
|
||||||
allocate_addresses=allocate_addresses,
|
allocate_addresses=allocate_addresses,
|
||||||
|
admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=TEST_TENANT,
|
tenant=TEST_TENANT,
|
||||||
hyperbus_mode=hyperbus_mode)
|
hyperbus_mode=hyperbus_mode)
|
||||||
|
@ -180,6 +180,7 @@ FEATURE_NSX_POLICY_NETWORKING = 'NSX Policy Networking'
|
|||||||
FEATURE_NSX_POLICY_MDPROXY = 'NSX Policy Metadata Proxy'
|
FEATURE_NSX_POLICY_MDPROXY = 'NSX Policy Metadata Proxy'
|
||||||
FEATURE_NSX_POLICY_DHCP = 'NSX Policy DHCP'
|
FEATURE_NSX_POLICY_DHCP = 'NSX Policy DHCP'
|
||||||
FEATURE_NSX_POLICY_GLOBAL_CONFIG = 'NSX Policy Global Config'
|
FEATURE_NSX_POLICY_GLOBAL_CONFIG = 'NSX Policy Global Config'
|
||||||
|
FEATURE_NSX_POLICY_ADMIN_STATE = 'NSX Policy Segment admin state'
|
||||||
|
|
||||||
# FEATURE available depending on Inventory service backend version
|
# FEATURE available depending on Inventory service backend version
|
||||||
FEATURE_CONTAINER_CLUSTER_INVENTORY = 'Container Cluster Inventory'
|
FEATURE_CONTAINER_CLUSTER_INVENTORY = 'Container Cluster Inventory'
|
||||||
|
@ -37,7 +37,6 @@ class NsxPolicyLib(lib.NsxLibBase):
|
|||||||
|
|
||||||
def init_api(self):
|
def init_api(self):
|
||||||
# Initialize the policy client
|
# Initialize the policy client
|
||||||
# TODO(annak): move the API class to separate file
|
|
||||||
self.policy_api = core_defs.NsxPolicyApi(self.client)
|
self.policy_api = core_defs.NsxPolicyApi(self.client)
|
||||||
|
|
||||||
# NSX manager api will be used as a pass-through for apis which are
|
# NSX manager api will be used as a pass-through for apis which are
|
||||||
@ -188,6 +187,8 @@ class NsxPolicyLib(lib.NsxLibBase):
|
|||||||
return True
|
return True
|
||||||
if feature == nsx_constants.FEATURE_ROUTE_REDISTRIBUTION_CONFIG:
|
if feature == nsx_constants.FEATURE_ROUTE_REDISTRIBUTION_CONFIG:
|
||||||
return True
|
return True
|
||||||
|
if feature == nsx_constants.FEATURE_NSX_POLICY_ADMIN_STATE:
|
||||||
|
return True
|
||||||
|
|
||||||
return (feature == nsx_constants.FEATURE_NSX_POLICY)
|
return (feature == nsx_constants.FEATURE_NSX_POLICY)
|
||||||
|
|
||||||
|
@ -905,9 +905,9 @@ class SegmentDef(BaseSegmentDef):
|
|||||||
def _version_dependant_attr_supported(self, attr):
|
def _version_dependant_attr_supported(self, attr):
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
if (version.LooseVersion(self.nsx_version) >=
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
||||||
if attr == 'metadata_proxy_id':
|
if attr in ('metadata_proxy_id',
|
||||||
return True
|
'dhcp_server_config_id',
|
||||||
if attr == 'dhcp_server_config_id':
|
'admin_state'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
@ -978,6 +978,15 @@ class SegmentDef(BaseSegmentDef):
|
|||||||
body_attr='dhcp_config_path',
|
body_attr='dhcp_config_path',
|
||||||
value=path)
|
value=path)
|
||||||
|
|
||||||
|
if (self.has_attr('admin_state') and
|
||||||
|
self._version_dependant_attr_supported('admin_state')):
|
||||||
|
if self.get_attr('admin_state'):
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_UP
|
||||||
|
else:
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_DOWN
|
||||||
|
self._set_attr_if_specified(body, 'admin_state',
|
||||||
|
value=admin_state)
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
@ -1028,6 +1037,15 @@ class DhcpV6StaticBindingConfig(DhcpV4StaticBindingConfig):
|
|||||||
'ip_addresses',
|
'ip_addresses',
|
||||||
'sntp_servers',
|
'sntp_servers',
|
||||||
'preferred_time'])
|
'preferred_time'])
|
||||||
|
if (self.has_attr('admin_state') and
|
||||||
|
self._version_dependant_attr_supported('admin_state')):
|
||||||
|
if self.get_attr('admin_state'):
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_UP
|
||||||
|
else:
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_DOWN
|
||||||
|
self._set_attr_if_specified(body, 'admin_state',
|
||||||
|
value=admin_state)
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
@ -1093,6 +1111,15 @@ class SegmentPortDef(ResourceDef):
|
|||||||
|
|
||||||
body['attachment'] = attachment
|
body['attachment'] = attachment
|
||||||
|
|
||||||
|
if (self.has_attr('admin_state') and
|
||||||
|
self._version_dependant_attr_supported('admin_state')):
|
||||||
|
if self.get_attr('admin_state'):
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_UP
|
||||||
|
else:
|
||||||
|
admin_state = nsx_constants.ADMIN_STATE_DOWN
|
||||||
|
self._set_attr_if_specified(body, 'admin_state',
|
||||||
|
value=admin_state)
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
def _version_dependant_attr_supported(self, attr):
|
||||||
@ -1100,6 +1127,8 @@ class SegmentPortDef(ResourceDef):
|
|||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
||||||
if attr == 'hyperbus_mode':
|
if attr == 'hyperbus_mode':
|
||||||
return True
|
return True
|
||||||
|
if attr == 'admin_state':
|
||||||
|
return True
|
||||||
|
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
"Ignoring %s for %s %s: this feature is not supported."
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
from distutils import version
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import decorator
|
import decorator
|
||||||
@ -1921,6 +1922,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||||||
ip_pool_id=IGNORE,
|
ip_pool_id=IGNORE,
|
||||||
metadata_proxy_id=IGNORE,
|
metadata_proxy_id=IGNORE,
|
||||||
dhcp_server_config_id=IGNORE,
|
dhcp_server_config_id=IGNORE,
|
||||||
|
admin_state=IGNORE,
|
||||||
tags=IGNORE,
|
tags=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
|
|
||||||
@ -1943,6 +1945,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||||||
ip_pool_id=ip_pool_id,
|
ip_pool_id=ip_pool_id,
|
||||||
metadata_proxy_id=metadata_proxy_id,
|
metadata_proxy_id=metadata_proxy_id,
|
||||||
dhcp_server_config_id=dhcp_server_config_id,
|
dhcp_server_config_id=dhcp_server_config_id,
|
||||||
|
admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
self._create_or_store(segment_def)
|
self._create_or_store(segment_def)
|
||||||
@ -1973,9 +1976,9 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||||||
def update(self, segment_id, name=IGNORE, description=IGNORE,
|
def update(self, segment_id, name=IGNORE, description=IGNORE,
|
||||||
tier1_id=IGNORE, tier0_id=IGNORE, subnets=IGNORE,
|
tier1_id=IGNORE, tier0_id=IGNORE, subnets=IGNORE,
|
||||||
dns_domain_name=IGNORE,
|
dns_domain_name=IGNORE,
|
||||||
vlan_ids=IGNORE, tags=IGNORE, metadata_proxy_id=IGNORE,
|
vlan_ids=IGNORE, metadata_proxy_id=IGNORE,
|
||||||
dhcp_server_config_id=IGNORE,
|
dhcp_server_config_id=IGNORE, admin_state=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT):
|
||||||
|
|
||||||
self._update(segment_id=segment_id,
|
self._update(segment_id=segment_id,
|
||||||
name=name,
|
name=name,
|
||||||
@ -1987,6 +1990,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||||||
vlan_ids=vlan_ids,
|
vlan_ids=vlan_ids,
|
||||||
metadata_proxy_id=metadata_proxy_id,
|
metadata_proxy_id=metadata_proxy_id,
|
||||||
dhcp_server_config_id=dhcp_server_config_id,
|
dhcp_server_config_id=dhcp_server_config_id,
|
||||||
|
admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
|
|
||||||
@ -2059,7 +2063,12 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
|||||||
@check_allowed_passthrough
|
@check_allowed_passthrough
|
||||||
def set_admin_state(self, segment_id, admin_state,
|
def set_admin_state(self, segment_id, admin_state,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
"""Set the segment admin state using the passthrough api"""
|
"""Set the segment admin state using the passthrough/policy api"""
|
||||||
|
if (version.LooseVersion(self.version) >=
|
||||||
|
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
||||||
|
return self.update(segment_id, admin_state=admin_state,
|
||||||
|
tenant=tenant)
|
||||||
|
|
||||||
realization_info = self.wait_until_realized(
|
realization_info = self.wait_until_realized(
|
||||||
segment_id, entity_type='RealizedLogicalSwitch', tenant=tenant)
|
segment_id, entity_type='RealizedLogicalSwitch', tenant=tenant)
|
||||||
|
|
||||||
@ -2101,6 +2110,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
|||||||
traffic_tag=IGNORE,
|
traffic_tag=IGNORE,
|
||||||
allocate_addresses=IGNORE,
|
allocate_addresses=IGNORE,
|
||||||
hyperbus_mode=IGNORE,
|
hyperbus_mode=IGNORE,
|
||||||
|
admin_state=IGNORE,
|
||||||
tags=IGNORE,
|
tags=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
|
|
||||||
@ -2117,6 +2127,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
|||||||
traffic_tag=traffic_tag,
|
traffic_tag=traffic_tag,
|
||||||
allocate_addresses=allocate_addresses,
|
allocate_addresses=allocate_addresses,
|
||||||
hyperbus_mode=hyperbus_mode,
|
hyperbus_mode=hyperbus_mode,
|
||||||
|
admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
self._create_or_store(port_def)
|
self._create_or_store(port_def)
|
||||||
@ -2146,6 +2157,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
|||||||
description=IGNORE,
|
description=IGNORE,
|
||||||
address_bindings=IGNORE,
|
address_bindings=IGNORE,
|
||||||
hyperbus_mode=IGNORE,
|
hyperbus_mode=IGNORE,
|
||||||
|
admin_state=IGNORE,
|
||||||
tags=IGNORE,
|
tags=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
|
|
||||||
@ -2155,6 +2167,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
|||||||
description=description,
|
description=description,
|
||||||
address_bindings=address_bindings,
|
address_bindings=address_bindings,
|
||||||
hyperbus_mode=hyperbus_mode,
|
hyperbus_mode=hyperbus_mode,
|
||||||
|
admin_state=admin_state,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
|
|
||||||
@ -2233,7 +2246,12 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
|||||||
@check_allowed_passthrough
|
@check_allowed_passthrough
|
||||||
def set_admin_state(self, segment_id, port_id, admin_state,
|
def set_admin_state(self, segment_id, port_id, admin_state,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
"""Set the segment port admin state using the passthrough api"""
|
"""Set the segment port admin state using the passthrough/policy api"""
|
||||||
|
if (version.LooseVersion(self.version) >=
|
||||||
|
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
||||||
|
return self.update(segment_id, port_id, admin_state=admin_state,
|
||||||
|
tenant=tenant)
|
||||||
|
|
||||||
realization_info = self.wait_until_realized(
|
realization_info = self.wait_until_realized(
|
||||||
segment_id, port_id, entity_type='RealizedLogicalPort',
|
segment_id, port_id, entity_type='RealizedLogicalPort',
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user