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

Anne Mulhern amulhern at redhat.com
Thu Jul 24 14:42:03 UTC 2014





----- Original Message -----
> From: "David Lehman" <dlehman at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, July 23, 2014 5:04:26 PM
> Subject: [PATCH 2/4] Add a DiskFile class for testing partitioning code as a	non-root user.
> 
> 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
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

It would be helpful to document that the class
is not intended to represent a real device. Maybe
it should find its home somewhere in testing subdirectory instead of blivet
subdirectory, as more appropriate to its intended use.

- mulhern


More information about the anaconda-patches mailing list