Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add meta option usage for pcs resource clone #648

Merged
merged 5 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
line
- Specifying `--full` to show IDs of elements now shows IDs of nvpairs as well

### Deprecated
- Keyword `meta` in `pcs resource clone` and `pcs resource promotable` commands
(it wasn't doing anything anyway) ([rhbz#2168155], [ghpull#648])

[ghissue#612]: https://github.com/ClusterLabs/pcs/issues/612
[ghpull#648]: https://github.com/ClusterLabs/pcs/pull/648
[rhbz#1423473]: https://bugzilla.redhat.com/show_bug.cgi?id=1423473
[rhbz#1860626]: https://bugzilla.redhat.com/show_bug.cgi?id=1860626
[rhbz#2163953]: https://bugzilla.redhat.com/show_bug.cgi?id=2163953
[rhbz#2168155]: https://bugzilla.redhat.com/show_bug.cgi?id=2168155
[rhbz#2175881]: https://bugzilla.redhat.com/show_bug.cgi?id=2175881
[rhbz#2177996]: https://bugzilla.redhat.com/show_bug.cgi?id=2177996
[rhbz#2179388]: https://bugzilla.redhat.com/show_bug.cgi?id=2179388
Expand Down
7 changes: 7 additions & 0 deletions pcs/cli/resource/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
group_by_keywords,
prepare_options,
)
from pcs.cli.reports.output import deprecation_warning


def parse_create_simple(arg_list):
Expand Down Expand Up @@ -50,6 +51,12 @@ def parse_clone(arg_list, promotable=False):
raise CmdLineInputError(
"op settings must be changed on base resource, not the clone",
)

if "meta" in groups:
deprecation_warning(
"option 'meta' is deprecated and will be removed in a future release."
)

parts["meta"] = prepare_options(
groups.get("options", []) + groups.get("meta", []),
)
Expand Down
8 changes: 7 additions & 1 deletion pcs/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,14 @@ def resource_update(args: List[str], modifiers: InputModifiers) -> None:
clone_child = utils.dom_elem_get_clone_ms_resource(clone)
if clone_child:
child_id = clone_child.getAttribute("id")
# Drop 'meta' keyword as it is not allowed in 'pcs resource
# clone' command ultimately called from here
new_args = ra_values + meta_values
for op_args in op_values:
if op_args:
new_args += ["op"] + op_args
return resource_update_clone(
dom, clone, child_id, args, wait, wait_timeout
dom, clone, child_id, new_args, wait, wait_timeout
)
utils.err("Unable to find resource: %s" % res_id)

Expand Down
38 changes: 34 additions & 4 deletions pcs_test/tier0/cli/resource/test_parse_args.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
from unittest import TestCase
from unittest import (
TestCase,
mock,
)

from pcs.cli.common.errors import CmdLineInputError
from pcs.cli.resource import parse_args


class ParseCloneArgs(TestCase):
def assert_produce(self, arg_list, result, promotable=False):
def setUp(self):
print_patcher = mock.patch("pcs.cli.reports.output.print_to_stderr")
self.print_mock = print_patcher.start()
self.addCleanup(print_patcher.stop)
self.meta_deprecated = (
"Deprecation Warning: option 'meta' is deprecated and will be "
"removed in a future release."
)

def assert_stderr(self, stderr=None):
if stderr is None:
self.print_mock.assert_not_called()
else:
self.print_mock.assert_called_once_with(stderr)

def assert_produce(self, arg_list, result, promotable=False, stderr=None):
self.assertEqual(
parse_args.parse_clone(arg_list, promotable=promotable),
result,
)
self.assert_stderr(stderr)

def assert_raises_cmdline(self, args, expected_msg, promotable=False):
def assert_raises_cmdline(
self, args, expected_msg, promotable=False, stderr=None
):
with self.assertRaises(CmdLineInputError) as cm:
parse_args.parse_clone(args, promotable=promotable)
self.assertEqual(cm.exception.message, expected_msg)
self.assert_stderr(stderr)

def test_no_args(self):
self.assert_produce([], {"clone_id": None, "meta": {}})
Expand All @@ -35,6 +57,7 @@ def test_meta_options(self):
self.assert_produce(
["meta", "a=b", "c=d"],
{"clone_id": None, "meta": {"a": "b", "c": "d"}},
stderr=self.meta_deprecated,
)

def test_clone_id_and_clone_meta_options(self):
Expand All @@ -44,6 +67,7 @@ def test_clone_id_and_clone_meta_options(self):
"clone_id": "CustomCloneId",
"meta": {"a": "b", "c": "d", "e": "f", "g": "h"},
},
stderr=self.meta_deprecated,
)

def test_op_options(self):
Expand All @@ -64,13 +88,18 @@ def test_missing_option_value(self):
)

def test_missing_meta_option_value(self):
self.assert_raises_cmdline(["meta", "m"], "missing value of 'm' option")
self.assert_raises_cmdline(
["meta", "m"],
"missing value of 'm' option",
stderr=self.meta_deprecated,
)

def test_promotable_keyword_and_option(self):
self.assert_raises_cmdline(
["CloneId", "promotable=true", "meta", "promotable=true"],
"you cannot specify both promotable option and promotable keyword",
promotable=True,
stderr=self.meta_deprecated,
)

def test_different_values_of_option_and_meta_option(self):
Expand All @@ -81,6 +110,7 @@ def test_different_values_of_option_and_meta_option(self):
" 'false'"
),
promotable=True,
stderr=self.meta_deprecated,
)


Expand Down
4 changes: 4 additions & 0 deletions pcs_test/tier1/cib_resource/test_clone_unclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ def test_clone_with_options(self):
"c=d"
).split(),
fixture_resources_xml(FIXTURE_CLONE_WITH_OPTIONS),
stderr_full=(
"Deprecation Warning: option 'meta' is deprecated and will be "
"removed in a future release.\n"
),
)

def test_group_last_member(self):
Expand Down