Permalink
Browse files

Add specs for selector terminuses of file_{content,metadata}

  • Loading branch information...
1 parent 9e920a8 commit 38c5a4efd8c369fb939eab5214af15b282b1c036 @nicklewis nicklewis committed Jun 25, 2012
View
29 lib/puppet/application/master.rb
@@ -163,8 +163,6 @@ def compile
def main
require 'etc'
- require 'puppet/file_serving/content'
- require 'puppet/file_serving/metadata'
xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
@@ -205,9 +203,7 @@ def main
end
end
- def setup
- raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
-
+ def setup_logs
# Handle the logging settings.
if options[:debug] or options[:verbose]
if options[:debug]
@@ -223,10 +219,11 @@ def setup
end
Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
+ end
- exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
-
- Puppet.settings.use :main, :master, :ssl, :metrics
+ def setup_terminuses
+ require 'puppet/file_serving/content'
+ require 'puppet/file_serving/metadata'
# Cache our nodes in yaml. Currently not configurable.
Puppet::Node.indirection.cache_class = :yaml
@@ -235,7 +232,9 @@ def setup
Puppet::FileServing::Metadata.indirection.terminus_class = :file_server
Puppet::FileBucket::File.indirection.terminus_class = :file
+ end
+ def setup_ssl
# Configure all of the SSL stuff.
if Puppet::SSL::CertificateAuthority.ca?
Puppet::SSL::Host.ca_location = :local
@@ -245,4 +244,18 @@ def setup
Puppet::SSL::Host.ca_location = :none
end
end
+
+ def setup
+ raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
+
+ setup_logs
+
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ Puppet.settings.use :main, :master, :ssl, :metrics
+
+ setup_terminuses
+
+ setup_ssl
+ end
end
View
1 lib/puppet/indirector/file_content/selector.rb
@@ -1,3 +1,4 @@
+require 'puppet/file_serving/content'
require 'puppet/indirector/file_content'
require 'puppet/indirector/code'
require 'puppet/file_serving/terminus_selector'
View
1 lib/puppet/indirector/file_metadata/selector.rb
@@ -1,3 +1,4 @@
+require 'puppet/file_serving/metadata'
require 'puppet/indirector/file_metadata'
require 'puppet/indirector/code'
require 'puppet/file_serving/terminus_selector'
View
11 spec/integration/file_serving/content_spec.rb 100755 → 100644
@@ -1,14 +1,9 @@
#!/usr/bin/env rspec
+
require 'spec_helper'
require 'puppet/file_serving/content'
-require 'shared_behaviours/file_serving'
-
-describe Puppet::FileServing::Content, " when finding files" do
- it_should_behave_like "Puppet::FileServing::Files"
- before do
- @test_class = Puppet::FileServing::Content
- @indirection = Puppet::FileServing::Content.indirection
- end
+describe Puppet::FileServing::Content do
+ it_should_behave_like "a file_serving model"
end
View
13 spec/integration/file_serving/metadata_spec.rb 100755 → 100644
@@ -1,15 +1,10 @@
#!/usr/bin/env rspec
+
require 'spec_helper'
require 'puppet/file_serving/metadata'
-require 'shared_behaviours/file_serving'
-require 'puppet/indirector/file_metadata/file_server'
-
-describe Puppet::FileServing::Metadata, " when finding files" do
- it_should_behave_like "Puppet::FileServing::Files"
- before do
- @test_class = Puppet::FileServing::Metadata
- @indirection = Puppet::FileServing::Metadata.indirection
- end
+describe Puppet::FileServing::Metadata do
+ it_should_behave_like "a file_serving model"
end
+
View
126 spec/shared_behaviours/file_serving.rb
@@ -1,66 +1,80 @@
#!/usr/bin/env rspec
-shared_examples_for "Puppet::FileServing::Files" do
- it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
- uri = "puppet://myhost/fakemod/my/file"
-
- # It appears that the mocking somehow interferes with the caching subsystem.
- # This mock somehow causes another terminus to get generated.
- @indirection.terminus(:rest).expects(:find)
- @indirection.find(uri)
- end
- it "should use the rest terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is not 'puppet' or 'apply'" do
- uri = "puppet:///fakemod/my/file"
- Puppet.settings.stubs(:value).returns "foo"
- Puppet.settings.stubs(:value).with(:name).returns("puppetd")
- Puppet.settings.stubs(:value).with(:modulepath).returns("")
- @indirection.terminus(:rest).expects(:find)
- @indirection.find(uri)
- end
+shared_examples_for "Puppet::FileServing::Files" do |indirection|
+ %w[find search].each do |method|
+ let(:request) { Puppet::Indirector::Request.new(indirection, method, 'foo') }
- it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'puppet'" do
- uri = "puppet:///fakemod/my/file"
- Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => []))
- Puppet.settings.stubs(:value).returns ""
- Puppet.settings.stubs(:value).with(:name).returns("puppet")
- Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
- @indirection.terminus(:file_server).expects(:find)
- @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
- @indirection.find(uri)
- end
+ before :each do
+ # Stub this so we can set the :name setting
+ Puppet::Util::Settings::ReadOnly.stubs(:include?)
+ end
- it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'apply'" do
- uri = "puppet:///fakemod/my/file"
- Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => []))
- Puppet.settings.stubs(:value).returns ""
- Puppet.settings.stubs(:value).with(:name).returns("apply")
- Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
- @indirection.terminus(:file_server).expects(:find)
- @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
- @indirection.find(uri)
- end
+ describe "##{method}" do
+ it "should proxy to file terminus if the path is absolute" do
+ request.key = make_absolute('/tmp/foo')
- it "should use the file terminus when the 'file' URI scheme is used" do
- uri = Puppet::Util.path_to_uri(File.expand_path('/fakemod/my/other file'))
- uri.scheme.should == 'file'
- @indirection.terminus(:file).expects(:find)
- @indirection.find(uri.to_s)
- end
+ described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
- it "should use the file terminus when a fully qualified path is provided" do
- uri = File.expand_path("/fakemod/my/file")
- @indirection.terminus(:file).expects(:find)
- @indirection.find(uri)
- end
+ subject.send(method, request)
+ end
+
+ it "should proxy to file terminus if the protocol is file" do
+ request.protocol = 'file'
+
+ described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
+
+ subject.send(method, request)
+ end
+
+ describe "when the protocol is puppet" do
+ before :each do
+ request.protocol = 'puppet'
+ end
+
+ describe "and a server is specified" do
+ before :each do
+ request.server = 'puppet_server'
+ end
+
+ it "should proxy to rest terminus if we're 'apply'" do
+ Puppet[:name] = 'apply'
+
+ described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
+
+ subject.send(method, request)
+ end
+
+ it "should proxy to rest terminus if we aren't 'apply'" do
+ Puppet[:name] = 'not_apply'
+
+ described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
+
+ subject.send(method, request)
+ end
+ end
+
+ describe "and no server is specified" do
+ before :each do
+ request.server = nil
+ end
+
+ it "should proxy to file_server if we're 'apply'" do
+ Puppet[:name] = 'apply'
+
+ described_class.indirection.terminus(:file_server).class.any_instance.expects(method).with(request)
+
+ subject.send(method, request)
+ end
+
+ it "should proxy to rest if we're not 'apply'" do
+ Puppet[:name] = 'not_apply'
- it "should use the configuration to test whether the request is allowed" do
- uri = "fakemod/my/file"
- mount = mock 'mount'
- config = stub 'configuration', :split_path => [mount, "eh"]
- @indirection.terminus(:file_server).stubs(:configuration).returns config
+ described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
- @indirection.terminus(:file_server).expects(:find)
- mount.expects(:allowed?).returns(true)
- @indirection.find(uri, :node => "foo", :ip => "bar")
+ subject.send(method, request)
+ end
+ end
+ end
+ end
end
end
View
73 spec/shared_behaviours/file_serving_model.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env rspec
+
+shared_examples_for "a file_serving model" do
+ include PuppetSpec::Files
+
+ describe "#indirection" do
+ before :each do
+ # Never connect to the network, no matter what
+ described_class.indirection.terminus(:rest).class.any_instance.stubs(:find)
+ end
+
+ describe "when running the master application" do
+ before :each do
+ Puppet::Application[:master].setup_terminuses
+ end
+
+ {
+ "/etc/sudoers" => :file_server,
+ "file:///etc/sudoers" => :file_server,
+ "puppet:///modules/foo/bar" => :file_server,
+ "puppet://server/modules/foo/bar" => :file_server,
+ }.each do |key, terminus|
+ it "should use the #{terminus} terminus when requesting #{key.inspect}" do
+ described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
+
+ described_class.indirection.find(key)
+ end
+ end
+ end
+
+ describe "when running the apply application" do
+ before :each do
+ # Stub this so we can set the 'name' setting
+ Puppet::Util::Settings::ReadOnly.stubs(:include?)
+ Puppet[:name] = 'apply'
+ end
+
+ {
+ "/etc/sudoers" => :file,
+ "file:///etc/sudoers" => :file,
+ "puppet:///modules/foo/bar" => :file_server,
+ "puppet://server/modules/foo/bar" => :rest,
+ }.each do |key, terminus|
+ it "should use the #{terminus} terminus when requesting #{key.inspect}" do
+ described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
+
+ described_class.indirection.find(key)
+ end
+ end
+ end
+
+ describe "when running another application" do
+ before :each do
+ # Stub this so we can set the 'name' setting
+ Puppet::Util::Settings::ReadOnly.stubs(:include?)
+ Puppet[:name] = 'agent'
+ end
+
+ {
+ "/etc/sudoers" => :file,
+ "file:///etc/sudoers" => :file,
+ "puppet:///modules/foo/bar" => :rest,
+ "puppet://server/modules/foo/bar" => :rest,
+ }.each do |key, terminus|
+ it "should use the #{terminus} terminus when requesting #{key.inspect}" do
+ described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
+
+ described_class.indirection.find(key)
+ end
+ end
+ end
+ end
+end
View
10 spec/unit/indirector/file_content/selector_spec.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+require 'puppet/indirector/file_content/selector'
+
+describe Puppet::Indirector::FileContent::Selector do
+ include PuppetSpec::Files
+
+ it_should_behave_like "Puppet::FileServing::Files", :file_content
+end
View
11 spec/unit/indirector/file_metadata/selector_spec.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+require 'puppet/indirector/file_metadata/selector'
+
+describe Puppet::Indirector::FileMetadata::Selector do
+ include PuppetSpec::Files
+
+ it_should_behave_like "Puppet::FileServing::Files", :file_metadata
+end
+

0 comments on commit 38c5a4e

Please sign in to comment.