Skip to content

Commit

Permalink
Merge pull request #982 from mulkieran/stop-pool
Browse files Browse the repository at this point in the history
Adapt for r6 version of StopPool method
  • Loading branch information
mulkieran authored May 3, 2023
2 parents 11cb5b8 + 419191b commit af4478d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 31 deletions.
5 changes: 3 additions & 2 deletions docs/stratis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ COMMANDS
--------
pool create [--key-desc <key_desc>] [--clevis <(nbde|tang|tpm2)> [--tang-url <tang_url>] [<(--thumbprint <thp> | --trust-url)>] [--no-overprovision] <pool_name> <blockdev> [<blockdev>..]::
Create a pool from one or more block devices, with the given pool name.
pool stop <pool_name>::
Stop a pool. Tear down the storage stack but leave all metadata intact.
pool stop <(--uuid <uuid> |--name <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 <uuid> |--name <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
Expand Down
3 changes: 2 additions & 1 deletion src/stratis_cli/_actions/_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
<arg name="return_string" type="s" direction="out" />
</method>
<method name="StopPool">
<arg name="pool" type="o" direction="in" />
<arg name="id" type="s" direction="in" />
<arg name="id_type" type="s" direction="in" />
<arg name="result" type="(bs)" direction="out" />
<arg name="return_code" type="q" direction="out" />
<arg name="return_string" type="s" direction="out" />
Expand Down
25 changes: 13 additions & 12 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 16 additions & 6 deletions src/stratis_cli/_parser/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions tests/whitebox/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/whitebox/integration/pool/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -239,15 +239,15 @@ 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"])

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}"])

Expand Down
6 changes: 3 additions & 3 deletions tests/whitebox/integration/pool/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion tests/whitebox/integration/pool/test_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

0 comments on commit af4478d

Please sign in to comment.