diff --git a/docs/stratis.txt b/docs/stratis.txt index d291ecd16..712f1ef46 100644 --- a/docs/stratis.txt +++ b/docs/stratis.txt @@ -38,8 +38,9 @@ COMMANDS -------- pool create [--key-desc ] [--clevis <(nbde|tang|tpm2)> [--tang-url ] [<(--thumbprint | --trust-url)>] [--no-overprovision] [..]:: Create a pool from one or more block devices, with the given pool name. -pool stop :: - Stop a pool. Tear down the storage stack but leave all metadata intact. +pool stop <(--uuid |--name )>:: + Stop a pool, specifying the pool by its UUID or by its name. Tear down + the storage stack but leave all metadata intact. pool start <(--uuid |--name )> --unlock-method <(keyring | clevis)>:: Start a pool, speciying the pool by its UUID or by its name. Use the --unlock-method option to specify method of unlocking the pool if it is 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..9c1930596 100644 --- a/src/stratis_cli/_actions/_pool.py +++ b/src/stratis_cli/_actions/_pool.py @@ -221,28 +221,29 @@ 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 raise StratisCliEngineError(return_code, message) - if not stopped: # pragma: no cover - raise StratisCliIncoherenceError( - f"Expected to stop pool with name {pool_name} but it was already stopped." - ) + if not stopped: + raise StratisCliNoChangeError("stop", pool_id) @staticmethod def start_pool(namespace): 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..aba5d3417 100644 --- a/tests/whitebox/integration/pool/test_stop.py +++ b/tests/whitebox/integration/pool/test_stop.py @@ -17,6 +17,7 @@ # isort: LOCAL from stratis_cli import StratisCliErrorCodes +from stratis_cli._errors import StratisCliNoChangeError from .._misc import RUNNER, TEST_RUNNER, SimTestCase, device_name_list @@ -42,6 +43,16 @@ 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) + + def test_stop_stopped(self): + """ + Stopping a stoppped pool should raise exception. + """ + command_line = self._MENU + [ + f"--name={self._POOLNAME}", + ] + RUNNER(command_line) + self.check_error(StratisCliNoChangeError, command_line, _ERROR)