diff --git a/octavia/amphorae/backends/utils/haproxy_query.py b/octavia/amphorae/backends/utils/haproxy_query.py index 889867ee01..94bfb879b1 100644 --- a/octavia/amphorae/backends/utils/haproxy_query.py +++ b/octavia/amphorae/backends/utils/haproxy_query.py @@ -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 diff --git a/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py b/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py index 59f0533de6..3f814d3d8c 100644 --- a/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py +++ b/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py @@ -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': { diff --git a/releasenotes/notes/fix-drain-status-detection-b9395fa4fe8c936f.yaml b/releasenotes/notes/fix-drain-status-detection-b9395fa4fe8c936f.yaml new file mode 100644 index 0000000000..6f60a4624a --- /dev/null +++ b/releasenotes/notes/fix-drain-status-detection-b9395fa4fe8c936f.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Correctly detect the member operating status "drain" when querying status + data from HAProxy.