Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 38c5a4efd8c369fb939eab5214af15b282b1c036 1 parent 9e920a8
Nick Lewis nicklewis authored
29 lib/puppet/application/master.rb
@@ -163,8 +163,6 @@ def compile
163 163
164 164 def main
165 165 require 'etc'
166   - require 'puppet/file_serving/content'
167   - require 'puppet/file_serving/metadata'
168 166
169 167 xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
170 168
@@ -205,9 +203,7 @@ def main
205 203 end
206 204 end
207 205
208   - def setup
209   - raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
210   -
  206 + def setup_logs
211 207 # Handle the logging settings.
212 208 if options[:debug] or options[:verbose]
213 209 if options[:debug]
@@ -223,10 +219,11 @@ def setup
223 219 end
224 220
225 221 Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
  222 + end
226 223
227   - exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
228   -
229   - Puppet.settings.use :main, :master, :ssl, :metrics
  224 + def setup_terminuses
  225 + require 'puppet/file_serving/content'
  226 + require 'puppet/file_serving/metadata'
230 227
231 228 # Cache our nodes in yaml. Currently not configurable.
232 229 Puppet::Node.indirection.cache_class = :yaml
@@ -235,7 +232,9 @@ def setup
235 232 Puppet::FileServing::Metadata.indirection.terminus_class = :file_server
236 233
237 234 Puppet::FileBucket::File.indirection.terminus_class = :file
  235 + end
238 236
  237 + def setup_ssl
239 238 # Configure all of the SSL stuff.
240 239 if Puppet::SSL::CertificateAuthority.ca?
241 240 Puppet::SSL::Host.ca_location = :local
@@ -245,4 +244,18 @@ def setup
245 244 Puppet::SSL::Host.ca_location = :none
246 245 end
247 246 end
  247 +
  248 + def setup
  249 + raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
  250 +
  251 + setup_logs
  252 +
  253 + exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
  254 +
  255 + Puppet.settings.use :main, :master, :ssl, :metrics
  256 +
  257 + setup_terminuses
  258 +
  259 + setup_ssl
  260 + end
248 261 end
1  lib/puppet/indirector/file_content/selector.rb
... ... @@ -1,3 +1,4 @@
  1 +require 'puppet/file_serving/content'
1 2 require 'puppet/indirector/file_content'
2 3 require 'puppet/indirector/code'
3 4 require 'puppet/file_serving/terminus_selector'
1  lib/puppet/indirector/file_metadata/selector.rb
... ... @@ -1,3 +1,4 @@
  1 +require 'puppet/file_serving/metadata'
1 2 require 'puppet/indirector/file_metadata'
2 3 require 'puppet/indirector/code'
3 4 require 'puppet/file_serving/terminus_selector'
11 spec/integration/file_serving/content_spec.rb 100755 → 100644
... ... @@ -1,14 +1,9 @@
1 1 #!/usr/bin/env rspec
  2 +
2 3 require 'spec_helper'
3 4
4 5 require 'puppet/file_serving/content'
5   -require 'shared_behaviours/file_serving'
6   -
7   -describe Puppet::FileServing::Content, " when finding files" do
8   - it_should_behave_like "Puppet::FileServing::Files"
9 6
10   - before do
11   - @test_class = Puppet::FileServing::Content
12   - @indirection = Puppet::FileServing::Content.indirection
13   - end
  7 +describe Puppet::FileServing::Content do
  8 + it_should_behave_like "a file_serving model"
14 9 end
13 spec/integration/file_serving/metadata_spec.rb 100755 → 100644
... ... @@ -1,15 +1,10 @@
1 1 #!/usr/bin/env rspec
  2 +
2 3 require 'spec_helper'
3 4
4 5 require 'puppet/file_serving/metadata'
5   -require 'shared_behaviours/file_serving'
6   -require 'puppet/indirector/file_metadata/file_server'
7   -
8   -describe Puppet::FileServing::Metadata, " when finding files" do
9   - it_should_behave_like "Puppet::FileServing::Files"
10 6
11   - before do
12   - @test_class = Puppet::FileServing::Metadata
13   - @indirection = Puppet::FileServing::Metadata.indirection
14   - end
  7 +describe Puppet::FileServing::Metadata do
  8 + it_should_behave_like "a file_serving model"
15 9 end
  10 +
