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

Richard Su rwsu at redhat.com
Wed Dec 21 01:12:11 UTC 2011


https://bugzilla.redhat.com/show_bug.cgi?id=746702

aeolus-configure and aeolus-cleanup calls aeolus-node-check to verify node config
files are correctly formatted. If there is a formatting problem, the file name
and the line number causing the issue are displayed.
---
 bin/aeolus-cleanup                                 |    7 +++-
 bin/aeolus-configure                               |    4 ++
 bin/aeolus-node-check                              |   43 ++++++++++++++++++++
 contrib/aeolus-configure.spec                      |    1 +
 spec/fixtures/nodes/good-node-file                 |    8 ++++
 .../no-colon-between-parameter-name-and-value      |    1 +
 .../nodes/no-space-between-dash-and-class-name     |    1 +
 .../no-space-between-parameter-name-and-value      |    1 +
 .../fixtures/nodes/one-space-before-parameter-name |    1 +
 .../nodes/three-spaces-before-parameter-name       |    1 +
 spec/node-check_spec.rb                            |   38 +++++++++++++++++
 11 files changed, 105 insertions(+), 1 deletions(-)
 create mode 100755 bin/aeolus-node-check
 create mode 100644 spec/fixtures/nodes/good-node-file
 create mode 100644 spec/fixtures/nodes/no-colon-between-parameter-name-and-value
 create mode 100644 spec/fixtures/nodes/no-space-between-dash-and-class-name
 create mode 100644 spec/fixtures/nodes/no-space-between-parameter-name-and-value
 create mode 100644 spec/fixtures/nodes/one-space-before-parameter-name
 create mode 100644 spec/fixtures/nodes/three-spaces-before-parameter-name
 create mode 100644 spec/node-check_spec.rb

diff --git a/bin/aeolus-cleanup b/bin/aeolus-cleanup
index 7d15559..dc447f5 100644
--- a/bin/aeolus-cleanup
+++ b/bin/aeolus-cleanup
@@ -57,6 +57,11 @@ export FACTER_AEOLUS_ENABLE_HTTPS=true
 export FACTER_AEOLUS_ENABLE_SECURITY=false
 export FACTER_AEOLUS_SAVE_DATA=$SAVE_DATA
 
+/usr/share/aeolus-configure/modules/aeolus/aeolus-node-check /etc/aeolus-configure/nodes/$PUPPET_NODE
+if [ $? != 0 ]; then
+    exit 1
+fi
+
 NODE_ARRAY=(`echo $PUPPET_NODE | tr "," "\n"`)
 for x in "${NODE_ARRAY[@]}"
 do
@@ -70,4 +75,4 @@ do
     if [ $? != 0 -a $? != 2 ] ; then
 	exit 1
     fi
-done
\ No newline at end of file
+done
diff --git a/bin/aeolus-configure b/bin/aeolus-configure
index 503851d..151584a 100755
--- a/bin/aeolus-configure
+++ b/bin/aeolus-configure
@@ -72,6 +72,10 @@ export FACTER_RAILS_TOKEN=`</dev/urandom tr -dc a-f0-9 | head -c128`
 NODE_ARRAY=(`echo $PUPPET_NODE | tr "," "\n"`)
 for x in "${NODE_ARRAY[@]}"
 do
+    /usr/share/aeolus-configure/modules/aeolus/aeolus-node-check /etc/aeolus-configure/nodes/$x
+    if [ $? != 0 ]; then
+	exit 1
+    fi
     puppet /usr/share/aeolus-configure/modules/aeolus/aeolus.pp \
        --modulepath=/usr/share/aeolus-configure/modules/ \
        --external_nodes "/bin/sh /usr/share/aeolus-configure/modules/aeolus/aeolus-node ${x}_configure" --node_terminus exec \
diff --git a/bin/aeolus-node-check b/bin/aeolus-node-check
new file mode 100755
index 0000000..4fe9ad8
--- /dev/null
+++ b/bin/aeolus-node-check
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+
+#   Copyright 2011 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+filename = ARGV[0]
+file = File.open(filename, 'r') or raise "Could not open file\n"
+counter = 1
+errors = []
+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
+
+if (errors.size() > 0)
+  puts "Errors found in #{filename}"
+  puts "parameters must be in the form [space][space][parameter name][colon][space][parameter value]"
+  puts "classes must be in the form [dash][space][class name]"
+  errors.each { |e| puts e }
+  exit 1
+end
+exit 0
diff --git a/contrib/aeolus-configure.spec b/contrib/aeolus-configure.spec
index b063410..03fc5ba 100644
--- a/contrib/aeolus-configure.spec
+++ b/contrib/aeolus-configure.spec
@@ -47,6 +47,7 @@ Aeolus Configure Puppet Recipe
 %{__cp} -R %{pbuild}/recipes/openssl/ %{buildroot}/%{aeolushome}/modules/openssl
 %{__cp} -R %{pbuild}/recipes/postgres/ %{buildroot}/%{aeolushome}/modules/postgres
 %{__cp} -R %{pbuild}/bin/aeolus-node %{buildroot}/%{aeolushome}/modules/aeolus/
