Only "parameters" and "classes" should be top level nodes.
If spaces are missing from the actual parameters, the config file would still
be valid YAML and not flagged as an error.
---
bin/aeolus-node-check | 28 ++++++++++++++++++-
.../nodes/no-two-spaces-before-parameter-name | 4 +++
spec/node-check_spec.rb | 1 +
3 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 spec/fixtures/nodes/no-two-spaces-before-parameter-name
diff --git a/bin/aeolus-node-check b/bin/aeolus-node-check
index 139ecd7..3647bd5 100755
--- a/bin/aeolus-node-check
+++ b/bin/aeolus-node-check
@@ -17,25 +17,49 @@
require "yaml"
filename = ARGV[0]
+errors = []
if File.exist?(filename) == false
puts "File not found: #{filename}"
exit 1
else
+
+ # file should be parseable
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}"
+ errors << "Incorrect format found on or before line
#{line_number}"
else
+ errors << e
+ end
+ end
+
+ # file should only have parameters and classes as top nodes
+ if errors.size == 0
+ begin
+ root = YAML::load_file(filename)
+ root.each do |key, value|
+ if key != "parameters" && key != "classes"
+ errors << "Please check formatting in line containing #{key}
#{value}"
+ end
+ end
+ rescue => e
+ errors << e
+ end
+ end
+
+ if errors.size > 0
+ puts "Error found in #{filename}"
+ errors.each do |e|
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/spec/fixtures/nodes/no-two-spaces-before-parameter-name
b/spec/fixtures/nodes/no-two-spaces-before-parameter-name
new file mode 100644
index 0000000..1513ea5
--- /dev/null
+++ b/spec/fixtures/nodes/no-two-spaces-before-parameter-name
@@ -0,0 +1,4 @@
+parameters:
+ enable_https: true
+rhevm_nfs_server:
server.com
+classes:
\ No newline at end of file
diff --git a/spec/node-check_spec.rb b/spec/node-check_spec.rb
index e4a687c..eb61c5f 100644
--- a/spec/node-check_spec.rb
+++ b/spec/node-check_spec.rb
@@ -28,6 +28,7 @@ describe "aeolus-node-check" 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("no-two-spaces-before-parameter-name", 1)
run_and_check_status("one-space-before-parameter-name", 1)
run_and_check_status("three-spaces-before-parameter-name", 1)
end
--
1.7.6.5