Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.7-devel' into 3.7-release
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Mar 16, 2023
2 parents 44c70c8 + ae17316 commit 99e485a
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 163 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit tests

on:
pull_request:
branches:
- 3.*-devel
- master
push:
branches:
- 3.*-devel
- master
schedule:
- cron: 0 0 * * 0

jobs:
build:

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get -qq update
sudo apt-get -y -qq install make ansible
sudo make install-requires
- name: Run tests
run: make unit-test
4 changes: 4 additions & 0 deletions blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def _post_process(self, devices=None):
# match the parted disks we just updated
for partition in (d for d in devices if isinstance(d, PartitionDevice)):
pdisk = partition.disk.format.parted_disk
if not pdisk:
log.warning("parted_disk not found for partition %s", partition.path)
partition.parted_partition = None
continue
partition.parted_partition = pdisk.getPartitionByPath(partition.path)

@with_flag("processing")
Expand Down
4 changes: 2 additions & 2 deletions blivet/devices/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ def _add(self, member):

def populate_ksdata(self, data):
super(BTRFSVolumeDevice, self).populate_ksdata(data)
data.data_level = self.data_level.name if self.data_level else None
data.metadata_level = self.metadata_level.name if self.metadata_level else None
data.dataLevel = self.data_level.name if self.data_level else None
data.metaDataLevel = self.metadata_level.name if self.metadata_level else None
data.devices = ["btrfs.%d" % p.id for p in self.parents]
data.preexist = self.exists

Expand Down
2 changes: 1 addition & 1 deletion blivet/devices/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ def populate_ksdata(self, data):

if self.req_grow:
# base size could be literal or percentage
data.max_size_mb = self.req_max_size.convert_to(MiB)
data.maxSizeMB = self.req_max_size.convert_to(MiB)
elif data.resize:
data.size = self.target_size.convert_to(MiB)

Expand Down
10 changes: 6 additions & 4 deletions blivet/devices/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,14 +1031,16 @@ def populate_ksdata(self, data):
data.size = self.req_base_size.round_to_nearest(MiB, rounding=ROUND_DOWN).convert_to(spec=MiB)
data.grow = self.req_grow
if self.req_grow:
data.max_size_mb = self.req_max_size.convert_to(MiB)
data.maxSizeMB = self.req_max_size.convert_to(MiB)

# data.disk = self.disk.name # by-id
if self.req_disks and len(self.req_disks) == 1:
data.disk = self.disk.name
data.prim_only = self.req_primary
data.primOnly = self.req_primary
else:
data.on_part = self.name # by-id
if self.format and self.format.uuid:
data.onPart = "UUID=" + self.format.uuid
else:
data.onPart = self.name

if data.resize:
# on s390x in particular, fractional sizes are reported, which
Expand Down
4 changes: 2 additions & 2 deletions blivet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_mount_device(mountpoint):
mountpoint = os.path.realpath(mountpoint) # eliminate symlinks
mount_device = None
with open("/proc/mounts") as mounts:
for mnt in mounts.readline():
for mnt in mounts.readlines():
try:
(device, path, _rest) = mnt.split(None, 2)
except ValueError:
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def detect_virt():
except (safe_dbus.DBusCallError, safe_dbus.DBusPropertyError):
return False
else:
return vm[0] in ('qemu', 'kvm', 'xen')
return vm[0] in ('qemu', 'kvm', 'xen', 'microsoft')


def natural_sort_key(device):
Expand Down
7 changes: 7 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Contents:
blivet/blivet
tests/tests

Technologies:

.. toctree::
:maxdepth: 1

lvmvdo

Indices and tables
==================

Expand Down
8 changes: 0 additions & 8 deletions tests/pylint/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,3 @@ int-import-graph=
# Force import order to recognize a module as part of the standard
# compatibility libraries.
known-standard-library=


