Remove leftover neutron-lbaas apis from all drivers

Change-Id: I01e4421bf0a63efdbf0366b26a3e9e1cf3d1a917
This commit is contained in:
asarfaty 2020-08-26 08:47:41 +02:00 committed by Adit Sarfaty
parent 97bf9ca2ce
commit 3148ed07fa
6 changed files with 0 additions and 388 deletions

View File

@ -224,74 +224,6 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager):
"""Delete all backend and DB resources of this loadbalancer"""
self.delete(context, lb, completor)
def refresh(self, context, lb):
# TODO(kobis): implement
pass
def _get_lb_virtual_servers(self, context, lb):
# Get all virtual servers that belong to this loadbalancer
vs_list = [vs['id'] for vs in lb['listeners']]
return vs_list
def stats(self, context, lb):
# Since multiple LBaaS loadbalancer can share the same LB service,
# get the corresponding virtual servers' stats instead of LB service.
stats = {'active_connections': 0,
'bytes_in': 0,
'bytes_out': 0,
'total_connections': 0}
service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service
vs_list = self._get_lb_virtual_servers(context, lb)
try:
rsp = service_client.get_statistics(lb['id'], silent=True)
for result in rsp.get('results', []):
for vs in result.get('virtual_servers', []):
# Skip the virtual server that doesn't belong
# to this loadbalancer
vs_id = lib_p_utils.path_to_id(vs['virtual_server_path'])
if vs_id not in vs_list:
continue
vs_stats = vs.get('statistics', {})
for stat in lb_const.LB_STATS_MAP:
lb_stat = lb_const.LB_STATS_MAP[stat]
stats[stat] += vs_stats.get(lb_stat, 0)
except nsxlib_exc.ManagerError:
msg = _('Failed to retrieve stats from LB service '
'for loadbalancer %(lb)s') % {'lb': lb['id']}
raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
return stats
def get_operating_status(self, context, id, with_members=False):
service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service
try:
service_status = service_client.get_status(id)
if not isinstance(service_status, dict):
service_status = {}
except nsxlib_exc.ManagerError:
LOG.warning("LB service %(lbs)s is not found",
{'lbs': id})
return {}
# get the loadbalancer status from the LB service
lb_status_results = service_status.get('results')
lb_status = lb_const.ONLINE
if lb_status_results:
result = lb_status_results[0]
lb_status = _get_octavia_lb_status(result)
statuses = {lb_const.LOADBALANCERS: [{'id': id, 'status': lb_status}],
lb_const.LISTENERS: [],
lb_const.POOLS: [],
lb_const.MEMBERS: []}
# TODO(asarfaty): Go over all VS of this loadbalancer by tags
# to add the listeners statuses from the virtual servers statuses
return statuses
def _nsx_status_to_lb_status(nsx_status):
if not nsx_status:

View File

