Fix exception about loadbalancer_stats

Octavia send loadbalancer statistics through rabbit with type
loadbalancer_stats but neutron_lbaas does not support this type.

Closes-Bug: #1636380
Change-Id: Ib50c8aad8ce4a8393d69f9c271a8cfb7bedac086
(cherry picked from commit 4a5af03452)
This commit is contained in:
He Qing 2017-03-24 19:15:39 +08:00 committed by Santhosh Fernandes
parent d2d535945d
commit 7a589a4b32
3 changed files with 21 additions and 2 deletions

View File

@ -61,9 +61,12 @@ class LoadBalancerBaseDriver(object):
self.plugin = plugin
def handle_streamed_event(self, container):
# TODO(crc32): update_stats will be implemented here in the future
if container.info_type not in LoadBalancerBaseDriver.model_map:
if container.info_type == constants.LISTENER_STATS_EVENT:
if container.info_type == constants.LOADBALANCER_STATS_EVENT:
context = ncontext.get_admin_context()
self.plugin.db.update_loadbalancer_stats(
context, container.info_id, container.info_payload)
elif container.info_type == constants.LISTENER_STATS_EVENT:
return
else:
exc = exceptions.ModelMapException(

View File

@ -167,6 +167,7 @@ MIN_CONNECT_VALUE = -1
LISTENER_EVENT = 'listener'
LISTENER_STATS_EVENT = 'listener_stats'
LOADBALANCER_EVENT = 'loadbalancer'
LOADBALANCER_STATS_EVENT = 'loadbalancer_stats'
MEMBER_EVENT = 'member'
OPERATING_STATUS = 'operating_status'
POOL_EVENT = 'pool'

View File

@ -136,6 +136,21 @@ class TestOctaviaMessagingConsumer(test_octavia_driver.BaseOctaviaDriverTest):
self.assertRaises(exceptions.ModelMapException,
self.consumer.endpoints[0].update_info, {}, cnt)
def test_update_loadbalancer_stats(self):
self.set_db_mocks()
stats = {
'bytes_in': 1,
'bytes_out': 2,
'active_connections': 3,
'total_connections': 4,
'request_errors': 5,
}
cnt = InfoContainer(constants.LOADBALANCER_STATS_EVENT, 'lb_id',
stats).to_dict()
self.consumer.endpoints[0].update_info({}, cnt)
self.driver.plugin.db.update_loadbalancer_stats.assert_called_with(
mock.ANY, 'lb_id', stats)
def test_updatedb_ignores_listener_stats(self):
self.set_db_mocks()
cnt = InfoContainer('listener_stats', 'id', self.payload).to_dict()