[PATCH rhel7-branch] Fix --device=link and --device not specified (#1085310)

Vratislav Podzimek vpodzime at redhat.com
Tue May 26 15:04:34 UTC 2015


On Tue, 2015-05-26 at 12:58 +0200, Radek Vykydal wrote:
> Resolves: rhbz#1085310
> 
> I'll come also with some kickstart tests for this.
> 
> ---
>  dracut/parse-kickstart | 36 ++++++++++++++++++++++++++++++------
>  1 file changed, 30 insertions(+), 6 deletions(-)
> 
> diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
> index 7c60405..cf93d13 100755
> --- a/dracut/parse-kickstart
> +++ b/dracut/parse-kickstart
> @@ -66,6 +66,21 @@ def read_cmdline(f):
>              args[k] = v
>      return args
>  
> +def first_device_with_link():
> +    for dev_dir in sorted(glob.glob("/sys/class/net/*")):
> +        ##define ARPHRD_ETHER    1               /* Ethernet 10Mbps              */
> +        ##define ARPHRD_INFINIBAND 32            /* InfiniBand                   */
> +        with open(dev_dir+"/type") as f:
> +            if f.read().strip() not in ("1", "32"):
> +                continue
> +        with open(dev_dir+"/carrier") as f:
> +            if f.read().strip() == "1":
> +                return os.path.basename(dev_dir)
> +    return ""
> +
> +def setting_only_hostname(net, args):
> +    return net.hostname and (len(args) == 2 or (len(args) == 3 and "--hostname" in args))
> +
>  proc_cmdline = read_cmdline("/proc/cmdline")
>  
>  # Here are the kickstart commands we care about:
> @@ -140,14 +155,23 @@ class Network(commands.network.F21_Network):
>          # first 'network' line
>          if len(self.network) == 1:
>              # Setting only hostname in kickstart
> -            if not net.device and net.hostname and not self.handler.ksdevice:
> +            if not net.device and not self.handler.ksdevice \
> +               and setting_only_hostname(net, args):
>                  return None
>              net.activate = True
> -            if net.device == "link" or not net.device:
> -                # NOTE: this might still be empty (e.g. 'ks=file:...')
> -                # XXX FIXME: handle "link" properly?
> -                log.debug("Using ksdevice %s for missing --device in first kickstart network command", self.handler.ksdevice)
> -                net.device = self.handler.ksdevice
> +            if not net.device:
> +                if self.handler.ksdevice:
> +                    net.device = self.handler.ksdevice
> +                    log.info("Using ksdevice %s for missing --device in first kickstart network command", self.handler.ksdevice)
> +                else:
> +                    net.device = "link"
> +            if net.device == "link":
> +                net.device = first_device_with_link()
> +                if not net.device:
> +                    log.warn("No device with link found for --device=link")
> +                    return
> +                else:
> +                    log.info("Using %s as first device with link found", net.device)
>              # tell dracut to bring this device up
>              netline = ksnet_to_dracut(args, lineno, net, bootdev=True)
>          else:
Looks good to me and reminds me of my first task in the team -- document
how these things were set in RHEL 6's loader code. Nice days those
were. :)

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list