@ -30,7 +30,6 @@ from vmware_nsx.plugins.nsx_v.vshield.common import (
constants as vcns_const)
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas import lb_const
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.octavia import constants as oct_const
@ -165,61 +164,6 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
#TODO(asarfaty): implement a better delete cascade for NSX-V
self.delete(context, lb, completor)
def refresh(self, context, lb):
# TODO(kobis): implement
pass
def stats(self, context, lb):
binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(context.session,
lb['id'])
stats = _get_edge_loadbalancer_statistics(self.vcns,
binding['edge_id'])
return stats
def get_operating_status(self, context, id, with_members=False):
"""Return a map of the operating status of all connected LB objects """
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
context.session, id)
if not lb_binding or not lb_binding['edge_id']:
return {}
edge_id = lb_binding['edge_id']
lb_stats = self.vcns.get_loadbalancer_statistics(edge_id)
lb_status = (lb_const.ONLINE if lb_stats is not None
else lb_const.OFFLINE)
statuses = {lb_const.LOADBALANCERS: [{'id': id, 'status': lb_status}],
lb_const.LISTENERS: [],
lb_const.POOLS: [],
lb_const.MEMBERS: []}
for vs in lb_stats[1].get('virtualServer', []):
vs_id = vs['name'][4:]
vs_status = (lb_const.ONLINE if vs['status'] == 'OPEN'
else lb_const.OFFLINE)
statuses[lb_const.LISTENERS].append(
{'id': vs_id, 'status': vs_status})
for pool in lb_stats[1].get('pool', []):
pool_id = pool['name'][5:]
pool_status = (lb_const.ONLINE if pool['status'] == 'UP'
else lb_const.OFFLINE)
statuses[lb_const.POOLS].append(
{'id': pool_id, 'status': pool_status})
if with_members:
for member in pool.get('member', []):
member_id = member['name'][7:]
member_status = (lb_const.ONLINE
if member['status'] == 'UP'
else lb_const.OFFLINE)
statuses[lb_const.MEMBERS].append(
{'id': member_id, 'status': member_status})
return statuses
def _handle_subnet_gw_change(self, *args, **kwargs):
# As the Edge appliance doesn't use DHCP, we should change the
# default gateway here when the subnet GW changes.
@ -268,27 +212,3 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
if not found:
return False
return True
def _get_edge_loadbalancer_statistics(vcns, edge_id):
stats = {'bytes_in': 0,
'bytes_out': 0,
'active_connections': 0,
'total_connections': 0}
try:
lb_stats = vcns.get_loadbalancer_statistics(edge_id)
except nsxv_exc.VcnsApiException:
msg = (_('Failed to read load balancer statistics, edge: %s') %
edge_id)
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
pools_stats = lb_stats[1].get('pool', [])
for pool_stats in pools_stats:
stats['bytes_in'] += pool_stats.get('bytesIn', 0)
stats['bytes_out'] += pool_stats.get('bytesOut', 0)
stats['active_connections'] += pool_stats.get('curSessions', 0)
stats['total_connections'] += pool_stats.get('totalSessions', 0)
return stats

View File

