[blivet][master/rhel7-branch] Add two functions to enable manual addition of ECKD DASDs. (#1070115)

Brian C. Lane bcl at redhat.com
Fri Aug 29 03:33:42 UTC 2014


On Thu, Aug 28, 2014 at 03:18:25PM -0400, Samantha N. Bueno wrote:
> This just adds a couple of functions which aid in manually adding DASDs.
> 
> sanitize_dasd_dev_input takes a device number as a string and verifies
> whether its format is an appropriate match against DASD device number
> formats.
> 
> online_dasd takes a device number as a string and will remove the device
> from the ignore list and attempt to bring it online.
> 
> Resolves: rhbz#1070115
> ---
>  blivet/devicelibs/dasd.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/blivet/devicelibs/dasd.py b/blivet/devicelibs/dasd.py
> index 5beb11d..4cbdaf3 100644
> --- a/blivet/devicelibs/dasd.py
> +++ b/blivet/devicelibs/dasd.py
> @@ -20,6 +20,7 @@
>  #
>  
>  import os
> +import string
>  from blivet.errors import DasdFormatError
>  from blivet.devices import deviceNameToDiskByPath
>  from blivet import util
> @@ -109,6 +110,49 @@ def dasd_needs_format(dasd):
>  
>      return False
>  
> +def sanitize_dasd_dev_input(dev):
> +    """ Given a user-supplied device number, make sure the input is sane, and
> +        raise an error if it is not.
> +    """

Can you describe the valid format in the docstring?

> +    if dev is None or dev == "":
> +        raise ValueError("You have not specified a device number or the number is invalid")
> +    dev = dev.lower()
> +    bus = dev[:string.rfind(dev, ".") + 1]
> +    dev = dev[string.rfind(dev, ".") + 1:]

I'd pull the rfind out into its own variable so you can check for -1
and raise an error (assuming no . is an error)


> +    dev = "0" * (4 - len(dev)) + dev
> +    if not len(bus):
> +        return "0.0." + dev
> +    else:
> +        return bus + dev
> +
> +def online_dasd(dev):
> +    """ Given a device number of format 0.0.abcd, switch the device to be
> +        online.
> +    """
> +    online = "/sys/bus/ccw/drivers/dasd-eckd/%s/online" % (dev)
> +
> +    if not os.path.exists(online):
> +        log.info("Freeing DASD device %s" % (dev,))
> +        util.run_program(["dasd_cio_free", "-d", dev])
> +
> +    if not os.path.exists(online):
> +        raise ValueError("DASD device %s not found, not even in device ignore list."
> +            % (dev))
> +
> +    try:
> +        f = open(online, "r")
> +        devonline = f.readline().strip()
> +        f.close()

If you use 'with open() as f:' you don't need the close. Same thing
below.

> +        if devonline == "1":
> +            raise ValueError("Device %s is already online." % (dev))
> +        else:
> +            f = open(online, "w")
> +            log.debug("echo %s > %s" % ("1", online))
> +            f.write("%s\n" % ("1"))
> +            f.close()
> +    except IOError as e:
> +        raise ValueError("Could not set DASD device %(dev)s online (%(e)s).") \
> +                        % {'devnum': dev, 'e': e}
>  
>  def write_dasd_conf(disks, root):
>      """ Write /etc/dasd.conf to target system for all DASD devices
> -- 
> 1.9.3

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list