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 | 41 ++++++++++++++++++++
contrib/aeolus-configure.spec | 1 +
spec/fixtures/nodes/good-node-file | 8 ++++
.../no-colon-between-parameter-name-and-value | 5 ++
.../nodes/no-space-between-dash-and-class-name | 2 +
.../no-space-between-parameter-name-and-value | 3 +
.../fixtures/nodes/one-space-before-parameter-name | 3 +
.../nodes/three-spaces-before-parameter-name | 3 +
spec/node-check_spec.rb | 38 ++++++++++++++++++
11 files changed, 114 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..b70fb97 100644
--- a/bin/aeolus-cleanup
+++ b/bin/aeolus-cleanup
@@ -60,6 +60,11 @@ export FACTER_AEOLUS_SAVE_DATA=$SAVE_DATA
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}_cleanup
+ 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}_cleanup" --node_terminus
exec \
@@ -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..1fa1f9f 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}_configure
+ 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..139ecd7
--- /dev/null
+++ b/bin/aeolus-node-check
@@ -0,0 +1,41 @@
+#!/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.
+
+require "yaml"
+
+filename = ARGV[0]
+
+if File.exist?(filename) == false
+ puts "File not found: #{filename}"
+ exit 1
+else
+ begin
+ YAML::parse_file(filename)
+ rescue => e
+ puts "Error found in #{filename}"
+ if e.to_s.index("line")
+ line_number = e.to_s.split("line")[1].split(",")[0].strip.to_i
+ 1
+ puts "Incorrect format found on or before line #{line_number}"
+ else
+ puts e
+ end
+ 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]"
+ exit 1
+ end
+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..fb1dc12
--- /dev/null
+++ b/spec/fixtures/nodes/no-colon-between-parameter-name-and-value
@@ -0,0 +1,5 @@
+---
+parameters:
+ enable_https: true
+ enable_security false
+ package_provider: rpm
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..d4f0888
--- /dev/null
+++ b/spec/fixtures/nodes/no-space-between-dash-and-class-name
@@ -0,0 +1,2 @@
+classes:
+-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..0d47524
--- /dev/null
+++ b/spec/fixtures/nodes/no-space-between-parameter-name-and-value
@@ -0,0 +1,3 @@
+parameters:
+ enable_https: true
+
rhevm_nfs_server:server.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..7edca1b
--- /dev/null
+++ b/spec/fixtures/nodes/one-space-before-parameter-name
@@ -0,0 +1,3 @@
+parameters:
+ enable_https: true
+ rhevm_nfs_server:
server.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..fcb458c
--- /dev/null
+++ b/spec/fixtures/nodes/three-spaces-before-parameter-name
@@ -0,0 +1,3 @@
+parameters:
+ enable_https: true
+ rhevm_nfs_server:
server.com
diff --git a/spec/node-check_spec.rb b/spec/node-check_spec.rb
new file mode 100644
index 0000000..e4a687c
--- /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 == "Error found in
./spec/fixtures/nodes/no-colon-between-parameter-name-and-value\nIncorrect format found on
or before line 5\nparameters must be in the form [space][space][parameter
name][colon][space][parameter value]\nclasses must be in the form [dash][space][class
name]\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