Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjelinek committed May 25, 2022
1 parent 8adbc18 commit 988a598
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pcs/lib/cib/constraint/resource_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def is_resource_in_same_group(cib, resource_id_list):
# We don't care about not found elements here, that is a job of another
# validator. We do not care if the id doesn't belong to a resource either
# for the same reason.
element_list, _ = get_elements_by_ids(cib, resource_id_list)
element_list, _ = get_elements_by_ids(cib, set(resource_id_list))

parent_list = []
for element in element_list:
Expand Down
1 change: 1 addition & 0 deletions pcs_test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ EXTRA_DIST = \
tier0/lib/commands/test_booth.py \
tier0/lib/commands/test_cib_options.py \
tier0/lib/commands/test_constraint_common.py \
tier0/lib/commands/test_constraint_order.py \
tier0/lib/commands/test_fencing_topology.py \
tier0/lib/commands/test_node.py \
tier0/lib/commands/test_pcsd.py \
Expand Down
81 changes: 81 additions & 0 deletions pcs_test/tier0/lib/commands/test_constraint_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from unittest import TestCase

from pcs.common import reports
from pcs.lib.commands import constraint

from pcs_test.tools import fixture
from pcs_test.tools.command_env import get_env_tools


class SetCreate(TestCase):
def setUp(self):
resources_xml = """
<resources>
<group id="grAB">
<primitive class="ocf" id="A" provider="pacemaker" type="Dummy"/>
<primitive class="ocf" id="B" provider="pacemaker" type="Dummy"/>
</group>
<group id="grC">
<primitive class="ocf" id="C" provider="pacemaker" type="Dummy"/>
</group>
<primitive class="ocf" id="D" provider="pacemaker" type="Dummy"/>
</resources>
"""
self.env_assist, self.config = get_env_tools(self)
self.config.runner.cib.load(resources=resources_xml)

def test_deny_resources_from_one_group_in_one_set(self):
self.env_assist.assert_raise_library_error(
lambda: constraint.order.create_with_set(
self.env_assist.get_env(),
[{"ids": ["A", "B"], "options": {}}],
{},
),
[
fixture.error(
reports.codes.CANNOT_SET_ORDER_CONSTRAINTS_FOR_RESOURCES_IN_ONE_GROUP,
)
],
expected_in_processor=False,
)

def test_deny_resources_from_one_group_in_different_sets(self):
self.env_assist.assert_raise_library_error(
lambda: constraint.order.create_with_set(
self.env_assist.get_env(),
[{"ids": ["A"], "options": {}}, {"ids": ["B"], "options": {}}],
{},
),
[
fixture.error(
reports.codes.CANNOT_SET_ORDER_CONSTRAINTS_FOR_RESOURCES_IN_ONE_GROUP,
)
],
expected_in_processor=False,
)

def test_allow_resources_from_different_groups(self):
constraints_xml = """
<constraints>
<rsc_order id="order_set_AACCAA">
<resource_set id="order_set_AACCAA_set">
<resource_ref id="A"/>
<resource_ref id="C"/>
</resource_set>
<resource_set id="order_set_AACCAA_set-1">
<resource_ref id="A"/>
<resource_ref id="D"/>
</resource_set>
</rsc_order>
</constraints>
"""
self.config.env.push_cib(constraints=constraints_xml)

constraint.order.create_with_set(
self.env_assist.get_env(),
[
{"ids": ["A", "C"], "options": {}},
{"ids": ["A", "D"], "options": {}},
],
{},
)
46 changes: 46 additions & 0 deletions pcs_test/tier1/legacy/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5377,3 +5377,49 @@ def test_complex_primitive_all(self):
"""
),
)


class OrderVsGroup(unittest.TestCase, AssertPcsMixin):
empty_cib = rc("cib-empty.xml")

def setUp(self):
self.temp_cib = get_tmp_file("tier1_constraint_order_vs_group")
write_file_to_tmpfile(self.empty_cib, self.temp_cib)
self.pcs_runner = PcsRunner(self.temp_cib.name)
self.assert_pcs_success(
"resource create A ocf:heartbeat:Dummy --group grAB".split()
)
self.assert_pcs_success(
"resource create B ocf:heartbeat:Dummy --group grAB".split()
)
self.assert_pcs_success(
"resource create C ocf:heartbeat:Dummy --group grC".split()
)
self.assert_pcs_success("resource create D ocf:heartbeat:Dummy".split())

def tearDown(self):
self.temp_cib.close()

def test_deny_resources_in_one_group(self):
self.assert_pcs_fail(
"constraint order A then B".split(),
"Error: Cannot create an order constraint for resources in the same group\n",
)

def test_allow_resources_in_different_groups(self):
self.assert_pcs_success(
"constraint order A then C".split(),
"Adding A C (kind: Mandatory) (Options: first-action=start then-action=start)\n",
)

def test_allow_grouped_and_not_grouped_resource(self):
self.assert_pcs_success(
"constraint order A then D".split(),
"Adding A D (kind: Mandatory) (Options: first-action=start then-action=start)\n",
)

def test_allow_group_and_resource(self):
self.assert_pcs_success(
"constraint order grAB then C".split(),
"Adding grAB C (kind: Mandatory) (Options: first-action=start then-action=start)\n",
)

0 comments on commit 988a598

Please sign in to comment.