From 9bc2ebb9c0f71d6a4e55321e4bad8fc98b2161f0 Mon Sep 17 00:00:00 2001 From: mulhern Date: Tue, 2 May 2023 12:54:49 -0400 Subject: [PATCH] Adapt for r6 version of StopPool method Signed-off-by: mulhern --- src/stratis_cli/_actions/_introspect.py | 3 ++- src/stratis_cli/_actions/_pool.py | 21 ++++++++++-------- src/stratis_cli/_parser/_pool.py | 22 ++++++++++++++----- tests/whitebox/_misc.py | 4 +--- tests/whitebox/integration/pool/test_list.py | 6 ++--- tests/whitebox/integration/pool/test_start.py | 6 ++--- tests/whitebox/integration/pool/test_stop.py | 2 +- 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/stratis_cli/_actions/_introspect.py b/src/stratis_cli/_actions/_introspect.py index f3681959c..841ad7d56 100644 --- a/src/stratis_cli/_actions/_introspect.py +++ b/src/stratis_cli/_actions/_introspect.py @@ -53,7 +53,8 @@ - + + diff --git a/src/stratis_cli/_actions/_pool.py b/src/stratis_cli/_actions/_pool.py index 54f3c3302..e2b8aedaa 100644 --- a/src/stratis_cli/_actions/_pool.py +++ b/src/stratis_cli/_actions/_pool.py @@ -221,19 +221,22 @@ def stop_pool(namespace): :raises StratisCliEngineError: """ # pylint: disable=import-outside-toplevel - from ._data import Manager, ObjectManager, pools + from ._data import Manager proxy = get_object(TOP_OBJECT) - managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {}) - pool_name = namespace.pool_name - (pool_object_path, _) = next( - pools(props={"Name": pool_name}) - .require_unique_match(True) - .search(managed_objects) + + (pool_id, id_type) = ( + (namespace.uuid.hex, PoolIdType.UUID) + if getattr(namespace, "name") is None + else (namespace.name, PoolIdType.NAME) ) ((stopped, _), return_code, message) = Manager.Methods.StopPool( - proxy, {"pool": pool_object_path} + proxy, + { + "id": pool_id, + "id_type": str(id_type), + }, ) if return_code != StratisdErrors.OK: # pragma: no cover @@ -241,7 +244,7 @@ def stop_pool(namespace): if not stopped: # pragma: no cover raise StratisCliIncoherenceError( - f"Expected to stop pool with name {pool_name} but it was already stopped." + "Expected to stop pool but it was already stopped." ) @staticmethod diff --git a/src/stratis_cli/_parser/_pool.py b/src/stratis_cli/_parser/_pool.py index d52a39197..e1ec72710 100644 --- a/src/stratis_cli/_parser/_pool.py +++ b/src/stratis_cli/_parser/_pool.py @@ -140,13 +140,23 @@ def _ensure_nat(arg): "Stop a pool. Tear down the pool's storage stack " "but do not erase any metadata." ), - "args": [ + "mut_ex_args": [ ( - "pool_name", - { - "action": "store", - "help": "Name of the pool to stop", - }, + True, + [ + ( + "--uuid", + { + "action": "store", + "type": UUID, + "help": "UUID of the pool to stop", + }, + ), + ( + "--name", + {"action": "store", "help": "name of the pool to stop"}, + ), + ], ) ], "func": PoolActions.stop_pool, diff --git a/tests/whitebox/_misc.py b/tests/whitebox/_misc.py index 219fb4a88..21d4a73d8 100644 --- a/tests/whitebox/_misc.py +++ b/tests/whitebox/_misc.py @@ -337,10 +337,8 @@ def stop_pool(pool_name): proxy = get_object(TOP_OBJECT) - (pool_object_path, _) = get_pool(proxy, pool_name) - ((stopped, pool_uuid), return_code, message) = Manager.Methods.StopPool( - proxy, {"pool": pool_object_path} + proxy, {"id_type": "name", "id": pool_name} ) if not return_code == _OK: diff --git a/tests/whitebox/integration/pool/test_list.py b/tests/whitebox/integration/pool/test_list.py index 25d833728..67eb2e746 100644 --- a/tests/whitebox/integration/pool/test_list.py +++ b/tests/whitebox/integration/pool/test_list.py @@ -155,7 +155,7 @@ def test_list(self): """ Test listing all with a stopped pool. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) TEST_RUNNER(self._MENU) @@ -239,7 +239,7 @@ def test_list_stopped(self): """ Test listing all with a stopped pool. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) TEST_RUNNER(self._MENU + ["--stopped"]) @@ -247,7 +247,7 @@ def test_list_stopped_detail(self): """ Test detailed view on a stopped pool. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) TEST_RUNNER(self._MENU + ["--stopped", f"--name={self._POOLNAME}"]) diff --git a/tests/whitebox/integration/pool/test_start.py b/tests/whitebox/integration/pool/test_start.py index bb0cc0f42..23ba48c25 100644 --- a/tests/whitebox/integration/pool/test_start.py +++ b/tests/whitebox/integration/pool/test_start.py @@ -45,7 +45,7 @@ def test_bad_uuid(self): """ Test trying to start a pool with non-existent UUID. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) command_line = self._MENU + [f"--uuid={uuid4()}"] self.check_error(StratisCliEngineError, command_line, _ERROR) @@ -65,7 +65,7 @@ def test_bad_name(self): """ Test trying to start a pool with non-existent name. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) command_line = self._MENU + ["--name=bogus"] self.check_error(StratisCliEngineError, command_line, _ERROR) @@ -74,7 +74,7 @@ def test_good_name(self): """ Test trying to start a pool with a good name. """ - command_line = ["pool", "stop", self._POOLNAME] + command_line = ["pool", "stop", f"--name={self._POOLNAME}"] RUNNER(command_line) command_line = self._MENU + [f"--name={self._POOLNAME}"] RUNNER(command_line) diff --git a/tests/whitebox/integration/pool/test_stop.py b/tests/whitebox/integration/pool/test_stop.py index 87e649b8d..f6034f37f 100644 --- a/tests/whitebox/integration/pool/test_stop.py +++ b/tests/whitebox/integration/pool/test_stop.py @@ -42,6 +42,6 @@ def test_stop(self): Stopping with known name should always succeed. """ command_line = self._MENU + [ - self._POOLNAME, + f"--name={self._POOLNAME}", ] TEST_RUNNER(command_line)