Skip to content

Commit eb8b77d

Browse files
authored
Merge pull request #1248 from mulkieran/add-devices-mock-checks
Use mock to avoid pre-checks for device add methods
2 parents 10ed9f0 + 4bd1e23 commit eb8b77d

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/stratis_cli/_actions/_pool.py

Lines changed: 2 additions & 2 deletions
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(
@@ -605,7 +605,7 @@ def add_cache_devices(namespace: Namespace): # pylint: disable=too-many-locals
605605
if return_code != StratisdErrors.OK:
606606
raise StratisCliEngineError(return_code, message)
607607

608-
if not added or len(devs_added) < len(blockdevs): # pragma: no cover
608+
if not added or len(devs_added) < len(blockdevs):
609609
devnodes_added = [
610610
MODev(info).Devnode()
611611
for (object_path, info) in devs(

tests/integration/pool/test_add.py

Lines changed: 47 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
@@ -226,6 +250,29 @@ def test_add_cache_again(self):
226250
RUNNER(command_line)
227251
self.check_error(StratisCliPartialChangeError, command_line, _ERROR)
228252

253+
def test_add_cache_again_mock_check(self):
254+
"""
255+
Test that trying to add the same devices twice results in a
256+
StratisCliIncoherence exception.
257+
There are 0 target resources that would change.
258+
There is 1 target resource that would not change.
259+
"""
260+
devices = _DEVICE_STRATEGY()
261+
command_line = self._MENU + [self._POOLNAME] + devices
262+
RUNNER(command_line)
263+
264+
# isort: LOCAL
265+
import stratis_cli # pylint: disable=import-outside-toplevel
266+
267+
with patch.object(
268+
# pylint: disable=protected-access
269+
stratis_cli._actions._pool, # pyright: ignore
270+
"_check_same_tier",
271+
autospec=True,
272+
return_value=None,
273+
):
274+
self.check_error(StratisCliIncoherenceError, command_line, _ERROR)
275+
229276
def test_add_cache_data(self):
230277
"""
231278
Test that adding 1 cache device that is already in the data tier raises

0 commit comments

Comments
 (0)