Skip to content

Commit 38c5a4e

Browse files
committed
Add specs for selector terminuses of file_{content,metadata}
1 parent 9e920a8 commit 38c5a4e

File tree

9 files changed

+194
-81
lines changed

9 files changed

+194
-81
lines changed

lib/puppet/application/master.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ def compile
163163

164164
def main
165165
require 'etc'
166-
require 'puppet/file_serving/content'
167-
require 'puppet/file_serving/metadata'
168166

169167
xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
170168

@@ -205,9 +203,7 @@ def main
205203
end
206204
end
207205

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
211207
# Handle the logging settings.
212208
if options[:debug] or options[:verbose]
213209
if options[:debug]
@@ -223,10 +219,11 @@ def setup
223219
end
224220

225221
Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
222+
end
226223

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'
230227

231228
# Cache our nodes in yaml. Currently not configurable.
232229
Puppet::Node.indirection.cache_class = :yaml
@@ -235,7 +232,9 @@ def setup
235232
Puppet::FileServing::Metadata.indirection.terminus_class = :file_server
236233

237234
Puppet::FileBucket::File.indirection.terminus_class = :file
235+
end
238236

237+
def setup_ssl
239238
# Configure all of the SSL stuff.
240239
if Puppet::SSL::CertificateAuthority.ca?
241240
Puppet::SSL::Host.ca_location = :local
@@ -245,4 +244,18 @@ def setup
245244
Puppet::SSL::Host.ca_location = :none
246245
end
247246
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
248261
end

lib/puppet/indirector/file_content/selector.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'puppet/file_serving/content'
12
require 'puppet/indirector/file_content'
23
require 'puppet/indirector/code'
34
require 'puppet/file_serving/terminus_selector'

lib/puppet/indirector/file_metadata/selector.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'puppet/file_serving/metadata'
12
require 'puppet/indirector/file_metadata'
23
require 'puppet/indirector/code'
34
require 'puppet/file_serving/terminus_selector'

spec/integration/file_serving/content_spec.rb

100755100644
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#!/usr/bin/env rspec
2+
23
require 'spec_helper'
34

45
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"
96

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"
149
end

spec/integration/file_serving/metadata_spec.rb

100755100644
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#!/usr/bin/env rspec
2+
23
require 'spec_helper'
34

45
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"
106

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"
159
end
10+
Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,80 @@
11
#!/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
112

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') }
206

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
3111

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')
4215

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)
4917

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'
5571

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)
6173

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
6579
end
6680
end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)