From: Oleg Bondarev Date: Wed, 4 Sep 2013 13:48:50 +0000 (+0400) Subject: LBaaS: make haproxy stats parsing more safe X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6d1037335bbe969cfbc6d9657c24865ca226c7e9;p=openstack-build%2Fneutron-build.git LBaaS: make haproxy stats parsing more safe Change-Id: Ic21b310608bb98be29ea50ab7c56ca859a9ed5c0 Closes-Bug: #1220692 --- diff --git a/neutron/services/loadbalancer/drivers/haproxy/namespace_driver.py b/neutron/services/loadbalancer/drivers/haproxy/namespace_driver.py index 04d1972bf..27ee9e204 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/namespace_driver.py +++ b/neutron/services/loadbalancer/drivers/haproxy/namespace_driver.py @@ -123,7 +123,7 @@ class HaproxyNSDriver(object): def _get_backend_stats(self, parsed_stats): TYPE_BACKEND_RESPONSE = '1' for stats in parsed_stats: - if stats['type'] == TYPE_BACKEND_RESPONSE: + if stats.get('type') == TYPE_BACKEND_RESPONSE: unified_stats = dict((k, stats.get(v, '')) for k, v in hacfg.STATS_MAP.items()) return unified_stats @@ -134,7 +134,7 @@ class HaproxyNSDriver(object): TYPE_SERVER_RESPONSE = '2' res = {} for stats in parsed_stats: - if stats['type'] == TYPE_SERVER_RESPONSE: + if stats.get('type') == TYPE_SERVER_RESPONSE: res[stats['svname']] = { lb_const.STATS_STATUS: (constants.INACTIVE if stats['status'] == 'DOWN' @@ -169,6 +169,8 @@ class HaproxyNSDriver(object): stat_names = [name.strip('# ') for name in stat_lines[0].split(',')] res_stats = [] for raw_values in stat_lines[1:]: + if not raw_values: + continue stat_values = [value.strip() for value in raw_values.split(',')] res_stats.append(dict(zip(stat_names, stat_values))) diff --git a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py index b2a5a7160..3e39b0bd2 100644 --- a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py +++ b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_namespace_driver.py @@ -141,7 +141,7 @@ class TestHaproxyNSDriver(base.BaseTestCase): 'req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,\n' '8e271901-69ed-403e-a59b-f53cf77ef208,BACKEND,1,2,3,4,0,' '10,7764,2365,0,0,,0,0,0,0,UP,1,1,0,,0,103780,0,,1,2,0,,0' - ',,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,\n' + ',,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,\n\n' 'a557019b-dc07-4688-9af4-f5cf02bb6d4b,' '32a6c2a3-420a-44c3-955d-86bd2fc6871e,0,0,0,1,,7,1120,' '224,,0,,0,0,0,0,UP,1,1,0,0,1,2623,303,,1,2,1,,7,,2,0,,'