diff --git a/src/stratis_cli/_actions/_pool.py b/src/stratis_cli/_actions/_pool.py index e3e451c5e..c3527c378 100644 --- a/src/stratis_cli/_actions/_pool.py +++ b/src/stratis_cli/_actions/_pool.py @@ -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( @@ -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( diff --git a/tests/integration/pool/test_add.py b/tests/integration/pool/test_add.py index 30c256842..6540428b4 100644 --- a/tests/integration/pool/test_add.py +++ b/tests/integration/pool/test_add.py @@ -15,6 +15,9 @@ Test 'add'. """ +# isort: STDLIB +from unittest.mock import patch + # isort: FIRSTPARTY from dbus_client_gen import DbusClientUniqueResultError @@ -22,6 +25,7 @@ from stratis_cli import StratisCliErrorCodes from stratis_cli._errors import ( StratisCliEngineError, + StratisCliIncoherenceError, StratisCliInUseOtherTierError, StratisCliInUseSameTierError, StratisCliPartialChangeError, @@ -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 @@ -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