@ -244,161 +244,3 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
def delete_cascade(self, context, lb, completor):
"""Delete all backend and DB resources of this loadbalancer"""
self.delete(context, lb, completor)
def refresh(self, context, lb):
# TODO(tongl): implement
pass
def _nsx_status_to_lb_status(self, nsx_status):
if not nsx_status:
# default fallback
return lb_const.ONLINE
# Statuses that are considered ONLINE:
if nsx_status.upper() in ['UP', 'UNKNOWN', 'PARTIALLY_UP',
'NO_STANDBY']:
return lb_const.ONLINE
# Statuses that are considered OFFLINE:
if nsx_status.upper() in ['PRIMARY_DOWN', 'DETACHED', 'DOWN', 'ERROR']:
return lb_const.OFFLINE
if nsx_status.upper() == 'DISABLED':
return lb_const.DISABLED
# default fallback
LOG.debug("NSX LB status %s - interpreted as ONLINE", nsx_status)
return lb_const.ONLINE
def get_lb_pool_members_statuses(self, nsx_pool_id, members_statuses):
# Combine the NSX pool members data and the NSX statuses to provide
# member statuses list
# Get the member id from the suffix of the member in the NSX pool list
# and find the matching ip+port member in the statuses list
# get the members list from the NSX
nsx_pool = self.core_plugin.nsxlib.load_balancer.pool.get(nsx_pool_id)
if not nsx_pool or not nsx_pool.get('members'):
return []
# create a map of existing members: ip+port -> lbaas ID (which is the
# suffix of the member name)
members_map = {}
for member in nsx_pool['members']:
ip = member['ip_address']
port = member['port']
if ip not in members_map:
members_map[ip] = {}
members_map[ip][port] = member['display_name'][-36:]
# go over the statuses map, and match the member ip_port, to the ID
# in the map
statuses = []
for member in members_statuses:
ip = member['ip_address']
port = member['port']
if ip in members_map and port in members_map[ip]:
member_id = members_map[ip][port]
member_status = self._nsx_status_to_lb_status(member['status'])
statuses.append({'id': member_id, 'status': member_status})
return statuses
def get_operating_status(self, context, id, with_members=False):
"""Return a map of the operating status of all connected LB objects """
service_client = self.core_plugin.nsxlib.load_balancer.service
lb_binding = nsx_db.get_nsx_lbaas_loadbalancer_binding(
context.session, id)
if not lb_binding:
LOG.warning("Failed to get loadbalancer %s operating status. "
"Mapping was not found", id)
return {}
lb_service_id = lb_binding['lb_service_id']
try:
service_status = service_client.get_status(lb_service_id)
if not isinstance(service_status, dict):
service_status = {}
vs_statuses = service_client.get_virtual_servers_status(
lb_service_id)
if not isinstance(vs_statuses, dict):
vs_statuses = {}
except nsxlib_exc.ManagerError:
LOG.warning("LB service %(lbs)s is not found",
{'lbs': lb_service_id})
return {}
# get the loadbalancer status from the LB service
lb_status = self._nsx_status_to_lb_status(
service_status.get('service_status'))
statuses = {lb_const.LOADBALANCERS: [{'id': id, 'status': lb_status}],
lb_const.LISTENERS: [],
lb_const.POOLS: [],
lb_const.MEMBERS: []}
# Add the listeners statuses from the virtual servers statuses
for vs in vs_statuses.get('results', []):
vs_status = self._nsx_status_to_lb_status(vs.get('status'))
vs_id = vs.get('virtual_server_id')
list_binding = nsx_db.get_nsx_lbaas_listener_binding_by_lb_and_vs(
context.session, id, vs_id)
if list_binding:
listener_id = list_binding['listener_id']
statuses[lb_const.LISTENERS].append(
{'id': listener_id, 'status': vs_status})
# Add the pools statuses from the LB service status
for pool in service_status.get('pools', []):
nsx_pool_id = pool.get('pool_id')
pool_status = self._nsx_status_to_lb_status(pool.get('status'))
pool_binding = nsx_db.get_nsx_lbaas_pool_binding_by_lb_pool(
context.session, id, nsx_pool_id)
if pool_binding:
pool_id = pool_binding['pool_id']
statuses[lb_const.POOLS].append(
{'id': pool_id, 'status': pool_status})
# Add the pools members
if with_members and pool.get('members'):
statuses[lb_const.MEMBERS].extend(
self.get_lb_pool_members_statuses(
nsx_pool_id, pool['members']))
return statuses
def stats(self, context, lb):
# Since multiple LBaaS loadbalancer can share the same LB service,
# get the corresponding virtual servers' stats instead of LB service.
stats = {'active_connections': 0,
'bytes_in': 0,
'bytes_out': 0,
'total_connections': 0}
service_client = self.core_plugin.nsxlib.load_balancer.service
lb_binding = nsx_db.get_nsx_lbaas_loadbalancer_binding(
context.session, lb['id'])
vs_list = self._get_lb_virtual_servers(context, lb)
if lb_binding:
lb_service_id = lb_binding.get('lb_service_id')
try:
rsp = service_client.get_stats(lb_service_id)
if rsp:
for vs in rsp.get('virtual_servers', []):
# Skip the virtual server that doesn't belong
# to this loadbalancer
if vs['virtual_server_id'] not in vs_list:
continue
vs_stats = vs.get('statistics', {})
for stat in lb_const.LB_STATS_MAP:
lb_stat = lb_const.LB_STATS_MAP[stat]
stats[stat] += vs_stats.get(lb_stat, 0)
except nsxlib_exc.ManagerError:
msg = _('Failed to retrieve stats from LB service '
'for loadbalancer %(lb)s') % {'lb': lb['id']}
raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
return stats
def _get_lb_virtual_servers(self, context, lb):
# Get all virtual servers that belong to this loadbalancer
vs_list = []
for listener in lb['listeners']:
vs_binding = nsx_db.get_nsx_lbaas_listener_binding(
context.session, lb['id'], listener['id'])
if vs_binding:
vs_list.append(vs_binding.get('lb_vs_id'))
return vs_list

View File

@ -355,12 +355,6 @@ class TestEdgeLbaasV2LoadbalancerOnRtr(BaseTestEdgeLbaasV2):
self.assertTrue(self.last_completor_called)
self.assertTrue(self.last_completor_succees)
def test_stats(self):
pass
def test_refresh(self):
pass
class TestEdgeLbaasV2LoadbalancerOnEdge(TestEdgeLbaasV2LoadbalancerOnRtr):
@property

