Revert "Use crm configure show xml to find defined resources"

This reverts commit 1fdeb0b3e0.

Change-Id: Iade3bbc06262c9234a87826e5a8e1f43535f74c6
This commit is contained in:
Chris MacNaughton (icey) 2018-09-05 14:02:59 +00:00
parent 1fdeb0b3e0
commit 8bdb2c402a
3 changed files with 8 additions and 102 deletions

View File

@ -39,10 +39,6 @@ class PropertyNotFound(Exception):
pass
class PcmkError(Exception):
pass
def wait_for_pcmk(retries=12, sleep=10):
crm_up = None
hostname = socket.gethostname()
@ -89,23 +85,11 @@ def online(node=None):
def crm_opt_exists(opt_name):
(code, output) = commands.getstatusoutput("crm configure show xml")
if code != 0:
raise PcmkError(code, output)
tree = etree.parse(StringIO(output))
root = tree.getroot()
resources = root.find('configuration').find('resources')
result = resources.findall(".//*[@id='%s']" % opt_name)
if len(result) == 0:
return False
elif len(result) == 1:
output = commands.getstatusoutput("crm configure show")[1]
if opt_name in output:
return True
else:
log('crm configure show xml:\n%s' % output, level=DEBUG)
raise PcmkError(len(result),
"Found more %d elements with id '%s'" % (len(result),
opt_name))
return False
def crm_res_running(opt_name):

View File

@ -279,7 +279,6 @@ class TestHooks(test_utils.CharmTestCase):
@mock.patch.object(hooks, 'maintenance_mode')
@mock.patch.object(hooks, 'is_leader')
@mock.patch.object(hooks, 'update_nrpe_config')
@mock.patch('pcmk.crm_opt_exists')
@mock.patch('pcmk.commit')
@mock.patch('pcmk.wait_for_pcmk')
@mock.patch.object(hooks, 'configure_corosync')
@ -290,11 +289,11 @@ class TestHooks(test_utils.CharmTestCase):
def test_config_changed(self, mock_mkdir, mock_rsync, mock_config,
mock_os_mkdir, mock_configure_corosync,
mock_wait_for_pcmk, mock_pcmk_commit,
mock_crm_opt_exists, mock_update_nrpe_config,
mock_is_leader, mock_maintenance_mode,
mock_hanode_relation_joined, mock_relation_ids):
mock_update_nrpe_config, mock_is_leader,
mock_maintenance_mode,
mock_hanode_relation_joined,
mock_relation_ids):
mock_crm_opt_exists.return_value = False
mock_config.side_effect = self.test_config.get
mock_relation_ids.return_value = ['hanode:1']
mock_wait_for_pcmk.return_value = True

View File

