From 7a589a4b32c63593793ae18f35bdf797f37a4e66 Mon Sep 17 00:00:00 2001 From: He Qing Date: Fri, 24 Mar 2017 19:15:39 +0800 Subject: [PATCH] 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 4a5af034520a4a7da1604efb853ba5b0ec8a46e7) --- neutron_lbaas/drivers/driver_base.py | 7 +++++-- neutron_lbaas/services/loadbalancer/constants.py | 1 + .../octavia/test_octavia_messaging_consumer.py | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/neutron_lbaas/drivers/driver_base.py b/neutron_lbaas/drivers/driver_base.py index 4cd25e906..bc562193f 100644 --- a/neutron_lbaas/drivers/driver_base.py +++ b/neutron_lbaas/drivers/driver_base.py @@ -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( diff --git a/neutron_lbaas/services/loadbalancer/constants.py b/neutron_lbaas/services/loadbalancer/constants.py index a2267e58f..71f4be79c 100644 --- a/neutron_lbaas/services/loadbalancer/constants.py +++ b/neutron_lbaas/services/loadbalancer/constants.py @@ -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' diff --git a/neutron_lbaas/tests/unit/drivers/octavia/test_octavia_messaging_consumer.py b/neutron_lbaas/tests/unit/drivers/octavia/test_octavia_messaging_consumer.py index e693f167e..43a82a22c 100644 --- a/neutron_lbaas/tests/unit/drivers/octavia/test_octavia_messaging_consumer.py +++ b/neutron_lbaas/tests/unit/drivers/octavia/test_octavia_messaging_consumer.py @@ -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()