View File

@ -617,45 +617,6 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
self.assertTrue(self.last_completor_called)
self.assertTrue(self.last_completor_succees)
def test_stats(self):
lb_with_listener = self.lb_dict
lb_with_listener['listeners'] = [self.listener_dict]
BYTES = 100
stats = {'results': [{'virtual_servers': [
{'virtual_server_path': 'infra/%s' % self.listener.id,
'statistics': {'bytes_in': BYTES, 'bytes_out': BYTES}}]}]}
expected = {'active_connections': 0,
'bytes_in': BYTES,
'bytes_out': BYTES,
'total_connections': 0}
with mock.patch.object(self.service_client, 'get_statistics',
return_value=stats):
statistics = self.edge_driver.loadbalancer.stats(
self.context, lb_with_listener)
self.assertEqual(expected, statistics)
def test_refresh(self):
pass
def test_status_update(self):
with mock.patch.object(self.service_client, 'get_status'
) as mock_get_lb_service_status, \
mock.patch.object(self.service_client, 'get_virtual_servers_status'
) as mock_get_vs_status, \
mock.patch.object(self.pool_client, 'get'
) as mock_get_pool:
mock_get_lb_service_status.return_value = SERVICE_STATUSES
mock_get_vs_status.return_value = VS_STATUSES
mock_get_pool.return_value = LB_POOL_WITH_MEMBER
statuses = self.edge_driver.loadbalancer.get_operating_status(
self.context, self.lb.id, with_members=True)
self.assertEqual(1, len(statuses['loadbalancers']))
self.assertEqual('ONLINE', statuses['loadbalancers'][0]['status'])
# The rest of the statuses are not yet supported
self.assertEqual(0, len(statuses['pools']))
self.assertEqual(0, len(statuses['listeners']))
self.assertEqual(0, len(statuses['members']))
def test_add_tags_callback(self):
callback = p_utils.add_service_tag_callback(LB_ID)

View File

@ -452,43 +452,6 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
self.assertTrue(self.last_completor_called)
self.assertTrue(self.last_completor_succees)
def test_stats(self):
pass
def test_refresh(self):
pass
def test_status_update(self):
with mock.patch.object(nsx_db, 'get_nsx_lbaas_loadbalancer_binding'
) as mock_get_lb_binding, \
mock.patch.object(self.service_client, 'get_status'
) as mock_get_lb_service_status, \
mock.patch.object(self.service_client, 'get_virtual_servers_status'
) as mock_get_vs_status, \
mock.patch.object(nsx_db, 'get_nsx_lbaas_pool_binding_by_lb_pool'
) as mock_get_pool_binding, \
mock.patch.object(self.pool_client, 'get'
) as mock_get_pool, \
mock.patch.object(nsx_db,
'get_nsx_lbaas_listener_binding_by_lb_and_vs'
) as mock_get_listener_binding:
mock_get_lb_binding.return_value = LB_BINDING
mock_get_pool_binding.return_value = POOL_BINDING
mock_get_listener_binding.return_value = LISTENER_BINDING
mock_get_lb_service_status.return_value = SERVICE_STATUSES
mock_get_vs_status.return_value = VS_STATUSES
mock_get_pool.return_value = LB_POOL_WITH_MEMBER
statuses = self.edge_driver.loadbalancer.get_operating_status(
self.context, self.lb.id, with_members=True)
self.assertEqual(1, len(statuses['loadbalancers']))
self.assertEqual('ONLINE', statuses['loadbalancers'][0]['status'])
self.assertEqual(1, len(statuses['pools']))
self.assertEqual('OFFLINE', statuses['pools'][0]['status'])
self.assertEqual(1, len(statuses['listeners']))
self.assertEqual('ONLINE', statuses['listeners'][0]['status'])
self.assertEqual(1, len(statuses['members']))
self.assertEqual('OFFLINE', statuses['members'][0]['status'])
class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
def setUp(self):