From 8ccabee2b44a531944f771c71ccbb9b659576158 Mon Sep 17 00:00:00 2001 From: Zhenmei Date: Mon, 3 Aug 2015 09:55:13 +0800 Subject: [PATCH] Fix fetching LBaas pool stats failure The response of API request is the turtle type, the second element of it is the expected body. Change-Id: I7a1adb7ab70310bd0c699c6268b70d7ac0169137 --- .../vshield/edge_loadbalancer_driver.py | 20 ++--- .../nsx_v/test_edge_loadbalancer_driver.py | 74 +++++++++++-------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py index 2f1bc81699..91e8c3d5a6 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py @@ -823,22 +823,22 @@ class EdgeLbDriver(object): lb_stats = self.vcns.get_loadbalancer_statistics( pool_mapping['edge_id']) - pools_stats = lb_stats.get('pool', []) - for pool_stats in pools_stats: - if pool_stats['poolId'] == pool_mapping['edge_pool_id']: - return {'bytes_in': pool_stats.get('bytesIn', 0), - 'bytes_out': pool_stats.get('bytesOut', 0), - 'active_connections': - pool_stats.get('curSessions', 0), - 'total_connections': - pool_stats.get('totalSessions', 0)} - except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): LOG.error( _LE('Failed to read load balancer statistics, edge: %s'), pool_mapping['edge_id']) + pools_stats = lb_stats[1].get('pool', []) + for pool_stats in pools_stats: + if pool_stats['poolId'] == pool_mapping['edge_pool_id']: + return {'bytes_in': pool_stats.get('bytesIn', 0), + 'bytes_out': pool_stats.get('bytesOut', 0), + 'active_connections': + pool_stats.get('curSessions', 0), + 'total_connections': + pool_stats.get('totalSessions', 0)} + return {'bytes_in': 0, 'bytes_out': 0, 'active_connections': 0, diff --git a/vmware_nsx/neutron/tests/unit/vmware/nsx_v/test_edge_loadbalancer_driver.py b/vmware_nsx/neutron/tests/unit/vmware/nsx_v/test_edge_loadbalancer_driver.py index 9fefb3781b..1ee95e8a14 100644 --- a/vmware_nsx/neutron/tests/unit/vmware/nsx_v/test_edge_loadbalancer_driver.py +++ b/vmware_nsx/neutron/tests/unit/vmware/nsx_v/test_edge_loadbalancer_driver.py @@ -596,38 +596,48 @@ class TestEdgeLbDriver(base.BaseTestCase): def test_stats(self): pool_mapping = {'edge_id': EDGE_ID, 'edge_pool_id': EDGE_POOL_ID} - pool_stats = { - 'timeStamp': 1427358733, - 'virtualServer': [ - {'name': 'MdSrv', - 'virtualServerId': 'virtualServer-1', - 'bytesIn': 0, - 'bytesOut': 0, - 'totalSessions': 0, - 'ipAddress': '169.254.128.2', - 'curSessions': 0}], - 'pool': [ - {'status': 'UP', - 'totalSessions': 10000, - 'rateMax': 0, - 'name': 'MDSrvPool', - 'bytesOut': 100000, - 'rateLimit': 0, - 'member': [ - {'status': 'UP', - 'name': 'Member-1', - 'bytesOut': 0, - 'memberId': 'member-1', - 'totalSessions': 20000, - 'ipAddress': '192.168.55.101', - 'httpReqRateMax': 0, - 'curSessions': 0, - 'bytesIn': 0}], - 'poolId': EDGE_POOL_ID, - 'maxSessions': 10000, - 'httpReqRateMax': 0, - 'curSessions': 5000, - 'bytesIn': 1000000}]} + pool_stats = ( + { + 'status': '200', + 'content-location': '', + 'transfer-encoding': 'chunked', + 'expires': 'Thu, 01 Jan 1970 00:00:00 GMT', + 'server': '', + 'cache-control': 'private, no-cache', + 'date': 'Thu, 30 Jul 2015 08:59:27 GMT', + 'content-type': 'application/json'}, + { + 'timeStamp': 1427358733, + 'virtualServer': [ + {'name': 'MdSrv', + 'virtualServerId': 'virtualServer-1', + 'bytesIn': 0, + 'bytesOut': 0, + 'totalSessions': 0, + 'ipAddress': '169.254.128.2', + 'curSessions': 0}], + 'pool': [ + {'status': 'UP', + 'totalSessions': 10000, + 'rateMax': 0, + 'name': 'MDSrvPool', + 'bytesOut': 100000, + 'rateLimit': 0, + 'member': [ + {'status': 'UP', + 'name': 'Member-1', + 'bytesOut': 0, + 'memberId': 'member-1', + 'totalSessions': 20000, + 'ipAddress': '192.168.55.101', + 'httpReqRateMax': 0, + 'curSessions': 0, + 'bytesIn': 0}], + 'poolId': EDGE_POOL_ID, + 'maxSessions': 10000, + 'httpReqRateMax': 0, + 'curSessions': 5000, + 'bytesIn': 1000000}]}) expected_stats = { 'active_connections': 5000, 'bytes_in': 1000000,