diff options
author | Luke Kanies <luke@madstop.com> | 2009-03-05 17:13:17 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-03-05 17:13:17 -0600 |
commit | 71e4919f6b60b36b9ba0b02d3619c0fb5e4df445 (patch) | |
tree | e616c169ef7b1909d20ab92624fb5d8857c1adfb | |
parent | 09bee9137d7a6415609a8abfdf727ee0361139e0 (diff) | |
download | puppet-71e4919f6b60b36b9ba0b02d3619c0fb5e4df445.tar.gz puppet-71e4919f6b60b36b9ba0b02d3619c0fb5e4df445.tar.xz puppet-71e4919f6b60b36b9ba0b02d3619c0fb5e4df445.zip |
Moving default fileserving mount creation to the Configuration class
It was previously in the parser, but the parser is only created
if the fileserver.conf exists, so the default mounts weren't
made if the file didn't exist.
This is a bit less encapsulation, but not much.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/file_serving/configuration.rb | 9 | ||||
-rw-r--r-- | lib/puppet/file_serving/configuration/parser.rb | 8 | ||||
-rwxr-xr-x | spec/unit/file_serving/configuration.rb | 15 | ||||
-rwxr-xr-x | spec/unit/file_serving/configuration/parser.rb | 12 |
4 files changed, 24 insertions, 20 deletions
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb index 608924c8b..6092c24e2 100644 --- a/lib/puppet/file_serving/configuration.rb +++ b/lib/puppet/file_serving/configuration.rb @@ -94,6 +94,11 @@ class Puppet::FileServing::Configuration private + def mk_default_mounts + @mounts["modules"] ||= Mount::Modules.new("modules") + @mounts["plugins"] ||= Mount::Plugins.new("plugins") + end + # Read the configuration file. def readconfig(check = true) config = Puppet[:fileserverconfig] @@ -114,5 +119,9 @@ class Puppet::FileServing::Configuration puts detail.backtrace if Puppet[:trace] Puppet.err "Error parsing fileserver configuration: %s; using old configuration" % detail end + + ensure + # Make sure we've got our plugins and modules. + mk_default_mounts end end diff --git a/lib/puppet/file_serving/configuration/parser.rb b/lib/puppet/file_serving/configuration/parser.rb index c86e00a62..50368fdaf 100644 --- a/lib/puppet/file_serving/configuration/parser.rb +++ b/lib/puppet/file_serving/configuration/parser.rb @@ -46,8 +46,6 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile } } - mk_default_mounts - validate() return @mounts @@ -83,12 +81,6 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile } end - def mk_default_mounts - ["plugins", "modules"].each do |name| - newmount(name) unless @mounts[name] - end - end - # Create a new mount. def newmount(name) if @mounts.include?(name) diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb index e62423caf..6f5dc115f 100755 --- a/spec/unit/file_serving/configuration.rb +++ b/spec/unit/file_serving/configuration.rb @@ -94,6 +94,21 @@ describe Puppet::FileServing::Configuration do config.send(:readconfig, false) config.mounted?("one").should be_true end + + it "should add modules and plugins mounts even if the file does not exist" do + FileTest.expects(:exists?).returns false # the file doesn't exist + config = Puppet::FileServing::Configuration.create + config.mounted?("modules").should be_true + config.mounted?("plugins").should be_true + end + + it "should add modules and plugins mounts even if they are not returned by the parser" do + @parser.expects(:parse).returns("one" => mock("mount")) + FileTest.expects(:exists?).returns true # the file doesn't exist + config = Puppet::FileServing::Configuration.create + config.mounted?("modules").should be_true + config.mounted?("plugins").should be_true + end end describe "when finding the specified mount" do diff --git a/spec/unit/file_serving/configuration/parser.rb b/spec/unit/file_serving/configuration/parser.rb index 389e58389..6faf81b4c 100755 --- a/spec/unit/file_serving/configuration/parser.rb +++ b/spec/unit/file_serving/configuration/parser.rb @@ -32,10 +32,6 @@ describe Puppet::FileServing::Configuration::Parser do describe Puppet::FileServing::Configuration::Parser, " when parsing" do include FSConfigurationParserTesting - before do - @parser.stubs(:add_modules_mount) - end - it "should allow comments" do @filehandle.expects(:each).yields("# this is a comment\n") proc { @parser.parse }.should_not raise_error @@ -68,14 +64,6 @@ describe Puppet::FileServing::Configuration::Parser do result["two"].should equal(mount2) end - it "should add plugins and modules mounts if they do not exist" do - mock_file_content "[one]\npath /foo" - - result = @parser.parse - result["plugins"].should_not be_nil - result["modules"].should_not be_nil - end - it "should only allow mount names that are alphanumeric plus dashes" do mock_file_content "[a*b]\n" proc { @parser.parse }.should raise_error(ArgumentError) |