Skip to content

Commit

Permalink
Adapt for r6 version of StopPool method
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed May 2, 2023
1 parent 11cb5b8 commit 9bc2ebb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
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
21 changes: 12 additions & 9 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,30 @@ 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."
"Expected to stop pool but it was already stopped."
)

@staticmethod
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
2 changes: 1 addition & 1 deletion tests/whitebox/integration/pool/test_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9bc2ebb

Please sign in to comment.