[PATCH 2/4] Add a DiskFile class for testing partitioning code as a non-root user.

David Lehman dlehman at redhat.com
Wed Jul 23 21:04:26 UTC 2014


There seems to be some special treatment from parted (first free sector
is reported as 32) but the main purpose is to test partitioning code
without committing the changes to disk. It may be perfectly viable to
commit to these devices, but I haven't tried it yet. My intention is to
write unit tests for things like partition allocation -- which require
parted Device and Disk instances -- without requiring root access.
---
 blivet/devices.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/blivet/devices.py b/blivet/devices.py
index 1028817..dfdea44 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1234,6 +1234,35 @@ class DiskDevice(StorageDevice):
 
         StorageDevice._preDestroy(self)
 
+class DiskFile(DiskDevice):
+    """ This is a file that we will pretend is a disk. """
+    _devDir = ""
+
+    def __init__(self, name, fmt=None,
+                 size=None, major=None, minor=None, sysfsPath='',
+                 parents=None, serial=None, vendor="", model="", bus="",
+                 exists=True):
+        _name = os.path.basename(name)
+        self._devDir = os.path.dirname(name)
+
+        super(DiskFile, self).__init__(_name, fmt=fmt, size=size,
+                            major=major, minor=minor, sysfsPath=sysfsPath,
+                            parents=parents, serial=serial, vendor=vendor,
+                            model=model, bus=bus, exists=exists)
+
+    #
+    # Regular files do not have sysfs entries.
+    #
+    @property
+    def sysfsPath(self):
+        return ""
+
+    @sysfsPath.setter
+    def sysfsPath(self, value):
+        pass
+
+    def updateSysfsPath(self):
+        pass
 
 class PartitionDevice(StorageDevice):
     """ A disk partition.
-- 
1.9.3



More information about the anaconda-patches mailing list