Please review pull request #55: (#14514) Use default config when hiera.yaml is missing opened by (kelseyhightower)
Description:
Hiera no longer raises an exception when the hiera configuration file
is missing; instead log a warning and use the following default config:
{
:backends => ["yaml"],
:hierarchy => "common",
:logger => "console"
}
This patch includes updated tests.
- Opened: Tue May 15 20:26:26 UTC 2012
- Based on: puppetlabs:1.0rc (b2ecc8d82d93c652b25d568d32cf74478a014adb)
- Requested merge: kelseyhightower:1.0rc (9808a64ea8691e1709b0b55ed47b203e7a29c2d3)
Diff follows:
diff --git a/lib/hiera/config.rb b/lib/hiera/config.rb
index fa1cbe8..a47dad7 100644
--- a/lib/hiera/config.rb
+++ b/lib/hiera/config.rb
@@ -10,10 +10,12 @@ def load(source)
:hierarchy => "common"}
if source.is_a?(String)
- raise "Config file #{source} not found" unless File.exist?(source)
-
- config = YAML.load_file(source)
- @config.merge! config if config
+ if File.exist?(source)
+ config = YAML.load_file(source)
+ @config.merge! config if config
+ else
+ Hiera.warn "Config file #{source} not found"
+ end
elsif source.is_a?(Hash)
@config.merge! source
end
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index fa31838..304fc2a 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -3,17 +3,25 @@
class Hiera
describe Config do
describe "#load" do
+ let(:default_config) do
+ {
+ :backends => ["yaml"],
+ :hierarchy => "common",
+ :logger => "console"
+ }
+ end
+
it "should treat string sources as a filename" do
- expect {
- Config.load("/nonexisting")
- }.to raise_error("Config file /nonexisting not found")
+ Hiera.expects(:warn).with("Config file /nonexisting not found")
+ Config.load("/nonexisting")
end
- it "should raise error for missing config files" do
+ it "should warn for missing config files" do
File.expects(:exist?).with("/nonexisting").returns(false)
YAML.expects(:load_file).with("/nonexisting").never
- expect { Config.load("/nonexisting") }.should raise_error RuntimeError, /not found/
+ Hiera.expects(:warn).with("Config file /nonexisting not found")
+ Config.load("/nonexisting")
end
it "should attempt to YAML load config files" do
@@ -27,7 +35,12 @@ class Hiera
File.expects(:exist?).with("/nonexisting").returns(true)
YAML.expects(:load_file).with("/nonexisting").returns(YAML.load(""))
- Config.load("/nonexisting").should == {:backends => ["yaml"], :hierarchy => "common", :logger => "console"}
+ Config.load("/nonexisting").should == default_config
+ end
+
+ it "should use defaults on missing YAML config file" do
+ Hiera.expects(:warn).with("Config file /nonexisting not found")
+ Config.load("/nonexisting").should == default_config
end
it "should use hash data as source if supplied" do
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
