Skip to content

Commit 37b2578

Browse files
committed
Dev: cibconfig: Prevent adding Pacemaker remote resources to groups, orders, or colocations
1 parent ab009e0 commit 37b2578

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

crmsh/cibconfig.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,14 +1702,21 @@ def check_sanity(self) -> VerifyResult:
17021702
if self.node is None: # eh?
17031703
logger.error("%s: no xml (strange)", self.obj_id)
17041704
return utils.get_check_rc()
1705+
1706+
rc = VerifyResult.SUCCESS
17051707
l = get_resource_meta_list()
17061708
if self.obj_type == "clone":
17071709
l += constants.clone_meta_attributes
17081710
elif self.obj_type == "ms":
17091711
l += constants.clone_meta_attributes + constants.ms_meta_attributes
17101712
elif self.obj_type == "group":
1713+
for c in self.node.iterchildren():
1714+
if c.tag == "primitive" and c.get("class") == "ocf" and c.get("type") == "remote":
1715+
logger.error("Remote resource '%s' cannot be in a group", c.get("id"))
1716+
rc |= VerifyResult.FATAL_ERROR
17111717
l += constants.group_meta_attributes
1712-
return sanity_check_meta(self.obj_id, self.node, l)
1718+
rc |= sanity_check_meta(self.obj_id, self.node, l)
1719+
return rc
17131720

17141721
def repr_gv(self, gv_obj, from_grp=False):
17151722
'''
@@ -1774,6 +1781,24 @@ def _check_if_constraint_ref_is_child(obj) -> VerifyResult:
17741781
return rc
17751782

17761783

1784+
def check_if_primitive_in_constraint_is_remote(obj) -> VerifyResult:
1785+
rc = VerifyResult.SUCCESS
1786+
primitives = []
1787+
if obj.obj_type == "colocation":
1788+
primitives = [obj.node.get("rsc"), obj.node.get("with-rsc")]
1789+
elif obj.obj_type == "order":
1790+
primitives = [obj.node.get("first"), obj.node.get("then")]
1791+
for rscid in primitives:
1792+
tgt = cib_factory.find_object(rscid)
1793+
if not tgt:
1794+
logger.warning("%s: resource %s does not exist", obj.obj_id, rscid)
1795+
rc |= VerifyResult.WARNING
1796+
elif tgt.node.get("class") == "ocf" and tgt.node.get("type") == "remote":
1797+
logger.error("Cannot put remote resource '%s' in %s constraint", rscid, obj.obj_type)
1798+
rc |= VerifyResult.FATAL_ERROR
1799+
return rc
1800+
1801+
17771802
class CibLocation(CibObject):
17781803
'''
17791804
Location constraint.
@@ -2000,7 +2025,9 @@ def check_sanity(self) -> VerifyResult:
20002025
if self.node is None:
20012026
logger.error("%s: no xml (strange)", self.obj_id)
20022027
return utils.get_check_rc()
2003-
return _check_if_constraint_ref_is_child(self)
2028+
rc1 = _check_if_constraint_ref_is_child(self)
2029+
rc2 = check_if_primitive_in_constraint_is_remote(self)
2030+
return rc1 | rc2
20042031

20052032

20062033
class CibRscTicket(CibSimpleConstraint):

0 commit comments

Comments
 (0)