summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-19 17:35:40 -0500
committerLuke Kanies <luke@madstop.com>2007-10-19 17:35:40 -0500
commit08099b7a383987e292357f285e05933e10205660 (patch)
treec8f08a3afca5c9b45f965c7c8d051023170ea0d5
parentec396729d76b26d0d08c0bd633f28fa3c68c414c (diff)
downloadpuppet-08099b7a383987e292357f285e05933e10205660.tar.gz
puppet-08099b7a383987e292357f285e05933e10205660.tar.xz
puppet-08099b7a383987e292357f285e05933e10205660.zip
File serving now works. I've tested a couple of ways to
use it, and added integration tests at the most important hook points. This provides the final class structure for all of these classes, but a lot of the class names are pretty bad, so I'm planning on going through all of them (especially the file_server stuff) and renaming. The functionality is all here for finding files, though (finally). Once the classes are renamed, I'll be adding searching ability (which will enable the recursive file copies) and then adding the link management and enabling ignoring files.
-rw-r--r--lib/puppet/file_serving/configuration.rb43
-rw-r--r--lib/puppet/file_serving/configuration/parser.rb11
-rw-r--r--lib/puppet/file_serving/mount.rb28
-rw-r--r--lib/puppet/file_serving/terminus_selector.rb4
-rw-r--r--lib/puppet/indirector/file_content/local.rb10
-rw-r--r--lib/puppet/indirector/file_content/modules.rb11
-rw-r--r--lib/puppet/indirector/file_content/mounts.rb21
-rw-r--r--lib/puppet/indirector/file_content/rest.rb2
-rw-r--r--lib/puppet/indirector/file_metadata/local.rb6
-rw-r--r--lib/puppet/indirector/file_metadata/modules.rb17
-rw-r--r--lib/puppet/indirector/file_metadata/mounts.rb21
-rw-r--r--lib/puppet/indirector/file_metadata/rest.rb2
-rw-r--r--lib/puppet/indirector/file_server.rb34
-rw-r--r--lib/puppet/indirector/module_files.rb47
-rw-r--r--lib/puppet/indirector/rest.rb2
-rw-r--r--lib/puppet/util/uri_helper.rb (renamed from lib/puppet/file_serving/terminus_helper.rb)6
-rwxr-xr-xspec/integration/file_serving/configuration.rb40
-rwxr-xr-xspec/integration/indirector/module_files.rb26
-rw-r--r--spec/lib/shared_behaviours/file_server_mounts.rb16
-rwxr-xr-xspec/unit/file_serving/configuration.rb116
-rwxr-xr-xspec/unit/file_serving/mount.rb61
-rwxr-xr-xspec/unit/file_serving/terminus_selector.rb22
-rwxr-xr-xspec/unit/indirector/file_content/modules.rb18
-rwxr-xr-xspec/unit/indirector/file_content/mounts.rb39
-rwxr-xr-xspec/unit/indirector/file_metadata/modules.rb40
-rwxr-xr-xspec/unit/indirector/file_metadata/mounts.rb40
-rwxr-xr-xspec/unit/indirector/file_server.rb106
-rwxr-xr-xspec/unit/indirector/module_files.rb96
-rwxr-xr-xspec/unit/util/uri_helper.rb (renamed from spec/unit/file_serving/terminus_helper.rb)25
29 files changed, 574 insertions, 336 deletions
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb
index 6cd99b267..03be1b9dd 100644
--- a/lib/puppet/file_serving/configuration.rb
+++ b/lib/puppet/file_serving/configuration.rb
@@ -28,21 +28,14 @@ class Puppet::FileServing::Configuration
private_class_method :new
- # Return a content instance.
- def content(path, options = {})
- mount, file_path = split_path(path, options[:node])
-
- return nil unless mount
-
- mount.file_instance :content, file_path, options
- end
-
# Search for a file.
def file_path(key, options = {})
mount, file_path = split_path(key, options[:node])
return nil unless mount
+ # The mount checks to see if the file exists, and returns nil
+ # if not.
return mount.file(file_path, options)
end
@@ -55,15 +48,6 @@ class Puppet::FileServing::Configuration
readconfig(false)
end
- # Return a metadata instance.
- def metadata(path, options = {})
- mount, file_path = split_path(path, options[:node])
-
- return nil unless mount
-
- mount.file_instance :metadata, file_path, options
- end
-
# Is a given mount available?
def mounted?(name)
@mounts.include?(name)
@@ -85,27 +69,6 @@ class Puppet::FileServing::Configuration
return children
end
- # Return the mount for the Puppet modules; allows file copying from
- # the modules.
- def modules_mount(module_name, client)
- unless hostname = (client || Facter.value("hostname"))
- raise ArgumentError, "Could not find hostname"
- end
- if node = Puppet::Node.find(hostname)
- env = node.environment
- else
- env = nil
- end
-
- # And use the environment to look up the module.
- mod = Puppet::Module::find(module_name, env)
- if mod
- return @mounts[Mount::MODULES].copy(mod.name, mod.files)
- else
- return nil
- end
- end
-
# Read the configuration file.
def readconfig(check = true)
config = Puppet[:fileserverconfig]
@@ -139,7 +102,7 @@ class Puppet::FileServing::Configuration
# Strip off the mount name.
mount_name, path = uri.sub(%r{^/}, '').split(File::Separator, 2)
- return nil unless mount = modules_mount(mount_name, node) || @mounts[mount_name]
+ return nil unless mount = @mounts[mount_name]
if path == ""
path = nil
diff --git a/lib/puppet/file_serving/configuration/parser.rb b/lib/puppet/file_serving/configuration/parser.rb
index 5b17d9801..707c3f9b1 100644
--- a/lib/puppet/file_serving/configuration/parser.rb
+++ b/lib/puppet/file_serving/configuration/parser.rb
@@ -3,6 +3,7 @@ require 'puppet/util/loadedfile'
class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
Mount = Puppet::FileServing::Mount
+ MODULES = 'modules'
# Parse our configuration file.
def parse
@@ -52,10 +53,10 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
# Add the mount for getting files from modules.
def add_module_mount
- unless @mounts[Mount::MODULES]
- mount = Mount.new(Mount::MODULES)
+ unless @mounts[MODULES]
+ mount = Mount.new(MODULES)
mount.allow("*")
- @mounts[Mount::MODULES] = mount
+ @mounts[MODULES] = mount
end
end
@@ -98,8 +99,8 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
# Set the path for a mount.
def path(mount, value)
- if mount.name == Mount::MODULES
- Puppet.warning "The '#{Mount::MODULES}' module can not have a path. Ignoring attempt to set it"
+ if mount.name == MODULES
+ Puppet.warning "The '#{MODULES}' module can not have a path. Ignoring attempt to set it"
else
begin
mount.path = value
diff --git a/lib/puppet/file_serving/mount.rb b/lib/puppet/file_serving/mount.rb
index be67e6d2b..8e5bd03e8 100644
--- a/lib/puppet/file_serving/mount.rb
+++ b/lib/puppet/file_serving/mount.rb
@@ -13,10 +13,12 @@ require 'puppet/file_serving/content'
class Puppet::FileServing::Mount < Puppet::Network::AuthStore
include Puppet::Util::Logging
- # A constant that defines how we refer to our modules mount.
- MODULES = "modules"
+ @@localmap = nil
- InstanceTypes = {:metadata => Puppet::FileServing::Metadata, :content => Puppet::FileServing::Content}
+ # Clear the cache. This is only ever used for testing.
+ def self.clear_cache
+ @@localmap = nil
+ end
attr_reader :name
@@ -30,14 +32,12 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
end
# Return an instance of the appropriate class.
- def file_instance(return_type, short_file, options = {})
- raise(ArgumentError, "Invalid file type %s" % return_type) unless InstanceTypes.include?(return_type)
-
+ def file(short_file, options = {})
file = file_path(short_file, options[:node])
return nil unless FileTest.exists?(file)
- return InstanceTypes[return_type].new(file)
+ return file
end
# Return a fully qualified path, given a short path and
@@ -85,11 +85,8 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Mark that we're expandable.
@expandable = true
else
- unless FileTest.exists?(path)
- raise ArgumentError, "%s does not exist" % path
- end
unless FileTest.directory?(path)
- raise ArgumentError, "%s is not a directory" % path
+ raise ArgumentError, "%s does not exist or is not a directory" % path
end
unless FileTest.readable?(path)
raise ArgumentError, "%s is not readable" % path
@@ -111,11 +108,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Verify our configuration is valid. This should really check to
# make sure at least someone will be allowed, but, eh.
def valid?
- if name == MODULES
- return @path.nil?
- else
- return ! @path.nil?
- end
+ return ! @path.nil?
end
private
@@ -157,6 +150,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Else, use the local information
map = localmap()
end
+
path.gsub(/%(.)/) do |v|
key = $1
if key == "%"
@@ -179,7 +173,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Cache this manufactured map, since if it's used it's likely
# to get used a lot.
def localmap
- unless defined? @@localmap
+ unless @@localmap
@@localmap = {
"h" => Facter.value("hostname"),
"H" => [Facter.value("hostname"),
diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/terminus_selector.rb
index 4525a8570..08009cd2b 100644
--- a/lib/puppet/file_serving/terminus_selector.rb
+++ b/lib/puppet/file_serving/terminus_selector.rb
@@ -29,6 +29,10 @@ module Puppet::FileServing::TerminusSelector
terminus = :mounts
end
+ if uri.path =~ /^\/modules\b/ and terminus == :mounts
+ terminus = :modules
+ end
+
return terminus
end
end
diff --git a/lib/puppet/indirector/file_content/local.rb b/lib/puppet/indirector/file_content/local.rb
index a597fea55..e429c6c25 100644
--- a/lib/puppet/indirector/file_content/local.rb
+++ b/lib/puppet/indirector/file_content/local.rb
@@ -3,19 +3,21 @@
# Copyright (c) 2007. All rights reserved.
require 'puppet/file_serving/content'
-require 'puppet/file_serving/terminus_helper'
+require 'puppet/util/uri_helper'
require 'puppet/indirector/file_content'
require 'puppet/indirector/file'
class Puppet::Indirector::FileContent::Local < Puppet::Indirector::File
desc "Retrieve file contents from disk."
- include Puppet::FileServing::TerminusHelper
+ include Puppet::Util::URIHelper
- def find(key)
+ def find(key, options = {})
uri = key2uri(key)
return nil unless FileTest.exists?(uri.path)
- Puppet::FileServing::Content.new uri.path
+ data = model.new(uri.path)
+
+ return data
end
end
diff --git a/lib/puppet/indirector/file_content/modules.rb b/lib/puppet/indirector/file_content/modules.rb
new file mode 100644
index 000000000..8563dacb4
--- /dev/null
+++ b/lib/puppet/indirector/file_content/modules.rb
@@ -0,0 +1,11 @@
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require 'puppet/file_serving/content'
+require 'puppet/indirector/file_content'
+require 'puppet/indirector/module_files'
+
+class Puppet::Indirector::FileContent::Modules < Puppet::Indirector::ModuleFiles
+ desc "Retrieve file contents from modules."
+end
diff --git a/lib/puppet/indirector/file_content/mounts.rb b/lib/puppet/indirector/file_content/mounts.rb
index 3d147d65a..b11fc628c 100644
--- a/lib/puppet/indirector/file_content/mounts.rb
+++ b/lib/puppet/indirector/file_content/mounts.rb
@@ -3,26 +3,9 @@
# Copyright (c) 2007. All rights reserved.
require 'puppet/file_serving/content'
-require 'puppet/file_serving/terminus_helper'
require 'puppet/indirector/file_content'
-require 'puppet/indirector/code'
+require 'puppet/indirector/file_server'
-class Puppet::Indirector::FileContent::Mounts < Puppet::Indirector::Code
+class Puppet::Indirector::FileContent::Mounts < Puppet::Indirector::FileServer
desc "Retrieve file contents using Puppet's fileserver."
-
- include Puppet::FileServing::TerminusHelper
-
- # This way it can be cleared or whatever and we aren't retaining
- # a reference to the old one.
- def configuration
- Puppet::FileServing::Configuration.create
- end
-
- def find(key)
- uri = key2uri(key)
-
- return nil unless path = configuration.file_path(uri.path) and FileTest.exists?(path)
-
- Puppet::FileServing::Content.new path
- end
end
diff --git a/lib/puppet/indirector/file_content/rest.rb b/lib/puppet/indirector/file_content/rest.rb
index 9e2de360c..31df7626d 100644
--- a/lib/puppet/indirector/file_content/rest.rb
+++ b/lib/puppet/indirector/file_content/rest.rb
@@ -3,7 +3,7 @@
# Copyright (c) 2007. All rights reserved.
require 'puppet/file_serving/content'
-require 'puppet/file_serving/terminus_helper'
+require 'puppet/util/uri_helper'
require 'puppet/indirector/file_content'
require 'puppet/indirector/rest'
diff --git a/lib/puppet/indirector/file_metadata/local.rb b/lib/puppet/indirector/file_metadata/local.rb
index e1d774cc8..f40d4ce43 100644
--- a/lib/puppet/indirector/file_metadata/local.rb
+++ b/lib/puppet/indirector/file_metadata/local.rb
@@ -4,19 +4,19 @@
require 'puppet/file_serving/metadata'
require 'puppet/indirector/file_metadata'
-require 'puppet/file_serving/terminus_helper'
+require 'puppet/util/uri_helper'
require 'puppet/indirector/code'
class Puppet::Indirector::FileMetadata::Local < Puppet::Indirector::Code
desc "Retrieve file metadata directly from the local filesystem."
- include Puppet::FileServing::TerminusHelper
+ include Puppet::Util::URIHelper
def find(key)
uri = key2uri(key)
return nil unless FileTest.exists?(uri.path)
- data = Puppet::FileServing::Metadata.new uri.path
+ data = model.new(uri.path)
data.get_attributes
return data
diff --git a/lib/puppet/indirector/file_metadata/modules.rb b/lib/puppet/indirector/file_metadata/modules.rb
new file mode 100644
index 000000000..739c40fca
--- /dev/null
+++ b/lib/puppet/indirector/file_metadata/modules.rb
@@ -0,0 +1,17 @@
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require 'puppet/file_serving/metadata'
+require 'puppet/indirector/file_metadata'
+require 'puppet/indirector/module_files'
+
+class Puppet::Indirector::FileMetadata::Modules < Puppet::Indirector::ModuleFiles
+ desc "Retrieve file metadata from modules."
+
+ def find(*args)
+ return unless instance = super
+ instance.get_attributes
+ instance
+ end
+end
diff --git a/lib/puppet/indirector/file_metadata/mounts.rb b/lib/puppet/indirector/file_metadata/mounts.rb
index 6d7fe15c6..b1e3b32fd 100644
--- a/lib/puppet/indirector/file_metadata/mounts.rb
+++ b/lib/puppet/indirector/file_metadata/mounts.rb
@@ -3,26 +3,9 @@
# Copyright (c) 2007. All rights reserved.
require 'puppet/file_serving/metadata'
-require 'puppet/file_serving/terminus_helper'
require 'puppet/indirector/file_metadata'
-require 'puppet/indirector/code'
+require 'puppet/indirector/file_server'
-class Puppet::Indirector::FileMetadata::Mounts < Puppet::Indirector::Code
+class Puppet::Indirector::FileMetadata::Mounts < Puppet::Indirector::FileServer
desc "Retrieve file metadata using Puppet's fileserver."
-
- include Puppet::FileServing::TerminusHelper
-
- # This way it can be cleared or whatever and we aren't retaining
- # a reference to the old one.
- def configuration
- Puppet::FileServing::Configuration.create
- end
-
- def find(key)
- uri = key2uri(key)
-
- return nil unless path = configuration.file_path(uri.path) and FileTest.exists?(path)
-
- Puppet::FileServing::Metadata.new path
- end
end
diff --git a/lib/puppet/indirector/file_metadata/rest.rb b/lib/puppet/indirector/file_metadata/rest.rb
index dcf875b25..0f3d9c6fd 100644
--- a/lib/puppet/indirector/file_metadata/rest.rb
+++ b/lib/puppet/indirector/file_metadata/rest.rb
@@ -3,7 +3,7 @@
# Copyright (c) 2007. All rights reserved.
require 'puppet/file_serving/metadata'
-require 'puppet/file_serving/terminus_helper'
+require 'puppet/util/uri_helper'
require 'puppet/indirector/file_metadata'
require 'puppet/indirector/rest'
diff --git a/lib/puppet/indirector/file_server.rb b/lib/puppet/indirector/file_server.rb
new file mode 100644
index 000000000..1b2e047e8
--- /dev/null
+++ b/lib/puppet/indirector/file_server.rb
@@ -0,0 +1,34 @@
+#
+# Created by Luke Kanies on 2007-10-19.
+# Copyright (c) 2007. All rights reserved.
+
+require 'puppet/util/uri_helper'
+require 'puppet/file_serving/configuration'
+require 'puppet/indirector/terminus'
+
+# Look files up using the file server.
+class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
+ include Puppet::Util::URIHelper
+
+ # Find our key using the fileserver.
+ def find(key, options = {})
+ uri = key2uri(key)
+
+ # First try the modules mount, at least for now.
+ if instance = indirection.terminus(:modules).find(key, options)
+ Puppet.warning "DEPRECATION NOTICE: Found file in module without using the 'modules' mount; please fix"
+ return instance
+ end
+
+ return nil unless path = configuration.file_path(uri.path, :node => options[:node]) and FileTest.exists?(path)
+
+ return model.new(path)
+ end
+
+ private
+
+ # Our fileserver configuration, if needed.
+ def configuration
+ Puppet::FileServing::Configuration.create
+ end
+end
diff --git a/lib/puppet/indirector/module_files.rb b/lib/puppet/indirector/module_files.rb
new file mode 100644
index 000000000..e0374d7a4
--- /dev/null
+++ b/lib/puppet/indirector/module_files.rb
@@ -0,0 +1,47 @@
+#
+# Created by Luke Kanies on 2007-10-19.
+# Copyright (c) 2007. All rights reserved.
+
+require 'puppet/util/uri_helper'
+require 'puppet/indirector/terminus'
+
+# Look files up in Puppet modules.
+class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
+ include Puppet::Util::URIHelper
+
+ # Find our key in a module.
+ def find(key, options = {})
+ uri = key2uri(key)
+
+ # Strip off /modules if it's there -- that's how requests get routed to this terminus.
+ # Also, strip off the leading slash if present.
+ module_name, relative_path = uri.path.sub(/^\/modules\b/, '').sub(%r{^/}, '').split(File::Separator, 2)
+
+ # And use the environment to look up the module.
+ return nil unless mod = find_module(module_name, options[:node])
+
+ path = File.join(mod.files, relative_path)
+
+ return nil unless FileTest.exists?(path)
+
+ return model.new(path)
+ end
+
+ private
+
+ # Determine the environment to use, if any.
+ def environment(node_name)
+ if node_name and node = Puppet::Node.find(node_name)
+ node.environment
+ elsif env = Puppet.settings[:environment] and env != ""
+ env
+ else
+ nil
+ end
+ end
+
+ # Try to find our module.
+ def find_module(module_name, node_name)
+ Puppet::Module::find(module_name, environment(node_name))
+ end
+end
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index 8d51aff09..7b7c932c4 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -2,7 +2,7 @@ require 'puppet/indirector/rest'
# Access objects via REST
class Puppet::Indirector::REST < Puppet::Indirector::Terminus
- def find(name)
+ def find(name, options = {})
indirection.model.new(name)
end
end
diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/util/uri_helper.rb
index b7f560c57..cb9320387 100644
--- a/lib/puppet/file_serving/terminus_helper.rb
+++ b/lib/puppet/util/uri_helper.rb
@@ -3,10 +3,10 @@
# Copyright (c) 2007. All rights reserved.
require 'uri'
-require 'puppet/file_serving'
-require 'puppet/file_serving/configuration'
+require 'puppet/util'
-module Puppet::FileServing::TerminusHelper
+# Helper methods for dealing with URIs.
+module Puppet::Util::URIHelper
def key2uri(key)
# Return it directly if it's fully qualified.
if key =~ /^#{::File::SEPARATOR}/
diff --git a/spec/integration/file_serving/configuration.rb b/spec/integration/file_serving/configuration.rb
new file mode 100755
index 000000000..5af198999
--- /dev/null
+++ b/spec/integration/file_serving/configuration.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/file_serving/configuration'
+
+describe Puppet::FileServing::Configuration, " when finding files with Puppet::FileServing::Mount" do
+ before do
+ @config = Puppet::FileServing::Configuration.create
+
+ @mount = Puppet::FileServing::Mount.new("mymount")
+ FileTest.stubs(:exists?).with("/my/path").returns(true)
+ FileTest.stubs(:readable?).with("/my/path").returns(true)
+ FileTest.stubs(:directory?).with("/my/path").returns(true)
+ @mount.path = "/my/path"
+
+ FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
+ @parser = mock 'parser'
+ @parser.stubs(:parse).returns("mymount" => @mount)
+ @parser.stubs(:changed?).returns(true)
+ Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/path/my/file").returns(false)
+ @config.file_path("/mymount/my/file").should be_nil
+ end
+
+ it "should return the full file path if the file exists" do
+ FileTest.expects(:exists?).with("/my/path/my/file").returns(true)
+ @config.file_path("/mymount/my/file").should == "/my/path/my/file"
+ end
+
+ after do
+ Puppet::FileServing::Configuration.clear_cache
+ end
+end
diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb
new file mode 100755
index 000000000..67209fb39
--- /dev/null
+++ b/spec/integration/indirector/module_files.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-19.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/indirector/file_metadata/modules'
+require 'puppet/indirector/module_files'
+
+describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module" do
+ it "should look for files in the module's 'files' directory" do
+ # We just test a subclass, since it's close enough.
+ @terminus = Puppet::Indirector::FileMetadata::Modules.new
+ @module = Puppet::Module.new("mymod", "/some/path/mymod")
+ Puppet::Module.expects(:find).with("mymod", nil).returns(@module)
+
+ filepath = "/some/path/mymod/files/myfile"
+
+ FileTest.expects(:exists?).with(filepath).returns(true)
+
+ @terminus.model.expects(:new).with(filepath)
+
+ @terminus.find("puppetmounts://host/modules/mymod/myfile")
+ end
+end
diff --git a/spec/lib/shared_behaviours/file_server_mounts.rb b/spec/lib/shared_behaviours/file_server_mounts.rb
index 955f88b44..99a2f2953 100644
--- a/spec/lib/shared_behaviours/file_server_mounts.rb
+++ b/spec/lib/shared_behaviours/file_server_mounts.rb
@@ -23,14 +23,28 @@ describe "Puppet::Indirector::FileServerMounts", :shared => true do
Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
Puppet::FileServing::Configuration.create.stubs(:modules_mount)
+
+ # Stub out the modules terminus
+ @modules = mock 'modules terminus'
end
it "should use the file server configuration to find files" do
+ @modules.stubs(:find).returns(nil)
+ @terminus.indirection.stubs(:terminus).with(:modules).returns(@modules)
+
path = "/my/mount/path/my/file"
FileTest.stubs(:exists?).with(path).returns(true)
@test_class.expects(:new).with(path).returns(:myinstance)
FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
- @mount1.expects(:file).with("my/file", {}).returns(path)
+ @mount1.expects(:file).with("my/file", :node => nil).returns(path)
+
+ @terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance
+ end
+
+ it "should try to use the modules terminus to find files" do
+ path = "puppetmounts://myhost/one/my/file"
+ @modules.stubs(:find).with(path, {}).returns(:myinstance)
+ @terminus.indirection.stubs(:terminus).with(:modules).returns(@modules)
@terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance
end
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb
index b0b3527e7..d491447e9 100755
--- a/spec/unit/file_serving/configuration.rb
+++ b/spec/unit/file_serving/configuration.rb
@@ -29,6 +29,10 @@ describe Puppet::FileServing::Configuration do
Puppet::FileServing::Configuration.clear_cache
Puppet::FileServing::Configuration.create.should_not equal(old)
end
+
+ after do
+ Puppet::FileServing::Configuration.clear_cache
+ end
end
describe Puppet::FileServing::Configuration, " when initializing" do
@@ -93,30 +97,6 @@ describe Puppet::FileServing::Configuration, " when parsing the configuration fi
end
end
-describe Puppet::FileServing::Configuration, " when using a module mount" do
- include FSConfigurationTesting
-
- before do
- @parser = mock 'parser'
- @parser.stubs(:changed?).returns true
- FileTest.stubs(:exists?).with(@path).returns(true)
- Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
-
- @mount1 = stub 'mount', :name => "one"
- @mounts = {"one" => @mount1}
-
- Facter.stubs(:value).with("hostname").returns("whatever")
-
- @config = Puppet::FileServing::Configuration.create
- end
-
- it "should use a module mount if a module's name matches the mount name"
-
- it "should use any provided node name during module creation"
-
- it "should prefer module mounts to static mounts"
-end
-
describe Puppet::FileServing::Configuration, " when finding files" do
include FSConfigurationTesting
@@ -132,7 +112,6 @@ describe Puppet::FileServing::Configuration, " when finding files" do
Facter.stubs(:value).with("hostname").returns("whatever")
@config = Puppet::FileServing::Configuration.create
- @config.stubs(:modules_mount).returns(nil)
end
it "should fail if the uri does not match a leading slash followed by a valid mount name" do
@@ -142,6 +121,7 @@ describe Puppet::FileServing::Configuration, " when finding files" do
it "should use the first term after the first slash for the mount name" do
@parser.expects(:parse).returns(@mounts)
+ FileTest.stubs(:exists?).returns(true)
@mount1.expects(:file)
@config.file_path("/one")
end
@@ -149,18 +129,21 @@ describe Puppet::FileServing::Configuration, " when finding files" do
it "should use the remainder of the URI after the mount name as the file name" do
@parser.expects(:parse).returns(@mounts)
@mount1.expects(:file).with("something/else", {})
+ FileTest.stubs(:exists?).returns(true)
@config.file_path("/one/something/else")
end
it "should treat a bare name as a mount and no relative file" do
@parser.expects(:parse).returns(@mounts)
@mount1.expects(:file).with(nil, {})
+ FileTest.stubs(:exists?).returns(true)
@config.file_path("/one")
end
it "should treat a name with a trailing slash equivalently to a name with no trailing slash" do
@parser.expects(:parse).returns(@mounts)
@mount1.expects(:file).with(nil, {})
+ FileTest.stubs(:exists?).returns(true)
@config.file_path("/one/")
end
@@ -170,88 +153,27 @@ describe Puppet::FileServing::Configuration, " when finding files" do
@config.file_path("/one/something").should be_nil
end
- it "should return nil if the mount does not contain the file"
-
- it "should reparse the configuration file when it has changed" do
- @mount1.stubs(:file).returns("whatever")
- @parser.expects(:changed?).returns(true)
+ it "should return nil if the mount does not contain the file" do
@parser.expects(:parse).returns(@mounts)
- @config.file_path("/one/something")
-
- @parser.expects(:changed?).returns(true)
- @parser.expects(:parse).returns({})
- @config.file_path("/one/something").should be_nil
- end
-end
-
-describe Puppet::FileServing::Configuration, " when finding file metadata" do
- include FSConfigurationTesting
-
- before do
- @parser = mock 'parser'
- FileTest.stubs(:exists?).with(@path).returns(true)
- Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
-
- @mount1 = stub 'mount', :name => "one"
- @mounts = {"one" => @mount1}
-
- @config = Puppet::FileServing::Configuration.create
- @config.stubs(:modules_mount).returns(nil)
- end
-
- it "should return nil if the mount cannot be found" do
- @parser.expects(:changed?).returns(true)
- @parser.expects(:parse).returns({})
- @config.metadata("/one/something").should be_nil
+ @mount1.expects(:file).with("something/else", {}).returns(nil)
+ @config.file_path("/one/something/else").should be_nil
end
- it "should use the mount object to return a Metadata instance if the mount exists" do
- @parser.expects(:changed?).returns(true)
+ it "should return the fully qualified path if the mount exists" do
@parser.expects(:parse).returns(@mounts)
- @mount1.expects(:file_instance).with(:metadata, "something", {}).returns(:mydata)
- @config.metadata("/one/something").should == :mydata
+ @mount1.expects(:file).with("something/else", {}).returns("/full/path")
+ @config.file_path("/one/something/else").should == "/full/path"
end
- it "should pass any options on to the mount" do
+ it "should reparse the configuration file when it has changed" do
+ @mount1.stubs(:file).returns("whatever")
@parser.expects(:changed?).returns(true)
@parser.expects(:parse).returns(@mounts)
- @mount1.expects(:file_instance).with(:metadata, "something", :node => "me").returns(:mydata)
- @config.metadata("/one/something", :node => "me").should == :mydata
- end
-end
-
-describe Puppet::FileServing::Configuration, " when finding file content" do
- include FSConfigurationTesting
-
- before do
- @parser = mock 'parser'
- FileTest.stubs(:exists?).with(@path).returns(true)
- Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
-
- @mount1 = stub 'mount', :name => "one"
- @mounts = {"one" => @mount1}
-
- @config = Puppet::FileServing::Configuration.create
- @config.stubs(:modules_mount).returns(nil)
- end
+ FileTest.stubs(:exists?).returns(true)
+ @config.file_path("/one/something")
- it "should return nil if the mount cannot be found" do
@parser.expects(:changed?).returns(true)
@parser.expects(:parse).returns({})
- @config.content("/one/something").should be_nil
- end
-
- it "should use the mount object to return a Content instance if the mount exists" do
- @parser.expects(:changed?).returns(true)
- @parser.expects(:parse).returns(@mounts)
- @mount1.expects(:file_instance).with(:content, "something", {}).returns(:mydata)
- @config.content("/one/something").should == :mydata
- end
-
- it "should pass any options on to the mount" do
- @parser.expects(:changed?).returns(true)
- @parser.expects(:parse).returns(@mounts)
- @mount1.expects(:file_instance).with(:content, "something", :node => "me").returns(:mydata)
- @config.content("/one/something", :node => "me").should == :mydata
+ @config.file_path("/one/something").should be_nil
end
end
diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb
index b646e10ca..e9a7f6ddc 100755
--- a/spec/unit/file_serving/mount.rb
+++ b/spec/unit/file_serving/mount.rb
@@ -3,6 +3,21 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/mount'
+module FileServingMountTesting
+ def stub_facter(hostname)
+ Facter.stubs(:value).with("hostname").returns(hostname.sub(/\..+/, ''))
+ Facter.stubs(:value).with("domain").returns(hostname.sub(/^[^.]+\./, ''))
+ end
+end
+
+describe Puppet::FileServing::Mount do
+ it "should provide a method for clearing its cached host information" do
+ Puppet::FileServing::Mount.new("whatever").send(:localmap)
+ Puppet::FileServing::Mount.clear_cache
+ Puppet::FileServing::Mount.send(:class_variable_get, "@@localmap").should be_nil
+ end
+end
+
describe Puppet::FileServing::Mount, " when initializing" do
it "should fail on non-alphanumeric name" do
proc { Puppet::FileServing::Mount.new("non alpha") }.should raise_error(ArgumentError)
@@ -23,19 +38,12 @@ describe Puppet::FileServing::Mount, " when setting the path" do
@dir = "/this/path/does/not/exist"
end
- it "should fail if the path does not exist" do
- FileTest.expects(:exists?).returns(false)
- proc { @mount.path = @dir }.should raise_error(ArgumentError)
- end
-
it "should fail if the path is not a directory" do
- FileTest.expects(:exists?).returns(true)
FileTest.expects(:directory?).returns(false)
proc { @mount.path = @dir }.should raise_error(ArgumentError)
end
it "should fail if the path is not readable" do
- FileTest.expects(:exists?).returns(true)
FileTest.expects(:directory?).returns(true)
FileTest.expects(:readable?).returns(false)
proc { @mount.path = @dir }.should raise_error(ArgumentError)
@@ -43,8 +51,9 @@ describe Puppet::FileServing::Mount, " when setting the path" do
end
describe Puppet::FileServing::Mount, " when finding files" do
+ include FileServingMountTesting
+
before do
- FileTest.stubs(:exists?).returns(true)
FileTest.stubs(:directory?).returns(true)
FileTest.stubs(:readable?).returns(true)
@mount = Puppet::FileServing::Mount.new("test")
@@ -91,8 +100,7 @@ describe Puppet::FileServing::Mount, " when finding files" do
end
it "should use local host information if no client data is provided" do
- Facter.stubs(:value).with("hostname").returns("myhost")
- Facter.stubs(:value).with("domain").returns("mydomain.com")
+ stub_facter("myhost.mydomain.com")
@mount.path = "/%h/%d/%H"
@mount.path().should == "/myhost/mydomain.com/myhost.mydomain.com"
end
@@ -100,45 +108,40 @@ describe Puppet::FileServing::Mount, " when finding files" do
it "should ignore links by default"
it "should follow links when asked"
+
+ after do
+ Puppet::FileServing::Mount.clear_cache
+ end
end
-describe Puppet::FileServing::Mount, " when providing file instances" do
+describe Puppet::FileServing::Mount, " when providing file paths" do
+ include FileServingMountTesting
+
before do
FileTest.stubs(:exists?).returns(true)
FileTest.stubs(:directory?).returns(true)
FileTest.stubs(:readable?).returns(true)
@mount = Puppet::FileServing::Mount.new("test", "/mount/%h")
+ stub_facter("myhost.mydomain.com")
@host = "host.domain.com"
end
it "should return nil if the file is absent" do
- Puppet::FileServing::Metadata.expects(:new).never
FileTest.stubs(:exists?).returns(false)
- @mount.file_instance(:metadata, "/my/path").should be_nil
+ @mount.file("/my/path").should be_nil
end
- it "should fail if any type other than metadata or content is requested" do
- proc { @mount.file_instance(:else, "/my/path") }.should raise_error(ArgumentError)
+ it "should return the file path if the file is absent" do
+ FileTest.stubs(:exists?).with("/my/path").returns(true)
+ @mount.file("/my/path").should == "/mount/myhost/my/path"
end
it "should treat a nil file name as the path to the mount itself" do
- Puppet::FileServing::Metadata.expects(:new).with("/mount/myhost").returns(:myobj)
FileTest.stubs(:exists?).returns(true)
- @mount.file_instance(:metadata, nil).should == :myobj
- end
-
- it "should return a Metadata instance if the file is present and metadata was asked for" do
- Puppet::FileServing::Metadata.expects(:new).returns(:myobj)
- @mount.file_instance(:metadata, "/my/path").should == :myobj
- end
-
- it "should return a Content instance if the file is present and content was asked for" do
- Puppet::FileServing::Content.expects(:new).returns(:myobj)
- @mount.file_instance(:content, "/my/path").should == :myobj
+ @mount.file(nil).should == "/mount/myhost"
end
it "should use the client host name if provided in the options" do
- Puppet::FileServing::Content.expects(:new).with("/mount/host/my/path").returns(:myobj)
- @mount.file_instance(:content, "/my/path", :node => @host).should == :myobj
+ @mount.file("/my/path", :node => @host).should == "/mount/host/my/path"
end
end
diff --git a/spec/unit/file_serving/terminus_selector.rb b/spec/unit/file_serving/terminus_selector.rb
index d21e42839..341c60fea 100755
--- a/spec/unit/file_serving/terminus_selector.rb
+++ b/spec/unit/file_serving/terminus_selector.rb
@@ -30,13 +30,22 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term
@object.select_terminus("puppet://host/module/file").should == :rest
end
- it "should choose :mounts when the protocol is 'puppetmounts'" do
- @object.select_terminus("puppetmounts://host/module/file").should == :mounts
+ it "should choose :modules when the protocol is 'puppetmounts' and the mount name is 'modules'" do
+ @object.select_terminus("puppetmounts://host/modules/mymod/file").should == :modules
end
- it "should choose :mounts when no server name is provided and the process name is 'puppet'" do
+ it "should choose :modules when no server name is provided, the process name is 'puppet', and the mount name is 'modules'" do
Puppet.settings.expects(:value).with(:name).returns("puppet")
- @object.select_terminus("puppet:///module/file").should == :mounts
+ @object.select_terminus("puppet:///modules/mymod/file").should == :modules
+ end
+
+ it "should choose :mounts when the protocol is 'puppetmounts' and the mount name is not 'modules'" do
+ @object.select_terminus("puppetmounts://host/notmodules/file").should == :mounts
+ end
+
+ it "should choose :mounts when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do
+ Puppet.settings.expects(:value).with(:name).returns("puppet")
+ @object.select_terminus("puppet:///notmodules/file").should == :mounts
end
it "should choose :rest when no server name is provided and the process name is not 'puppet'" do
@@ -52,6 +61,11 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term
@object.select_terminus("/module/file").should == :local
end
+ # This is so that we only choose modules over mounts, not local
+ it "should choose :local when the protocol is 'file' and the fully qualified path starts with '/modules'" do
+ @object.select_terminus("file://host/modules/file").should == :local
+ end
+
it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do
proc { @object.select_terminus("http:///module/file") }.should raise_error(ArgumentError)
end
diff --git a/spec/unit/indirector/file_content/modules.rb b/spec/unit/indirector/file_content/modules.rb
new file mode 100755
index 000000000..00f02bb0b
--- /dev/null
+++ b/spec/unit/indirector/file_content/modules.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_content/modules'
+
+describe Puppet::Indirector::FileContent::Modules do
+ it "should be registered with the file_content indirection" do
+ Puppet::Indirector::Terminus.terminus_class(:file_content, :modules).should equal(Puppet::Indirector::FileContent::Modules)
+ end
+
+ it "should be a subclass of the ModuleFiles terminus" do
+ Puppet::Indirector::FileContent::Modules.superclass.should equal(Puppet::Indirector::ModuleFiles)
+ end
+end
diff --git a/spec/unit/indirector/file_content/mounts.rb b/spec/unit/indirector/file_content/mounts.rb
index 0a137d57e..00149dfd4 100755
--- a/spec/unit/indirector/file_content/mounts.rb
+++ b/spec/unit/indirector/file_content/mounts.rb
@@ -12,42 +12,7 @@ describe Puppet::Indirector::FileContent::Mounts do
Puppet::Indirector::Terminus.terminus_class(:file_content, :mounts).should equal(Puppet::Indirector::FileContent::Mounts)
end
- it "should be a subclass of the Code terminus" do
- Puppet::Indirector::FileContent::Mounts.superclass.should equal(Puppet::Indirector::Code)
- end
-end
-
-describe Puppet::Indirector::FileContent::Mounts, "when finding a single file" do
- before do
- @content = Puppet::Indirector::FileContent::Mounts.new
- @uri = "puppetmounts://host/my/local"
- end
-
- it "should use the path portion of the URI as the file name" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local")
- @content.find(@uri)
- end
-
- it "should use the FileServing configuration to convert the file name to a fully qualified path" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local")
- @content.find(@uri)
- end
-
- it "should return nil if no fully qualified path is found" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns(nil)
- @content.find(@uri).should be_nil
- end
-
- it "should return nil if the configuration returns a file path that does not exist" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(false)
- @content.find(@uri).should be_nil
- end
-
- it "should return a Content instance if a file is found and it exists" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(true)
- Puppet::FileServing::Content.expects(:new).with("/some/file").returns(:mycontent)
- @content.find(@uri).should == :mycontent
+ it "should be a subclass of the FileServer terminus" do
+ Puppet::Indirector::FileContent::Mounts.superclass.should equal(Puppet::Indirector::FileServer)
end
end
diff --git a/spec/unit/indirector/file_metadata/modules.rb b/spec/unit/indirector/file_metadata/modules.rb
new file mode 100755
index 000000000..94e1bf0dc
--- /dev/null
+++ b/spec/unit/indirector/file_metadata/modules.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_metadata/modules'
+
+describe Puppet::Indirector::FileMetadata::Modules do
+ it "should be registered with the file_metadata indirection" do
+ Puppet::Indirector::Terminus.terminus_class(:file_metadata, :modules).should equal(Puppet::Indirector::FileMetadata::Modules)
+ end
+
+ it "should be a subclass of the ModuleFiles terminus" do
+ Puppet::Indirector::FileMetadata::Modules.superclass.should equal(Puppet::Indirector::ModuleFiles)
+ end
+end
+
+describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do
+ before do
+ @finder = Puppet::Indirector::FileMetadata::Modules.new
+ @finder.stubs(:environment).returns(nil)
+ @module = Puppet::Module.new("mymod", "/path/to")
+ @finder.stubs(:find_module).returns(@module)
+ end
+
+ it "should return nil if the file is not found" do
+ FileTest.expects(:exists?).with("/path/to/files/my/file").returns false
+ @finder.find("puppetmounts://hostname/modules/mymod/my/file").should be_nil
+ end
+
+ it "should retrieve the instance's attributes if the file is found" do
+ FileTest.expects(:exists?).with("/path/to/files/my/file").returns true
+ instance = mock 'metadta'
+ Puppet::FileServing::Metadata.expects(:new).returns instance
+ instance.expects :get_attributes
+ @finder.find("puppetmounts://hostname/modules/mymod/my/file")
+ end
+end
diff --git a/spec/unit/indirector/file_metadata/mounts.rb b/spec/unit/indirector/file_metadata/mounts.rb
index 558e920ee..33f977163 100755
--- a/spec/unit/indirector/file_metadata/mounts.rb
+++ b/spec/unit/indirector/file_metadata/mounts.rb
@@ -12,43 +12,7 @@ describe Puppet::Indirector::FileMetadata::Mounts do
Puppet::Indirector::Terminus.terminus_class(:file_metadata, :mounts).should equal(Puppet::Indirector::FileMetadata::Mounts)
end
- it "should be a subclass of the Code terminus" do
- Puppet::Indirector::FileMetadata::Mounts.superclass.should equal(Puppet::Indirector::Code)
+ it "should be a subclass of the FileServer terminus" do
+ Puppet::Indirector::FileMetadata::Mounts.superclass.should equal(Puppet::Indirector::FileServer)
end
end
-
-describe Puppet::Indirector::FileMetadata::Mounts, "when finding a single file" do
- before do
- @metadata = Puppet::Indirector::FileMetadata::Mounts.new
- @uri = "puppetmounts://host/my/local"
- end
-
- it "should use the path portion of the URI as the file name" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local")
- @metadata.find(@uri)
- end
-
- it "should use the FileServing configuration to convert the file name to a fully qualified path" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local")
- @metadata.find(@uri)
- end
-
- it "should return nil if no fully qualified path is found" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns(nil)
- @metadata.find(@uri).should be_nil
- end
-
- it "should return nil if the configuration returns a file path that does not exist" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(false)
- @metadata.find(@uri).should be_nil
- end
-
- it "should return a Metadata instance if a file is found and it exists" do
- Puppet::FileServing::Configuration.create.expects(:file_path).with("/my/local").returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(true)
- Puppet::FileServing::Metadata.expects(:new).with("/some/file").returns(:mymetadata)
- @metadata.find(@uri).should == :mymetadata
- end
-end
-
diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb
new file mode 100755
index 000000000..5a53610e4
--- /dev/null
+++ b/spec/unit/indirector/file_server.rb
@@ -0,0 +1,106 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-19.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/indirector/file_server'
+require 'puppet/file_serving/configuration'
+
+module FileServerTerminusTesting
+ def setup
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @model = mock 'model'
+ @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
+ Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
+
+ @file_server_class = Class.new(Puppet::Indirector::FileServer) do
+ def self.to_s
+ "Testing::Mytype"
+ end
+ end
+
+ @file_server = @file_server_class.new
+
+ @uri = "puppetmounts://host/my/local/file"
+ @configuration = mock 'configuration'
+ Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
+
+ @module_server = mock 'module_server'
+ @indirection.stubs(:terminus).with(:modules).returns(@module_server)
+ end
+end
+
+describe Puppet::Indirector::FileServer, " when finding files" do
+ include FileServerTerminusTesting
+
+ it "should see if the modules terminus has the file" do
+ @module_server.expects(:find).with(@uri, {})
+ @configuration.stubs(:file_path)
+ @file_server.find(@uri)
+ end
+
+ it "should pass the client name to the modules terminus if one is provided" do
+ @module_server.expects(:find).with(@uri, :node => "mynode")
+ @configuration.stubs(:file_path)
+ @file_server.find(@uri, :node => "mynode")
+ end
+
+ it "should return any results from the modules terminus" do
+ @module_server.expects(:find).with(@uri, {}).returns(:myinstance)
+ @file_server.find(@uri).should == :myinstance
+ end
+
+ it "should produce a deprecation notice if it finds a file in the module terminus" do
+ @module_server.expects(:find).with(@uri, {}).returns(:myinstance)
+ Puppet.expects(:warning)
+ @file_server.find(@uri)
+ end
+
+ it "should use the path portion of the URI as the file name" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @module_server.stubs(:find).returns(nil)
+ @file_server.find(@uri)
+ end
+
+ it "should use the FileServing configuration to convert the file name to a fully qualified path" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @module_server.stubs(:find).returns(nil)
+ @file_server.find(@uri)
+ end
+
+ it "should pass the node name to the FileServing configuration if one is provided" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => "testing")
+ @module_server.stubs(:find)
+ @file_server.find(@uri, :node => "testing")
+ end
+
+ it "should return nil if no fully qualified path is found" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
+ @module_server.stubs(:find).returns(nil)
+ @file_server.find(@uri).should be_nil
+ end
+
+ it "should return nil if the configuration returns a file path that does not exist" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
+ FileTest.expects(:exists?).with("/some/file").returns(false)
+ @module_server.stubs(:find).returns(nil)
+ @file_server.find(@uri).should be_nil
+ end
+
+ it "should return an instance of the model created with the full path if a file is found and it exists" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
+ FileTest.expects(:exists?).with("/some/file").returns(true)
+ @module_server.stubs(:find).returns(nil)
+ @model.expects(:new).with("/some/file").returns(:myinstance)
+ @file_server.find(@uri).should == :myinstance
+ end
+end
+
+
+describe Puppet::Indirector::FileServer, " when returning file paths" do
+ it "should follow links if the links option is set to :follow"
+
+ it "should ignore links if the links option is not set to follow"
+end
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb
new file mode 100755
index 000000000..2e1373748
--- /dev/null
+++ b/spec/unit/indirector/module_files.rb
@@ -0,0 +1,96 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-19.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/indirector/module_files'
+
+module ModuleFilesTerminusTesting
+ def setup
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @model = mock 'model'
+ @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
+ Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
+
+ @module_files_class = Class.new(Puppet::Indirector::ModuleFiles) do
+ def self.to_s
+ "Testing::Mytype"
+ end
+ end
+
+ @module_files = @module_files_class.new
+
+ @uri = "puppetmounts://host/modules/my/local/file"
+ @module = Puppet::Module.new("mymod", "/module/path")
+ end
+end
+
+describe Puppet::Indirector::ModuleFiles, " when finding files" do
+ include ModuleFilesTerminusTesting
+
+ it "should strip off the leading '/modules' mount name" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.find(@uri)
+ end
+
+ it "should not strip off leading terms that start with '/modules' but are longer words" do
+ Puppet::Module.expects(:find).with('modulestart', nil).returns nil
+ @module_files.find("puppetmounts://host/modulestart/my/local/file")
+ end
+
+ it "should search for a module whose name is the first term in the remaining file path" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.find(@uri)
+ end
+
+ it "should search for a file relative to the module's files directory" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file")
+ @module_files.find(@uri)
+ end
+
+ it "should return nil if the module does not exist" do
+ Puppet::Module.expects(:find).with('my', nil).returns nil
+ @module_files.find(@uri).should be_nil
+ end
+
+ it "should return nil if the module exists but the file does not" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
+ @module_files.find(@uri).should be_nil
+ end
+
+ it "should return an instance of the model created with the full path if a module is found and the file exists" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @model.expects(:new).with("/module/path/files/local/file").returns(:myinstance)
+ @module_files.find(@uri).should == :myinstance
+ end
+
+ it "should use the node's environment to look up the module if the node name is provided" do
+ node = stub "node", :environment => "testing"
+ Puppet::Node.expects(:find).with("mynode").returns(node)
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.find(@uri, :node => "mynode")
+ end
+
+ it "should use the local environment setting to look up the module if the node name is not provided and the environment is not set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("testing")
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.find(@uri)
+ end
+
+ it "should not us an environment when looking up the module if the node name is not provided and the environment is set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("")
+ Puppet::Module.expects(:find).with('my', nil)
+ @module_files.find(@uri)
+ end
+end
+
+describe Puppet::Indirector::ModuleFiles, " when returning file paths" do
+ it "should follow links if the links option is set to :follow"
+
+ it "should ignore links if the links option is not set to follow"
+end
diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/util/uri_helper.rb
index f136da553..f454a2ced 100755
--- a/spec/unit/file_serving/terminus_helper.rb
+++ b/spec/unit/util/uri_helper.rb
@@ -5,19 +5,18 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require 'puppet/file_serving/terminus_helper'
+require 'puppet/util/uri_helper'
-module TerminusHelperTesting
- def setup
+describe Puppet::Util::URIHelper, " when converting a key to a URI" do
+ before do
@helper = Object.new
- @config = mock 'fs configuration'
- Puppet::FileServing::Configuration.stubs(:create).returns(@config)
- @helper.extend(Puppet::FileServing::TerminusHelper)
+ @helper.extend(Puppet::Util::URIHelper)
end
-end
-describe Puppet::FileServing::TerminusHelper, " when converting a key to a URI" do
- include TerminusHelperTesting
+ it "should return the URI instance" do
+ URI.expects(:parse).with("file:///myhost/blah").returns(:myuri)
+ @helper.key2uri("/myhost/blah").should == :myuri
+ end
it "should escape the key before parsing" do
URI.expects(:escape).with("mykey").returns("http://myhost/blah")
@@ -40,11 +39,3 @@ describe Puppet::FileServing::TerminusHelper, " when converting a key to a URI"
@helper.key2uri("/myhost/blah").should == :myuri
end
end
-
-describe Puppet::FileServing::TerminusHelper, " when returning file paths" do
- include TerminusHelperTesting
-
- it "should follow links if the links option is set to :follow"
-
- it "should ignore links if the links option is not set to follow"
-end