126 spec/shared_behaviours/file_serving.rb
... ... @@ -1,66 +1,80 @@
1 1 #!/usr/bin/env rspec
2   -shared_examples_for "Puppet::FileServing::Files" do
3   - it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
4   - uri = "puppet://myhost/fakemod/my/file"
5   -
6   - # It appears that the mocking somehow interferes with the caching subsystem.
7   - # This mock somehow causes another terminus to get generated.
8   - @indirection.terminus(:rest).expects(:find)
9   - @indirection.find(uri)
10   - end
11 2
12   - 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
13   - uri = "puppet:///fakemod/my/file"
14   - Puppet.settings.stubs(:value).returns "foo"
15   - Puppet.settings.stubs(:value).with(:name).returns("puppetd")
16   - Puppet.settings.stubs(:value).with(:modulepath).returns("")
17   - @indirection.terminus(:rest).expects(:find)
18   - @indirection.find(uri)
19   - end
  3 +shared_examples_for "Puppet::FileServing::Files" do |indirection|
  4 + %w[find search].each do |method|
  5 + let(:request) { Puppet::Indirector::Request.new(indirection, method, 'foo') }
20 6
21   - 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
22   - uri = "puppet:///fakemod/my/file"
23   - Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => []))
24   - Puppet.settings.stubs(:value).returns ""
25   - Puppet.settings.stubs(:value).with(:name).returns("puppet")
26   - Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
27   - @indirection.terminus(:file_server).expects(:find)
28   - @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
29   - @indirection.find(uri)
30   - end
  7 + before :each do
  8 + # Stub this so we can set the :name setting
  9 + Puppet::Util::Settings::ReadOnly.stubs(:include?)
  10 + end
31 11
32   - 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
33   - uri = "puppet:///fakemod/my/file"
34   - Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => []))
35   - Puppet.settings.stubs(:value).returns ""
36   - Puppet.settings.stubs(:value).with(:name).returns("apply")
37   - Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
38   - @indirection.terminus(:file_server).expects(:find)
39   - @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
40   - @indirection.find(uri)
41   - end
  12 + describe "##{method}" do
  13 + it "should proxy to file terminus if the path is absolute" do
  14 + request.key = make_absolute('/tmp/foo')
42 15
43   - it "should use the file terminus when the 'file' URI scheme is used" do
44   - uri = Puppet::Util.path_to_uri(File.expand_path('/fakemod/my/other file'))
45   - uri.scheme.should == 'file'
46   - @indirection.terminus(:file).expects(:find)
47   - @indirection.find(uri.to_s)
48   - end
  16 + described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
49 17
50   - it "should use the file terminus when a fully qualified path is provided" do
51   - uri = File.expand_path("/fakemod/my/file")
52   - @indirection.terminus(:file).expects(:find)
53   - @indirection.find(uri)
54   - end
  18 + subject.send(method, request)
  19 + end
  20 +
  21 + it "should proxy to file terminus if the protocol is file" do
  22 + request.protocol = 'file'
  23 +
  24 + described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
  25 +
  26 + subject.send(method, request)
  27 + end
  28 +
  29 + describe "when the protocol is puppet" do
  30 + before :each do
  31 + request.protocol = 'puppet'
  32 + end
  33 +
  34 + describe "and a server is specified" do
  35 + before :each do
  36 + request.server = 'puppet_server'
  37 + end
  38 +
  39 + it "should proxy to rest terminus if we're 'apply'" do
  40 + Puppet[:name] = 'apply'
  41 +
  42 + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
  43 +
  44 + subject.send(method, request)
  45 + end
  46 +
  47 + it "should proxy to rest terminus if we aren't 'apply'" do
  48 + Puppet[:name] = 'not_apply'
  49 +
  50 + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
  51 +
  52 + subject.send(method, request)
  53 + end
  54 + end
  55 +
  56 + describe "and no server is specified" do
  57 + before :each do
  58 + request.server = nil
  59 + end
  60 +
  61 + it "should proxy to file_server if we're 'apply'" do
  62 + Puppet[:name] = 'apply'
  63 +
  64 + described_class.indirection.terminus(:file_server).class.any_instance.expects(method).with(request)
  65 +
  66 + subject.send(method, request)
  67 + end
  68 +
  69 + it "should proxy to rest if we're not 'apply'" do
  70 + Puppet[:name] = 'not_apply'
