From 1e5e35b6292a28a634bd4d42288e51c67ae22b10 Mon Sep 17 00:00:00 2001 From: bixiaoyan Date: Mon, 13 May 2024 10:38:04 +0800 Subject: [PATCH] fix score syntax in location constraints --- ...ore-syntax-in-colocation-constraints.patch | 309 ++++++++++++++++++ pcs.spec | 6 +- 2 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 fix-score-syntax-in-colocation-constraints.patch diff --git a/fix-score-syntax-in-colocation-constraints.patch b/fix-score-syntax-in-colocation-constraints.patch new file mode 100644 index 0000000..9c4d80a --- /dev/null +++ b/fix-score-syntax-in-colocation-constraints.patch @@ -0,0 +1,309 @@ +From 29d7a675134b9f7f04766b5b570d001e2ca421c1 Mon Sep 17 00:00:00 2001 +From: Tomas Jelinek +Date: Mon, 29 Apr 2024 17:29:14 +0200 +Subject: [PATCH] fix score syntax in colocation constraints + +--- + CHANGELOG.md | 2 ++ + pcs/cli/constraint/output/colocation.py | 9 ++------ + pcs/constraint.py | 18 +++++++++++++-- + pcs/pcs.8.in | 6 ++++- + pcs/usage.py | 3 ++- + pcs_test/tier1/constraint/test_config.py | 4 ++-- + pcs_test/tier1/legacy/test_constraints.py | 28 +++++++++++++++++------ + pcs_test/tier1/test_misc.py | 2 ++ + pcsd/capabilities.xml.in | 8 +++++++ + pcsd/pcs.rb | 2 +- + 10 files changed, 61 insertions(+), 21 deletions(-) + +diff --git a/CHANGELOG.md b/CHANGELOG.md +index 1b5d9fc8..18a5ba05 100644 +--- a/CHANGELOG.md ++++ b/CHANGELOG.md +@@ -39,6 +39,8 @@ + - upstart and nagios resources + - some date-spec and duration options in rules + - Specifying rules as multiple arguments, use a single string argument instead ++- Specifying score as a standalone value in `pcs constraint colocation add`, use ++ score=value instead + + [ghissue#772]: https://github.com/ClusterLabs/pcs/issues/772 + [ghissue#780]: https://github.com/ClusterLabs/pcs/issues/780 +diff --git a/pcs/cli/constraint/output/colocation.py b/pcs/cli/constraint/output/colocation.py +index 7a13ed27..d7d709ca 100644 +--- a/pcs/cli/constraint/output/colocation.py ++++ b/pcs/cli/constraint/output/colocation.py +@@ -174,21 +174,16 @@ def plain_constraint_to_cmd( + ) + return [] + result = [ +- "pcs -- constraint colocation add {resource_role}{resource_id} with {with_resource_role}{with_resource_id}{score}".format( ++ "pcs -- constraint colocation add {resource_role}{resource_id} with {with_resource_role}{with_resource_id}".format( + resource_role=format_optional(constraint_dto.resource_role), + resource_id=quote(constraint_dto.resource_id), + with_resource_role=format_optional( + constraint_dto.with_resource_role + ), + with_resource_id=quote(constraint_dto.with_resource_id), +- score=format_optional( +- constraint_dto.attributes.score, template=" {}" +- ), + ) + ] +- pairs = _attributes_to_cmd_pairs( +- constraint_dto.attributes, filter_out=("score",) +- ) ++ pairs = _attributes_to_cmd_pairs(constraint_dto.attributes) + if pairs is None: + return [] + params = pairs_to_cmd(pairs) +diff --git a/pcs/constraint.py b/pcs/constraint.py +index 6f1c3935..e4b1086d 100644 +--- a/pcs/constraint.py ++++ b/pcs/constraint.py +@@ -158,6 +158,8 @@ def _validate_resources_not_in_same_group(cib_dom, resource1, resource2): + # with [score] [options] + # with [score] [options] + # with [score] [options] ++# Specifying score as a single argument is deprecated, though. The correct way ++# is score=value in options. + def colocation_add(lib, argv, modifiers): + """ + Options: +@@ -173,8 +175,16 @@ def colocation_add(lib, argv, modifiers): + Commandline options: no options + """ + if not argv: +- return SCORE_INFINITY, [] +- score = SCORE_INFINITY if "=" in argv[0] else argv.pop(0) ++ return None, [] ++ score = None ++ if "=" not in argv[0]: ++ score = argv.pop(0) ++ # TODO added to pcs in the first 0.12.x version ++ deprecation_warning( ++ "Specifying score as a standalone value is deprecated and " ++ "might be removed in a future release, use score=value instead" ++ ) ++ + # create a list of 2-tuples (name, value) + arg_array = [ + parse_args.split_option(arg, allow_empty_value=False) +@@ -255,6 +265,10 @@ def colocation_add(lib, argv, modifiers): + % value + ) + id_in_nvpairs = True ++ elif name == "score": ++ score = value ++ if score is None: ++ score = SCORE_INFINITY + if not id_in_nvpairs: + nv_pairs.append( + ( +diff --git a/pcs/pcs.8.in b/pcs/pcs.8.in +index 32f2ba66..08eab2f1 100644 +--- a/pcs/pcs.8.in ++++ b/pcs/pcs.8.in +@@ -1157,7 +1157,7 @@ Remove resource from any ordering constraint + colocation [config] [\fB\-\-full\fR] [@OUTPUT_FORMAT_SYNTAX_DOC@] + List all current colocation constraints (if \fB\-\-full\fR is specified show the internal constraint id's as well). @OUTPUT_FORMAT_DESC_DOC@ + .TP +-colocation add [] with [] [score] [options] [id=constraint\-id] ++colocation add [] with [] [score=] [] [id=] + Request to run on the same node where pacemaker has determined should run. Positive values of score mean the resources should be run on the same node, negative values mean the resources should not be run on the same node. Specifying 'INFINITY' (or '\-INFINITY') for the score forces to run (or not run) with (score defaults to "INFINITY"). A role can be: 'Promoted', 'Unpromoted', 'Started', 'Stopped' (if no role is specified, it defaults to 'Started'). + .TP + colocation set [resourceN]... [options] [set ... [options]] [setoptions [constraint_options]] +@@ -1643,6 +1643,10 @@ Several date-spec and duration options have been removed in pacemaker 3. Therefo + Using spaces in dates in location constraint rules is no longer allowed. + .br + Rules are supposed to be specified as a single string argument. Specifying rules as multiple arguments has been deprecated and might be removed in a future release. ++.SS "constraint" ++.TP ++colocation add ++Specifying score as a standalone value is deprecated in favor of score=value. This makes the command consistent with other commands for creating constraints. + .SS "stonith" + .TP + level add | clear | delete | remove +diff --git a/pcs/usage.py b/pcs/usage.py +index a4af30d4..d8bec4c7 100644 +--- a/pcs/usage.py ++++ b/pcs/usage.py +@@ -2478,7 +2478,8 @@ Commands: + {output_format_desc} + + colocation add [] with [] +- [score] [options] [id=constraint-id] ++ [score=] [] ++ [id=] + Request to run on the same node where pacemaker has + determined should run. Positive values of score + mean the resources should be run on the same node, negative values +diff --git a/pcs_test/tier1/constraint/test_config.py b/pcs_test/tier1/constraint/test_config.py +index de39b3a5..4bcf0c97 100644 +--- a/pcs_test/tier1/constraint/test_config.py ++++ b/pcs_test/tier1/constraint/test_config.py +@@ -234,8 +234,8 @@ class ConstraintConfigCmdUnsupported(TestCase): + stdout, + ( + "pcs -- constraint location add location-OK resource%R1 node1 INFINITY;\n" +- "pcs -- constraint colocation add R1 with R3 INFINITY \\\n" +- " id=colocation-OK;\n" ++ "pcs -- constraint colocation add R1 with R3 \\\n" ++ " id=colocation-OK score=INFINITY;\n" + "pcs -- constraint colocation \\\n" + " set R1 R3 \\\n" + " setoptions id=colocation-set-OK;\n" +diff --git a/pcs_test/tier1/legacy/test_constraints.py b/pcs_test/tier1/legacy/test_constraints.py +index 97343dc4..72ef8762 100644 +--- a/pcs_test/tier1/legacy/test_constraints.py ++++ b/pcs_test/tier1/legacy/test_constraints.py +@@ -58,6 +58,10 @@ DEPRECATED_LOCATION_CONSTRAINT_REMOVE = ( + "Deprecation Warning: This command is deprecated and will be removed. " + "Please use 'pcs constraint delete' or 'pcs constraint remove' instead.\n" + ) ++DEPRECATED_STANDALONE_SCORE = ( ++ "Deprecation Warning: Specifying score as a standalone value is deprecated " ++ "and might be removed in a future release, use score=value instead\n" ++) + + empty_cib = rc("cib-empty-3.7.xml") + large_cib = rc("cib-large.xml") +@@ -520,7 +524,7 @@ class ConstraintTest(unittest.TestCase, AssertPcsMixin): + "constraint colocation add D1 with D2 100".split(), + ) + self.assertEqual(stdout, "") +- self.assertEqual(stderr, "") ++ self.assertEqual(stderr, DEPRECATED_STANDALONE_SCORE) + self.assertEqual(retval, 0) + + stdout, stderr, retval = pcs( +@@ -528,12 +532,12 @@ class ConstraintTest(unittest.TestCase, AssertPcsMixin): + "--force -- constraint colocation add D1 with D2 -100".split(), + ) + self.assertEqual(stdout, "") +- self.assertEqual(stderr, "") ++ self.assertEqual(stderr, DEPRECATED_STANDALONE_SCORE) + self.assertEqual(retval, 0) + + stdout, stderr, retval = pcs( + self.temp_cib.name, +- "constraint colocation add Master with D5 100".split(), ++ "constraint colocation add Master with D5 score=100".split(), + ) + self.assertEqual(stdout, "") + self.assertEqual(stderr, "") +@@ -570,7 +574,7 @@ class ConstraintTest(unittest.TestCase, AssertPcsMixin): + + stdout, stderr, retval = pcs( + self.temp_cib.name, +- f"constraint colocation add {const.PCMK_ROLE_UNPROMOTED} M5-master with started M6-master 500".split(), ++ f"constraint colocation add {const.PCMK_ROLE_UNPROMOTED} M5-master with started M6-master score=500".split(), + ) + self.assertEqual(stdout, "") + self.assertEqual(stderr, "") +@@ -715,6 +719,14 @@ class ConstraintTest(unittest.TestCase, AssertPcsMixin): + "-- constraint colocation add D1 with D2 -100 id=abcd node-attribute=y".split(), + ) + self.assertEqual(stdout, "") ++ self.assertEqual(stderr, DEPRECATED_STANDALONE_SCORE) ++ self.assertEqual(retval, 0) ++ ++ stdout, stderr, retval = pcs( ++ self.temp_cib.name, ++ "-- constraint colocation add D2 with D1 score=-100 id=efgh node-attribute=y".split(), ++ ) ++ self.assertEqual(stdout, "") + self.assertEqual(stderr, "") + self.assertEqual(retval, 0) + +@@ -725,6 +737,8 @@ class ConstraintTest(unittest.TestCase, AssertPcsMixin): + Colocation Constraints: + resource 'D1' with resource 'D2' + score=-100 ++ resource 'D2' with resource 'D1' ++ score=-100 + """ + ), + ) +@@ -2774,7 +2788,7 @@ Error: duplicate constraint already exists, use --force to override + + stdout, stderr, retval = pcs( + self.temp_cib.name, +- "constraint colocation add D1 with D2 50".split(), ++ "constraint colocation add D1 with D2 score=50".split(), + ) + self.assertEqual(stdout, "") + ac( +@@ -2788,7 +2802,7 @@ Error: duplicate constraint already exists, use --force to override + + stdout, stderr, retval = pcs( + self.temp_cib.name, +- "constraint colocation add D1 with D2 50 --force".split(), ++ "constraint colocation add D1 with D2 score=50 --force".split(), + ) + self.assertEqual(stdout, "") + self.assertEqual(stderr, "") +@@ -3161,7 +3175,7 @@ Error: duplicate constraint already exists, use --force to override + + stdout, stderr, retval = pcs( + self.temp_cib.name, +- "constraint colocation add D2 with D1 100 id=id2".split(), ++ "constraint colocation add D2 with D1 score=100 id=id2".split(), + ) + self.assertEqual(stdout, "") + self.assertEqual(stderr, "") +diff --git a/pcs_test/tier1/test_misc.py b/pcs_test/tier1/test_misc.py +index 45a72ce1..d83613cc 100644 +--- a/pcs_test/tier1/test_misc.py ++++ b/pcs_test/tier1/test_misc.py +@@ -35,6 +35,7 @@ class ParseArgvDashDash(TestCase, AssertPcsMixin): + outdent( + """\ + Deprecation Warning: Using '-123' without '--' is deprecated, those parameters will be considered position independent options in future pcs versions ++ Deprecation Warning: Specifying score as a standalone value is deprecated and might be removed in a future release, use score=value instead + Error: Resource 'R1' does not exist + """ + ), +@@ -67,6 +68,7 @@ class ParseArgvDashDash(TestCase, AssertPcsMixin): + ["--"] + self.cmd + ["-123"], + outdent( + """\ ++ Deprecation Warning: Specifying score as a standalone value is deprecated and might be removed in a future release, use score=value instead + Error: Resource 'R1' does not exist + """ + ), +diff --git a/pcsd/capabilities.xml.in b/pcsd/capabilities.xml.in +index 8eb0768a..fea55443 100644 +--- a/pcsd/capabilities.xml.in ++++ b/pcsd/capabilities.xml.in +@@ -1040,6 +1040,14 @@ + pcs commands: constraint colocation add + + ++ ++ ++ Score for a constraint is passed as 'score={value}', not as a standalone ++ argument. ++ ++ pcs commands: constraint colocation add ++ ++ + + + Create and delete a colocation constraint for sets of resources. +diff --git a/pcsd/pcs.rb b/pcsd/pcs.rb +index 0647df12..c8553d14 100644 +--- a/pcsd/pcs.rb ++++ b/pcsd/pcs.rb +@@ -195,7 +195,7 @@ def add_colocation_constraint( + score = "INFINITY" + end + command = [ +- "constraint", "colocation", "add", resourceA, "with", resourceB, score ++ "constraint", "colocation", "add", resourceA, "with", resourceB, "score=#{score}" + ] + flags = [] + flags << '--force' if force +-- +2.25.1 + diff --git a/pcs.spec b/pcs.spec index a004dd4..1388cdf 100644 --- a/pcs.spec +++ b/pcs.spec @@ -1,6 +1,6 @@ Name: pcs Version: 0.11.7 -Release: 12 +Release: 13 License: GPL-2.0-only AND Apache-2.0 AND MIT AND BSD-3-Clause AND (BSD-2-Clause OR Ruby) AND (BSD-2-Clause OR GPL-2.0-or-later) URL: https://github.com/ClusterLabs/pcs Group: System Environment/Base @@ -46,6 +46,7 @@ Patch6: add-dtos-and-converting-functions-for-resources-stat.patch Patch7: fixes-after-review.patch Patch8: store-clone-instance-id-in-resource-status-dtos.patch Patch9: increase-a-timeout-in-a-test.patch +Patch10: fix-score-syntax-in-colocation-constraints.patch # ui patches: >200 # Patch201: bzNUMBER-01-name.patch @@ -406,6 +407,9 @@ run_all_tests %license pyagentx_LICENSE.txt %changelog +* Mon May 13 2024 bixiaoyan - 0.11.7-13 +- fix score syntax in location constraints + * Sat May 11 2024 bixiaoyan - 0.11.7-12 - export rule constraints in a non-deprecated way -- Gitee