From bcca8dd9afebe7acbdce498a08ff3838b6e5175f Mon Sep 17 00:00:00 2001 From: Mikhail Konyakhin Date: Thu, 11 Aug 2016 18:15:59 +0300 Subject: [PATCH] fix validate_cmd for yaml, update tests and add validate file name. --- manifests/fact.pp | 4 ++-- manifests/facts.pp | 2 +- spec/classes/puppet_facts_spec.rb | 10 ++++++++++ spec/defines/fact_spec.rb | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/manifests/fact.pp b/manifests/fact.pp index 4e39e8a..ce5d3fd 100644 --- a/manifests/fact.pp +++ b/manifests/fact.pp @@ -10,7 +10,7 @@ include ::puppet::defaults $facterbasepath = $::puppet::defaults::facterbasepath - validate_string($title) + validate_re($title, '^[0-9A-Za-z_\-]+$', 'The $title fact does not match ^[0-9A-Za-z_\-]+$') $facter_data = { "${title}" => $value } file { "${facterbasepath}/facts.d/${title}.yaml": @@ -18,7 +18,7 @@ owner => 'root', group => 'puppet', mode => '0640', - validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file ''\"", + validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"", content => template('puppet/fact.yaml.erb'), } diff --git a/manifests/facts.pp b/manifests/facts.pp index e653545..97b8d33 100644 --- a/manifests/facts.pp +++ b/manifests/facts.pp @@ -21,7 +21,7 @@ owner => 'root', group => 'puppet', mode => '0640', - validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file ''\"", + validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"", content => template('puppet/local_facts.yaml.erb'), } diff --git a/spec/classes/puppet_facts_spec.rb b/spec/classes/puppet_facts_spec.rb index 137ce93..3b6b781 100644 --- a/spec/classes/puppet_facts_spec.rb +++ b/spec/classes/puppet_facts_spec.rb @@ -94,6 +94,8 @@ /facts for my.client.cert/ ).with_content( /FQDN my.fq.hostname/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" )#.with_content( # /Environment production/ #) @@ -106,6 +108,8 @@ /FQDN my.fq.hostname/ ).with_content( /Environment production/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end @@ -119,6 +123,8 @@ /key1: val1/ ).with_content( /key2: val2/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end#custom_facts set key values is string @@ -139,6 +145,8 @@ /- val21/ ).with_content( /- val22/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end#custom_facts set key values is array @@ -155,6 +163,8 @@ /key2:/ ).with_content( /key21: val21/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end#custom_facts set key values is hash diff --git a/spec/defines/fact_spec.rb b/spec/defines/fact_spec.rb index 455ac72..33a01ef 100644 --- a/spec/defines/fact_spec.rb +++ b/spec/defines/fact_spec.rb @@ -109,6 +109,8 @@ /---/ ).with_content( /my_fact: my_val/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end @@ -132,6 +134,8 @@ /- my_val0/ ).with_content( /- my_val1/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end @@ -155,6 +159,8 @@ /my_key0: my_val0/ ).with_content( /my_key1: my_val1/ + ).with_validate_cmd( + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" ) end end