55 71
56   - it "should use the configuration to test whether the request is allowed" do
57   - uri = "fakemod/my/file"
58   - mount = mock 'mount'
59   - config = stub 'configuration', :split_path => [mount, "eh"]
60   - @indirection.terminus(:file_server).stubs(:configuration).returns config
  72 + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
61 73
62   - @indirection.terminus(:file_server).expects(:find)
63   - mount.expects(:allowed?).returns(true)
64   - @indirection.find(uri, :node => "foo", :ip => "bar")
  74 + subject.send(method, request)
  75 + end
  76 + end
  77 + end
  78 + end
65 79 end
66 80 end
73 spec/shared_behaviours/file_serving_model.rb
... ... @@ -0,0 +1,73 @@
  1 +#!/usr/bin/env rspec
  2 +
  3 +shared_examples_for "a file_serving model" do
  4 + include PuppetSpec::Files
  5 +
  6 + describe "#indirection" do
  7 + before :each do
  8 + # Never connect to the network, no matter what
  9 + described_class.indirection.terminus(:rest).class.any_instance.stubs(:find)
  10 + end
  11 +
  12 + describe "when running the master application" do
  13 + before :each do
  14 + Puppet::Application[:master].setup_terminuses
  15 + end
  16 +
  17 + {
  18 + "/etc/sudoers" => :file_server,
  19 + "file:///etc/sudoers" => :file_server,
  20 + "puppet:///modules/foo/bar" => :file_server,
  21 + "puppet://server/modules/foo/bar" => :file_server,
  22 + }.each do |key, terminus|
  23 + it "should use the #{terminus} terminus when requesting #{key.inspect}" do
  24 + described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
  25 +
  26 + described_class.indirection.find(key)
  27 + end
  28 + end
  29 + end
  30 +
  31 + describe "when running the apply application" do
  32 + before :each do
  33 + # Stub this so we can set the 'name' setting
  34 + Puppet::Util::Settings::ReadOnly.stubs(:include?)
  35 + Puppet[:name] = 'apply'
  36 + end
  37 +
  38 + {
  39 + "/etc/sudoers" => :file,
  40 + "file:///etc/sudoers" => :file,
  41 + "puppet:///modules/foo/bar" => :file_server,
  42 + "puppet://server/modules/foo/bar" => :rest,
  43 + }.each do |key, terminus|
  44 + it "should use the #{terminus} terminus when requesting #{key.inspect}" do
  45 + described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
  46 +
  47 + described_class.indirection.find(key)
  48 + end
  49 + end
  50 + end
  51 +
  52 + describe "when running another application" do
  53 + before :each do
  54 + # Stub this so we can set the 'name' setting
  55 + Puppet::Util::Settings::ReadOnly.stubs(:include?)
  56 + Puppet[:name] = 'agent'
  57 + end
  58 +
  59 + {
  60 + "/etc/sudoers" => :file,
  61 + "file:///etc/sudoers" => :file,
  62 + "puppet:///modules/foo/bar" => :rest,
  63 + "puppet://server/modules/foo/bar" => :rest,
  64 + }.each do |key, terminus|
  65 + it "should use the #{terminus} terminus when requesting #{key.inspect}" do
  66 + described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
  67 +
  68 + described_class.indirection.find(key)
  69 + end
  70 + end
  71 + end
  72 + end
  73 +end
10 spec/unit/indirector/file_content/selector_spec.rb
... ... @@ -0,0 +1,10 @@
  1 +#!/usr/bin/env rspec
  2 +require 'spec_helper'
  3 +
  4 +require 'puppet/indirector/file_content/selector'
  5 +
  6 +describe Puppet::Indirector::FileContent::Selector do
  7 + include PuppetSpec::Files
  8 +
  9 + it_should_behave_like "Puppet::FileServing::Files", :file_content
  10 +end
11 spec/unit/indirector/file_metadata/selector_spec.rb
... ... @@ -0,0 +1,11 @@
  1 +#!/usr/bin/env rspec
  2 +require 'spec_helper'
  3 +
  4 +require 'puppet/indirector/file_metadata/selector'
  5 +
  6 +describe Puppet::Indirector::FileMetadata::Selector do
  7 + include PuppetSpec::Files
  8 +
  9 + it_should_behave_like "Puppet::FileServing::Files", :file_metadata
  10 +end
  11 +

0 comments on commit 38c5a4e

Please sign in to comment.
Something went wrong with that request. Please try again.