Update update_advertisement depending on NSX version

Using the load balancing related args for the router
update_advertisement should be done only if the NSX version
supports the load balancing feature.

Change-Id: I1a94ee58e6b8908e6122a69f6515dfdf2d2c1b28
This commit is contained in:
Adit Sarfaty 2017-09-17 10:07:17 +03:00
parent 90f223d1b2
commit 63dbcea970
2 changed files with 58 additions and 0 deletions

View File

@ -646,6 +646,52 @@ class LogicalRouterTestCase(BaseTestResource):
(router_id, rule_id)), (router_id, rule_id)),
headers=self.default_headers()) headers=self.default_headers())
def test_update_advertisement(self):
router = self.get_mocked_resource()
router_id = test_constants.FAKE_ROUTER_UUID
data = {'advertise_nat_routes': 'a',
'advertise_nsx_connected_routes': 'b',
'advertise_static_routes': False,
'enabled': True,
'advertise_lb_vip': False,
'advertise_lb_snat_ip': False}
with mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='2.1.0'), \
mock.patch.object(router.client, 'get',
return_value={}):
router.update_advertisement(
router_id, **data)
test_client.assert_json_call(
'put', router,
('https://1.2.3.4/api/v1/logical-routers/%s/routing/'
'advertisement' % router_id),
data=jsonutils.dumps(data, sort_keys=True),
headers=self.default_headers())
def test_update_advertisement_no_lb(self):
router = self.get_mocked_resource()
router_id = test_constants.FAKE_ROUTER_UUID
data = {'advertise_nat_routes': 'a',
'advertise_nsx_connected_routes': 'b',
'advertise_static_routes': False,
'enabled': True}
with mock.patch("vmware_nsxlib.v3.NsxLib.get_version",
return_value='1.1.0'), \
mock.patch.object(router.client, 'get',
return_value={}):
# lb args will be ignored on this nsx version
router.update_advertisement(
router_id,
advertise_lb_vip=False,
advertise_lb_snat_ip=False,
**data)
test_client.assert_json_call(
'put', router,
('https://1.2.3.4/api/v1/logical-routers/%s/routing/'
'advertisement' % router_id),
data=jsonutils.dumps(data, sort_keys=True),
headers=self.default_headers())
class LogicalRouterPortTestCase(BaseTestResource): class LogicalRouterPortTestCase(BaseTestResource):

View File

@ -587,6 +587,18 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase):
def update_advertisement(self, logical_router_id, **kwargs): def update_advertisement(self, logical_router_id, **kwargs):
resource = ('logical-routers/%s/routing/advertisement' % resource = ('logical-routers/%s/routing/advertisement' %
logical_router_id) logical_router_id)
# ignore load balancing flags if lb is the not supported
if (self.nsxlib and
not self.nsxlib.feature_supported(
nsx_constants.FEATURE_LOAD_BALANCER)):
for arg in ('advertise_lb_vip', 'advertise_lb_snat_ip'):
if kwargs[arg]:
LOG.error("Ignoring %(arg)s for router %(rtr)s "
"update_advertisement: This feature is not "
"supported.",
{'arg': arg, 'rtr': logical_router_id})
del kwargs[arg]
return self._update_resource_with_retry(resource, kwargs) return self._update_resource_with_retry(resource, kwargs)
def create(self, display_name, tags, edge_cluster_uuid=None, tier_0=False, def create(self, display_name, tags, edge_cluster_uuid=None, tier_0=False,