[PATCH configure] BZ 746702 - Check node config files are in correct format before executing puppet

John Eckersberg jeckersb at redhat.com
Tue Dec 20 21:52:27 UTC 2011


(This patch doesn't apply cleanly anymore due to the changes for
BZ731863 in commit 3d8c09b5)

This looks pretty good from a visual inspection.  The only potential
issue I see is this chunk:

> +while (line = file.gets)
> +  if (line != "\n" && line[0..0] != "#" && line[0..10] != "parameters:" && line[0..7] != "classes:" && line[0..1] != "--")
> +    # skip any non parameter or classes lines
> +    if (line[0..1] == "  " && line[2..2] != " " && line.index(":") != nil && line.split(":")[1][0..0] == " ")
> +      # matches correct parameter line
> +    elsif (line[0..1] == "- ")
> +      # matches correct classes line
> +    else
> +      errors << "incorrect format in line #{counter}: #{line}"
> +    end
> +  end
> +  counter = counter + 1
> +end
> +file.close

The node configuration is a YAML file, so you should be able to parse
the file using YAML::load_file.  If the file is not valid YAML, this
will throw an exception that you can catch and use the exception
mesesage to send back a sane error to the user.

This will also let you do some more sanity checking on the structure of
the file.  For example, assuming you have the result (bound to 'parsed')
from parsing the file, you could assert some things like:

parsed.instance_of? Hash
parsed.has_key? 'classes'
parsed.has_key? 'parameters'
parsed['classes'].instance_of? Array
parsed['parameters'].instance_of? Hash



More information about the aeolus-devel mailing list