[PATCH 3/5] Don't corrupt the environment when setting up StorageTestCase.

Anne Mulhern amulhern at redhat.com
Fri Mar 21 12:20:59 UTC 2014





----- Original Message -----
> From: "David Lehman" <dlehman at redhat.com>
> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> Sent: Thursday, March 20, 2014 6:36:49 PM
> Subject: Re: [PATCH 3/5] Don't corrupt the environment when setting up	StorageTestCase.
> 
> On Thu, 2014-03-20 at 16:36 -0400, Anne Mulhern wrote:
> > 
> > 
> > 
> > ----- Original Message -----
> > > From: "David Lehman" <dlehman at redhat.com>
> > > To: anaconda-patches at lists.fedorahosted.org
> > > Sent: Thursday, March 20, 2014 1:06:38 PM
> > > Subject: [PATCH 3/5] Don't corrupt the environment when setting up
> > > 	StorageTestCase.
> > > 
> > > Also adds some necessary patching to PartitionDevice related to resize
> > > so that it does not require setting up a mocked parted.Geometry.
> > > ---
> > >  tests/storagetestcase.py | 72
> > >  +++++++++++++++++++-----------------------------
> > >  1 file changed, 29 insertions(+), 43 deletions(-)
> > > 
> > > diff --git a/tests/storagetestcase.py b/tests/storagetestcase.py
> > > index 6d8cdbd..4afc50a 100644
> > > --- a/tests/storagetestcase.py
> > > +++ b/tests/storagetestcase.py
> > > @@ -30,15 +30,7 @@ class StorageTestCase(unittest.TestCase):
> > >          system, along with a couple of convenience methods.
> > >  
> > >      """
> > > -    def __init__(self, *args, **kwargs):
> > > -        super(StorageTestCase, self).__init__(*args, **kwargs)
> > > -        blivet.util.execWithRedirect = Mock()
> > > -        blivet.util.execWithCapture = Mock()
> > > -
> > > -        self.setUpStorage()
> > > -
> > > -    def setUpStorage(self):
> > > -        self.setUpDeviceLibs()
> > > +    def setUp(self):
> > >          self.storage = blivet.Blivet()
> > >  
> > >          # device status
> > > @@ -52,36 +44,25 @@ class StorageTestCase(unittest.TestCase):
> > >          # prevent PartitionDevice from trying to dig around in the
> > >          partition's
> > >          # geometry
> > >          blivet.devices.PartitionDevice._setTargetSize =
> > >          StorageDevice._setTargetSize
> > > -
> > > -        # prevent Ext2FS from trying to run resize2fs to get a
> > > filesystem's
> > > -        # minimum size
> > > -        blivet.formats.fs.Ext2FS.minSize =
> > > blivet.formats.DeviceFormat.minSize
> > > -
> > > -    def setUpDeviceLibs(self):
> > > -        # devicelibs shouldn't be touching or looking at the host system
> > > -
> > > -        # lvm is easy because all calls to /sbin/lvm are via lvm()
> > > -        blivet.devicelibs.lvm.lvm = Mock()
> > > -
> > > -        # mdraid is easy because all calls to /sbin/mdadm are via
> > > mdadm()
> > > -        blivet.devicelibs.mdraid.mdadm = Mock()
> > > -
> > > -        # swap
> > > -        blivet.devicelibs.swap.swapstatus = Mock(return_value=False)
> > > -        blivet.devicelibs.swap.swapon = Mock()
> > > -        blivet.devicelibs.swap.swapoff = Mock()
> > > -
> > > -        # dm
> > > -        blivet.devicelibs.dm = Mock()
> > > -
> > > -        # crypto/luks
> > > -	blivet.devicelibs.crypto.luks_status = Mock(return_value=False)
> > > -	blivet.devicelibs.crypto.luks_uuid = Mock()
> > > -	blivet.devicelibs.crypto.luks_format = Mock()
> > > -	blivet.devicelibs.crypto.luks_open = Mock()
> > > -	blivet.devicelibs.crypto.luks_close = Mock()
> > > -	blivet.devicelibs.crypto.luks_add_key = Mock()
> > > -	blivet.devicelibs.crypto.luks_remove_key = Mock()
> > > +        blivet.devices.PartitionDevice.maxSize = StorageDevice.maxSize
> > > +
> > > +        def partition_probe(device):
> > > +            if isinstance(device._partedPartition, Mock):
> > > +                # don't clobber a Mock we already set up here
> > > +                part_mock = device._partedPartition
> > > +            else:
> > > +                part_mock = Mock()
> > > +
> > > +            attrs = {"getLength.return_value": int(device._size),
> > > +                     "getDeviceNodeName.return_value": device.name,
> > > +                     "type": parted.PARTITION_NORMAL}
> > > +            part_mock.configure_mock(**attrs)
> > > +            device._partedPartition = part_mock
> > > +            device._currentSize = device._size
> > > +            device._partType = parted.PARTITION_NORMAL
> > > +            device._bootable = False
> > > +
> > > +        PartitionDevice.probe = partition_probe
> > >  
> > >      def newDevice(*args, **kwargs):
> > >          """ Return a new Device instance suitable for testing. """
> > > @@ -94,8 +75,7 @@ class StorageTestCase(unittest.TestCase):
> > >          if exists:
> > >              # set up mock parted.Device w/ correct size
> > >              device._partedDevice = Mock()
> > > -            device._partedDevice.getSize =
> > > Mock(return_value=float(device.size))
> > > -            device._partedDevice.getLength =
> > > Mock(return_value=float(device.size))
> > > +            device._partedDevice.getLength =
> > > Mock(return_value=int(device.size.convertTo(spec="B")))
> > >              device._partedDevice.sectorSize = 512
> > >  
> > >          if isinstance(device, blivet.devices.PartitionDevice):
> > > @@ -112,8 +92,14 @@ class StorageTestCase(unittest.TestCase):
> > >              partedPartition.type = part_type
> > >              partedPartition.path = device.path
> > >              partedPartition.getDeviceNodeName =
> > >              Mock(return_value=device.name)
> > > -            partedPartition.getSize =
> > > Mock(return_value=float(device.size))
> > > -            partedPartition.getLength =
> > > Mock(return_value=float(device.size))
> > > +            if len(device.parents) == 1:
> > > +                disk_name = device.parents[0].name
> > > +                number = device.name.replace(disk_name, "")
> > > +                try:
> > > +                    partedPartition.number = int(number)
> > > +                except ValueError:
> > > +                    pass
> > > +
> > >              device._partedPartition = partedPartition
> > >  
> > >          device.exists = exists
> > > --
> > > 1.8.5.3
> > > 
> > > _______________________________________________
> > > anaconda-patches mailing list
> > > anaconda-patches at lists.fedorahosted.org
> > > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> > > 
> > 
> > It failed to apply, but if it runs, I'm OK with it.
> 
> Weird. I did write it on the branch I wrote the container patches on,
> but I had no trouble applying it to master using 'git am'. Anyway, it
> does work as advertised.
> 

I realized why this happened. Until recently, Zimbra allowed me to save patch emails as text so I could use git-am to apply patches.

But just recently, it stopped, and so now I have a different workflow that forces me to use patch, not git-am, which no doubt has a slightly different algorithm.

I should either fix this Zimbra problem or find a different mailer.

- mulhern

> > 
> > - mulhern
> > _______________________________________________
> > anaconda-patches mailing list
> > anaconda-patches at lists.fedorahosted.org
> > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list