[EXCEPTIONS]

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception
19 changes: 14 additions & 5 deletions tests/unit_tests/action_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# device classes for brevity's sake -- later on, that is
from blivet.devices import StorageDevice
from blivet.devices import DiskDevice
from blivet.devices import DMDevice
from blivet.devices import PartitionDevice
from blivet.devices import MDRaidArrayDevice
from blivet.devices import LVMVolumeGroupDevice
Expand All @@ -27,6 +28,8 @@
from blivet.formats.fs import FATFS
from blivet.formats.fs import XFS
from blivet.formats.lvmpv import LVMPhysicalVolume
from blivet.formats.mdraid import MDRaidMember
from blivet.formats.swap import SwapSpace

# action classes
from blivet.deviceaction import ActionCreateDevice
Expand All @@ -42,6 +45,7 @@

DEVICE_CLASSES = [
DiskDevice,
DMDevice,
PartitionDevice,
MDRaidArrayDevice,
LVMVolumeGroupDevice,
Expand All @@ -57,7 +61,9 @@
Ext4FS,
FATFS,
XFS,
LVMPhysicalVolume
LVMPhysicalVolume,
MDRaidMember,
SwapSpace
]


Expand All @@ -83,6 +89,10 @@ def fn_with_patch(*args, **kwargs):
patcher = patch.object(cls, "formattable", return_value=True)
patcher.start()

if cls._resizable:
patcher = patch.object(cls, "resizable", return_value=True)
patcher.start()

fn(*args, **kwargs)

patch.stopall()
Expand All @@ -94,7 +104,7 @@ class DeviceActionTestCase(BlivetTestCase):

""" DeviceActionTestSuite """

def setUp(self):
def setUp(self, *args): # pylint: disable=unused-argument
""" Create something like a preexisting autopart on two disks (sda,sdb).
The other two disks (sdc,sdd) are left for individual tests to use.
Expand Down Expand Up @@ -285,9 +295,6 @@ def test_action_creation(self):
lv_root = self.storage.devicetree.get_device_by_name("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
lv_root.format.exists = False
with self.assertRaises(ValueError):
ActionResizeFormat(lv_root, lv_root.size - Size("1000 MiB"))
lv_root.format.exists = True

# instantiation of device create action for existing device should
# fail
Expand Down Expand Up @@ -469,6 +476,7 @@ def test_action_obsoletes(self):
#
# - obsoletes all but ActionConfigureFormat actions w/ lower id on the
# same existing device with the same attribute being configured
sdc1.format._writelabel = Mock(available=True)
configure_format_1 = ActionConfigureFormat(sdc1, "label", "new_label")
configure_format_1.apply()
configure_format_2 = ActionConfigureFormat(sdc1, "label", "new_label2")
Expand Down Expand Up @@ -663,6 +671,7 @@ def test_action_dependencies(self):
self.assertNotEqual(lv_root, None)
lv_root.format._min_instance_size = Size("10 MiB")
lv_root.format._target_size = lv_root.format._min_instance_size
lv_root.format._size = lv_root.size
# lv_root.format._resizable = True
shrink_format = ActionResizeFormat(lv_root,
lv_root.size - Size("5 GiB"))
Expand Down
8 changes: 5 additions & 3 deletions tests/unit_tests/blivettestcase.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import unittest
try:
from unittest.mock import Mock
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock
from mock import Mock, patch

import parted

Expand All @@ -26,7 +26,9 @@ class BlivetTestCase(unittest.TestCase):
"""

def setUp(self):
@patch("blivet.formats.fs.Ext4FS.supported", return_value=True)
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
def setUp(self, *args): # pylint: disable=unused-argument,arguments-differ
self.storage = blivet.Blivet()

# device status
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/dbus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def mock_dbus_device(obj_id):
class DBusBlivetTestCase(TestCase):
@patch.object(DBusObject, "_init_dbus_object")
@patch("blivet.dbus.blivet.callbacks")
@patch("blivet.formats.fs.Ext4FS.supported", return_value=True)
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
def setUp(self, *args): # pylint: disable=unused-argument,arguments-differ
self.dbus_object = DBusBlivet(Mock(name="ObjectManager"))
self.dbus_object._blivet = Mock()
Expand Down
44 changes: 40 additions & 4 deletions tests/unit_tests/devicefactory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class DeviceFactoryTestCase(unittest.TestCase):

