[blivet] Validate device names

David Lehman dlehman at redhat.com
Tue May 20 14:26:44 UTC 2014



On 05/19/2014 04:38 PM, David Shea wrote:
> A couple things:
>
> On 05/19/2014 02:22 PM, David Shea wrote:
>> +class DeviceNameTestCase(unittest.TestCase):
>> +    """Test device name validation"""
>> +
>> +    def testStorageDevice(self):
>> +        from blivet.devices import StorageDevice
>
> 1) I obviously didn't run pylint on everything or I would have caught
> this redundant import, and
>
> 2) dlehman mentioned on IRC that it would be nice to have a real setter
> for blivet.devices.Device.name, as foretold by the TODO comment in
> devicefactory.py. Going that route means that on the anaconda side,
> changing to a crummy device name and hitting "Update Settings" will give
> you an error right there, which is nice, but just hitting Done without
> hitting update silently ignores your changes, which is not so great. So
> maybe that's worth another anaconda change.
>
> But for right now, does anyone have any opinions on how to override one
> of a getter/setter pair in a subclass? Right now I'm going with
> something like:
>
> class Device(object):
>      @property
>      def name(self):
>          return self._name
>
>      @name.setter
>      def name(self, value):
>          self._name = value
>
> class SubDevice(Device):
>      @Device.name.getter
>      def name(self):
>          do stuff


There are several places where we do something like this in the base class:

     size = property(lambda x: x._getSize(),
                     lambda x, y: x._setSize(y),
                     doc="The device's size")

Which allows you to simply override _getSize or _setSize in any subclass 
without any additional code to update the property. For all I know that 
might be deprecated now, though.

David

>
>
> which I think looks kinda gross myself, but which I also think is less
> annoying than overriding two methods when you really only need one. So
> if anyone has thoughts on that I'm all ears.
> _______________________________________________
> 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