Skip to content

Commit

Permalink
Dev: ra: Prevent to add unknown operation
Browse files Browse the repository at this point in the history
- When adding unknown operation, sanity check should give an error instead of a warning
- And sanity check will return a big number to indicate this is a fatal
  error, so that the commit process will be aborted
  • Loading branch information
liangxin1300 committed Jan 27, 2025
1 parent 155bd2c commit 5d54ee1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crmsh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,6 @@

PCMK_SERVICE = "pacemaker.service"
SBD_SERVICE = "sbd.service"

SANITY_FATAL_RC = 100
# vim:ts=4:sw=4:et:
4 changes: 2 additions & 2 deletions crmsh/ra.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ def sanity_check_op(op, op_dict):
if self.ra_class == "stonith" and op in ("start", "stop"):
return rc
if op not in self.actions():
logger.warning("%s: action '%s' not found in Resource Agent meta-data", ident, op)
rc |= 1
logger.error("Action '%s' not found in Resource Agent meta-data", op)
rc |= constants.SANITY_FATAL_RC

Check warning on line 596 in crmsh/ra.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ra.py#L595-L596

Added lines #L595 - L596 were not covered by tests
return rc
rc |= sanity_check_op_interval(op, op_dict)
rc |= sanity_check_op_timeout(op, op_dict)
Expand Down
4 changes: 4 additions & 0 deletions crmsh/ui_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ def _verify(self, set_obj_semantic, set_obj_all):
rc1 = set_obj_all.verify()
if config.core.check_frequency != "never":
rc2 = set_obj_semantic.semantic_check(set_obj_all)
if rc2 >= constants.SANITY_FATAL_RC:
cib_factory.reset()

Check warning on line 748 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L748

Added line #L748 was not covered by tests
else:
rc2 = 0
return rc1 and rc2 <= 1
Expand Down Expand Up @@ -926,6 +928,8 @@ def _commit(self, force=False, replace=False):
rc2 = self._verify(mkset_obj("xml", "changed"), mkset_obj("xml"))
if rc1 and rc2:
return cib_factory.commit(replace=replace)
if not cib_factory.has_cib_changed():
return False

Check warning on line 932 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L932

Added line #L932 was not covered by tests
if force or config.core.force:
logger.info("commit forced")
return cib_factory.commit(force=True, replace=replace)
Expand Down

0 comments on commit 5d54ee1

Please sign in to comment.