[Ovirt-devel] [PATCH node] Updated the configuration processing to remove the need for scripts.

Jim Meyering jim at meyering.net
Tue Oct 21 18:05:29 UTC 2008


"Darryl L. Pierce" <dpierce at redhat.com> wrote:
...

Hi Darryl,

Here's a nit about warn, and a fix for one more problem.
Sorry I didn't spot the latter sooner.

> diff --git a/scripts/ovirt-process-config b/scripts/ovirt-process-config
> new file mode 100755
> index 0000000..83a3eb3
> --- /dev/null
> +++ b/scripts/ovirt-process-config
> @@ -0,0 +1,59 @@
> +#!/bin/bash
> +
> +ME=$(basename "$0")
> +warn() { printf "$ME: $@\n" >&2; }

That definition of warn in obsolete and slightly buggy.
Please use this one instead:

  warn() { printf '%s: %s\n' "$ME" "$*" >&2; }

Yes, we *will* factor these out, if only to avoid
having to review them over and over again.

> +try_h() { printf "Try \`$ME -h' for more information.\n" >&2; exit 1;}
> +try_help() { printf "Usage: \`$ME [config] [module output] [config output]\n" >&2; exit 1;}
> +
> +case $# in
> +  0|1|2) warn "too few arguments"; try_help;;
> +  3) ;;
> +  *) warn "too many arguments"; try_help;;
> +esac
> +
> +CONFIG=$1
> +OVIRT_KERNEL_MODULE_FILE=$2
> +OVIRT_CONFIG_OUTPUT_FILE=$3
> +
> +modconf=$(awk '/bonding=/ {
> +        match($0, "^[ \t]*bonding=(.*)", data)

Please match the same regexp in those two cases.
Otherwise, a commented out (or something like foobonding=...) line
will cause this script to emit invalid output.

   modconf=$(awk '/^[ \t]*bonding=.+/ {
           match($0, "^[ \t]*bonding=(.+)", data)

Also, note that I changed the "*" to a "+", so that an
empty RHS will not match.

> +
> +        if (match("[^[:alnum:]=_ at -]", data[1]) >= 0) {
> +            printf "invalid bonding alias: \"%s\"\n", data[1];
> +            exit 1;
> +        }
> +
> +        alias=data[1]
> +
> +        printf("install %s bonding", alias)
> +    }' $CONFIG)
> +
> +echo "$modconf" > $OVIRT_KERNEL_MODULE_FILE
> +
> +networking=$(awk '/ifcfg=/ {
> +    match($0, "^[ \t]*ifcfg=(.*)", data)

Please do the same here.

> +    split(data[1], ifcfg, "|")
> +
> +    mac = ifcfg[1]
> +    iface = ifcfg[2]
> +    ifcfg_dir = "/files/etc/sysconfig/network-scripts"
> +
> +    printf("rm %s/ifcfg-%s\n", ifcfg_dir, iface)
> +    printf("set %s/ifcfg-%s/DEVICE %s\n", ifcfg_dir, iface, iface)
> +
> +    for (line in ifcfg) {
> +        if(line > 2) {
> +            match(ifcfg[line], "(^[^=]+)=(.*)", values)
> +            field=values[1]
> +            value=values[2]
> +
> +            printf("set %s/ifcfg-%s/%s %s\n", ifcfg_dir, iface, field, value)
> +        }
> +    }
> +
> +
> +    printf("save\n")
> +
> +}' $CONFIG)
> +
> +echo "$networking" > $OVIRT_CONFIG_OUTPUT_FILE




More information about the ovirt-devel mailing list