def test_bug41660_1(): xml = """<primitive id="bug41660" class="ocf" provider="pacemaker" type="Dummy"> \ <meta_attributes id="bug41660-meta"> \ <nvpair id="bug41660-meta-target-role" name="target-role" value="Stopped"/> \ </meta_attributes> \ </primitive> """ data = etree.fromstring(xml) obj = factory.create_from_node(data) print etree.tostring(obj.node) data = obj.repr_cli(format=-1) print data exp = 'primitive bug41660 ocf:pacemaker:Dummy meta target-role=Stopped' assert data == exp assert obj.cli_use_validate() commit_holder = factory.commit try: factory.commit = lambda *args: True from ui_resource import set_deep_meta_attr set_deep_meta_attr("bug41660", "target-role", "Started") eq_(['Started'], obj.node.xpath('.//nvpair[@name="target-role"]/@value')) finally: factory.commit = commit_holder
def test_bug41660_3(): xml = """ <clone id="libvirtd-clone"> <primitive class="lsb" id="libvirtd" type="libvirtd"> <operations> <op id="libvirtd-monitor-interval-15" interval="15" name="monitor" start-delay="15" timeout="15"/> <op id="libvirtd-start-interval-0" interval="0" name="start" on-fail="restart" timeout="15"/> <op id="libvirtd-stop-interval-0" interval="0" name="stop" on-fail="ignore" timeout="15"/> </operations> <meta_attributes id="libvirtd-meta_attributes"/> </primitive> <meta_attributes id="libvirtd-clone-meta_attributes"> <nvpair id="libvirtd-clone-meta_attributes-target-role" name="target-role" value="Stopped"/> </meta_attributes> </clone> """ data = etree.fromstring(xml) obj = factory.create_from_node(data) assert obj is not None data = obj.repr_cli(format=-1) print data exp = 'clone libvirtd-clone libvirtd meta target-role=Stopped' assert data == exp assert obj.cli_use_validate() commit_holder = factory.commit try: factory.commit = lambda *args: True from ui_resource import set_deep_meta_attr set_deep_meta_attr("libvirtd-clone", "target-role", "Started") eq_(['Started'], obj.node.xpath('.//nvpair[@name="target-role"]/@value')) finally: factory.commit = commit_holder
def test_bug41660_2(): xml = """ <clone id="libvirtd-clone"> <primitive class="lsb" id="libvirtd" type="libvirtd"> <operations> <op id="libvirtd-monitor-interval-15" interval="15" name="monitor" start-delay="15" timeout="15"/> <op id="libvirtd-start-interval-0" interval="0" name="start" on-fail="restart" timeout="15"/> <op id="libvirtd-stop-interval-0" interval="0" name="stop" on-fail="ignore" timeout="15"/> </operations> <meta_attributes id="libvirtd-meta_attributes"/> </primitive> <meta_attributes id="libvirtd-clone-meta"> <nvpair id="libvirtd-interleave" name="interleave" value="true"/> <nvpair id="libvirtd-ordered" name="ordered" value="true"/> <nvpair id="libvirtd-clone-meta-target-role" name="target-role" value="Stopped"/> </meta_attributes> </clone> """ data = etree.fromstring(xml) obj = factory.new_object('clone', 'libvirtd-clone') assert obj is not None obj.node = data obj.set_id() data = obj.repr_cli(format=-1) print data exp = 'clone libvirtd-clone libvirtd meta interleave=true ordered=true target-role=Stopped' assert data == exp #assert obj.cli_use_validate() def mock_commit_rsc(node): xmlutil.xml_processnodes(node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) xmlutil.xml_processnodes(node, xmlutil.is_emptyops, xmlutil.rmnodes) print etree.tostring(node) assert etree.tostring(node).count( 'name="target-role" value="Started"') == 1 return True def mock_cibdump2elem(section=None): if section == 'configuration': return xmlutil.cibtext2elem("""<configuration><resources>""" + xml + """</resources></configuration>""") assert False commit_rsc_holder = xmlutil.commit_rsc cibdump2elem_holder = xmlutil.cibdump2elem try: xmlutil.commit_rsc = mock_commit_rsc xmlutil.cibdump2elem = mock_cibdump2elem from ui_resource import set_deep_meta_attr set_deep_meta_attr("target-role", "Started", "libvirtd-clone") finally: xmlutil.commit_rsc = commit_rsc_holder xmlutil.cibdump2elem = cibdump2elem_holder
def test_bug41660_2(): xml = """ <clone id="libvirtd-clone"> <primitive class="lsb" id="libvirtd" type="libvirtd"> <operations> <op id="libvirtd-monitor-interval-15" interval="15" name="monitor" start-delay="15" timeout="15"/> <op id="libvirtd-start-interval-0" interval="0" name="start" on-fail="restart" timeout="15"/> <op id="libvirtd-stop-interval-0" interval="0" name="stop" on-fail="ignore" timeout="15"/> </operations> <meta_attributes id="libvirtd-meta_attributes"/> </primitive> <meta_attributes id="libvirtd-clone-meta"> <nvpair id="libvirtd-interleave" name="interleave" value="true"/> <nvpair id="libvirtd-ordered" name="ordered" value="true"/> <nvpair id="libvirtd-clone-meta-target-role" name="target-role" value="Stopped"/> </meta_attributes> </clone> """ data = etree.fromstring(xml) obj = factory.new_object('clone', 'libvirtd-clone') assert obj is not None obj.node = data obj.set_id() data = obj.repr_cli(format=-1) print data exp = 'clone libvirtd-clone libvirtd meta interleave=true ordered=true target-role=Stopped' assert data == exp #assert obj.cli_use_validate() def mock_commit_rsc(node): xmlutil.xml_processnodes(node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) xmlutil.xml_processnodes(node, xmlutil.is_emptyops, xmlutil.rmnodes) print etree.tostring(node) assert etree.tostring(node).count('name="target-role" value="Started"') == 1 return True def mock_cibdump2elem(section=None): if section == 'configuration': return xmlutil.cibtext2elem( """<configuration><resources>""" + xml + """</resources></configuration>""") assert False commit_rsc_holder = xmlutil.commit_rsc cibdump2elem_holder = xmlutil.cibdump2elem try: xmlutil.commit_rsc = mock_commit_rsc xmlutil.cibdump2elem = mock_cibdump2elem from ui_resource import set_deep_meta_attr set_deep_meta_attr("target-role", "Started", "libvirtd-clone") finally: xmlutil.commit_rsc = commit_rsc_holder xmlutil.cibdump2elem = cibdump2elem_holder
def test_bug41660_1(): xml = """<primitive id="bug41660" class="ocf" provider="pacemaker" type="Dummy"> \ <meta_attributes id="bug41660-meta"> \ <nvpair id="bug41660-meta-target-role" name="target-role" value="Stopped"/> \ </meta_attributes> \ </primitive> """ data = etree.fromstring(xml) obj = factory.new_object('primitive', 'bug41660') assert obj is not None obj.node = data obj.set_id() data = obj.repr_cli(format=-1) print data exp = 'primitive bug41660 ocf:pacemaker:Dummy meta target-role=Stopped' assert data == exp assert obj.cli_use_validate() def mock_commit_rsc(node): xmlutil.xml_processnodes(node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) xmlutil.xml_processnodes(node, xmlutil.is_emptyops, xmlutil.rmnodes) print etree.tostring(node) assert 'name="target-role" value="Started"' in etree.tostring(node) return True def mock_cibdump2elem(section=None): if section == 'configuration': return xmlutil.cibtext2elem("""<configuration><resources>""" + xml + """</resources></configuration>""") assert False commit_rsc_holder = xmlutil.commit_rsc cibdump2elem_holder = xmlutil.cibdump2elem try: xmlutil.commit_rsc = mock_commit_rsc xmlutil.cibdump2elem = mock_cibdump2elem from ui_resource import set_deep_meta_attr set_deep_meta_attr("target-role", "Started", "bug41660") finally: xmlutil.commit_rsc = commit_rsc_holder xmlutil.cibdump2elem = cibdump2elem_holder
def _stop_if_running(self, rscs): rscstate = xmlutil.RscState() to_stop = [rsc for rsc in rscs if rscstate.is_running(rsc)] from ui_resource import set_deep_meta_attr if len(to_stop) > 0: ok = all(set_deep_meta_attr(rsc, 'target-role', 'Stopped', commit=False) for rsc in to_stop) if not ok or not cib_factory.commit(): raise ValueError("Failed to stop one or more running resources: %s" % (', '.join(to_stop)))
def test_bug41660_1(): xml = """<primitive id="bug41660" class="ocf" provider="pacemaker" type="Dummy"> \ <meta_attributes id="bug41660-meta"> \ <nvpair id="bug41660-meta-target-role" name="target-role" value="Stopped"/> \ </meta_attributes> \ </primitive> """ data = etree.fromstring(xml) obj = factory.new_object('primitive', 'bug41660') assert obj is not None obj.node = data obj.set_id() data = obj.repr_cli(format=-1) print data exp = 'primitive bug41660 ocf:pacemaker:Dummy meta target-role=Stopped' assert data == exp assert obj.cli_use_validate() def mock_commit_rsc(node): xmlutil.xml_processnodes(node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) xmlutil.xml_processnodes(node, xmlutil.is_emptyops, xmlutil.rmnodes) print etree.tostring(node) assert 'name="target-role" value="Started"' in etree.tostring(node) return True def mock_cibdump2elem(section=None): if section == 'configuration': return xmlutil.cibtext2elem( """<configuration><resources>""" + xml + """</resources></configuration>""") assert False commit_rsc_holder = xmlutil.commit_rsc cibdump2elem_holder = xmlutil.cibdump2elem try: xmlutil.commit_rsc = mock_commit_rsc xmlutil.cibdump2elem = mock_cibdump2elem from ui_resource import set_deep_meta_attr set_deep_meta_attr("target-role", "Started", "bug41660") finally: xmlutil.commit_rsc = commit_rsc_holder xmlutil.cibdump2elem = cibdump2elem_holder
def _stop_if_running(self, rscs): rscstate = xmlutil.RscState() to_stop = [rsc for rsc in rscs if rscstate.is_running(rsc)] from ui_resource import set_deep_meta_attr if len(to_stop) > 0: ok = all( set_deep_meta_attr(rsc, 'target-role', 'Stopped', commit=False) for rsc in to_stop) if not ok or not cib_factory.commit(): raise ValueError( "Failed to stop one or more running resources: %s" % (', '.join(to_stop)))