puppet 2.6.4 → 2.6.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +147 -0
- data/LICENSE +2 -2
- data/Rakefile +3 -4
- data/lib/puppet.rb +1 -1
- data/lib/puppet/application.rb +22 -5
- data/lib/puppet/application/apply.rb +2 -18
- data/lib/puppet/application/doc.rb +1 -4
- data/lib/puppet/application/inspect.rb +178 -0
- data/lib/puppet/configurer.rb +9 -11
- data/lib/puppet/configurer/plugin_handler.rb +0 -2
- data/lib/puppet/defaults.rb +12 -3
- data/lib/puppet/external/pson/pure/generator.rb +1 -22
- data/lib/puppet/file_bucket/dipper.rb +9 -3
- data/lib/puppet/file_bucket/file.rb +14 -94
- data/lib/puppet/indirector.rb +4 -0
- data/lib/puppet/indirector/catalog/active_record.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
- data/lib/puppet/indirector/indirection.rb +18 -8
- data/lib/puppet/indirector/resource/ral.rb +7 -2
- data/lib/puppet/indirector/rest.rb +19 -2
- data/lib/puppet/network/http/api/v1.rb +3 -0
- data/lib/puppet/network/http/handler.rb +16 -1
- data/lib/puppet/network/http/rack/rest.rb +1 -3
- data/lib/puppet/network/rest_authconfig.rb +4 -12
- data/lib/puppet/network/rights.rb +28 -14
- data/lib/puppet/parser/ast.rb +4 -0
- data/lib/puppet/parser/compiler.rb +18 -3
- data/lib/puppet/parser/functions/defined.rb +28 -6
- data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
- data/lib/puppet/parser/templatewrapper.rb +1 -0
- data/lib/puppet/property.rb +16 -1
- data/lib/puppet/property/keyvalue.rb +0 -2
- data/lib/puppet/property/list.rb +0 -2
- data/lib/puppet/provider/file/posix.rb +1 -3
- data/lib/puppet/provider/file/win32.rb +1 -3
- data/lib/puppet/provider/maillist/mailman.rb +3 -5
- data/lib/puppet/provider/mount.rb +2 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
- data/lib/puppet/provider/package/freebsd.rb +2 -2
- data/lib/puppet/provider/zone/solaris.rb +1 -1
- data/lib/puppet/reference/configuration.rb +2 -2
- data/lib/puppet/reference/function.rb +4 -0
- data/lib/puppet/relationship.rb +4 -0
- data/lib/puppet/reports/store.rb +1 -19
- data/lib/puppet/resource.rb +11 -2
- data/lib/puppet/resource/status.rb +24 -3
- data/lib/puppet/resource/type.rb +24 -16
- data/lib/puppet/resource/type_collection.rb +4 -1
- data/lib/puppet/simple_graph.rb +4 -0
- data/lib/puppet/transaction.rb +1 -28
- data/lib/puppet/transaction/event.rb +9 -4
- data/lib/puppet/transaction/report.rb +42 -22
- data/lib/puppet/transaction/resource_harness.rb +99 -71
- data/lib/puppet/type.rb +22 -9
- data/lib/puppet/type/cron.rb +1 -5
- data/lib/puppet/type/exec.rb +4 -34
- data/lib/puppet/type/file.rb +19 -26
- data/lib/puppet/type/file/checksum.rb +1 -1
- data/lib/puppet/type/file/content.rb +2 -1
- data/lib/puppet/type/file/ctime.rb +18 -0
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +10 -44
- data/lib/puppet/type/file/mtime.rb +17 -0
- data/lib/puppet/type/file/owner.rb +1 -1
- data/lib/puppet/type/file/source.rb +0 -1
- data/lib/puppet/type/file/target.rb +1 -1
- data/lib/puppet/type/file/type.rb +5 -12
- data/lib/puppet/type/host.rb +1 -1
- data/lib/puppet/type/mount.rb +2 -2
- data/lib/puppet/type/package.rb +0 -2
- data/lib/puppet/type/service.rb +11 -5
- data/lib/puppet/type/user.rb +7 -9
- data/lib/puppet/type/yumrepo.rb +2 -2
- data/lib/puppet/type/zpool.rb +0 -4
- data/lib/puppet/util/checksums.rb +24 -1
- data/lib/puppet/util/command_line.rb +6 -2
- data/lib/puppet/util/command_line/puppet +5 -1
- data/lib/puppet/util/command_line/puppetca +2 -2
- data/lib/puppet/util/command_line/puppetd +11 -9
- data/lib/puppet/util/command_line/puppetdoc +2 -2
- data/lib/puppet/util/command_line/puppetmasterd +5 -0
- data/lib/puppet/util/log.rb +15 -8
- data/lib/puppet/util/log/destinations.rb +2 -0
- data/lib/puppet/util/log_paths.rb +1 -1
- data/lib/puppet/util/logging.rb +1 -1
- data/lib/puppet/util/metric.rb +1 -0
- data/lib/puppet/util/reference.rb +1 -10
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/zaml.rb +30 -31
- data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
- data/spec/integration/application/apply_spec.rb +1 -2
- data/spec/integration/defaults_spec.rb +1 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
- data/spec/integration/indirector/report/rest_spec.rb +13 -17
- data/spec/integration/network/formats_spec.rb +2 -5
- data/spec/integration/network/server/mongrel_spec.rb +1 -2
- data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
- data/spec/integration/provider/package_spec.rb +1 -3
- data/spec/integration/provider/service/init_spec.rb +3 -9
- data/spec/integration/reference/providers_spec.rb +2 -2
- data/spec/integration/resource/catalog_spec.rb +1 -2
- data/spec/integration/transaction/report_spec.rb +1 -1
- data/spec/monkey_patches/alias_should_to_must.rb +2 -0
- data/spec/shared_behaviours/file_server_terminus.rb +1 -1
- data/spec/shared_behaviours/file_serving.rb +1 -1
- data/spec/shared_behaviours/memory_terminus.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/application/agent_spec.rb +1 -0
- data/spec/unit/application/apply_spec.rb +7 -7
- data/spec/unit/application/doc_spec.rb +2 -2
- data/spec/unit/application/filebucket_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +278 -0
- data/spec/unit/application/kick_spec.rb +1 -3
- data/spec/unit/application/master_spec.rb +1 -3
- data/spec/unit/application/queue_spec.rb +1 -0
- data/spec/unit/application_spec.rb +63 -5
- data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
- data/spec/unit/configurer_spec.rb +33 -49
- data/spec/unit/file_bucket/dipper_spec.rb +69 -77
- data/spec/unit/file_bucket/file_spec.rb +12 -127
- data/spec/unit/file_serving/fileset_spec.rb +1 -0
- data/spec/unit/file_serving/metadata_spec.rb +4 -4
- data/spec/unit/indirector/active_record_spec.rb +1 -0
- data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
- data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
- data/spec/unit/indirector/facts/couch_spec.rb +1 -2
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
- data/spec/unit/indirector/file_server_spec.rb +6 -7
- data/spec/unit/indirector/indirection_spec.rb +71 -2
- data/spec/unit/indirector/ldap_spec.rb +2 -6
- data/spec/unit/indirector/node/active_record_spec.rb +1 -3
- data/spec/unit/indirector/queue_spec.rb +1 -3
- data/spec/unit/indirector/rest_spec.rb +37 -1
- data/spec/unit/indirector/ssl_file_spec.rb +5 -5
- data/spec/unit/indirector_spec.rb +6 -1
- data/spec/unit/module_spec.rb +1 -3
- data/spec/unit/network/formats_spec.rb +2 -5
- data/spec/unit/network/http/api/v1_spec.rb +4 -0
- data/spec/unit/network/http/compression_spec.rb +1 -3
- data/spec/unit/network/http/handler_spec.rb +39 -0
- data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
- data/spec/unit/network/http/mongrel_spec.rb +3 -9
- data/spec/unit/network/http/rack/rest_spec.rb +1 -3
- data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
- data/spec/unit/network/http/rack_spec.rb +2 -3
- data/spec/unit/network/http/webrick_spec.rb +1 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/network/rights_spec.rb +43 -23
- data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
- data/spec/unit/parameter_spec.rb +1 -2
- data/spec/unit/parser/collector_spec.rb +3 -6
- data/spec/unit/parser/compiler_spec.rb +90 -5
- data/spec/unit/parser/lexer_spec.rb +3 -2
- data/spec/unit/parser/templatewrapper_spec.rb +1 -0
- data/spec/unit/property/keyvalue_spec.rb +5 -5
- data/spec/unit/property/list_spec.rb +7 -7
- data/spec/unit/provider/mount/parsed_spec.rb +1 -2
- data/spec/unit/provider/mount_spec.rb +8 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
- data/spec/unit/provider/package/freebsd_spec.rb +55 -0
- data/spec/unit/provider/service/init_spec.rb +2 -0
- data/spec/unit/rails/host_spec.rb +1 -3
- data/spec/unit/rails/param_value_spec.rb +2 -3
- data/spec/unit/rails/resource_spec.rb +2 -3
- data/spec/unit/rails_spec.rb +5 -15
- data/spec/unit/relationship_spec.rb +2 -6
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/reports/store_spec.rb +31 -0
- data/spec/unit/reports/tagmail_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +2 -6
- data/spec/unit/resource/status_spec.rb +53 -3
- data/spec/unit/resource/type_collection_spec.rb +0 -8
- data/spec/unit/resource/type_spec.rb +50 -4
- data/spec/unit/resource_spec.rb +10 -6
- data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
- data/spec/unit/transaction/event_spec.rb +21 -2
- data/spec/unit/transaction/report_spec.rb +91 -35
- data/spec/unit/transaction/resource_harness_spec.rb +289 -208
- data/spec/unit/transaction_spec.rb +1 -6
- data/spec/unit/type/augeas_spec.rb +1 -3
- data/spec/unit/type/file/content_spec.rb +63 -10
- data/spec/unit/type/file/ctime.rb +35 -0
- data/spec/unit/type/file/ensure_spec.rb +8 -7
- data/spec/unit/type/file/group_spec.rb +5 -5
- data/spec/unit/type/file/mtime.rb +35 -0
- data/spec/unit/type/file/owner_spec.rb +7 -7
- data/spec/unit/type/file/selinux_spec.rb +2 -2
- data/spec/unit/type/file/source_spec.rb +3 -3
- data/spec/unit/type/file/type.rb +20 -0
- data/spec/unit/type/file_spec.rb +131 -8
- data/spec/unit/type/mount_spec.rb +4 -4
- data/spec/unit/type/package_spec.rb +3 -3
- data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
- data/spec/unit/type/user_spec.rb +31 -3
- data/spec/unit/type/zpool_spec.rb +12 -12
- data/spec/unit/type_spec.rb +2 -2
- data/spec/unit/util/checksums_spec.rb +9 -1
- data/spec/unit/util/command_line_spec.rb +29 -0
- data/spec/unit/util/log/destinations_spec.rb +13 -0
- data/spec/unit/util/log_spec.rb +24 -12
- data/spec/unit/util/logging_spec.rb +1 -1
- data/spec/unit/util/metric_spec.rb +7 -7
- data/spec/unit/util/pson_spec.rb +15 -0
- data/spec/unit/util/queue/stomp_spec.rb +2 -6
- data/spec/unit/util/settings/file_setting_spec.rb +1 -3
- data/spec/unit/util/zaml_spec.rb +51 -0
- data/test/language/snippets.rb +3 -0
- data/test/lib/puppettest/fileparsing.rb +2 -0
- data/test/lib/puppettest/reporttesting.rb +1 -1
- data/test/lib/puppettest/support/utils.rb +1 -1
- data/test/network/server/mongrel_test.rb +0 -6
- data/test/other/report.rb +1 -1
- data/test/ral/providers/cron/crontab.rb +4 -1
- data/test/ral/type/file.rb +1 -1
- data/test/ral/type/filesources.rb +1 -4
- metadata +1119 -1113
- data/lib/puppet/transaction/change.rb +0 -87
- data/spec/Rakefile +0 -91
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
- data/spec/spec_specs/runnable_spec.rb +0 -95
- data/spec/unit/transaction/change_spec.rb +0 -193
@@ -7,13 +7,16 @@ require 'digest/md5'
|
|
7
7
|
require 'digest/sha1'
|
8
8
|
|
9
9
|
describe Puppet::FileBucket::File do
|
10
|
+
include PuppetSpec::Files
|
11
|
+
|
10
12
|
before do
|
11
13
|
# this is the default from spec_helper, but it keeps getting reset at odd times
|
12
|
-
|
14
|
+
@bucketdir = tmpdir('bucket')
|
15
|
+
Puppet[:bucketdir] = @bucketdir
|
13
16
|
|
14
17
|
@digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
15
18
|
@checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
16
|
-
@dir = '
|
19
|
+
@dir = File.join(@bucketdir, '4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0')
|
17
20
|
|
18
21
|
@contents = "file contents"
|
19
22
|
end
|
@@ -22,17 +25,6 @@ describe Puppet::FileBucket::File do
|
|
22
25
|
Puppet::FileBucket::File.new(@contents).to_s.should == @contents
|
23
26
|
end
|
24
27
|
|
25
|
-
it "should calculate the checksum type from the passed in checksum" do
|
26
|
-
Puppet::FileBucket::File.new(@contents, :checksum => @checksum).checksum_type.should == "md5"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should allow contents to be specified in a block" do
|
30
|
-
bucket = Puppet::FileBucket::File.new(nil) do |fb|
|
31
|
-
fb.contents = "content"
|
32
|
-
end
|
33
|
-
bucket.contents.should == "content"
|
34
|
-
end
|
35
|
-
|
36
28
|
it "should raise an error if changing content" do
|
37
29
|
x = Puppet::FileBucket::File.new("first")
|
38
30
|
proc { x.contents = "new" }.should raise_error
|
@@ -42,14 +34,6 @@ describe Puppet::FileBucket::File do
|
|
42
34
|
proc { Puppet::FileBucket::File.new(5) }.should raise_error(ArgumentError)
|
43
35
|
end
|
44
36
|
|
45
|
-
it "should raise an error if setting contents to a non-string" do
|
46
|
-
proc do
|
47
|
-
Puppet::FileBucket::File.new(nil) do |x|
|
48
|
-
x.contents = 5
|
49
|
-
end
|
50
|
-
end.should raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
|
53
37
|
it "should set the contents appropriately" do
|
54
38
|
Puppet::FileBucket::File.new(@contents).contents.should == @contents
|
55
39
|
end
|
@@ -62,33 +46,6 @@ describe Puppet::FileBucket::File do
|
|
62
46
|
Puppet::FileBucket::File.new(@contents).checksum.should == @checksum
|
63
47
|
end
|
64
48
|
|
65
|
-
it "should remove the old checksum value if the algorithm is changed" do
|
66
|
-
sum = Puppet::FileBucket::File.new(@contents)
|
67
|
-
sum.checksum.should_not be_nil
|
68
|
-
|
69
|
-
newsum = Digest::SHA1.hexdigest(@contents).to_s
|
70
|
-
sum.checksum_type = :sha1
|
71
|
-
sum.checksum.should == "{sha1}#{newsum}"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should support specifying the checksum_type during initialization" do
|
75
|
-
sum = Puppet::FileBucket::File.new(@contents, :checksum_type => :sha1)
|
76
|
-
sum.checksum_type.should == :sha1
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should fail when an unsupported checksum_type is used" do
|
80
|
-
proc { Puppet::FileBucket::File.new(@contents, :checksum_type => :nope) }.should raise_error(ArgumentError)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should fail if given an checksum at initialization that does not match the contents" do
|
84
|
-
proc { Puppet::FileBucket::File.new(@contents, :checksum => "{md5}00000000000000000000000000000000") }.should raise_error(RuntimeError)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should fail if assigned a checksum that does not match the contents" do
|
88
|
-
bucket = Puppet::FileBucket::File.new(@contents)
|
89
|
-
proc { bucket.checksum = "{md5}00000000000000000000000000000000" }.should raise_error(RuntimeError)
|
90
|
-
end
|
91
|
-
|
92
49
|
describe "when using back-ends" do
|
93
50
|
it "should redirect using Puppet::Indirector" do
|
94
51
|
Puppet::Indirector::Indirection.instance(:file_bucket_file).model.should equal(Puppet::FileBucket::File)
|
@@ -107,50 +64,6 @@ describe Puppet::FileBucket::File do
|
|
107
64
|
end
|
108
65
|
end
|
109
66
|
|
110
|
-
describe "when saving files" do
|
111
|
-
it "should save the contents to the calculated path" do
|
112
|
-
::File.stubs(:directory?).with(@dir).returns(true)
|
113
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns false
|
114
|
-
|
115
|
-
mockfile = mock "file"
|
116
|
-
mockfile.expects(:print).with(@contents)
|
117
|
-
::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440).yields(mockfile)
|
118
|
-
|
119
|
-
Puppet::FileBucket::File.new(@contents).save
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should make any directories necessary for storage" do
|
123
|
-
FileUtils.expects(:mkdir_p).with do |arg|
|
124
|
-
::File.umask == 0007 and arg == @dir
|
125
|
-
end
|
126
|
-
::File.expects(:directory?).with(@dir).returns(false)
|
127
|
-
::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440)
|
128
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns false
|
129
|
-
|
130
|
-
Puppet::FileBucket::File.new(@contents).save
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should append the path to the paths file" do
|
134
|
-
remote_path = '/path/on/the/remote/box'
|
135
|
-
|
136
|
-
::File.expects(:directory?).with(@dir).returns(true)
|
137
|
-
::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440)
|
138
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns false
|
139
|
-
|
140
|
-
mockfile = mock "file"
|
141
|
-
mockfile.expects(:puts).with('/path/on/the/remote/box')
|
142
|
-
::File.expects(:exist?).with("#{@dir}/paths").returns false
|
143
|
-
::File.expects(:open).with("#{@dir}/paths", ::File::WRONLY|::File::CREAT|::File::APPEND).yields mockfile
|
144
|
-
Puppet::FileBucket::File.new(@contents, :path => remote_path).save
|
145
|
-
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should accept a path" do
|
150
|
-
remote_path = '/path/on/the/remote/box'
|
151
|
-
Puppet::FileBucket::File.new(@contents, :path => remote_path).path.should == remote_path
|
152
|
-
end
|
153
|
-
|
154
67
|
it "should return a url-ish name" do
|
155
68
|
Puppet::FileBucket::File.new(@contents).name.should == "md5/4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
156
69
|
end
|
@@ -160,18 +73,6 @@ describe Puppet::FileBucket::File do
|
|
160
73
|
lambda { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.should raise_error
|
161
74
|
end
|
162
75
|
|
163
|
-
it "should accept a url-ish name" do
|
164
|
-
bucket = Puppet::FileBucket::File.new(@contents)
|
165
|
-
lambda { bucket.name = "sha1/034fa2ed8e211e4d20f20e792d777f4a30af1a93/new/path" }.should_not raise_error
|
166
|
-
bucket.checksum_type.should == "sha1"
|
167
|
-
bucket.checksum_data.should == '034fa2ed8e211e4d20f20e792d777f4a30af1a93'
|
168
|
-
bucket.path.should == "new/path"
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should return a url-ish name with a path" do
|
172
|
-
Puppet::FileBucket::File.new(@contents, :path => 'my/path').name.should == "md5/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/my/path"
|
173
|
-
end
|
174
|
-
|
175
76
|
it "should convert the contents to PSON" do
|
176
77
|
Puppet::FileBucket::File.new(@contents).to_pson.should == '{"contents":"file contents"}'
|
177
78
|
end
|
@@ -180,47 +81,31 @@ describe Puppet::FileBucket::File do
|
|
180
81
|
Puppet::FileBucket::File.from_pson({"contents"=>"file contents"}).contents.should == "file contents"
|
181
82
|
end
|
182
83
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
::FileUtils.expects(:mkdir_p).with(@dir)
|
187
|
-
::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440)
|
188
|
-
|
189
|
-
bucketfile = Puppet::FileBucket::File.new(@contents)
|
190
|
-
bucketfile.save
|
191
|
-
|
84
|
+
def make_bucketed_file
|
85
|
+
FileUtils.mkdir_p(@dir)
|
86
|
+
File.open("#{@dir}/contents", 'w') { |f| f.write @contents }
|
192
87
|
end
|
193
88
|
|
194
89
|
describe "using the indirector's find method" do
|
195
90
|
it "should return nil if a file doesn't exist" do
|
196
|
-
::File.
|
197
|
-
|
198
|
-
bucketfile = Puppet::FileBucket::File.find("{md5}#{@digest}")
|
91
|
+
bucketfile = Puppet::FileBucket::File.find("md5/#{@digest}")
|
199
92
|
bucketfile.should == nil
|
200
93
|
end
|
201
94
|
|
202
95
|
it "should find a filebucket if the file exists" do
|
203
|
-
|
204
|
-
::File.
|
205
|
-
::File.expects(:read).with("#{@dir}/contents").returns @contents
|
206
|
-
|
207
|
-
bucketfile = Puppet::FileBucket::File.find("{md5}#{@digest}")
|
96
|
+
make_bucketed_file
|
97
|
+
bucketfile = Puppet::FileBucket::File.find("md5/#{@digest}")
|
208
98
|
bucketfile.should_not == nil
|
209
99
|
end
|
210
100
|
|
211
101
|
describe "using RESTish digest notation" do
|
212
102
|
it "should return nil if a file doesn't exist" do
|
213
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns false
|
214
|
-
|
215
103
|
bucketfile = Puppet::FileBucket::File.find("md5/#{@digest}")
|
216
104
|
bucketfile.should == nil
|
217
105
|
end
|
218
106
|
|
219
107
|
it "should find a filebucket if the file exists" do
|
220
|
-
|
221
|
-
::File.expects(:exist?).with("#{@dir}/paths").returns false
|
222
|
-
::File.expects(:read).with("#{@dir}/contents").returns @contents
|
223
|
-
|
108
|
+
make_bucketed_file
|
224
109
|
bucketfile = Puppet::FileBucket::File.find("md5/#{@digest}")
|
225
110
|
bucketfile.should_not == nil
|
226
111
|
end
|
@@ -306,6 +306,7 @@ end
|
|
306
306
|
describe Puppet::FileServing::Fileset, "when merging other filesets" do
|
307
307
|
before do
|
308
308
|
@paths = %w{/first/path /second/path /third/path}
|
309
|
+
File.stubs(:lstat).returns stub("stat", :directory? => false)
|
309
310
|
|
310
311
|
@filesets = @paths.collect do |path|
|
311
312
|
File.stubs(:lstat).with(path).returns stub("stat", :directory? => true)
|
@@ -230,8 +230,8 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do
|
|
230
230
|
@metadata.destination.should == "/path/to/link"
|
231
231
|
end
|
232
232
|
|
233
|
-
|
234
|
-
|
233
|
+
pending "should produce tab-separated mode, type, owner, group, and destination for xmlrpc" do
|
234
|
+
# "We'd like this to be true, but we need to always collect the checksum because in the server/client/server round trip we lose the distintion between manage and follow."
|
235
235
|
@metadata.attributes_with_tabs.should == "#{0755}\tlink\t10\t20\t/path/to/link"
|
236
236
|
end
|
237
237
|
|
@@ -255,8 +255,8 @@ describe Puppet::FileServing::Metadata, " when pointing to a link" do
|
|
255
255
|
@file.collect
|
256
256
|
@file.destination.should == "/some/other/path"
|
257
257
|
end
|
258
|
-
|
259
|
-
|
258
|
+
pending "should not collect the checksum if links are :manage" do
|
259
|
+
# We'd like this to be true, but we need to always collect the checksum because in the server/client/server round trip we lose the distintion between manage and follow.
|
260
260
|
@file.collect
|
261
261
|
@file.checksum.should be_nil
|
262
262
|
end
|
@@ -3,8 +3,26 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
4
4
|
|
5
5
|
|
6
|
-
describe "Puppet::Resource::Catalog::ActiveRecord" do
|
7
|
-
|
6
|
+
describe "Puppet::Resource::Catalog::ActiveRecord", :if => Puppet.features.rails? do
|
7
|
+
require 'puppet/rails'
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
class Tableless < ActiveRecord::Base
|
11
|
+
def self.columns
|
12
|
+
@columns ||= []
|
13
|
+
end
|
14
|
+
def self.column(name, sql_type=nil, default=nil, null=true)
|
15
|
+
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Host < Tableless
|
20
|
+
column :name, :string, :null => false
|
21
|
+
column :ip, :string
|
22
|
+
column :environment, :string
|
23
|
+
column :last_compile, :datetime
|
24
|
+
end
|
25
|
+
end
|
8
26
|
|
9
27
|
before do
|
10
28
|
require 'puppet/indirector/catalog/active_record'
|
@@ -76,15 +94,17 @@ describe "Puppet::Resource::Catalog::ActiveRecord" do
|
|
76
94
|
|
77
95
|
describe "when saving an instance" do
|
78
96
|
before do
|
79
|
-
@host =
|
97
|
+
@host = Host.new(:name => "foo")
|
98
|
+
@host.stubs(:merge_resources)
|
99
|
+
@host.stubs(:save)
|
80
100
|
@host.stubs(:railsmark).yields
|
81
101
|
|
82
|
-
@node =
|
83
|
-
Puppet::Node.stubs(:find).returns(@node)
|
102
|
+
@node = Puppet::Node.new("foo", :environment => "environment")
|
103
|
+
Puppet::Node.indirection.stubs(:find).with("foo").returns(@node)
|
84
104
|
|
85
105
|
Puppet::Rails::Host.stubs(:find_by_name).returns @host
|
86
106
|
@catalog = Puppet::Resource::Catalog.new("foo")
|
87
|
-
@request =
|
107
|
+
@request = Puppet::Indirector::Request.new(:active_record, :save, @catalog)
|
88
108
|
end
|
89
109
|
|
90
110
|
it "should find the Rails host with the same name" do
|
@@ -111,25 +131,21 @@ describe "Puppet::Resource::Catalog::ActiveRecord" do
|
|
111
131
|
it "should set host ip if we could find a matching node" do
|
112
132
|
@node.stubs(:parameters).returns({"ipaddress" => "192.168.0.1"})
|
113
133
|
|
114
|
-
@host.expects(:ip=).with '192.168.0.1'
|
115
|
-
|
116
134
|
@terminus.save(@request)
|
135
|
+
@host.ip.should == '192.168.0.1'
|
117
136
|
end
|
118
137
|
|
119
138
|
it "should set host environment if we could find a matching node" do
|
120
|
-
@node.stubs(:environment).returns("myenv")
|
121
|
-
|
122
|
-
@host.expects(:environment=).with 'myenv'
|
123
|
-
|
124
139
|
@terminus.save(@request)
|
140
|
+
@host.environment.should == "environment"
|
125
141
|
end
|
126
142
|
|
127
143
|
it "should set the last compile time on the host" do
|
128
144
|
now = Time.now
|
129
145
|
Time.expects(:now).returns now
|
130
|
-
@host.expects(:last_compile=).with now
|
131
146
|
|
132
147
|
@terminus.save(@request)
|
148
|
+
@host.last_compile.should == now
|
133
149
|
end
|
134
150
|
|
135
151
|
it "should save the Rails host instance" do
|
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
4
4
|
|
5
|
+
require 'puppet/rails'
|
5
6
|
require 'puppet/node/facts'
|
6
7
|
|
7
|
-
describe "Puppet::Node::Facts::ActiveRecord" do
|
8
|
-
confine "Missing Rails" => Puppet.features.rails?
|
9
|
-
|
8
|
+
describe "Puppet::Node::Facts::ActiveRecord", :if => Puppet.features.rails? do
|
10
9
|
before do
|
11
10
|
require 'puppet/indirector/facts/active_record'
|
12
11
|
Puppet.features.stubs(:rails?).returns true
|
@@ -4,8 +4,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
4
4
|
|
5
5
|
require 'puppet/node/facts'
|
6
6
|
|
7
|
-
describe "Puppet::Node::Facts::Couch" do
|
8
|
-
confine "couchrest gem is missing; cannot test couch terminus" => Puppet.features.couchdb?
|
7
|
+
describe "Puppet::Node::Facts::Couch", :if => Puppet.features.couchdb? do
|
9
8
|
require 'puppet/indirector/facts/couch' if Puppet.features.couchdb?
|
10
9
|
|
11
10
|
before do
|
@@ -5,6 +5,8 @@ require ::File.dirname(__FILE__) + '/../../../spec_helper'
|
|
5
5
|
require 'puppet/indirector/file_bucket_file/file'
|
6
6
|
|
7
7
|
describe Puppet::FileBucketFile::File do
|
8
|
+
include PuppetSpec::Files
|
9
|
+
|
8
10
|
it "should be a subclass of the Code terminus class" do
|
9
11
|
Puppet::FileBucketFile::File.superclass.should equal(Puppet::Indirector::Code)
|
10
12
|
end
|
@@ -13,194 +15,232 @@ describe Puppet::FileBucketFile::File do
|
|
13
15
|
Puppet::FileBucketFile::File.doc.should be_instance_of(String)
|
14
16
|
end
|
15
17
|
|
16
|
-
describe "
|
17
|
-
|
18
|
-
Puppet.settings.expects(:use).with(:filebucket)
|
19
|
-
Puppet::FileBucketFile::File.new
|
20
|
-
end
|
21
|
-
end
|
18
|
+
describe "non-stubbing tests" do
|
19
|
+
include PuppetSpec::Files
|
22
20
|
|
23
|
-
|
24
|
-
describe "the find_by_checksum method" do
|
25
21
|
before do
|
26
|
-
|
27
|
-
Puppet[:bucketdir] = "/dev/null/bucket"
|
28
|
-
|
29
|
-
@digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
30
|
-
@checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
31
|
-
@dir = '/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0'
|
32
|
-
|
33
|
-
@contents = "file contents"
|
22
|
+
Puppet[:bucketdir] = tmpdir('bucketdir')
|
34
23
|
end
|
35
24
|
|
36
|
-
|
37
|
-
::File.
|
38
|
-
|
39
|
-
|
40
|
-
bucketfile.should == nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should find a filebucket if the file exists" do
|
44
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns true
|
45
|
-
::File.expects(:exist?).with("#{@dir}/paths").returns false
|
46
|
-
::File.expects(:read).with("#{@dir}/contents").returns @contents
|
47
|
-
|
48
|
-
bucketfile = Puppet::FileBucketFile::File.new.send(:find_by_checksum, "{md5}#{@digest}", {})
|
49
|
-
bucketfile.should_not == nil
|
25
|
+
def save_bucket_file(contents, path = "/who_cares")
|
26
|
+
bucket_file = Puppet::FileBucket::File.new(contents)
|
27
|
+
bucket_file.save("md5/#{Digest::MD5.hexdigest(contents)}#{path}")
|
28
|
+
bucket_file.checksum_data
|
50
29
|
end
|
51
30
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
Puppet.stubs(:[]).with(:bucketdir).returns(@dir)
|
78
|
-
|
79
|
-
@contents_path = '/what/ever/7/0/9/2/4/d/6/f/70924d6fa4b2d745185fa4660703a5c0/contents'
|
80
|
-
@paths_path = '/what/ever/7/0/9/2/4/d/6/f/70924d6fa4b2d745185fa4660703a5c0/paths'
|
31
|
+
describe "when servicing a save request" do
|
32
|
+
describe "when supplying a path" do
|
33
|
+
it "should store the path if not already stored" do
|
34
|
+
checksum = save_bucket_file("stuff", "/foo/bar")
|
35
|
+
dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a"
|
36
|
+
File.read("#{dir_path}/contents").should == "stuff"
|
37
|
+
File.read("#{dir_path}/paths").should == "foo/bar\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should leave the paths file alone if the path is already stored" do
|
41
|
+
checksum = save_bucket_file("stuff", "/foo/bar")
|
42
|
+
checksum = save_bucket_file("stuff", "/foo/bar")
|
43
|
+
dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a"
|
44
|
+
File.read("#{dir_path}/contents").should == "stuff"
|
45
|
+
File.read("#{dir_path}/paths").should == "foo/bar\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should store an additional path if the new path differs from those already stored" do
|
49
|
+
checksum = save_bucket_file("stuff", "/foo/bar")
|
50
|
+
checksum = save_bucket_file("stuff", "/foo/baz")
|
51
|
+
dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a"
|
52
|
+
File.read("#{dir_path}/contents").should == "stuff"
|
53
|
+
File.read("#{dir_path}/paths").should == "foo/bar\nfoo/baz\n"
|
54
|
+
end
|
55
|
+
end
|
81
56
|
|
82
|
-
|
57
|
+
describe "when not supplying a path" do
|
58
|
+
it "should save the file and create an empty paths file" do
|
59
|
+
checksum = save_bucket_file("stuff", "")
|
60
|
+
dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a"
|
61
|
+
File.read("#{dir_path}/contents").should == "stuff"
|
62
|
+
File.read("#{dir_path}/paths").should == ""
|
63
|
+
end
|
64
|
+
end
|
83
65
|
end
|
84
66
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
67
|
+
describe "when servicing a head/find request" do
|
68
|
+
describe "when supplying a path" do
|
69
|
+
it "should return false/nil if the file isn't bucketed" do
|
70
|
+
Puppet::FileBucket::File.head("md5/0ae2ec1980410229885fe72f7b44fe55/foo/bar").should == false
|
71
|
+
Puppet::FileBucket::File.find("md5/0ae2ec1980410229885fe72f7b44fe55/foo/bar").should == nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return false/nil if the file is bucketed but with a different path" do
|
75
|
+
checksum = save_bucket_file("I'm the contents of a file", '/foo/bar')
|
76
|
+
Puppet::FileBucket::File.head("md5/#{checksum}/foo/baz").should == false
|
77
|
+
Puppet::FileBucket::File.find("md5/#{checksum}/foo/baz").should == nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return true/file if the file is already bucketed with the given path" do
|
81
|
+
contents = "I'm the contents of a file"
|
82
|
+
checksum = save_bucket_file(contents, '/foo/bar')
|
83
|
+
Puppet::FileBucket::File.head("md5/#{checksum}/foo/bar").should == true
|
84
|
+
find_result = Puppet::FileBucket::File.find("md5/#{checksum}/foo/bar")
|
85
|
+
find_result.should be_a(Puppet::FileBucket::File)
|
86
|
+
find_result.checksum.should == "{md5}#{checksum}"
|
87
|
+
find_result.to_s.should == contents
|
88
|
+
end
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
describe "when not supplying a path" do
|
92
|
+
[false, true].each do |trailing_slash|
|
93
|
+
describe "#{trailing_slash ? 'with' : 'without'} a trailing slash" do
|
94
|
+
trailing_string = trailing_slash ? '/' : ''
|
95
|
+
|
96
|
+
it "should return false/nil if the file isn't bucketed" do
|
97
|
+
Puppet::FileBucket::File.head("md5/0ae2ec1980410229885fe72f7b44fe55#{trailing_string}").should == false
|
98
|
+
Puppet::FileBucket::File.find("md5/0ae2ec1980410229885fe72f7b44fe55#{trailing_string}").should == nil
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return true/file if the file is already bucketed" do
|
102
|
+
contents = "I'm the contents of a file"
|
103
|
+
checksum = save_bucket_file(contents, '/foo/bar')
|
104
|
+
Puppet::FileBucket::File.head("md5/#{checksum}#{trailing_string}").should == true
|
105
|
+
find_result = Puppet::FileBucket::File.find("md5/#{checksum}#{trailing_string}")
|
106
|
+
find_result.should be_a(Puppet::FileBucket::File)
|
107
|
+
find_result.checksum.should == "{md5}#{checksum}"
|
108
|
+
find_result.to_s.should == contents
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
93
113
|
end
|
94
114
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
bucketfile.stubs(:checksum_data).returns(@digest)
|
101
|
-
bucketfile.stubs(:checksum).returns(@checksum)
|
102
|
-
|
103
|
-
bucketfile.expects(:contents=).with(content)
|
104
|
-
Puppet::FileBucket::File.expects(:new).with(nil, {:checksum => "{md5}#{@digest}"}).yields(bucketfile).returns(bucketfile)
|
105
|
-
|
106
|
-
::File.expects(:exist?).with(@contents_path).returns(true)
|
107
|
-
::File.expects(:exist?).with(@paths_path).returns(false)
|
108
|
-
::File.expects(:read).with(@contents_path).returns(content)
|
115
|
+
describe "when diffing files" do
|
116
|
+
it "should generate an empty string if there is no diff" do
|
117
|
+
checksum = save_bucket_file("I'm the contents of a file")
|
118
|
+
Puppet::FileBucket::File.find("md5/#{checksum}", :diff_with => checksum).should == ''
|
119
|
+
end
|
109
120
|
|
110
|
-
|
111
|
-
|
121
|
+
it "should generate a proper diff if there is a diff" do
|
122
|
+
checksum1 = save_bucket_file("foo\nbar\nbaz")
|
123
|
+
checksum2 = save_bucket_file("foo\nbiz\nbaz")
|
124
|
+
diff = Puppet::FileBucket::File.find("md5/#{checksum1}", :diff_with => checksum2)
|
125
|
+
diff.should == <<HERE
|
126
|
+
2c2
|
127
|
+
< bar
|
128
|
+
---
|
129
|
+
> biz
|
130
|
+
HERE
|
131
|
+
end
|
112
132
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
133
|
+
it "should raise an exception if the hash to diff against isn't found" do
|
134
|
+
checksum = save_bucket_file("whatever")
|
135
|
+
bogus_checksum = "d1bf072d0e2c6e20e3fbd23f022089a1"
|
136
|
+
lambda { Puppet::FileBucket::File.find("md5/#{checksum}", :diff_with => bogus_checksum) }.should raise_error "could not find diff_with #{bogus_checksum}"
|
137
|
+
end
|
117
138
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
139
|
+
it "should return nil if the hash to diff from isn't found" do
|
140
|
+
checksum = save_bucket_file("whatever")
|
141
|
+
bogus_checksum = "d1bf072d0e2c6e20e3fbd23f022089a1"
|
142
|
+
Puppet::FileBucket::File.find("md5/#{bogus_checksum}", :diff_with => checksum).should == nil
|
143
|
+
end
|
122
144
|
end
|
123
|
-
|
124
145
|
end
|
125
146
|
|
126
|
-
describe "when
|
127
|
-
|
128
|
-
Puppet
|
129
|
-
|
130
|
-
@bucket = stub_everything "bucket"
|
131
|
-
@bucket.expects(:checksum_data).returns(@digest)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should use the value of the :bucketdir setting as the root directory" do
|
135
|
-
path = Puppet::FileBucketFile::File.new.send(:contents_path_for, @bucket)
|
136
|
-
path.should =~ %r{^/dev/null/bucketdir}
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should choose a path 8 directories deep with each directory name being the respective character in the filebucket" do
|
140
|
-
path = Puppet::FileBucketFile::File.new.send(:contents_path_for, @bucket)
|
141
|
-
dirs = @digest[0..7].split("").join(File::SEPARATOR)
|
142
|
-
path.should be_include(dirs)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should use the full filebucket as the final directory name" do
|
146
|
-
path = Puppet::FileBucketFile::File.new.send(:contents_path_for, @bucket)
|
147
|
-
::File.basename(::File.dirname(path)).should == @digest
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should use 'contents' as the actual file name" do
|
151
|
-
path = Puppet::FileBucketFile::File.new.send(:contents_path_for, @bucket)
|
152
|
-
::File.basename(path).should == "contents"
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should use the bucketdir, the 8 sum character directories, the full filebucket, and 'contents' as the full file name" do
|
156
|
-
path = Puppet::FileBucketFile::File.new.send(:contents_path_for, @bucket)
|
157
|
-
path.should == ['/dev/null/bucketdir', @digest[0..7].split(""), @digest, "contents"].flatten.join(::File::SEPARATOR)
|
147
|
+
describe "when initializing" do
|
148
|
+
it "should use the filebucket settings section" do
|
149
|
+
Puppet.settings.expects(:use).with(:filebucket)
|
150
|
+
Puppet::FileBucketFile::File.new
|
158
151
|
end
|
159
152
|
end
|
160
153
|
|
161
|
-
describe "when saving files" do
|
162
|
-
before do
|
163
|
-
# this is the default from spec_helper, but it keeps getting reset at odd times
|
164
|
-
Puppet[:bucketdir] = "/dev/null/bucket"
|
165
|
-
|
166
|
-
@digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
167
|
-
@checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
|
168
|
-
@dir = '/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0'
|
169
|
-
|
170
|
-
@contents = "file contents"
|
171
154
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
155
|
+
[true, false].each do |override_bucket_path|
|
156
|
+
describe "when bucket path #{if override_bucket_path then 'is' else 'is not' end} overridden" do
|
157
|
+
[true, false].each do |supply_path|
|
158
|
+
describe "when #{supply_path ? 'supplying' : 'not supplying'} a path" do
|
159
|
+
before :each do
|
160
|
+
Puppet.settings.stubs(:use)
|
161
|
+
@store = Puppet::FileBucketFile::File.new
|
162
|
+
@contents = "my content"
|
163
|
+
|
164
|
+
@digest = "f2bfa7fc155c4f42cb91404198dda01f"
|
165
|
+
@digest.should == Digest::MD5.hexdigest(@contents)
|
166
|
+
|
167
|
+
@bucket_dir = tmpdir("bucket")
|
168
|
+
|
169
|
+
if override_bucket_path
|
170
|
+
Puppet[:bucketdir] = "/bogus/path" # should not be used
|
171
|
+
else
|
172
|
+
Puppet[:bucketdir] = @bucket_dir
|
173
|
+
end
|
174
|
+
|
175
|
+
@dir = "#{@bucket_dir}/f/2/b/f/a/7/f/c/f2bfa7fc155c4f42cb91404198dda01f"
|
176
|
+
@contents_path = "#{@dir}/contents"
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "when retrieving files" do
|
180
|
+
before :each do
|
181
|
+
|
182
|
+
request_options = {}
|
183
|
+
if override_bucket_path
|
184
|
+
request_options[:bucket_path] = @bucket_dir
|
185
|
+
end
|
186
|
+
|
187
|
+
key = "md5/#{@digest}"
|
188
|
+
if supply_path
|
189
|
+
key += "/path/to/file"
|
190
|
+
end
|
191
|
+
|
192
|
+
@request = Puppet::Indirector::Request.new(:indirection_name, :find, key, request_options)
|
193
|
+
end
|
194
|
+
|
195
|
+
def make_bucketed_file
|
196
|
+
FileUtils.mkdir_p(@dir)
|
197
|
+
File.open(@contents_path, 'w') { |f| f.write @contents }
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should return an instance of Puppet::FileBucket::File created with the content if the file exists" do
|
201
|
+
make_bucketed_file
|
202
|
+
|
203
|
+
if supply_path
|
204
|
+
@store.find(@request).should == nil
|
205
|
+
@store.head(@request).should == false # because path didn't match
|
206
|
+
else
|
207
|
+
bucketfile = @store.find(@request)
|
208
|
+
bucketfile.should be_a(Puppet::FileBucket::File)
|
209
|
+
bucketfile.contents.should == @contents
|
210
|
+
@store.head(@request).should == true
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should return nil if no file is found" do
|
215
|
+
@store.find(@request).should be_nil
|
216
|
+
@store.head(@request).should == false
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "when saving files" do
|
221
|
+
it "should save the contents to the calculated path" do
|
222
|
+
options = {}
|
223
|
+
if override_bucket_path
|
224
|
+
options[:bucket_path] = @bucket_dir
|
225
|
+
end
|
226
|
+
|
227
|
+
key = "md5/#{@digest}"
|
228
|
+
if supply_path
|
229
|
+
key += "//path/to/file"
|
230
|
+
end
|
231
|
+
|
232
|
+
file_instance = Puppet::FileBucket::File.new(@contents, options)
|
233
|
+
request = Puppet::Indirector::Request.new(:indirection_name, :save, key, file_instance)
|
234
|
+
|
235
|
+
@store.save(request)
|
236
|
+
File.read("#{@dir}/contents").should == @contents
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
194
240
|
end
|
195
|
-
::File.expects(:directory?).with(@dir).returns(false)
|
196
|
-
::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440)
|
197
|
-
::File.expects(:exist?).with("#{@dir}/contents").returns false
|
198
|
-
|
199
|
-
Puppet::FileBucketFile::File.new.send(:save_to_disk, @bucket)
|
200
241
|
end
|
201
242
|
end
|
202
243
|
|
203
|
-
|
204
244
|
describe "when verifying identical files" do
|
205
245
|
before do
|
206
246
|
# this is the default from spec_helper, but it keeps getting reset at odd times
|
@@ -231,60 +271,4 @@ describe Puppet::FileBucketFile::File do
|
|
231
271
|
end
|
232
272
|
|
233
273
|
end
|
234
|
-
|
235
|
-
|
236
|
-
describe "when writing to the paths file" do
|
237
|
-
before do
|
238
|
-
Puppet[:bucketdir] = '/dev/null/bucketdir'
|
239
|
-
@digest = '70924d6fa4b2d745185fa4660703a5c0'
|
240
|
-
@bucket = stub_everything "bucket"
|
241
|
-
|
242
|
-
@paths_path = '/dev/null/bucketdir/7/0/9/2/4/d/6/f/70924d6fa4b2d745185fa4660703a5c0/paths'
|
243
|
-
|
244
|
-
@paths = []
|
245
|
-
@bucket.stubs(:paths).returns(@paths)
|
246
|
-
@bucket.stubs(:checksum_data).returns(@digest)
|
247
|
-
end
|
248
|
-
|
249
|
-
it "should create a file if it doesn't exist" do
|
250
|
-
@bucket.expects(:path).returns('path/to/save').at_least_once
|
251
|
-
File.expects(:exist?).with(@paths_path).returns(false)
|
252
|
-
file = stub "file"
|
253
|
-
file.expects(:puts).with('path/to/save')
|
254
|
-
File.expects(:open).with(@paths_path, ::File::WRONLY|::File::CREAT|::File::APPEND).yields(file)
|
255
|
-
|
256
|
-
Puppet::FileBucketFile::File.new.send(:save_path_to_paths_file, @bucket)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should append to a file if it exists" do
|
260
|
-
@bucket.expects(:path).returns('path/to/save').at_least_once
|
261
|
-
File.expects(:exist?).with(@paths_path).returns(true)
|
262
|
-
old_file = stub "file"
|
263
|
-
old_file.stubs(:readlines).returns []
|
264
|
-
File.expects(:open).with(@paths_path).yields(old_file)
|
265
|
-
|
266
|
-
file = stub "file"
|
267
|
-
file.expects(:puts).with('path/to/save')
|
268
|
-
File.expects(:open).with(@paths_path, ::File::WRONLY|::File::CREAT|::File::APPEND).yields(file)
|
269
|
-
|
270
|
-
Puppet::FileBucketFile::File.new.send(:save_path_to_paths_file, @bucket)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should not alter a file if it already contains the path" do
|
274
|
-
@bucket.expects(:path).returns('path/to/save').at_least_once
|
275
|
-
File.expects(:exist?).with(@paths_path).returns(true)
|
276
|
-
old_file = stub "file"
|
277
|
-
old_file.stubs(:readlines).returns ["path/to/save\n"]
|
278
|
-
File.expects(:open).with(@paths_path).yields(old_file)
|
279
|
-
|
280
|
-
Puppet::FileBucketFile::File.new.send(:save_path_to_paths_file, @bucket)
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should do nothing if there is no path" do
|
284
|
-
@bucket.expects(:path).returns(nil).at_least_once
|
285
|
-
|
286
|
-
Puppet::FileBucketFile::File.new.send(:save_path_to_paths_file, @bucket)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
274
|
end
|