@ -73,70 +73,6 @@ CRM_CONFIGURE_SHOW_XML_MAINT_MODE_TRUE = '''<?xml version="1.0" ?>
''' # noqa
CRM_CONFIGURE_SHOW_XML_OPT_EXISTS = '''<?xml version="1.0" ?>
<cib num_updates="30" dc-uuid="1000" update-origin="juju-3a5deb-radosgw-5" crm_feature_set="3.0.10" validate-with="pacemaker-2.4" update-client="crmd" epoch="32" admin_epoch="0" update-user="hacluster" cib-last-written="Tue Sep 4 01:09:37 2018" have-quorum="1">
<configuration>
<crm_config>
<cluster_property_set id="cib-bootstrap-options">
<nvpair id="cib-bootstrap-options-have-watchdog" name="have-watchdog" value="false"/>
<nvpair id="cib-bootstrap-options-dc-version" name="dc-version" value="1.1.14-70404b0"/>
<nvpair id="cib-bootstrap-options-cluster-infrastructure" name="cluster-infrastructure" value="corosync"/>
<nvpair id="cib-bootstrap-options-cluster-name" name="cluster-name" value="debian"/>
<nvpair name="no-quorum-policy" value="stop" id="cib-bootstrap-options-no-quorum-policy"/>
<nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/>
<nvpair id="cib-bootstrap-options-last-lrm-refresh" name="last-lrm-refresh" value="1536023377"/>
</cluster_property_set>
</crm_config>
<nodes>
<node id="1002" uname="juju-3a5deb-radosgw-5"/>
<node id="1000" uname="juju-3a5deb-radosgw-4"/>
<node id="1001" uname="juju-3a5deb-radosgw-6"/>
</nodes>
<resources>
<group id="grp_ceph-radosgw_hostnames">
<primitive id="res_ceph-radosgw_admin_hostname" class="ocf" provider="maas" type="dns">
<instance_attributes id="res_ceph-radosgw_admin_hostname-instance_attributes">
<nvpair name="fqdn" value="rgw-public.maas" id="res_ceph-radosgw_admin_hostname-instance_attributes-fqdn"/>
<nvpair name="ip_address" value="10.5.0.8" id="res_ceph-radosgw_admin_hostname-instance_attributes-ip_address"/>
<nvpair name="maas_url" value="http://localhost/MAAS" id="res_ceph-radosgw_admin_hostname-instance_attributes-maas_url"/>
<nvpair name="maas_credentials" value="ubuntu" id="res_ceph-radosgw_admin_hostname-instance_attributes-maas_credentials"/>
</instance_attributes>
</primitive>
<primitive id="res_ceph-radosgw_int_hostname" class="ocf" provider="maas" type="dns">
<instance_attributes id="res_ceph-radosgw_int_hostname-instance_attributes">
<nvpair name="fqdn" value="rgw-internal.maas" id="res_ceph-radosgw_int_hostname-instance_attributes-fqdn"/>
<nvpair name="ip_address" value="10.5.0.8" id="res_ceph-radosgw_int_hostname-instance_attributes-ip_address"/>
<nvpair name="maas_url" value="http://localhost/MAAS" id="res_ceph-radosgw_int_hostname-instance_attributes-maas_url"/>
<nvpair name="maas_credentials" value="ubuntu" id="res_ceph-radosgw_int_hostname-instance_attributes-maas_credentials"/>
</instance_attributes>
</primitive>
<primitive id="res_ceph-radosgw_public_hostname" class="ocf" provider="maas" type="dns">
<instance_attributes id="res_ceph-radosgw_public_hostname-instance_attributes">
<nvpair name="fqdn" value="rgw-public.maas" id="res_ceph-radosgw_public_hostname-instance_attributes-fqdn"/>
<nvpair name="ip_address" value="10.5.0.8" id="res_ceph-radosgw_public_hostname-instance_attributes-ip_address"/>
<nvpair name="maas_url" value="http://localhost/MAAS" id="res_ceph-radosgw_public_hostname-instance_attributes-maas_url"/>
<nvpair name="maas_credentials" value="ubuntu" id="res_ceph-radosgw_public_hostname-instance_attributes-maas_credentials"/>
</instance_attributes>
</primitive>
</group>
<clone id="cl_cephrg_haproxy">
<primitive id="res_cephrg_haproxy" class="lsb" type="haproxy">
<operations>
<op name="monitor" interval="5s" id="res_cephrg_haproxy-monitor-5s"/>
</operations>
</primitive>
</clone>
</resources>
<constraints/>
<rsc_defaults>
<meta_attributes id="rsc-options">
<nvpair name="resource-stickiness" value="100" id="rsc-options-resource-stickiness"/>
</meta_attributes>
</rsc_defaults>
</configuration>
</cib>
''' # noqa
class TestPcmk(unittest.TestCase):
def setUp(self):
@ -256,16 +192,3 @@ class TestPcmk(unittest.TestCase):
self.assertEqual(f.read(),
('primitive res_test IPaddr2 \\\n'
'\tparams ip=1.2.3.4 cidr_netmask=255.255.0.0'))
@mock.patch('commands.getstatusoutput')
def test_crm_opt_exists(self, mock_getstatusoutput):
mock_getstatusoutput.return_value = (0,
CRM_CONFIGURE_SHOW_XML_OPT_EXISTS)
self.assertTrue(pcmk.crm_opt_exists(
'res_ceph-radosgw_public_hostname'))
self.assertFalse(pcmk.crm_opt_exists('foobar'))
self.assertFalse(pcmk.crm_opt_exists('rsc-options'))
mock_getstatusoutput.return_value = (1, 'error')
self.assertRaises(pcmk.PcmkError, pcmk.crm_opt_exists,
'res_ceph-radosgw_public_hostname')