_disk_size = Size("2 GiB")

def setUp(self):
@patch("blivet.formats.fs.Ext4FS.supported", return_value=True)
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def setUp(self, *args): # pylint: disable=unused-argument,arguments-differ
if self.device_type is None:
raise unittest.SkipTest("abstract base class")

Expand Down Expand Up @@ -122,7 +125,10 @@ def _validate_factory_device(self, *args, **kwargs):

self.assertTrue(set(device.disks).issubset(kwargs["disks"]))

def test_device_factory(self):
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
@patch("blivet.devices.dm.DMDevice.type_external_dependencies", return_value=set())
def test_device_factory(self, *args): # pylint: disable=unused-argument
device_type = self.device_type
kwargs = {"disks": self.b.disks,
"size": Size("400 MiB"),
Expand Down Expand Up @@ -210,6 +216,8 @@ def _get_size_delta(self, devices=None):
return Size("1 MiB")

@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_get_free_disk_space(self, *args): # pylint: disable=unused-argument
# get_free_disk_space should return the total free space on disks
kwargs = self._get_test_factory_args()
Expand Down Expand Up @@ -238,6 +246,8 @@ def test_get_free_disk_space(self, *args): # pylint: disable=unused-argument
delta=self._get_size_delta(devices=[device]))

@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_normalize_size(self, *args): # pylint: disable=unused-argument
# _normalize_size should adjust target size to within the format limits
fstype = "ext2"
Expand Down Expand Up @@ -286,11 +296,16 @@ def test_normalize_size(self, *args): # pylint: disable=unused-argument
sum(d.size for d in self.b.disks),
delta=self._get_size_delta(devices=[device]))

def test_default_factory_type(self):
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_default_factory_type(self, *args): # pylint: disable=unused-argument
factory = devicefactory.get_device_factory(self.b)
self.assertIsInstance(factory, devicefactory.LVMFactory)

@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
@patch("blivet.formats.swap.SwapSpace.formattable", return_value=True)
def test_factory_defaults(self, *args): # pylint: disable=unused-argument
ctor_kwargs = self._get_test_factory_args()
factory = devicefactory.get_device_factory(self.b, self.device_type, **ctor_kwargs)
Expand Down Expand Up @@ -322,7 +337,9 @@ class PartitionFactoryTestCase(DeviceFactoryTestCase):
device_type = devicefactory.DEVICE_TYPE_PARTITION
factory_class = devicefactory.PartitionFactory

def test_bug1178884(self):
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_bug1178884(self, *args): # pylint: disable=unused-argument
# Test a change of format and size where old size is too large for the
# new format but not for the old one.
device_type = self.device_type
Expand Down Expand Up @@ -384,6 +401,12 @@ def _validate_factory_device(self, *args, **kwargs):
@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.devices.lvm.LVMVolumeGroupDevice.type_external_dependencies", return_value=set())
@patch("blivet.devices.lvm.LVMLogicalVolumeBase.type_external_dependencies", return_value=set())
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
@patch("blivet.formats.mdraid.MDRaidMember.formattable", return_value=True)
@patch("blivet.formats.mdraid.MDRaidMember.destroyable", return_value=True)
@patch("blivet.devices.md.MDRaidArrayDevice.type_external_dependencies", return_value=set())
@patch("blivet.devices.dm.DMDevice.type_external_dependencies", return_value=set())
def test_device_factory(self, *args): # pylint: disable=unused-argument,arguments-differ
super(LVMFactoryTestCase, self).test_device_factory()

