Merge "Support setting hyperbus_mode in SegmentPort Api"
This commit is contained in:
commit
ea2f4ea568
@ -4010,6 +4010,18 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||
super(TestPolicySegmentPort, self).setUp()
|
||||
self.resourceApi = self.policy_lib.segment_port
|
||||
|
||||
def test_feature_supported(self):
|
||||
with mock.patch.object(self.policy_lib, "get_version",
|
||||
return_value='2.5.0'):
|
||||
self.assertFalse(
|
||||
self.policy_lib.feature_supported(
|
||||
nsx_constants.FEATURE_SWITCH_HYPERBUS_MODE))
|
||||
with mock.patch.object(self.policy_lib, "get_version",
|
||||
return_value='3.0.0'):
|
||||
self.assertTrue(
|
||||
self.policy_lib.feature_supported(
|
||||
nsx_constants.FEATURE_SWITCH_HYPERBUS_MODE))
|
||||
|
||||
def test_create(self):
|
||||
name = 'test'
|
||||
description = 'desc'
|
||||
@ -4022,18 +4034,67 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||
traffic_tag = 10
|
||||
allocate_addresses = "BOTH"
|
||||
tags = [{'scope': 'a', 'tag': 'b'}]
|
||||
hyperbus_mode = 'DISABLE'
|
||||
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
with mock.patch.object(
|
||||
self.policy_api, "create_or_update") as api_call, \
|
||||
mock.patch.object(self.resourceApi, 'version', '3.0.0'):
|
||||
result = 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,
|
||||
hyperbus_mode=hyperbus_mode,
|
||||
tags=tags,
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.SegmentPortDef(
|
||||
nsx_version='3.0.0',
|
||||
segment_id=segment_id,
|
||||
port_id=mock.ANY,
|
||||
name=name,
|
||||
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)
|
||||
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def test_create_with_unsupported_attribute(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'
|
||||
|
||||
with mock.patch.object(
|
||||
self.policy_api, "create_or_update") as api_call, \
|
||||
mock.patch.object(self.resourceApi, 'version', '0.0.0'):
|
||||
result = 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)
|
||||
|
||||
tenant=TEST_TENANT, hyperbus_mode=hyperbus_mode)
|
||||
expected_def = core_defs.SegmentPortDef(
|
||||
nsx_version=self.policy_lib.get_version(),
|
||||
segment_id=segment_id,
|
||||
port_id=mock.ANY,
|
||||
name=name,
|
||||
@ -4061,16 +4122,20 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||
traffic_tag = 10
|
||||
allocate_addresses = "BOTH"
|
||||
tags = [{'scope': 'a', 'tag': 'b'}]
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
hyperbus_mode = 'DISABLE'
|
||||
with mock.patch.object(
|
||||
self.policy_api, "create_or_update") as api_call, \
|
||||
mock.patch.object(self.resourceApi, 'version', '3.0.0'):
|
||||
self.resourceApi.attach(
|
||||
segment_id, port_id,
|
||||
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,
|
||||
allocate_addresses=allocate_addresses,
|
||||
hyperbus_mode=hyperbus_mode, tags=tags,
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.SegmentPortDef(
|
||||
nsx_version='3.0.0',
|
||||
segment_id=segment_id,
|
||||
port_id=port_id,
|
||||
attachment_type=attachment_type,
|
||||
@ -4079,6 +4144,7 @@ class TestPolicySegmentPort(NsxPolicyLibTestCase):
|
||||
context_id=context_id,
|
||||
traffic_tag=traffic_tag,
|
||||
allocate_addresses=allocate_addresses,
|
||||
hyperbus_mode=hyperbus_mode,
|
||||
tags=tags,
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
|
@ -171,6 +171,7 @@ FEATURE_ROUTER_ALLOCATION_PROFILE = 'Router Allocation Profile'
|
||||
FEATURE_ENABLE_STANDBY_RELOCATION = 'Router Enable standby relocation'
|
||||
FEATURE_PARTIAL_UPDATES = 'Partial Update with PATCH'
|
||||
FEATURE_RELAX_SCALE_VALIDATION = 'Relax Scale Validation for LbService'
|
||||
FEATURE_SWITCH_HYPERBUS_MODE = 'Switch hyperbus mode with policy API'
|
||||
|
||||
# Features available depending on the Policy Manager backend version
|
||||
FEATURE_NSX_POLICY = 'NSX Policy'
|
||||
|
@ -172,6 +172,8 @@ class NsxPolicyLib(lib.NsxLibBase):
|
||||
# features available since 3.0.0
|
||||
if feature == nsx_constants.FEATURE_PARTIAL_UPDATES:
|
||||
return True
|
||||
if feature == nsx_constants.FEATURE_SWITCH_HYPERBUS_MODE:
|
||||
return True
|
||||
|
||||
return (feature == nsx_constants.FEATURE_NSX_POLICY)
|
||||
|
||||
|
@ -16,12 +16,18 @@
|
||||
|
||||
import abc
|
||||
|
||||
from distutils import version
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from vmware_nsxlib.v3 import nsx_constants
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
from vmware_nsxlib.v3.policy import constants
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
TENANTS_PATH_PATTERN = "%s/"
|
||||
DOMAINS_PATH_PATTERN = TENANTS_PATH_PATTERN + "domains/"
|
||||
IP_BLOCKS_PATH_PATTERN = TENANTS_PATH_PATTERN + "ip-blocks/"
|
||||
@ -838,10 +844,26 @@ class SegmentPortDef(ResourceDef):
|
||||
'app_id',
|
||||
'traffic_tag',
|
||||
'allocate_addresses'])
|
||||
self._set_attr_if_supported(body, 'hyperbus_mode')
|
||||
body['attachment'] = attachment
|
||||
|
||||
return body
|
||||
|
||||
def _version_dependant_attr_supported(self, attr):
|
||||
if (version.LooseVersion(self.nsx_version) >=
|
||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
||||
if attr == 'hyperbus_mode':
|
||||
return True
|
||||
else:
|
||||
LOG.warning(
|
||||
"Ignoring %s for %s %s: this feature is not supported."
|
||||
"Current NSX version: %s. Minimum supported version: %s",
|
||||
attr, self.resource_type, self.attrs.get('name', ''),
|
||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class SegmentBindingMapDefBase(ResourceDef):
|
||||
|
||||
|
@ -2005,6 +2005,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
context_id=IGNORE,
|
||||
traffic_tag=IGNORE,
|
||||
allocate_addresses=IGNORE,
|
||||
hyperbus_mode=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
@ -2020,6 +2021,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
context_id=context_id,
|
||||
traffic_tag=traffic_tag,
|
||||
allocate_addresses=allocate_addresses,
|
||||
hyperbus_mode=hyperbus_mode,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
self._create_or_store(port_def)
|
||||
@ -2048,6 +2050,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
name=IGNORE,
|
||||
description=IGNORE,
|
||||
address_bindings=IGNORE,
|
||||
hyperbus_mode=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
@ -2056,6 +2059,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
name=name,
|
||||
description=description,
|
||||
address_bindings=address_bindings,
|
||||
hyperbus_mode=hyperbus_mode,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
||||
@ -2077,10 +2081,11 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
app_id=None,
|
||||
context_id=None,
|
||||
traffic_tag=None,
|
||||
hyperbus_mode=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
port_def = self.entry_def(segment_id=segment_id,
|
||||
port_def = self._init_def(segment_id=segment_id,
|
||||
port_id=port_id,
|
||||
attachment_type=attachment_type,
|
||||
allocate_addresses=allocate_addresses,
|
||||
@ -2088,6 +2093,7 @@ class NsxPolicySegmentPortApi(NsxPolicyResourceBase):
|
||||
app_id=app_id,
|
||||
context_id=context_id,
|
||||
traffic_tag=traffic_tag,
|
||||
hyperbus_mode=hyperbus_mode,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
||||
|
@ -393,13 +393,13 @@ class LBServiceDef(ResourceDef):
|
||||
version.LooseVersion(nsx_constants.NSX_VERSION_2_5_1)):
|
||||
if attr == 'relax_scale_validation':
|
||||
return True
|
||||
else:
|
||||
LOG.warning(
|
||||
"Ignoring %s for %s %s: this feature is not supported."
|
||||
"Current NSX version: %s. Minimum supported version: %s",
|
||||
attr, self.resource_type, self.attrs.get('name', ''),
|
||||
self.nsx_version, nsx_constants.NSX_VERSION_2_5_1)
|
||||
return False
|
||||
else:
|
||||
LOG.warning(
|
||||
"Ignoring %s for %s %s: this feature is not supported."
|
||||
"Current NSX version: %s. Minimum supported version: %s",
|
||||
attr, self.resource_type, self.attrs.get('name', ''),
|
||||
self.nsx_version, nsx_constants.NSX_VERSION_2_5_1)
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user