def test_remove_nothing_when_no_matching_found(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)

        self.assertFalse(
            ticket.remove_plain(
                constraint_section,
                ticket_key="tA",
                resource_id="rA",
            ))

        assert_xml_equal(
            etree.tostring(constraint_section).decode(),
            """
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """,
        )
    def test_remove_tickets_constraints_for_resource(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t1" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t3" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)

        self.assertTrue(
            ticket.remove_plain(
                constraint_section,
                ticket_key="tA",
                resource_id="rA",
            ))

        assert_xml_equal(
            etree.tostring(constraint_section).decode(),
            """
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """,
        )
Exemple #3
0
def remove(env, ticket_key, resource_id):
    """
    remove all ticket constraint from resource
    If resource is in resource set with another resources then only resource ref
    is removed. If resource is alone in resource set whole constraint is removed.
    """
    constraint_section = get_constraints(env.get_cib())
    any_plain_removed = ticket.remove_plain(constraint_section, ticket_key,
                                            resource_id)
    any_with_resource_set_removed = ticket.remove_with_resource_set(
        constraint_section, ticket_key, resource_id)

    env.push_cib()

    return any_plain_removed or any_with_resource_set_removed
Exemple #4
0
def remove(env, ticket_key, resource_id):
    """
    remove all ticket constraint from resource
    If resource is in resource set with another resources then only resource ref
    is removed. If resource is alone in resource set whole constraint is removed.
    """
    cib = env.get_cib()
    constraint_section = get_constraints(cib)
    any_plain_removed = ticket.remove_plain(
        constraint_section,
        ticket_key,
        resource_id
    )
    any_with_resource_set_removed = ticket.remove_with_resource_set(
        constraint_section,
        ticket_key,
        resource_id
    )

    env.push_cib(cib)

    return any_plain_removed or any_with_resource_set_removed
    def test_remove_nothing_when_no_matching_found(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)

        self.assertFalse(ticket.remove_plain(
            constraint_section,
            ticket_key="tA",
            resource_id="rA",
        ))

        assert_xml_equal(etree.tostring(constraint_section).decode(), """
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)
    def test_remove_tickets_constraints_for_resource(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t1" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t3" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)

        self.assertTrue(ticket.remove_plain(
            constraint_section,
            ticket_key="tA",
            resource_id="rA",
        ))

        assert_xml_equal(etree.tostring(constraint_section).decode(), """
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)