Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def add_data_devices(namespace: Namespace): # pylint: disable=too-many-locals
if return_code != StratisdErrors.OK: # pragma: no cover
raise StratisCliEngineError(return_code, message)

if not added or len(devs_added) < len(blockdevs): # pragma: no cover
if not added or len(devs_added) < len(blockdevs):
devnodes_added = [
MODev(info).Devnode()
for (object_path, info) in devs(
Expand Down Expand Up @@ -605,7 +605,7 @@ def add_cache_devices(namespace: Namespace): # pylint: disable=too-many-locals
if return_code != StratisdErrors.OK:
raise StratisCliEngineError(return_code, message)

if not added or len(devs_added) < len(blockdevs): # pragma: no cover
if not added or len(devs_added) < len(blockdevs):
devnodes_added = [
MODev(info).Devnode()
for (object_path, info) in devs(
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/pool/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
Test 'add'.
"""

# isort: STDLIB
from unittest.mock import patch

# isort: FIRSTPARTY
from dbus_client_gen import DbusClientUniqueResultError

# isort: LOCAL
from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import (
StratisCliEngineError,
StratisCliIncoherenceError,
StratisCliInUseOtherTierError,
StratisCliInUseSameTierError,
StratisCliPartialChangeError,
Expand Down Expand Up @@ -114,6 +118,26 @@ def test_add_data_again(self):
command_line = self._MENU + [self._POOLNAME] + self._DEVICES
self.check_error(StratisCliPartialChangeError, command_line, _ERROR)

def test_add_data_again_mock_check(self):
"""
Test that trying to add the same devices twice results in a
StratisCliIncoherenceError exception.
There are 0 target resources that would change.
There is 1 target resource that would not change.
"""
command_line = self._MENU + [self._POOLNAME] + self._DEVICES
# isort: LOCAL
import stratis_cli # pylint: disable=import-outside-toplevel

with patch.object(
# pylint: disable=protected-access
stratis_cli._actions._pool, # pyright: ignore
"_check_same_tier",
autospec=True,
return_value=None,
):
self.check_error(StratisCliIncoherenceError, command_line, _ERROR)

def test_add_data_cache(self):
"""
Test that adding 1 data device that is already in the cache tier raises
Expand Down Expand Up @@ -226,6 +250,29 @@ def test_add_cache_again(self):
RUNNER(command_line)
self.check_error(StratisCliPartialChangeError, command_line, _ERROR)

def test_add_cache_again_mock_check(self):
"""
Test that trying to add the same devices twice results in a
StratisCliIncoherence exception.
There are 0 target resources that would change.
There is 1 target resource that would not change.
"""
devices = _DEVICE_STRATEGY()
command_line = self._MENU + [self._POOLNAME] + devices
RUNNER(command_line)

# isort: LOCAL
import stratis_cli # pylint: disable=import-outside-toplevel

with patch.object(
# pylint: disable=protected-access
stratis_cli._actions._pool, # pyright: ignore
"_check_same_tier",
autospec=True,
return_value=None,
):
self.check_error(StratisCliIncoherenceError, command_line, _ERROR)

def test_add_cache_data(self):
"""
Test that adding 1 cache device that is already in the data tier raises
Expand Down
Loading