+%{__cp} -R %{pbuild}/bin/aeolus-node-check %{buildroot}/%{aeolushome}/modules/aeolus/
 %{__cp} -R %{pbuild}/bin/aeolus-check-services %{buildroot}/%{_bindir}/
 %{__cp} -R %{pbuild}/bin/aeolus-restart-services %{buildroot}/%{_sbindir}/
 %{__cp} -R %{pbuild}/bin/aeolus-configure %{buildroot}/%{_sbindir}/
diff --git a/spec/fixtures/nodes/good-node-file b/spec/fixtures/nodes/good-node-file
new file mode 100644
index 0000000..af4f2c1
--- /dev/null
+++ b/spec/fixtures/nodes/good-node-file
@@ -0,0 +1,8 @@
+#
+
+#
+---
+parameters:
+  enable_https: true
+classes:
+- aeolus::conductor
\ No newline at end of file
diff --git a/spec/fixtures/nodes/no-colon-between-parameter-name-and-value b/spec/fixtures/nodes/no-colon-between-parameter-name-and-value
new file mode 100644
index 0000000..76d3c1d
--- /dev/null
+++ b/spec/fixtures/nodes/no-colon-between-parameter-name-and-value
@@ -0,0 +1 @@
+  rhevm_nfs_server virtlab108.virt.bos.redhat.com
\ No newline at end of file
diff --git a/spec/fixtures/nodes/no-space-between-dash-and-class-name b/spec/fixtures/nodes/no-space-between-dash-and-class-name
new file mode 100644
index 0000000..2e07555
--- /dev/null
+++ b/spec/fixtures/nodes/no-space-between-dash-and-class-name
@@ -0,0 +1 @@
+-aeolus::conductor
\ No newline at end of file
diff --git a/spec/fixtures/nodes/no-space-between-parameter-name-and-value b/spec/fixtures/nodes/no-space-between-parameter-name-and-value
new file mode 100644
index 0000000..648195e
--- /dev/null
+++ b/spec/fixtures/nodes/no-space-between-parameter-name-and-value
@@ -0,0 +1 @@
+  rhevm_nfs_server:virtlab108.virt.bos.redhat.com
\ No newline at end of file
diff --git a/spec/fixtures/nodes/one-space-before-parameter-name b/spec/fixtures/nodes/one-space-before-parameter-name
new file mode 100644
index 0000000..8b990aa
--- /dev/null
+++ b/spec/fixtures/nodes/one-space-before-parameter-name
@@ -0,0 +1 @@
+ rhevm_nfs_server: virtlab108.virt.bos.redhat.com
\ No newline at end of file
diff --git a/spec/fixtures/nodes/three-spaces-before-parameter-name b/spec/fixtures/nodes/three-spaces-before-parameter-name
new file mode 100644
index 0000000..31c41ad
--- /dev/null
+++ b/spec/fixtures/nodes/three-spaces-before-parameter-name
@@ -0,0 +1 @@
+   rhevm_nfs_server: virtlab108.virt.bos.redhat.com
diff --git a/spec/node-check_spec.rb b/spec/node-check_spec.rb
new file mode 100644
index 0000000..d7d33cb
--- /dev/null
+++ b/spec/node-check_spec.rb
@@ -0,0 +1,38 @@
+#   Copyright 2011 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+def run_and_check_status (node, expected_exit_status)
+  `./bin/aeolus-node-check ./spec/fixtures/nodes/#{node}`
+  $?.exitstatus.should be(expected_exit_status), "#{node}"
+end
+
+
+describe "aeolus-node-check" do
+  it "error message display" do
+    output=`./bin/aeolus-node-check ./spec/fixtures/nodes/no-colon-between-parameter-name-and-value`
+    output.should == "Errors found in ./spec/fixtures/nodes/no-colon-between-parameter-name-and-value\nparameters must be in the form [space][space][parameter name][colon][space][parameter value]\nclasses must be in the form [dash][space][class name]\nincorrect format in line 1:   rhevm_nfs_server virtlab108.virt.bos.redhat.com\n"
+  end
+
+  it "should raise an error with these files" do
+    run_and_check_status("no-colon-between-parameter-name-and-value", 1)
+    run_and_check_status("no-space-between-dash-and-class-name", 1)
+    run_and_check_status("no-space-between-parameter-name-and-value", 1)
+    run_and_check_status("one-space-before-parameter-name", 1)
+    run_and_check_status("three-spaces-before-parameter-name", 1)
+  end
+
+  it "should run successful without error" do
+    run_and_check_status("good-node-file", 0)
+  end
+end
-- 
1.7.6.4




More information about the aeolus-devel mailing list