LBaaS: make haproxy stats parsing more safe
Change-Id: Ic21b310608bb98be29ea50ab7c56ca859a9ed5c0 Closes-Bug: #1220692
This commit is contained in:
parent
508fa4ba6f
commit
ffebee618b
@ -123,7 +123,7 @@ class HaproxyNSDriver(object):
|
|||||||
def _get_backend_stats(self, parsed_stats):
|
def _get_backend_stats(self, parsed_stats):
|
||||||
TYPE_BACKEND_RESPONSE = '1'
|
TYPE_BACKEND_RESPONSE = '1'
|
||||||
for stats in parsed_stats:
|
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, ''))
|
unified_stats = dict((k, stats.get(v, ''))
|
||||||
for k, v in hacfg.STATS_MAP.items())
|
for k, v in hacfg.STATS_MAP.items())
|
||||||
return unified_stats
|
return unified_stats
|
||||||
@ -134,7 +134,7 @@ class HaproxyNSDriver(object):
|
|||||||
TYPE_SERVER_RESPONSE = '2'
|
TYPE_SERVER_RESPONSE = '2'
|
||||||
res = {}
|
res = {}
|
||||||
for stats in parsed_stats:
|
for stats in parsed_stats:
|
||||||
if stats['type'] == TYPE_SERVER_RESPONSE:
|
if stats.get('type') == TYPE_SERVER_RESPONSE:
|
||||||
res[stats['svname']] = {
|
res[stats['svname']] = {
|
||||||
lb_const.STATS_STATUS: (constants.INACTIVE
|
lb_const.STATS_STATUS: (constants.INACTIVE
|
||||||
if stats['status'] == 'DOWN'
|
if stats['status'] == 'DOWN'
|
||||||
@ -169,6 +169,8 @@ class HaproxyNSDriver(object):
|
|||||||
stat_names = [name.strip('# ') for name in stat_lines[0].split(',')]
|
stat_names = [name.strip('# ') for name in stat_lines[0].split(',')]
|
||||||
res_stats = []
|
res_stats = []
|
||||||
for raw_values in stat_lines[1:]:
|
for raw_values in stat_lines[1:]:
|
||||||
|
if not raw_values:
|
||||||
|
continue
|
||||||
stat_values = [value.strip() for value in raw_values.split(',')]
|
stat_values = [value.strip() for value in raw_values.split(',')]
|
||||||
res_stats.append(dict(zip(stat_names, stat_values)))
|
res_stats.append(dict(zip(stat_names, stat_values)))
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
|
|||||||
'req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,\n'
|
'req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,\n'
|
||||||
'8e271901-69ed-403e-a59b-f53cf77ef208,BACKEND,1,2,3,4,0,'
|
'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'
|
'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,'
|
'a557019b-dc07-4688-9af4-f5cf02bb6d4b,'
|
||||||
'32a6c2a3-420a-44c3-955d-86bd2fc6871e,0,0,0,1,,7,1120,'
|
'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,,'
|
'224,,0,,0,0,0,0,UP,1,1,0,0,1,2623,303,,1,2,1,,7,,2,0,,'
|
||||||
|
Loading…
Reference in New Issue
Block a user