From 6579b18d687f76ab7ed506f8d932f87fda6c3e5a Mon Sep 17 00:00:00 2001 From: Michal Kelner Mishali Date: Sun, 30 Dec 2018 10:30:57 +0200 Subject: [PATCH] NSX|T: Support T1 LR HA relocation The platform is adding resiliency on T1 using LR HA relocation The goal is to have it enabled by default on Neutron created routers and have a admin-util to enable on existing ones. Change-Id: I3d9ec704d42a79f5f9f858d503416025e8664ad4 Signed-off-by: Michal Kelner Mishali --- vmware_nsxlib/tests/unit/v3/test_resources.py | 83 ++++++++++++++----- vmware_nsxlib/v3/__init__.py | 2 + vmware_nsxlib/v3/core_resources.py | 21 ++++- vmware_nsxlib/v3/nsx_constants.py | 1 + 4 files changed, 85 insertions(+), 22 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index bdf0f3b4..98f1b25b 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -631,6 +631,43 @@ class LogicalRouterTestCase(BaseTestResource): super(LogicalRouterTestCase, self).setUp( core_resources.NsxLibLogicalRouter) + def test_create_logical_router_v1_1(self): + """Test creating a router returns the correct response and 201 status. + + """ + fake_router = test_constants.FAKE_ROUTER.copy() + router = self.get_mocked_resource() + tier0_router = True + description = 'dummy' + tz_id = 'tz_id' + allocation_pool = { + 'allocation_pool_type': 'LoadBalancerAllocationPool', + 'allocation_size': 'SMALL' + } + with mock.patch("vmware_nsxlib.v3.NsxLib.get_version", + return_value='1.1.0'): + router.create(fake_router['display_name'], None, None, + tier0_router, + description=description, transport_zone_id=tz_id, + allocation_pool=allocation_pool) + + data = { + 'display_name': fake_router['display_name'], + 'router_type': 'TIER0' if tier0_router else 'TIER1', + 'tags': None, + 'description': description, + 'advanced_config': {'transport_zone_id': tz_id}, + 'allocation_profile': { + 'allocation_pool': allocation_pool + } + } + + test_client.assert_json_call( + 'post', router, + 'https://1.2.3.4/api/v1/logical-routers', + data=jsonutils.dumps(data, sort_keys=True), + headers=self.default_headers()) + def test_create_logical_router(self): """Test creating a router returns the correct response and 201 status. @@ -644,26 +681,32 @@ class LogicalRouterTestCase(BaseTestResource): 'allocation_pool_type': 'LoadBalancerAllocationPool', 'allocation_size': 'SMALL' } - router.create(fake_router['display_name'], None, None, tier0_router, - description=description, transport_zone_id=tz_id, - allocation_pool=allocation_pool) + enable_standby_relocation = True + with mock.patch("vmware_nsxlib.v3.NsxLib.get_version", + return_value='2.4.0'): + router.create(fake_router['display_name'], None, None, + tier0_router, + description=description, transport_zone_id=tz_id, + allocation_pool=allocation_pool, + enable_standby_relocation=enable_standby_relocation) - data = { - 'display_name': fake_router['display_name'], - 'router_type': 'TIER0' if tier0_router else 'TIER1', - 'tags': None, - 'description': description, - 'advanced_config': {'transport_zone_id': tz_id}, - 'allocation_profile': { - 'allocation_pool': allocation_pool + data = { + 'display_name': fake_router['display_name'], + 'router_type': 'TIER0' if tier0_router else 'TIER1', + 'tags': None, + 'description': description, + 'advanced_config': {'transport_zone_id': tz_id}, + 'allocation_profile': { + 'allocation_pool': allocation_pool, + 'enable_standby_relocation': enable_standby_relocation + } } - } - test_client.assert_json_call( - 'post', router, - 'https://1.2.3.4/api/v1/logical-routers', - data=jsonutils.dumps(data, sort_keys=True), - headers=self.default_headers()) + test_client.assert_json_call( + 'post', router, + 'https://1.2.3.4/api/v1/logical-routers', + data=jsonutils.dumps(data, sort_keys=True), + headers=self.default_headers()) def test_update_logical_router(self): fake_router = test_constants.FAKE_ROUTER.copy() @@ -674,13 +717,15 @@ class LogicalRouterTestCase(BaseTestResource): description = 'dummy' edge_cluster_id = 'ec_id' tz_id = 'tz_id' + enable_standby_relocation = True with mock.patch.object(router.client, 'get', return_value=fake_router),\ mock.patch("vmware_nsxlib.v3.NsxLib.get_version", - return_value='2.2.0'): + return_value='2.4.0'): router.update(uuid, display_name=name, description=description, edge_cluster_id=edge_cluster_id, - transport_zone_id=tz_id) + transport_zone_id=tz_id, + enable_standby_relocation=enable_standby_relocation) fake_router["display_name"] = name fake_router["description"] = description diff --git a/vmware_nsxlib/v3/__init__.py b/vmware_nsxlib/v3/__init__.py index 89de65b1..83cf9630 100644 --- a/vmware_nsxlib/v3/__init__.py +++ b/vmware_nsxlib/v3/__init__.py @@ -146,6 +146,8 @@ class NsxLib(lib.NsxLibBase): return True if (feature == nsx_constants.FEATURE_ICMP_STRICT): return True + if (feature == nsx_constants.FEATURE_ENABLE_STANDBY_RELOCATION): + return True if (version.LooseVersion(self.get_version()) >= version.LooseVersion(nsx_constants.NSX_VERSION_2_3_0)): diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index f1d7992c..1f74f57d 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -695,7 +695,8 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): ' %s.' % (logical_router_id)) def create(self, display_name, tags, edge_cluster_uuid=None, tier_0=False, - description=None, transport_zone_id=None, allocation_pool=None): + description=None, transport_zone_id=None, + allocation_pool=None, enable_standby_relocation=False): # TODO(salv-orlando): If possible do not manage edge clusters # in the main plugin logic. router_type = (nsx_constants.ROUTER_TYPE_TIER0 if tier_0 else @@ -710,9 +711,17 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): if transport_zone_id: body['advanced_config'] = { 'transport_zone_id': transport_zone_id} + allocation_profile = {} if allocation_pool: - body['allocation_profile'] = { - 'allocation_pool': allocation_pool} + allocation_profile['allocation_pool'] = allocation_pool + if (enable_standby_relocation and self.nsxlib and + self.nsxlib.feature_supported( + nsx_constants.FEATURE_ENABLE_STANDBY_RELOCATION)): + allocation_profile[ + 'enable_standby_relocation'] = enable_standby_relocation + if allocation_profile: + body['allocation_profile'] = allocation_profile + return self.client.create(self.get_path(), body=body) def delete(self, lrouter_id, force=False): @@ -728,6 +737,12 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase): if arg == 'transport_zone_id': body['advanced_config'] = { 'transport_zone_id': kwargs['transport_zone_id']} + elif arg == 'enable_standby_relocation': + if (self.nsxlib and self.nsxlib.feature_supported( + nsx_constants.FEATURE_ENABLE_STANDBY_RELOCATION)): + body['allocation_profile'] = { + 'enable_standby_relocation': + kwargs['enable_standby_relocation']} else: body[arg] = kwargs[arg] diff --git a/vmware_nsxlib/v3/nsx_constants.py b/vmware_nsxlib/v3/nsx_constants.py index 1dfb1fc0..25f250e8 100644 --- a/vmware_nsxlib/v3/nsx_constants.py +++ b/vmware_nsxlib/v3/nsx_constants.py @@ -158,6 +158,7 @@ FEATURE_NO_DNAT_NO_SNAT = 'No DNAT/No SNAT' FEATURE_ENS_WITH_SEC = 'ENS with security' FEATURE_ICMP_STRICT = 'Strict list of supported ICMP types and codes' FEATURE_ROUTER_ALLOCATION_PROFILE = 'Router Allocation Profile' +FEATURE_ENABLE_STANDBY_RELOCATION = 'Router Enable standby relocation' # Features available depending on the Policy Manager backend version FEATURE_NSX_POLICY = 'NSX Policy'