Expand Down Expand Up @@ -563,6 +586,8 @@ def test_normalize_size(self, *args): # pylint: disable=unused-argument
@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.devices.lvm.LVMVolumeGroupDevice.type_external_dependencies", return_value=set())
@patch("blivet.devices.lvm.LVMLogicalVolumeBase.type_external_dependencies", return_value=set())
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_lv_unique_name(self, *args): # pylint: disable=unused-argument,arguments-differ
device_type = self.device_type
kwargs = {"disks": self.b.disks,
Expand Down Expand Up @@ -661,6 +686,8 @@ def _validate_factory_device(self, *args, **kwargs):
@patch("blivet.devices.lvm.LVMLogicalVolumeBase.type_external_dependencies", return_value=set())
@patch("blivet.devices.lvm.LVMVDOPoolMixin.type_external_dependencies", return_value=set())
@patch("blivet.devices.lvm.LVMVDOLogicalVolumeMixin.type_external_dependencies", return_value=set())
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_device_factory(self, *args): # pylint: disable=unused-argument,arguments-differ
device_type = self.device_type
kwargs = {"disks": self.b.disks,
Expand Down Expand Up @@ -760,12 +787,19 @@ def test_lv_unique_name(self, *args): # pylint: disable=unused-argument,argumen
super(LVMVDOFactoryTestCase, self).test_lv_unique_name()


@patch("blivet.formats.mdraid.MDRaidMember.formattable", return_value=True)
@patch("blivet.formats.mdraid.MDRaidMember.destroyable", return_value=True)
@patch("blivet.devices.md.MDRaidArrayDevice.type_external_dependencies", return_value=set())
class MDFactoryTestCase(DeviceFactoryTestCase):
device_type = devicefactory.DEVICE_TYPE_MD
device_class = MDRaidArrayDevice
factory_class = devicefactory.MDFactory

@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
@patch("blivet.formats.swap.SwapSpace.formattable", return_value=True)
@patch("blivet.devices.dm.DMDevice.type_external_dependencies", return_value=set())
def test_device_factory(self, *args): # pylint: disable=unused-argument,arguments-differ
# RAID0 across two disks
device_type = self.device_type
Expand Down Expand Up @@ -948,6 +982,8 @@ def _validate_factory_device(self, *args, **kwargs):
@patch("blivet.devices.stratis.StratisFilesystemDevice.type_external_dependencies", return_value=set())
@patch("blivet.devices.stratis.StratisPoolDevice.type_external_dependencies", return_value=set())
@patch("blivet.static_data.lvm_info.blockdev.lvm.lvs", return_value=[])
@patch("blivet.formats.fs.Ext4FS.formattable", return_value=True)
@patch("blivet.formats.fs.XFS.formattable", return_value=True)
def test_device_factory(self, *args): # pylint: disable=unused-argument,arguments-differ
device_type = self.device_type
kwargs = {"disks": self.b.disks,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/devices_test/device_dependencies_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def test_availability_mdraidplugin(self):
# dev is not among its unavailable dependencies
availability.BLOCKDEV_MDRAID_PLUGIN._method = availability.AvailableMethod
availability.MKFS_HFSPLUS_APP._method = availability.AvailableMethod # macefi
availability.BLOCKDEV_CRYPTO_PLUGIN._method = availability.AvailableMethod # luks
availability.KPARTX_APP._method = availability.AvailableMethod # luks
self.assertNotIn(availability.BLOCKDEV_MDRAID_PLUGIN, self.luks.unavailable_dependencies)
self.assertIsNotNone(ActionCreateDevice(self.luks))
self.assertIsNotNone(ActionDestroyDevice(self.luks))
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/devices_test/device_methods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def set_patches(self):
self.patchers["md"] = patch("blivet.devices.md.blockdev.md")
self.patchers["is_disk"] = patch.object(self.device_class, "is_disk",
new=PropertyMock(return_value=False))
self.patchers["controllable"] = patch.object(self.device_class, "controllable",
new=PropertyMock(return_value=True))
self.patchers["pvs_info"] = patch("blivet.devices.md.pvs_info")
self.patchers["lvm"] = patch("blivet.devices.md.blockdev.lvm")

Expand Down
Loading

0 comments on commit 99e485a

Please sign in to comment.