From de5d91e2036de2934a4eec79d35a714f3ed24b10 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 22 Oct 2007 22:37:52 -0500 Subject: Renaming the :local termini for metadata and content to :file. --- lib/puppet/file_serving/terminus_selector.rb | 4 +- lib/puppet/indirector/file_content/file.rb | 28 ++++++++++ lib/puppet/indirector/file_content/local.rb | 28 ---------- lib/puppet/indirector/file_metadata/file.rb | 32 +++++++++++ lib/puppet/indirector/file_metadata/local.rb | 32 ----------- spec/lib/shared_behaviours/file_serving.rb | 8 +-- spec/unit/file_serving/terminus_selector.rb | 14 ++--- spec/unit/indirector/file_content/file.rb | 70 ++++++++++++++++++++++++ spec/unit/indirector/file_content/local.rb | 70 ------------------------ spec/unit/indirector/file_metadata/file.rb | 82 ++++++++++++++++++++++++++++ spec/unit/indirector/file_metadata/local.rb | 82 ---------------------------- 11 files changed, 225 insertions(+), 225 deletions(-) create mode 100644 lib/puppet/indirector/file_content/file.rb delete mode 100644 lib/puppet/indirector/file_content/local.rb create mode 100644 lib/puppet/indirector/file_metadata/file.rb delete mode 100644 lib/puppet/indirector/file_metadata/local.rb create mode 100755 spec/unit/indirector/file_content/file.rb delete mode 100755 spec/unit/indirector/file_content/local.rb create mode 100755 spec/unit/indirector/file_metadata/file.rb delete mode 100755 spec/unit/indirector/file_metadata/local.rb diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/terminus_selector.rb index aa08f087e..06b53ddb1 100644 --- a/lib/puppet/file_serving/terminus_selector.rb +++ b/lib/puppet/file_serving/terminus_selector.rb @@ -9,11 +9,11 @@ require 'puppet/file_serving' # in file-serving indirections. This is necessary because # the terminus varies based on the URI asked for. module Puppet::FileServing::TerminusSelector - PROTOCOL_MAP = {"puppet" => :rest, "file" => :local, "puppetmounts" => :file_server} + PROTOCOL_MAP = {"puppet" => :rest, "file" => :file, "puppetmounts" => :file_server} # Pick an appropriate terminus based on the protocol. def select_terminus(full_uri, options = {}) - # Short-circuit to :local if it's a fully-qualified path. + # Short-circuit to :file if it's a fully-qualified path. return PROTOCOL_MAP["file"] if full_uri =~ /^#{::File::SEPARATOR}/ begin uri = URI.parse(URI.escape(full_uri)) diff --git a/lib/puppet/indirector/file_content/file.rb b/lib/puppet/indirector/file_content/file.rb new file mode 100644 index 000000000..4503a7919 --- /dev/null +++ b/lib/puppet/indirector/file_content/file.rb @@ -0,0 +1,28 @@ +# +# Created by Luke Kanies on 2007-10-16. +# 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::File < Puppet::Indirector::File + desc "Retrieve file contents from disk." + + include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper + + def find(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + model.new(uri.path, :links => options[:links]) + end + + def search(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + path2instances(uri.path, options) + end +end diff --git a/lib/puppet/indirector/file_content/local.rb b/lib/puppet/indirector/file_content/local.rb deleted file mode 100644 index a9c45d59e..000000000 --- a/lib/puppet/indirector/file_content/local.rb +++ /dev/null @@ -1,28 +0,0 @@ -# -# Created by Luke Kanies on 2007-10-16. -# 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::Util::URIHelper - include Puppet::FileServing::TerminusHelper - - def find(key, options = {}) - uri = key2uri(key) - return nil unless FileTest.exists?(uri.path) - model.new(uri.path, :links => options[:links]) - end - - def search(key, options = {}) - uri = key2uri(key) - return nil unless FileTest.exists?(uri.path) - path2instances(uri.path, options) - end -end diff --git a/lib/puppet/indirector/file_metadata/file.rb b/lib/puppet/indirector/file_metadata/file.rb new file mode 100644 index 000000000..823c26c36 --- /dev/null +++ b/lib/puppet/indirector/file_metadata/file.rb @@ -0,0 +1,32 @@ +# +# Created by Luke Kanies on 2007-10-16. +# Copyright (c) 2007. All rights reserved. + +require 'puppet/file_serving/metadata' +require 'puppet/file_serving/terminus_helper' +require 'puppet/indirector/file_metadata' +require 'puppet/util/uri_helper' +require 'puppet/indirector/code' + +class Puppet::Indirector::FileMetadata::File < Puppet::Indirector::Code + desc "Retrieve file metadata directly from the local filesystem." + + include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper + + def find(key, options = {}) + uri = key2uri(key) + + return nil unless FileTest.exists?(uri.path) + data = model.new(uri.path, :links => options[:links]) + data.collect_attributes + + return data + end + + def search(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + path2instances(uri.path, options).each { |instance| instance.collect_attributes } + end +end diff --git a/lib/puppet/indirector/file_metadata/local.rb b/lib/puppet/indirector/file_metadata/local.rb deleted file mode 100644 index d696bc769..000000000 --- a/lib/puppet/indirector/file_metadata/local.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# Created by Luke Kanies on 2007-10-16. -# Copyright (c) 2007. All rights reserved. - -require 'puppet/file_serving/metadata' -require 'puppet/file_serving/terminus_helper' -require 'puppet/indirector/file_metadata' -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::Util::URIHelper - include Puppet::FileServing::TerminusHelper - - def find(key, options = {}) - uri = key2uri(key) - - return nil unless FileTest.exists?(uri.path) - data = model.new(uri.path, :links => options[:links]) - data.collect_attributes - - return data - end - - def search(key, options = {}) - uri = key2uri(key) - return nil unless FileTest.exists?(uri.path) - path2instances(uri.path, options).each { |instance| instance.collect_attributes } - end -end diff --git a/spec/lib/shared_behaviours/file_serving.rb b/spec/lib/shared_behaviours/file_serving.rb index b0aa14fc0..6eaec6850 100644 --- a/spec/lib/shared_behaviours/file_serving.rb +++ b/spec/lib/shared_behaviours/file_serving.rb @@ -36,15 +36,15 @@ describe "Puppet::FileServing::Files", :shared => true do @test_class.find(uri) end - it "should use the local terminus when the 'file' URI scheme is used" do + it "should use the file terminus when the 'file' URI scheme is used" do uri = "file:///mymod/my/file" - @indirection.terminus(:local).expects(:find).with(uri) + @indirection.terminus(:file).expects(:find).with(uri) @test_class.find(uri) end - it "should use the local terminus when a fully qualified path is provided" do + it "should use the file terminus when a fully qualified path is provided" do uri = "/mymod/my/file" - @indirection.terminus(:local).expects(:find).with(uri) + @indirection.terminus(:file).expects(:find).with(uri) @test_class.find(uri) end end diff --git a/spec/unit/file_serving/terminus_selector.rb b/spec/unit/file_serving/terminus_selector.rb index 046f71bdc..9c2c01bfd 100755 --- a/spec/unit/file_serving/terminus_selector.rb +++ b/spec/unit/file_serving/terminus_selector.rb @@ -65,17 +65,17 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term @object.select_terminus("puppet:///module/file").should == :rest end - it "should choose :local when the protocol is 'file'" do - @object.select_terminus("file://host/module/file").should == :local + it "should choose :file when the protocol is 'file'" do + @object.select_terminus("file://host/module/file").should == :file end - it "should choose :local when the URI is a normal path name" do - @object.select_terminus("/module/file").should == :local + it "should choose :file when the URI is a normal path name" do + @object.select_terminus("/module/file").should == :file 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 + # This is so that we only choose modules over mounts, not file + it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do + @object.select_terminus("file://host/modules/file").should == :file end it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do diff --git a/spec/unit/indirector/file_content/file.rb b/spec/unit/indirector/file_content/file.rb new file mode 100755 index 000000000..da2c90770 --- /dev/null +++ b/spec/unit/indirector/file_content/file.rb @@ -0,0 +1,70 @@ +#!/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/file' + +describe Puppet::Indirector::FileContent::File do + it "should be registered with the file_content indirection" do + Puppet::Indirector::Terminus.terminus_class(:file_content, :file).should equal(Puppet::Indirector::FileContent::File) + end + + it "should be a subclass of the File terminus" do + Puppet::Indirector::FileContent::File.superclass.should equal(Puppet::Indirector::File) + end +end + +describe Puppet::Indirector::FileContent::File, "when finding a single file" do + it "should return a Content instance created with the full path to the file if the file exists" do + @content = Puppet::Indirector::FileContent::File.new + @uri = "file:///my/local" + + FileTest.expects(:exists?).with("/my/local").returns true + Puppet::FileServing::Content.expects(:new).with("/my/local", :links => nil).returns(:mycontent) + @content.find(@uri).should == :mycontent + end + + it "should pass the :links setting on to the created Content instance if the file exists" do + @content = Puppet::Indirector::FileContent::File.new + @uri = "file:///my/local" + + FileTest.expects(:exists?).with("/my/local").returns true + Puppet::FileServing::Content.expects(:new).with("/my/local", :links => :manage).returns(:mycontent) + @content.find(@uri, :links => :manage) + end + + it "should return nil if the file does not exist" do + @content = Puppet::Indirector::FileContent::File.new + @uri = "file:///my/local" + + FileTest.expects(:exists?).with("/my/local").returns false + @content.find(@uri).should be_nil + end +end + +describe Puppet::Indirector::FileContent::File, "when searching for multiple files" do + before do + @content = Puppet::Indirector::FileContent::File.new + @uri = "file:///my/local" + end + + it "should return nil if the file does not exist" do + FileTest.expects(:exists?).with("/my/local").returns false + @content.find(@uri).should be_nil + end + + it "should use :path2instances from the terminus_helper to return instances if the file exists" do + FileTest.expects(:exists?).with("/my/local").returns true + @content.expects(:path2instances).with("/my/local", {}) + @content.search(@uri) + end + + it "should pass any options on to :path2instances" do + FileTest.expects(:exists?).with("/my/local").returns true + @content.expects(:path2instances).with("/my/local", :testing => :one, :other => :two) + @content.search(@uri, :testing => :one, :other => :two) + end +end diff --git a/spec/unit/indirector/file_content/local.rb b/spec/unit/indirector/file_content/local.rb deleted file mode 100755 index 442667518..000000000 --- a/spec/unit/indirector/file_content/local.rb +++ /dev/null @@ -1,70 +0,0 @@ -#!/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/local' - -describe Puppet::Indirector::FileContent::Local do - it "should be registered with the file_content indirection" do - Puppet::Indirector::Terminus.terminus_class(:file_content, :local).should equal(Puppet::Indirector::FileContent::Local) - end - - it "should be a subclass of the File terminus" do - Puppet::Indirector::FileContent::Local.superclass.should equal(Puppet::Indirector::File) - end -end - -describe Puppet::Indirector::FileContent::Local, "when finding a single file" do - it "should return a Content instance created with the full path to the file if the file exists" do - @content = Puppet::Indirector::FileContent::Local.new - @uri = "file:///my/local" - - FileTest.expects(:exists?).with("/my/local").returns true - Puppet::FileServing::Content.expects(:new).with("/my/local", :links => nil).returns(:mycontent) - @content.find(@uri).should == :mycontent - end - - it "should pass the :links setting on to the created Content instance if the file exists" do - @content = Puppet::Indirector::FileContent::Local.new - @uri = "file:///my/local" - - FileTest.expects(:exists?).with("/my/local").returns true - Puppet::FileServing::Content.expects(:new).with("/my/local", :links => :manage).returns(:mycontent) - @content.find(@uri, :links => :manage) - end - - it "should return nil if the file does not exist" do - @content = Puppet::Indirector::FileContent::Local.new - @uri = "file:///my/local" - - FileTest.expects(:exists?).with("/my/local").returns false - @content.find(@uri).should be_nil - end -end - -describe Puppet::Indirector::FileContent::Local, "when searching for multiple files" do - before do - @content = Puppet::Indirector::FileContent::Local.new - @uri = "file:///my/local" - end - - it "should return nil if the file does not exist" do - FileTest.expects(:exists?).with("/my/local").returns false - @content.find(@uri).should be_nil - end - - it "should use :path2instances from the terminus_helper to return instances if the file exists" do - FileTest.expects(:exists?).with("/my/local").returns true - @content.expects(:path2instances).with("/my/local", {}) - @content.search(@uri) - end - - it "should pass any options on to :path2instances" do - FileTest.expects(:exists?).with("/my/local").returns true - @content.expects(:path2instances).with("/my/local", :testing => :one, :other => :two) - @content.search(@uri, :testing => :one, :other => :two) - end -end diff --git a/spec/unit/indirector/file_metadata/file.rb b/spec/unit/indirector/file_metadata/file.rb new file mode 100755 index 000000000..c88d559a7 --- /dev/null +++ b/spec/unit/indirector/file_metadata/file.rb @@ -0,0 +1,82 @@ +#!/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/file' + +describe Puppet::Indirector::FileMetadata::File do + it "should be registered with the file_metadata indirection" do + Puppet::Indirector::Terminus.terminus_class(:file_metadata, :file).should equal(Puppet::Indirector::FileMetadata::File) + end +end + +describe Puppet::Indirector::FileMetadata::File, "when finding a single file" do + before do + @metadata = Puppet::Indirector::FileMetadata::File.new + @uri = "file:///my/local" + + @data = mock 'metadata' + end + + it "should return a Metadata instance created with the full path to the file if the file exists" do + @data.stubs(:collect_attributes) + + FileTest.expects(:exists?).with("/my/local").returns true + Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data) + @metadata.find(@uri).should == @data + end + + it "should pass the :links setting on to the created Content instance if the file exists" do + @data.stubs(:collect_attributes) + + FileTest.expects(:exists?).with("/my/local").returns true + Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => :manage).returns(@data) + @metadata.find(@uri, :links => :manage) + end + + it "should collect its attributes when a file is found" do + @data.expects(:collect_attributes) + + FileTest.expects(:exists?).with("/my/local").returns true + Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data) + @metadata.find(@uri).should == @data + end + + it "should return nil if the file does not exist" do + FileTest.expects(:exists?).with("/my/local").returns false + @metadata.find(@uri).should be_nil + end +end + +describe Puppet::Indirector::FileMetadata::File, "when searching for multiple files" do + before do + @metadata = Puppet::Indirector::FileMetadata::File.new + @uri = "file:///my/local" + end + + it "should return nil if the file does not exist" do + FileTest.expects(:exists?).with("/my/local").returns false + @metadata.find(@uri).should be_nil + end + + it "should use :path2instances from the terminus_helper to return instances if the file exists" do + FileTest.expects(:exists?).with("/my/local").returns true + @metadata.expects(:path2instances).with("/my/local", {}).returns([]) + @metadata.search(@uri) + end + + it "should pass any options on to :path2instances" do + FileTest.expects(:exists?).with("/my/local").returns true + @metadata.expects(:path2instances).with("/my/local", :testing => :one, :other => :two).returns([]) + @metadata.search(@uri, :testing => :one, :other => :two) + end + + it "should collect the attributes of the instances returned" do + FileTest.expects(:exists?).with("/my/local").returns true + @metadata.expects(:path2instances).with("/my/local", {}).returns( [mock("one", :collect_attributes => nil), mock("two", :collect_attributes => nil)] ) + @metadata.search(@uri) + end +end diff --git a/spec/unit/indirector/file_metadata/local.rb b/spec/unit/indirector/file_metadata/local.rb deleted file mode 100755 index 289aee449..000000000 --- a/spec/unit/indirector/file_metadata/local.rb +++ /dev/null @@ -1,82 +0,0 @@ -#!/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/local' - -describe Puppet::Indirector::FileMetadata::Local do - it "should be registered with the file_metadata indirection" do - Puppet::Indirector::Terminus.terminus_class(:file_metadata, :local).should equal(Puppet::Indirector::FileMetadata::Local) - end -end - -describe Puppet::Indirector::FileMetadata::Local, "when finding a single file" do - before do - @metadata = Puppet::Indirector::FileMetadata::Local.new - @uri = "file:///my/local" - - @data = mock 'metadata' - end - - it "should return a Metadata instance created with the full path to the file if the file exists" do - @data.stubs(:collect_attributes) - - FileTest.expects(:exists?).with("/my/local").returns true - Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data) - @metadata.find(@uri).should == @data - end - - it "should pass the :links setting on to the created Content instance if the file exists" do - @data.stubs(:collect_attributes) - - FileTest.expects(:exists?).with("/my/local").returns true - Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => :manage).returns(@data) - @metadata.find(@uri, :links => :manage) - end - - it "should collect its attributes when a file is found" do - @data.expects(:collect_attributes) - - FileTest.expects(:exists?).with("/my/local").returns true - Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data) - @metadata.find(@uri).should == @data - end - - it "should return nil if the file does not exist" do - FileTest.expects(:exists?).with("/my/local").returns false - @metadata.find(@uri).should be_nil - end -end - -describe Puppet::Indirector::FileMetadata::Local, "when searching for multiple files" do - before do - @metadata = Puppet::Indirector::FileMetadata::Local.new - @uri = "file:///my/local" - end - - it "should return nil if the file does not exist" do - FileTest.expects(:exists?).with("/my/local").returns false - @metadata.find(@uri).should be_nil - end - - it "should use :path2instances from the terminus_helper to return instances if the file exists" do - FileTest.expects(:exists?).with("/my/local").returns true - @metadata.expects(:path2instances).with("/my/local", {}).returns([]) - @metadata.search(@uri) - end - - it "should pass any options on to :path2instances" do - FileTest.expects(:exists?).with("/my/local").returns true - @metadata.expects(:path2instances).with("/my/local", :testing => :one, :other => :two).returns([]) - @metadata.search(@uri, :testing => :one, :other => :two) - end - - it "should collect the attributes of the instances returned" do - FileTest.expects(:exists?).with("/my/local").returns true - @metadata.expects(:path2instances).with("/my/local", {}).returns( [mock("one", :collect_attributes => nil), mock("two", :collect_attributes => nil)] ) - @metadata.search(@uri) - end -end -- cgit