Fix detection of member operating status DRAIN

When querying the status from HAProxy all values get read as
strings. Because the check wrongly assumed integer type values
it never detected the DRAIN status.

Story: 2009817
Task: 44389

Change-Id: If7d68c95173b8da66050659d1fb86225880dafdd
This commit is contained in:
Tom Weininger 2022-01-28 15:58:01 +01:00
parent 76e731ad73
commit d350f0908f
3 changed files with 15 additions and 8 deletions

View File

@ -115,20 +115,22 @@ class HAProxyQuery(object):
for line in results:
# pxname: pool, svname: server_name, status: status
# Due to a bug in some versions of HAProxy, DRAIN mode isn't
# calculated correctly, but we can spoof the correct value here.
if line['status'] == consts.UP and line['weight'] == 0:
line['status'] = consts.DRAIN
if line['pxname'] not in final_results:
final_results[line['pxname']] = dict(members={})
if line['svname'] == 'BACKEND':
# BACKEND describes a pool of servers in HAProxy
pool_id, listener_id = line['pxname'].split(':')
final_results[line['pxname']]['pool_uuid'] = pool_id
final_results[line['pxname']]['listener_uuid'] = listener_id
final_results[line['pxname']]['status'] = line['status']
else:
# Due to a bug in some versions of HAProxy, DRAIN mode isn't
# calculated correctly, but we can spoof the correct
# value here.
if line['status'] == consts.UP and line['weight'] == '0':
line['status'] = consts.DRAIN
final_results[line['pxname']]['members'][line['svname']] = (
line['status'])
return final_results

View File

@ -39,7 +39,7 @@ STATS_SOCKET_SAMPLE = (
"tcp-servers:listener-id,id-34833,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,1,1,"
"560,560,,1,5,1,,0,,2,0,,0,L4TOUT,,30000,,,,,,,0,,,,0,0,,,,,-1,,,0,0,0,0,"
"\n"
"tcp-servers:listener-id,id-34836,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,1,1,"
"tcp-servers:listener-id,id-34836,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,0,1,0,1,1,"
"552,552,,1,5,2,,0,,2,0,,0,L4TOUT,,30001,,,,,,,0,,,,0,0,,,,,-1,,,0,0,0,0,"
"\n"
"tcp-servers:listener-id,id-34839,0,0,0,0,,0,0,0,,0,,0,0,0,0,DRAIN,0,1,0,"
@ -48,7 +48,7 @@ STATS_SOCKET_SAMPLE = (
"tcp-servers:listener-id,id-34842,0,0,0,0,,0,0,0,,0,,0,0,0,0,MAINT,0,1,0,"
"0,0,552,0,,1,5,2,,0,,2,0,,0,L7OK,,30001,,,,,,,0,,,,0,0,,,,,-1,,,0,0,0,0,"
"\n"
"tcp-servers:listener-id,BACKEND,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,"
"tcp-servers:listener-id,BACKEND,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,UP,1,0,0,,"
"1,552,552,,1,5,0,,0,,1,0,,0,,,,,,,,,,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,"
)
@ -105,7 +105,7 @@ class QueryTestCase(base.TestCase):
'pool_uuid': 'tcp-servers',
'members':
{'id-34833': constants.UP,
'id-34836': constants.UP,
'id-34836': constants.DRAIN,
'id-34839': constants.DRAIN,
'id-34842': constants.MAINT}},
'http-servers:listener-id': {

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Correctly detect the member operating status "drain" when querying status
data from HAProxy.