Skip to content

Commit 19b2dde

Browse files
committed
Use mock to avoid pre-checks for device add methods
This will allow coverage in some unusual error paths. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 10ed9f0 commit 19b2dde

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/stratis_cli/_actions/_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def add_data_devices(namespace: Namespace): # pylint: disable=too-many-locals
550550
if return_code != StratisdErrors.OK: # pragma: no cover
551551
raise StratisCliEngineError(return_code, message)
552552

553-
if not added or len(devs_added) < len(blockdevs): # pragma: no cover
553+
if not added or len(devs_added) < len(blockdevs):
554554
devnodes_added = [
555555
MODev(info).Devnode()
556556
for (object_path, info) in devs(

tests/integration/pool/test_add.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
Test 'add'.
1616
"""
1717

18+
# isort: STDLIB
19+
from unittest.mock import patch
20+
1821
# isort: FIRSTPARTY
1922
from dbus_client_gen import DbusClientUniqueResultError
2023

2124
# isort: LOCAL
2225
from stratis_cli import StratisCliErrorCodes
2326
from stratis_cli._errors import (
2427
StratisCliEngineError,
28+
StratisCliIncoherenceError,
2529
StratisCliInUseOtherTierError,
2630
StratisCliInUseSameTierError,
2731
StratisCliPartialChangeError,
@@ -114,6 +118,26 @@ def test_add_data_again(self):
114118
command_line = self._MENU + [self._POOLNAME] + self._DEVICES
115119
self.check_error(StratisCliPartialChangeError, command_line, _ERROR)
116120

121+
def test_add_data_again_mock_check(self):
122+
"""
123+
Test that trying to add the same devices twice results in a
124+
StratisCliIncoherenceError exception.
125+
There are 0 target resources that would change.
126+
There is 1 target resource that would not change.
127+
"""
128+
command_line = self._MENU + [self._POOLNAME] + self._DEVICES
129+
# isort: LOCAL
130+
import stratis_cli # pylint: disable=import-outside-toplevel
131+
132+
with patch.object(
133+
# pylint: disable=protected-access
134+
stratis_cli._actions._pool, # pyright: ignore
135+
"_check_same_tier",
136+
autospec=True,
137+
return_value=None,
138+
):
139+
self.check_error(StratisCliIncoherenceError, command_line, _ERROR)
140+
117141
def test_add_data_cache(self):
118142
"""
119143
Test that adding 1 data device that is already in the cache tier raises

0 commit comments

Comments
 (0)