Skip to content
Draft
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
1 change: 0 additions & 1 deletion .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
- job: copr_build
trigger: pull_request
identifier: copr_pull
manual_trigger: true
targets:
- fedora-all

Expand Down
2 changes: 2 additions & 0 deletions docs/stratis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pool init-cache <pool_name> <blockdev> [<blockdev>..]::
drives, such as SSDs, are used for this purpose.
pool add-cache <pool_name> <blockdev> [<blockdev>..]::
Add one or more blockdevs to an existing pool with an initialized cache.
pool remove-cache <(--uuid <uuid> |--name <name>)>::
Remove a pool's cache.
pool extend-data <pool_name> [--device-uuid <uuid>]::
Increase the pool's data capacity with additional storage space offered by
its component data devices through, e.g., expansion of a component RAID
Expand Down
5 changes: 5 additions & 0 deletions src/stratis_cli/_actions/_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
<arg name="return_code" type="q" direction="out" />
<arg name="return_string" type="s" direction="out" />
</method>
<method name="RemoveCache">
<arg name="results" type="(bas)" direction="out" />
<arg name="return_code" type="q" direction="out" />
<arg name="return_string" type="s" direction="out" />
</method>
<method name="SetName">
<arg name="name" type="s" direction="in" />
<arg name="result" type="(bs)" direction="out" />
Expand Down
41 changes: 41 additions & 0 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,47 @@ def add_cache_devices(namespace: Namespace):
)
)

@staticmethod
def remove_cache(namespace: Namespace):
"""
Remove the cache from this pool.

:raises StratisCliEngineError:
:raises StratisCliIncoherenceError:
:raises StratisCliNoChangeError:
"""
from ._data import MOPool, ObjectManager, Pool, pools # noqa: PLC0415

pool_id = PoolId.from_parser_namespace(namespace)
assert pool_id is not None

proxy = get_object(TOP_OBJECT)
managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {})

(pool_object_path, pool_info) = next(
pools(props=pool_id.managed_objects_key())
.require_unique_match(True)
.search(managed_objects)
)

if not bool(MOPool(pool_info).HasCache()):
raise StratisCliNoChangeError("remove-cache", "cache")

((removed, devs_removed), return_code, message) = Pool.Methods.RemoveCache(
get_object(pool_object_path), {}
)

if return_code != StratisdErrors.OK: # pragma: no cover
raise StratisCliEngineError(return_code, message)

if not removed: # pragma: no cover
raise StratisCliIncoherenceError(
(
f"Expected to remove the cache from {pool_id} but "
"stratisd reports that it did not remove the cache."
)
)

@staticmethod
def extend_data(namespace: Namespace):
"""
Expand Down
16 changes: 16 additions & 0 deletions src/stratis_cli/_parser/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,22 @@ def verify(self, namespace: Namespace, parser: ArgumentParser):
"func": PoolActions.add_cache_devices,
},
),
(
"remove-cache",
{
"help": "Remove an active pool's cache",
"func": PoolActions.remove_cache,
"groups": [
(
"Pool Identifier",
{
"description": ("Choose one option to specify the pool"),
"mut_ex_args": [(True, UUID_OR_NAME)],
},
)
],
},
),
(
"extend-data",
{
Expand Down
81 changes: 81 additions & 0 deletions tests/integration/pool/test_remove_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2026 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Test 'remove-cache'.
"""

from uuid import uuid4

from dbus_client_gen import DbusClientUniqueResultError
from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import StratisCliNoChangeError

from .._misc import RUNNER, TEST_RUNNER, SimTestCase, device_name_list

_DEVICE_STRATEGY = device_name_list(1, 1)
_DEVICE_STRATEGY_2 = device_name_list(2, 2)
_ERROR = StratisCliErrorCodes.ERROR


class RemoveCacheTestCase1(SimTestCase):
"""
Test removing a cache where the cache is non-existent.
"""

_MENU = ["--propagate", "pool", "remove-cache"]
_POOLNAME = "deadpool"

def setUp(self):
super().setUp()
command_line = ["pool", "create", self._POOLNAME] + _DEVICE_STRATEGY()
RUNNER(command_line)

def test_remove(self):
"""
Verify that trying to remove a non-existent cache returns
StratisCliNoChangeError.
"""
command_line = self._MENU + [f"--name={self._POOLNAME}"]
self.check_error(StratisCliNoChangeError, command_line, _ERROR)

def test_non_existent_pool(self):
"""
Verify that trying to remove a cache from a non-existent pool raises
DbusClientUniqueResultError.
"""
command_line = self._MENU + [f"--uuid={uuid4()}"]
self.check_error(DbusClientUniqueResultError, command_line, _ERROR)


class RemoveCacheTestCase2(SimTestCase):
"""
Test removing a cache.
"""

_MENU = ["--propagate", "pool", "remove-cache"]
_POOLNAME = "deadpool"

def setUp(self):
super().setUp()
command_line = ["pool", "create", self._POOLNAME] + _DEVICE_STRATEGY()
RUNNER(command_line)
command_line = ["pool", "init-cache", self._POOLNAME] + _DEVICE_STRATEGY_2()
RUNNER(command_line)

def test_remove(self):
"""
Verify that remove an existing cache succeeds.
"""
command_line = self._MENU + [f"--name={self._POOLNAME}"]
TEST_RUNNER(command_line)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Loading