Merge "Drop the use of 'crm node status' on jammy."
This commit is contained in:
commit
cf1c3eeeb3
@ -29,6 +29,10 @@ from charmhelpers.core.hookenv import (
|
|||||||
DEBUG,
|
DEBUG,
|
||||||
WARNING,
|
WARNING,
|
||||||
)
|
)
|
||||||
|
from charmhelpers.core.host import (
|
||||||
|
get_distrib_codename,
|
||||||
|
CompareHostReleases,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ServicesNotUp(Exception):
|
class ServicesNotUp(Exception):
|
||||||
@ -183,10 +187,18 @@ def crm_res_running_on_node(resource, node):
|
|||||||
|
|
||||||
def list_nodes():
|
def list_nodes():
|
||||||
"""List member nodes."""
|
"""List member nodes."""
|
||||||
cmd = ['crm', 'node', 'status']
|
nodes = []
|
||||||
out = subprocess.check_output(cmd).decode('utf-8')
|
if CompareHostReleases(get_distrib_codename()) >= 'jammy':
|
||||||
tree = etree.fromstring(out)
|
cmd = ['crm', 'node', 'show']
|
||||||
nodes = [n.attrib['uname'] for n in tree.iter('node')]
|
out = subprocess.check_output(cmd).decode('utf-8')
|
||||||
|
for line in out.strip().split('\n'):
|
||||||
|
nodes.append(line.split('(')[0])
|
||||||
|
else:
|
||||||
|
cmd = ['crm', 'node', 'status']
|
||||||
|
out = subprocess.check_output(cmd).decode('utf-8')
|
||||||
|
tree = etree.fromstring(out)
|
||||||
|
nodes = [n.attrib['uname'] for n in tree.iter('node')]
|
||||||
|
|
||||||
return sorted(nodes)
|
return sorted(nodes)
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ from charmhelpers.core.host import (
|
|||||||
file_hash,
|
file_hash,
|
||||||
lsb_release,
|
lsb_release,
|
||||||
init_is_systemd,
|
init_is_systemd,
|
||||||
|
get_distrib_codename,
|
||||||
CompareHostReleases,
|
CompareHostReleases,
|
||||||
)
|
)
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
@ -1167,16 +1168,26 @@ def is_in_standby_mode(node_name):
|
|||||||
@param node_name: The name of the node to check
|
@param node_name: The name of the node to check
|
||||||
@returns boolean - True if node_name is in standby mode
|
@returns boolean - True if node_name is in standby mode
|
||||||
"""
|
"""
|
||||||
out = (subprocess
|
if CompareHostReleases(get_distrib_codename()) >= 'jammy':
|
||||||
.check_output(['crm', 'node', 'status', node_name])
|
out = (subprocess.check_output(['crm', 'node', 'attribute',
|
||||||
.decode('utf-8'))
|
node_name, 'show', 'standby'])
|
||||||
root = ET.fromstring(out)
|
.decode('utf-8'))
|
||||||
|
attrs = {}
|
||||||
|
for item in re.split('[ ]+', out.strip()):
|
||||||
|
tokens = item.split('=')
|
||||||
|
attrs[tokens[0]] = tokens[1]
|
||||||
|
standby_mode = attrs['name'] == 'standby' and attrs['value'] == 'on'
|
||||||
|
else:
|
||||||
|
out = (subprocess
|
||||||
|
.check_output(['crm', 'node', 'status', node_name])
|
||||||
|
.decode('utf-8'))
|
||||||
|
root = ET.fromstring(out)
|
||||||
|
|
||||||
standby_mode = False
|
standby_mode = False
|
||||||
for nvpair in root.iter('nvpair'):
|
for nvpair in root.iter('nvpair'):
|
||||||
if (nvpair.attrib.get('name') == 'standby' and
|
if (nvpair.attrib.get('name') == 'standby' and
|
||||||
nvpair.attrib.get('value') == 'on'):
|
nvpair.attrib.get('value') == 'on'):
|
||||||
standby_mode = True
|
standby_mode = True
|
||||||
return standby_mode
|
return standby_mode
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,15 @@ import utils
|
|||||||
import pcmk
|
import pcmk
|
||||||
|
|
||||||
|
|
||||||
|
FOCAL_NODE_STATUS_STANDBY = '''<node id="1000" uname="juju-3ff82c-focal-1">
|
||||||
|
<instance_attributes id="nodes-1000">
|
||||||
|
<nvpair id="nodes-1000-standby" name="standby" value="on"/>
|
||||||
|
</instance_attributes>
|
||||||
|
</node>
|
||||||
|
'''
|
||||||
|
JAMMY_NODE_STATUS_STANDBY = 'scope=nodes name=standby value=on\n'
|
||||||
|
|
||||||
|
|
||||||
def write_file(path, content, *args, **kwargs):
|
def write_file(path, content, *args, **kwargs):
|
||||||
with open(path, 'wt') as f:
|
with open(path, 'wt') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
@ -1367,3 +1376,23 @@ class UtilsTestCase(unittest.TestCase):
|
|||||||
127, "fake crm command")
|
127, "fake crm command")
|
||||||
with self.assertRaises(utils.RemoveCorosyncNodeFailed):
|
with self.assertRaises(utils.RemoveCorosyncNodeFailed):
|
||||||
utils.update_node_list()
|
utils.update_node_list()
|
||||||
|
|
||||||
|
@mock.patch('subprocess.check_output', autospec=True)
|
||||||
|
@mock.patch.object(utils, 'get_distrib_codename', autospec=True)
|
||||||
|
def test_is_in_standby_mode(self, get_distrib_codename, check_output):
|
||||||
|
node_name = 'juju-3ff82c-focal-1'
|
||||||
|
get_distrib_codename.return_value = 'focal'
|
||||||
|
check_output.return_value = FOCAL_NODE_STATUS_STANDBY.encode()
|
||||||
|
self.assertTrue(utils.is_in_standby_mode(node_name))
|
||||||
|
|
||||||
|
check_output.assert_called_with(['crm', 'node', 'status', node_name])
|
||||||
|
|
||||||
|
get_distrib_codename.reset_mock()
|
||||||
|
check_output.reset_mock()
|
||||||
|
|
||||||
|
get_distrib_codename.return_value = 'jammy'
|
||||||
|
check_output.return_value = JAMMY_NODE_STATUS_STANDBY.encode()
|
||||||
|
self.assertTrue(utils.is_in_standby_mode(node_name))
|
||||||
|
|
||||||
|
check_output.assert_called_with(['crm', 'node', 'attribute', node_name,
|
||||||
|
'show', 'standby'])
|
||||||
|
Loading…
Reference in New Issue
Block a user