-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1131 from vojtechtrefny/3.8-devel_devices-fix-adding
Do not add new PVs to the LVM devices file if it doesn't exist and VG…
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
from contextlib import contextmanager | ||
|
||
import unittest | ||
|
||
from blivet.formats.lvmpv import LVMPhysicalVolume | ||
|
||
|
||
class LVMPVNodevTestCase(unittest.TestCase): | ||
|
||
@contextmanager | ||
def patches(self): | ||
patchers = dict() | ||
mocks = dict() | ||
|
||
patchers["blockdev"] = patch("blivet.formats.lvmpv.blockdev") | ||
patchers["lvm"] = patch("blivet.formats.lvmpv.lvm") | ||
patchers["vgs_info"] = patch("blivet.formats.lvmpv.vgs_info") | ||
patchers["os"] = patch("blivet.formats.lvmpv.os") | ||
|
||
for name, patcher in patchers.items(): | ||
mocks[name] = patcher.start() | ||
|
||
yield mocks | ||
|
||
for patcher in patchers.values(): | ||
patcher.stop() | ||
|
||
def test_lvm_devices(self): | ||
fmt = LVMPhysicalVolume(device="/dev/test") | ||
|
||
with self.patches() as mock: | ||
# LVM devices file not enabled/supported -> devices_add should not be called | ||
mock["lvm"].HAVE_LVMDEVICES = False | ||
|
||
fmt._create() | ||
|
||
mock["blockdev"].lvm.devices_add.assert_not_called() | ||
|
||
with self.patches() as mock: | ||
# LVM devices file enabled and devices file exists -> devices_add should be called | ||
mock["lvm"].HAVE_LVMDEVICES = True | ||
mock["os"].path.exists.return_value = True | ||
|
||
fmt._create() | ||
|
||
mock["blockdev"].lvm.devices_add.assert_called_with("/dev/test") | ||
|
||
with self.patches() as mock: | ||
# LVM devices file enabled and devices file doesn't exist | ||
# and no existing VGs present -> devices_add should be called | ||
mock["lvm"].HAVE_LVMDEVICES = True | ||
mock["os"].path.exists.return_value = False | ||
mock["vgs_info"].cache = {} | ||
|
||
fmt._create() | ||
|
||
mock["blockdev"].lvm.devices_add.assert_called_with("/dev/test") | ||
|
||
with self.patches() as mock: | ||
# LVM devices file enabled and devices file doesn't exist | ||
# and existing VGs present -> devices_add should not be called | ||
mock["lvm"].HAVE_LVMDEVICES = True | ||
mock["os"].path.exists.return_value = False | ||
mock["vgs_info"].cache = {"fake_vg_uuid": "fake_vg_data"} | ||
|
||
fmt._create() | ||
|
||
mock["blockdev"].lvm.devices_add.assert_not_called() |