Update 'crm node show' parsing to trim ': member'

The command 'crm node show' is used on jammy to retrieve the list of
nodes defined in a cluster. The output for nodes includes ': member'
which breaks ensuing commands that are using list_nodes() output.

For example:
juju-3f6cb6-zaza-4135aa8b2509-8.project.serverstack: member

This change trims everything including and after the ':' from the
output.

Closes-Bug: #1994160
Change-Id: I54a4f854f3e293503ec97d99a49b6dc51ee50c87
(cherry picked from commit f73ca4d52f)
This commit is contained in:
Corey Bryant 2022-10-25 16:48:21 +00:00 committed by Felipe Reyes
parent 8e6904ecae
commit 6dc05401c6
2 changed files with 6 additions and 2 deletions

View File

@ -193,7 +193,9 @@ def list_nodes():
out = subprocess.check_output(cmd).decode('utf-8')
for line in out.strip().split('\n'):
if re.match(r'^\S+', line):
nodes.append(line.split('(')[0])
line = line.split('(')[0]
line = line.split(':')[0]
nodes.append(line)
else:
cmd = ['crm', 'node', 'status']
out = subprocess.check_output(cmd).decode('utf-8')

View File

@ -152,6 +152,7 @@ CRM_STATUS_XML = b"""
CRM_NODE_SHOW_OUTPUT = b"""juju-c1-zaza-3(1000): member
standby=off maintenance=true
juju-c1-zaza-5(1002): member
juju-3f6cb6-zaza-4135aa8b2509-8.project.serverstack: member
"""
@ -378,7 +379,8 @@ class TestPcmk(unittest.TestCase):
self.assertSequenceEqual(
pcmk.list_nodes(),
['juju-c1-zaza-3', 'juju-c1-zaza-5']
['juju-3f6cb6-zaza-4135aa8b2509-8.project.serverstack',
'juju-c1-zaza-3', 'juju-c1-zaza-5']
)
check_output.assert_called_with(['crm', 'node', 'show'])