NSX|V3: Support LBaaS monitor update

Adding implementation for the LBaaS driver to update the backend
health monitor
In addition - add failure notification in the monitor create code

Change-Id: I96410f60835fd2920d4c53bab59725b8d0d147ef
This commit is contained in:
Adit Sarfaty 2018-06-13 14:15:18 +03:00
parent 225206afad
commit a22c9e0b59
2 changed files with 48 additions and 9 deletions

View File

@ -37,7 +37,6 @@ class EdgeHealthMonitorManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
@log_helpers.log_method_call
def _build_monitor_args(self, hm):
# TODO(asarfaty): Add description to backend parameters
if hm['type'] in lb_const.NSXV3_MONITOR_MAP:
monitor_type = lb_const.NSXV3_MONITOR_MAP.get(hm['type'])
else:
@ -97,11 +96,36 @@ class EdgeHealthMonitorManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
nsx_db.add_nsx_lbaas_monitor_binding(
context.session, lb_id, pool_id, hm['id'], lb_monitor['id'],
lb_pool_id)
else:
completor(success=False)
msg = _('Failed to attach monitor %(monitor)s to pool '
'%(pool)s: NSX pool was not found on the DB') % {
'monitor': hm['id'],
'pool': pool_id}
raise n_exc.BadRequest(resource='lbaas-hm', msg=msg)
completor(success=True)
def update(self, context, old_hm, new_hm, completor):
# TODO(asarfaty): Shouldn't this be implemented?
lb_id = new_hm['pool']['loadbalancer_id']
pool_id = new_hm['pool']['id']
monitor_client = self.core_plugin.nsxlib.load_balancer.monitor
binding = nsx_db.get_nsx_lbaas_monitor_binding(
context.session, lb_id, pool_id, new_hm['id'])
if binding:
lb_monitor_id = binding['lb_monitor_id']
monitor_body = self._build_monitor_args(new_hm)
monitor_name = utils.get_name_and_uuid(new_hm['name'] or 'monitor',
new_hm['id'])
monitor_client.update(lb_monitor_id, display_name=monitor_name,
**monitor_body)
else:
completor(success=False)
msg = _('Failed to update monitor %(monitor)s: NSX monitor was '
'not found in DB') % {'monitor': new_hm['id'],
'pool': pool_id}
raise n_exc.BadRequest(resource='lbaas-hm', msg=msg)
completor(success=True)
def delete(self, context, hm, completor):
@ -134,4 +158,8 @@ class EdgeHealthMonitorManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
nsx_db.delete_nsx_lbaas_monitor_binding(context.session, lb_id,
pool_id, hm['id'])
else:
# Do not fail a delete action
pass
completor(success=True)

View File

@ -653,14 +653,25 @@ class TestEdgeLbaasV2HealthMonitor(BaseTestEdgeLbaasV2):
delete=False)
def test_update(self):
new_hm = lb_models.HealthMonitor(HM_ID, LB_TENANT_ID, 'PING', 3, 3,
3, pool=self.pool)
self.edge_driver.healthmonitor.update(self.context, self.hm, new_hm)
with mock.patch.object(self.monitor_client, 'update'
) as mock_update_monitor, \
mock.patch.object(nsx_db, 'get_nsx_lbaas_monitor_binding'
) as mock_get_monitor_binding:
mock_get_monitor_binding.return_value = HM_BINDING
new_hm = lb_models.HealthMonitor(
HM_ID, LB_TENANT_ID, 'PING', 5, 5,
5, pool=self.pool, name='new_name')
self.edge_driver.healthmonitor.update(
self.context, self.hm, new_hm)
mock_update_monitor.assert_called_with(
LB_MONITOR_ID, display_name=mock.ANY,
fall_count=5, interval=5, timeout=5,
resource_type='LbIcmpMonitor')
mock_successful_completion = (
self.lbv2_driver.health_monitor.successful_completion)
mock_successful_completion.assert_called_with(self.context, new_hm,
delete=False)
mock_successful_completion = (
self.lbv2_driver.health_monitor.successful_completion)
mock_successful_completion.assert_called_with(self.context, new_hm,
delete=False)
def test_delete(self):
with mock.patch.object(nsx_db, 'get_nsx_lbaas_monitor_binding'