puppet 2.7.6 → 2.7.8

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.

Files changed (206) hide show
  1. data/CHANGELOG +168 -0
  2. data/conf/auth.conf +5 -4
  3. data/conf/redhat/puppet.spec +16 -1
  4. data/conf/solaris/pkginfo +2 -2
  5. data/conf/suse/puppet.spec +9 -3
  6. data/ext/upload_facts.rb +120 -0
  7. data/install.rb +11 -16
  8. data/lib/puppet.rb +1 -1
  9. data/lib/puppet/application/agent.rb +0 -3
  10. data/lib/puppet/application/apply.rb +0 -3
  11. data/lib/puppet/application/queue.rb +21 -1
  12. data/lib/puppet/defaults.rb +6 -4
  13. data/lib/puppet/face/file/store.rb +1 -1
  14. data/lib/puppet/feature/base.rb +2 -1
  15. data/lib/puppet/file_bucket/dipper.rb +3 -2
  16. data/lib/puppet/file_serving/content.rb +1 -1
  17. data/lib/puppet/file_serving/metadata.rb +5 -2
  18. data/lib/puppet/indirector/facts/inventory_service.rb +20 -0
  19. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -2
  20. data/lib/puppet/indirector/report/processor.rb +1 -1
  21. data/lib/puppet/network/handler/filebucket.rb +2 -0
  22. data/lib/puppet/network/handler/fileserver.rb +1 -1
  23. data/lib/puppet/network/handler/master.rb +1 -0
  24. data/lib/puppet/network/handler/report.rb +2 -0
  25. data/lib/puppet/network/handler/runner.rb +1 -0
  26. data/lib/puppet/network/handler/status.rb +2 -0
  27. data/lib/puppet/network/http/mongrel/rest.rb +8 -1
  28. data/lib/puppet/network/http_server.rb +3 -0
  29. data/lib/puppet/network/http_server/mongrel.rb +129 -0
  30. data/lib/puppet/network/rest_authconfig.rb +12 -4
  31. data/lib/puppet/parameter.rb +18 -0
  32. data/lib/puppet/parser/compiler.rb +1 -1
  33. data/lib/puppet/parser/grammar.ra +1 -1
  34. data/lib/puppet/parser/parser.rb +360 -350
  35. data/lib/puppet/property.rb +3 -3
  36. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  37. data/lib/puppet/provider/exec/windows.rb +6 -7
  38. data/lib/puppet/provider/file/windows.rb +9 -2
  39. data/lib/puppet/provider/group/aix.rb +8 -8
  40. data/lib/puppet/provider/group/groupadd.rb +1 -3
  41. data/lib/puppet/provider/group/ldap.rb +8 -10
  42. data/lib/puppet/provider/group/windows_adsi.rb +8 -2
  43. data/lib/puppet/provider/package/aix.rb +1 -1
  44. data/lib/puppet/provider/package/macports.rb +3 -3
  45. data/lib/puppet/provider/package/msi.rb +12 -5
  46. data/lib/puppet/provider/package/nim.rb +1 -1
  47. data/lib/puppet/provider/package/pkgdmg.rb +3 -3
  48. data/lib/puppet/provider/package/ports.rb +1 -1
  49. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +560 -0
  50. data/lib/puppet/provider/service/base.rb +2 -2
  51. data/lib/puppet/provider/service/bsd.rb +4 -3
  52. data/lib/puppet/provider/service/daemontools.rb +25 -25
  53. data/lib/puppet/provider/service/debian.rb +6 -4
  54. data/lib/puppet/provider/service/freebsd.rb +1 -1
  55. data/lib/puppet/provider/service/gentoo.rb +4 -3
  56. data/lib/puppet/provider/service/init.rb +3 -8
  57. data/lib/puppet/provider/service/launchd.rb +129 -96
  58. data/lib/puppet/provider/service/redhat.rb +2 -3
  59. data/lib/puppet/provider/service/runit.rb +20 -20
  60. data/lib/puppet/provider/service/smf.rb +8 -7
  61. data/lib/puppet/provider/service/src.rb +5 -6
  62. data/lib/puppet/provider/service/systemd.rb +1 -1
  63. data/lib/puppet/provider/service/upstart.rb +3 -5
  64. data/lib/puppet/provider/service/windows.rb +7 -7
  65. data/lib/puppet/provider/sshkey/parsed.rb +2 -3
  66. data/lib/puppet/provider/user/aix.rb +21 -21
  67. data/lib/puppet/provider/user/hpux.rb +3 -1
  68. data/lib/puppet/provider/user/ldap.rb +7 -7
  69. data/lib/puppet/provider/user/user_role_add.rb +10 -6
  70. data/lib/puppet/provider/user/useradd.rb +3 -1
  71. data/lib/puppet/provider/user/windows_adsi.rb +4 -3
  72. data/lib/puppet/rb_tree_map.rb +388 -0
  73. data/lib/puppet/reference/configuration.rb +7 -7
  74. data/lib/puppet/reference/indirection.rb +5 -6
  75. data/lib/puppet/reference/metaparameter.rb +3 -1
  76. data/lib/puppet/reference/network.rb +8 -8
  77. data/lib/puppet/reference/providers.rb +17 -21
  78. data/lib/puppet/reference/type.rb +12 -9
  79. data/lib/puppet/resource.rb +2 -5
  80. data/lib/puppet/resource/catalog.rb +1 -1
  81. data/lib/puppet/ssl/certificate_request.rb +70 -0
  82. data/lib/puppet/ssl/host.rb +6 -0
  83. data/lib/puppet/transaction.rb +158 -55
  84. data/lib/puppet/transaction/event_manager.rb +1 -1
  85. data/lib/puppet/type.rb +60 -30
  86. data/lib/puppet/type/augeas.rb +83 -49
  87. data/lib/puppet/type/computer.rb +1 -1
  88. data/lib/puppet/type/cron.rb +11 -11
  89. data/lib/puppet/type/exec.rb +28 -21
  90. data/lib/puppet/type/file.rb +17 -7
  91. data/lib/puppet/type/file/content.rb +2 -2
  92. data/lib/puppet/type/file/ensure.rb +15 -12
  93. data/lib/puppet/type/file/mode.rb +30 -5
  94. data/lib/puppet/type/file/source.rb +11 -10
  95. data/lib/puppet/type/file/target.rb +2 -2
  96. data/lib/puppet/type/filebucket.rb +1 -1
  97. data/lib/puppet/type/group.rb +4 -5
  98. data/lib/puppet/type/host.rb +1 -1
  99. data/lib/puppet/type/interface.rb +13 -10
  100. data/lib/puppet/type/k5login.rb +6 -6
  101. data/lib/puppet/type/macauthorization.rb +37 -36
  102. data/lib/puppet/type/maillist.rb +2 -2
  103. data/lib/puppet/type/mcx.rb +6 -6
  104. data/lib/puppet/type/mount.rb +3 -2
  105. data/lib/puppet/type/notify.rb +1 -1
  106. data/lib/puppet/type/package.rb +24 -23
  107. data/lib/puppet/type/router.rb +4 -1
  108. data/lib/puppet/type/schedule.rb +52 -44
  109. data/lib/puppet/type/scheduled_task.rb +222 -0
  110. data/lib/puppet/type/selmodule.rb +10 -6
  111. data/lib/puppet/type/service.rb +11 -11
  112. data/lib/puppet/type/ssh_authorized_key.rb +2 -5
  113. data/lib/puppet/type/sshkey.rb +1 -1
  114. data/lib/puppet/type/stage.rb +1 -1
  115. data/lib/puppet/type/tidy.rb +10 -8
  116. data/lib/puppet/type/user.rb +61 -53
  117. data/lib/puppet/type/vlan.rb +4 -4
  118. data/lib/puppet/type/whit.rb +6 -2
  119. data/lib/puppet/type/yumrepo.rb +33 -31
  120. data/lib/puppet/type/zfs.rb +34 -32
  121. data/lib/puppet/type/zone.rb +21 -19
  122. data/lib/puppet/type/zpool.rb +3 -3
  123. data/lib/puppet/util.rb +24 -6
  124. data/lib/puppet/util/adsi.rb +12 -7
  125. data/lib/puppet/util/checksums.rb +1 -1
  126. data/lib/puppet/util/diff.rb +1 -1
  127. data/lib/puppet/util/nagios_maker.rb +2 -2
  128. data/lib/puppet/util/reference.rb +16 -17
  129. data/lib/puppet/util/settings/file_setting.rb +14 -2
  130. data/lib/puppet/util/windows/security.rb +96 -32
  131. data/spec/integration/file_serving/terminus_helper_spec.rb +1 -1
  132. data/spec/integration/indirector/direct_file_server_spec.rb +9 -15
  133. data/spec/integration/indirector/file_content/file_server_spec.rb +1 -1
  134. data/spec/integration/indirector/file_metadata/file_server_spec.rb +1 -1
  135. data/spec/integration/provider/package_spec.rb +4 -0
  136. data/spec/integration/provider/service/init_spec.rb +8 -2
  137. data/spec/integration/reference/providers_spec.rb +1 -1
  138. data/spec/integration/ssl/certificate_request_spec.rb +1 -2
  139. data/spec/integration/ssl/certificate_revocation_list_spec.rb +1 -2
  140. data/spec/integration/ssl/host_spec.rb +1 -2
  141. data/spec/integration/transaction_spec.rb +25 -17
  142. data/spec/integration/type/exec_spec.rb +77 -0
  143. data/spec/integration/type/file_spec.rb +322 -2
  144. data/spec/integration/util/windows/security_spec.rb +393 -230
  145. data/spec/integration/util_spec.rb +16 -0
  146. data/spec/lib/puppet_spec/files.rb +3 -7
  147. data/spec/unit/application/apply_spec.rb +0 -9
  148. data/spec/unit/application/inspect_spec.rb +1 -0
  149. data/spec/unit/configurer/downloader_spec.rb +3 -3
  150. data/spec/unit/face/certificate_spec.rb +6 -2
  151. data/spec/unit/file_bucket/dipper_spec.rb +67 -10
  152. data/spec/unit/file_bucket/file_spec.rb +22 -28
  153. data/spec/unit/file_serving/content_spec.rb +1 -1
  154. data/spec/unit/file_serving/metadata_spec.rb +30 -3
  155. data/spec/unit/indirector/facts/inventory_service_spec.rb +22 -0
  156. data/spec/unit/indirector/file_bucket_file/file_spec.rb +21 -24
  157. data/spec/unit/indirector/node/store_configs_spec.rb +1 -0
  158. data/spec/unit/indirector/resource/ral_spec.rb +1 -1
  159. data/spec/unit/indirector/resource_type/parser_spec.rb +2 -2
  160. data/spec/unit/indirector/rest_spec.rb +1 -1
  161. data/spec/unit/network/handler/ca_spec.rb +1 -1
  162. data/spec/unit/network/http/mongrel/rest_spec.rb +54 -25
  163. data/spec/unit/parameter_spec.rb +36 -0
  164. data/spec/unit/parser/parser_spec.rb +4 -0
  165. data/spec/unit/property_spec.rb +2 -2
  166. data/spec/unit/provider/exec/windows_spec.rb +2 -8
  167. data/spec/unit/provider/file/posix_spec.rb +6 -0
  168. data/spec/unit/provider/file/windows_spec.rb +18 -0
  169. data/spec/unit/provider/group/windows_adsi_spec.rb +22 -6
  170. data/spec/unit/provider/mount/parsed_spec.rb +1 -1
  171. data/spec/unit/provider/package/msi_spec.rb +2 -2
  172. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +1571 -0
  173. data/spec/unit/provider/service/launchd_spec.rb +143 -130
  174. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +5 -0
  175. data/spec/unit/provider/user/user_role_add_spec.rb +39 -9
  176. data/spec/unit/provider/user/useradd_spec.rb +1 -1
  177. data/spec/unit/provider/user/windows_adsi_spec.rb +8 -1
  178. data/spec/unit/rb_tree_map_spec.rb +572 -0
  179. data/spec/unit/resource/catalog_spec.rb +1 -1
  180. data/spec/unit/simple_graph_spec.rb +9 -9
  181. data/spec/unit/ssl/host_spec.rb +60 -12
  182. data/spec/unit/transaction/report_spec.rb +3 -3
  183. data/spec/unit/transaction_spec.rb +394 -11
  184. data/spec/unit/type/exec_spec.rb +35 -15
  185. data/spec/unit/type/file/content_spec.rb +11 -10
  186. data/spec/unit/type/file/mode_spec.rb +73 -19
  187. data/spec/unit/type/file/source_spec.rb +1 -1
  188. data/spec/unit/type/file_spec.rb +15 -0
  189. data/spec/unit/type/group_spec.rb +1 -1
  190. data/spec/unit/type/mount_spec.rb +5 -5
  191. data/spec/unit/type/resources_spec.rb +3 -3
  192. data/spec/unit/type/scheduled_task_spec.rb +102 -0
  193. data/spec/unit/type/ssh_authorized_key_spec.rb +2 -3
  194. data/spec/unit/type/user_spec.rb +2 -1
  195. data/spec/unit/type_spec.rb +48 -4
  196. data/spec/unit/util/adsi_spec.rb +18 -7
  197. data/spec/unit/util/checksums_spec.rb +20 -2
  198. data/spec/unit/util/execution_stub_spec.rb +10 -5
  199. data/spec/unit/util/logging_spec.rb +6 -6
  200. data/spec/unit/util/rdoc/parser_spec.rb +1 -1
  201. data/spec/unit/util/reference_spec.rb +29 -0
  202. data/spec/unit/util/settings/file_setting_spec.rb +8 -2
  203. data/spec/unit/util_spec.rb +115 -0
  204. data/test/other/transactions.rb +5 -11
  205. data/test/ral/type/exec.rb +1 -1
  206. metadata +24 -11
@@ -9,5 +9,21 @@ describe Puppet::Util do
9
9
 
10
10
  Puppet::Util.execute(command, :combine => true).split.should =~ [*'1'..'10']
11
11
  end
12
+
13
+ it "should return output and set $CHILD_STATUS" do
14
+ command = "ruby -e 'puts \"foo\"; exit 42'"
15
+
16
+ output = Puppet::Util.execute(command, {:failonfail => false})
17
+
18
+ output.should == "foo\n"
19
+ $CHILD_STATUS.exitstatus.should == 42
20
+ end
21
+
22
+ it "should raise an error if non-zero exit status is returned" do
23
+ command = "ruby -e 'exit 43'"
24
+
25
+ expect { Puppet::Util.execute(command) }.to raise_error(Puppet::ExecutionFailure, /Execution of '#{command}' returned 43: /)
26
+ $CHILD_STATUS.exitstatus.should == 43
27
+ end
12
28
  end
13
29
  end
@@ -30,13 +30,9 @@ module PuppetSpec::Files
30
30
  end
31
31
 
32
32
  def make_absolute(path)
33
- return path unless Puppet.features.microsoft_windows?
34
- # REMIND UNC
35
- return path if path =~ /^[A-Za-z]:/
36
-
37
- pwd = Dir.getwd
38
- return "#{pwd[0,2]}#{path}" if pwd =~ /^[A-Za-z]:/
39
- return "C:#{path}"
33
+ path = File.expand_path(path)
34
+ path[0] = 'c' if Puppet.features.microsoft_windows?
35
+ path
40
36
  end
41
37
 
42
38
  def tmpfile(name)
@@ -66,15 +66,6 @@ describe Puppet::Application::Apply do
66
66
  @apply.options.stubs(:[]).with(any_parameters)
67
67
  end
68
68
 
69
- it "should set show_diff on --noop" do
70
- Puppet[:noop] = true
71
- Puppet[:show_diff] = false
72
-
73
- @apply.setup
74
-
75
- Puppet[:show_diff].should == true
76
- end
77
-
78
69
  it "should set console as the log destination if logdest option wasn't provided" do
79
70
  Puppet::Log.expects(:newdestination).with(:console)
80
71
 
@@ -57,6 +57,7 @@ describe Puppet::Application::Inspect do
57
57
  it "should audit the specified properties" do
58
58
  catalog = Puppet::Resource::Catalog.new
59
59
  file = Tempfile.new("foo")
60
+ file.binmode
60
61
  file.puts("file contents")
61
62
  file.close
62
63
  resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
@@ -97,8 +97,8 @@ describe Puppet::Configurer::Downloader do
97
97
 
98
98
  describe "when creating the catalog to do the downloading" do
99
99
  before do
100
- @path = File.expand_path("/download/path")
101
- @dler = Puppet::Configurer::Downloader.new("foo", @path, File.expand_path("source"))
100
+ @path = make_absolute("/download/path")
101
+ @dler = Puppet::Configurer::Downloader.new("foo", @path, make_absolute("source"))
102
102
  end
103
103
 
104
104
  it "should create a catalog and add the file to it" do
@@ -122,7 +122,7 @@ describe Puppet::Configurer::Downloader do
122
122
  @dler = Puppet::Configurer::Downloader.new("foo", @dl_name, source_name)
123
123
  end
124
124
 
125
- it "should not skip downloaded resources when filtering on tags", :fails_on_windows => true do
125
+ it "should not skip downloaded resources when filtering on tags" do
126
126
  Puppet[:tags] = 'maytag'
127
127
  @dler.evaluate
128
128
 
@@ -57,6 +57,10 @@ describe Puppet::Face[:certificate, '0.0.1'] do
57
57
  let(:host) { Puppet::SSL::Host.new(hostname) }
58
58
  let(:csr) { host.certificate_request }
59
59
 
60
+ before :each do
61
+ Puppet[:autosign] = false
62
+ end
63
+
60
64
  describe "for the current host" do
61
65
  let(:hostname) { Puppet[:certname] }
62
66
 
@@ -131,7 +135,7 @@ describe Puppet::Face[:certificate, '0.0.1'] do
131
135
  let(:host) { Puppet::SSL::Host.new(hostname) }
132
136
  let(:hostname) { "foobar" }
133
137
 
134
- it "should sign the certificate request if one is waiting" do
138
+ it "should sign the certificate request if one is waiting", :unless => Puppet.features.microsoft_windows? do
135
139
  subject.generate(hostname, options)
136
140
 
137
141
  subject.sign(hostname, options)
@@ -147,7 +151,7 @@ describe Puppet::Face[:certificate, '0.0.1'] do
147
151
  end.to raise_error(ArgumentError, /Could not find certificate request for #{hostname}/)
148
152
  end
149
153
 
150
- describe "when ca_location is local" do
154
+ describe "when ca_location is local", :unless => Puppet.features.microsoft_windows? do
151
155
  describe "when the request has dns alt names" do
152
156
  before :each do
153
157
  subject.generate(hostname, options.merge(:dns_alt_names => 'some,alt,names'))
@@ -11,7 +11,7 @@ describe Puppet::FileBucket::Dipper do
11
11
 
12
12
  def make_tmp_file(contents)
13
13
  file = tmpfile("file_bucket_file")
14
- File.open(file, 'w') { |f| f.write(contents) }
14
+ File.open(file, 'wb') { |f| f.write(contents) }
15
15
  file
16
16
  end
17
17
 
@@ -34,25 +34,25 @@ describe Puppet::FileBucket::Dipper do
34
34
  lambda { @dipper.backup(file) }.should raise_error(Puppet::Error)
35
35
  end
36
36
 
37
- it "should backup files to a local bucket", :fails_on_windows => true do
37
+ it "should backup files to a local bucket" do
38
38
  Puppet[:bucketdir] = "/non/existent/directory"
39
39
  file_bucket = tmpdir("bucket")
40
40
 
41
41
  @dipper = Puppet::FileBucket::Dipper.new(:Path => file_bucket)
42
42
 
43
- file = make_tmp_file('my contents')
44
- checksum = "2975f560750e71c478b8e3b39a956adb"
45
- Digest::MD5.hexdigest('my contents').should == checksum
43
+ file = make_tmp_file("my\r\ncontents")
44
+ checksum = "f0d7d4e480ad698ed56aeec8b6bd6dea"
45
+ Digest::MD5.hexdigest("my\r\ncontents").should == checksum
46
46
 
47
47
  @dipper.backup(file).should == checksum
48
- File.exists?("#{file_bucket}/2/9/7/5/f/5/6/0/2975f560750e71c478b8e3b39a956adb/contents").should == true
48
+ File.exists?("#{file_bucket}/f/0/d/7/d/4/e/4/f0d7d4e480ad698ed56aeec8b6bd6dea/contents").should == true
49
49
  end
50
50
 
51
51
  it "should not backup a file that is already in the bucket" do
52
52
  @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
53
53
 
54
- file = make_tmp_file('my contents')
55
- checksum = Digest::MD5.hexdigest('my contents')
54
+ file = make_tmp_file("my\r\ncontents")
55
+ checksum = Digest::MD5.hexdigest("my\r\ncontents")
56
56
 
57
57
  Puppet::FileBucket::File.indirection.expects(:head).returns true
58
58
  Puppet::FileBucket::File.indirection.expects(:save).never
@@ -76,8 +76,8 @@ describe Puppet::FileBucket::Dipper do
76
76
  it "should backup files to a remote server" do
77
77
  @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
78
78
 
79
- file = make_tmp_file('my contents')
80
- checksum = Digest::MD5.hexdigest('my contents')
79
+ file = make_tmp_file("my\r\ncontents")
80
+ checksum = Digest::MD5.hexdigest("my\r\ncontents")
81
81
 
82
82
  real_path = Pathname.new(file).realpath
83
83
 
@@ -110,4 +110,61 @@ describe Puppet::FileBucket::Dipper do
110
110
  request.port.should == 31337
111
111
  request.key.should == "md5/#{checksum}"
112
112
  end
113
+
114
+ describe "#restore" do
115
+ shared_examples_for "a restorable file" do
116
+ let(:contents) { "my\ncontents" }
117
+ let(:md5) { Digest::MD5.hexdigest(contents) }
118
+ let(:dest) { tmpfile('file_bucket_dest') }
119
+
120
+ it "should restore the file" do
121
+ request = nil
122
+
123
+ klass.any_instance.expects(:find).with { |r| request = r }.returns(Puppet::FileBucket::File.new(contents))
124
+
125
+ dipper.restore(dest, md5).should == md5
126
+ Digest::MD5.file(dest).hexdigest.should == md5
127
+
128
+ request.key.should == "md5/#{md5}"
129
+ request.server.should == server
130
+ request.port.should == port
131
+ end
132
+
133
+ it "should skip restoring if existing file has the same checksum" do
134
+ crnl = "my\r\ncontents"
135
+ File.open(dest, 'wb') {|f| f.print(crnl) }
136
+
137
+ dipper.expects(:getfile).never
138
+ dipper.restore(dest, Digest::MD5.hexdigest(crnl)).should be_nil
139
+ end
140
+
141
+ it "should overwrite existing file if it has different checksum" do
142
+ klass.any_instance.expects(:find).returns(Puppet::FileBucket::File.new(contents))
143
+
144
+ File.open(dest, 'wb') {|f| f.print('other contents') }
145
+
146
+ dipper.restore(dest, md5).should == md5
147
+ end
148
+ end
149
+
150
+ describe "when restoring from a remote server" do
151
+ let(:klass) { Puppet::FileBucketFile::Rest }
152
+ let(:server) { "puppetmaster" }
153
+ let(:port) { 31337 }
154
+
155
+ it_behaves_like "a restorable file" do
156
+ let (:dipper) { Puppet::FileBucket::Dipper.new(:Server => server, :Port => port.to_s) }
157
+ end
158
+ end
159
+
160
+ describe "when restoring from a local server" do
161
+ let(:klass) { Puppet::FileBucketFile::File }
162
+ let(:server) { nil }
163
+ let(:port) { nil }
164
+
165
+ it_behaves_like "a restorable file" do
166
+ let (:dipper) { Puppet::FileBucket::Dipper.new(:Path => "/my/bucket") }
167
+ end
168
+ end
169
+ end
113
170
  end
@@ -8,20 +8,15 @@ require 'digest/sha1'
8
8
  describe Puppet::FileBucket::File do
9
9
  include PuppetSpec::Files
10
10
 
11
- before do
12
- # this is the default from spec_helper, but it keeps getting reset at odd times
13
- @bucketdir = tmpdir('bucket')
14
- Puppet[:bucketdir] = @bucketdir
15
-
16
- @digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
17
- @checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
18
- @dir = File.join(@bucketdir, '4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0')
19
-
20
- @contents = "file contents"
21
- end
11
+ let(:contents) { "file\r\n contents" }
12
+ let(:digest) { "8b3702ad1aed1ace7e32bde76ffffb2d" }
13
+ let(:checksum) { "{md5}#{digest}" }
14
+ # this is the default from spec_helper, but it keeps getting reset at odd times
15
+ let(:bucketdir) { Puppet[:bucketdir] = tmpdir('bucket') }
16
+ let(:destdir) { File.join(bucketdir, "8/b/3/7/0/2/a/d/#{digest}") }
22
17
 
23
18
  it "should have a to_s method to return the contents" do
24
- Puppet::FileBucket::File.new(@contents).to_s.should == @contents
19
+ Puppet::FileBucket::File.new(contents).to_s.should == contents
25
20
  end
26
21
 
27
22
  it "should raise an error if changing content" do
@@ -40,15 +35,15 @@ describe Puppet::FileBucket::File do
40
35
  end
41
36
 
42
37
  it "should set the contents appropriately" do
43
- Puppet::FileBucket::File.new(@contents).contents.should == @contents
38
+ Puppet::FileBucket::File.new(contents).contents.should == contents
44
39
  end
45
40
 
46
41
  it "should default to 'md5' as the checksum algorithm if the algorithm is not in the name" do
47
- Puppet::FileBucket::File.new(@contents).checksum_type.should == "md5"
42
+ Puppet::FileBucket::File.new(contents).checksum_type.should == "md5"
48
43
  end
49
44
 
50
45
  it "should calculate the checksum" do
51
- Puppet::FileBucket::File.new(@contents).checksum.should == @checksum
46
+ Puppet::FileBucket::File.new(contents).checksum.should == checksum
52
47
  end
53
48
 
54
49
  describe "when using back-ends" do
@@ -62,16 +57,16 @@ describe Puppet::FileBucket::File do
62
57
  end
63
58
 
64
59
  it "should return a url-ish name" do
65
- Puppet::FileBucket::File.new(@contents).name.should == "md5/4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
60
+ Puppet::FileBucket::File.new(contents).name.should == "md5/#{digest}"
66
61
  end
67
62
 
68
63
  it "should reject a url-ish name with an invalid checksum" do
69
- bucket = Puppet::FileBucket::File.new(@contents)
70
- expect { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.to raise_error(NoMethodError, /undefined method .name=/)
64
+ bucket = Puppet::FileBucket::File.new(contents)
65
+ expect { bucket.name = "sha1/ae548c0cd614fb7885aaa0b6cb191c34/new/path" }.to raise_error(NoMethodError, /undefined method .name=/)
71
66
  end
72
67
 
73
68
  it "should convert the contents to PSON" do
74
- Puppet::FileBucket::File.new(@contents).to_pson.should == '{"contents":"file contents"}'
69
+ Puppet::FileBucket::File.new("file contents").to_pson.should == '{"contents":"file contents"}'
75
70
  end
76
71
 
77
72
  it "should load from PSON" do
@@ -79,34 +74,33 @@ describe Puppet::FileBucket::File do
79
74
  end
80
75
 
81
76
  def make_bucketed_file
82
- FileUtils.mkdir_p(@dir)
83
- File.open("#{@dir}/contents", 'w') { |f| f.write @contents }
77
+ FileUtils.mkdir_p(destdir)
78
+ File.open("#{destdir}/contents", 'wb') { |f| f.write contents }
84
79
  end
85
80
 
86
81
  describe "using the indirector's find method" do
87
82
  it "should return nil if a file doesn't exist" do
88
- bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{@digest}")
83
+ bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{digest}")
89
84
  bucketfile.should == nil
90
85
  end
91
86
 
92
87
  it "should find a filebucket if the file exists" do
93
88
  make_bucketed_file
94
- bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{@digest}")
95
- bucketfile.should_not == nil
89
+ bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{digest}")
90
+ bucketfile.checksum.should == checksum
96
91
  end
97
92
 
98
93
  describe "using RESTish digest notation" do
99
94
  it "should return nil if a file doesn't exist" do
100
- bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{@digest}")
95
+ bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{digest}")
101
96
  bucketfile.should == nil
102
97
  end
103
98
 
104
99
  it "should find a filebucket if the file exists" do
105
100
  make_bucketed_file
106
- bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{@digest}")
107
- bucketfile.should_not == nil
101
+ bucketfile = Puppet::FileBucket::File.indirection.find("md5/#{digest}")
102
+ bucketfile.checksum.should == checksum
108
103
  end
109
-
110
104
  end
111
105
  end
112
106
  end
@@ -73,7 +73,7 @@ describe Puppet::FileServing::Content do
73
73
  it "should return an opened File when converted to raw" do
74
74
  content = Puppet::FileServing::Content.new("/path")
75
75
 
76
- File.expects(:new).with("/path","r").returns :file
76
+ File.expects(:new).with("/path","rb").returns :file
77
77
 
78
78
  content.to_raw.should == :file
79
79
  end
@@ -139,7 +139,7 @@ describe Puppet::FileServing::Metadata do
139
139
  let(:checksum) { Digest::MD5.hexdigest("some content\n") }
140
140
 
141
141
  before :each do
142
- File.open(path, "w") {|f| f.print("some content\n")}
142
+ File.open(path, "wb") {|f| f.print("some content\n")}
143
143
  end
144
144
 
145
145
  it "should default to a checksum of type MD5 with the file's current checksum" do
@@ -198,7 +198,7 @@ describe Puppet::FileServing::Metadata do
198
198
  let(:fmode) { File.lstat(path).mode & 0777 }
199
199
 
200
200
  before :each do
201
- File.open(target, "w") {|f| f.print("some content\n")}
201
+ File.open(target, "wb") {|f| f.print("some content\n")}
202
202
  set_mode(0644, target)
203
203
 
204
204
  FileUtils.symlink(target, path)
@@ -223,7 +223,7 @@ describe Puppet::FileServing::Metadata do
223
223
  let(:path) { tmpfile('file_serving_metadata_find_file') }
224
224
 
225
225
  before :each do
226
- File.open(path, "w") {|f| f.print("some content\n")}
226
+ File.open(path, "wb") {|f| f.print("some content\n")}
227
227
  set_mode(0755, path)
228
228
  end
229
229
 
@@ -277,6 +277,33 @@ describe Puppet::FileServing::Metadata do
277
277
 
278
278
  it_should_behave_like "metadata collector"
279
279
 
280
+ describe "if ACL metadata cannot be collected" do
281
+ let(:path) { tmpdir('file_serving_metadata_acl') }
282
+ let(:metadata) do
283
+ data = described_class.new(path)
284
+ data.collect
285
+ data
286
+ end
287
+
288
+ it "should default owner" do
289
+ Puppet::Util::Windows::Security.stubs(:get_owner).returns nil
290
+
291
+ metadata.owner.should == 'S-1-5-32-544'
292
+ end
293
+
294
+ it "should default group" do
295
+ Puppet::Util::Windows::Security.stubs(:get_group).returns nil
296
+
297
+ metadata.group.should == 'S-1-0-0'
298
+ end
299
+
300
+ it "should default mode" do
301
+ Puppet::Util::Windows::Security.stubs(:get_mode).returns nil
302
+
303
+ metadata.mode.should == 0644
304
+ end
305
+ end
306
+
280
307
  def set_mode(mode, path)
281
308
  Puppet::Util::Windows::Security.set_mode(mode, path)
282
309
  end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ require 'puppet/indirector/facts/inventory_service'
5
+
6
+ describe Puppet::Node::Facts::InventoryService do
7
+ it "should suppress failures and warn when saving facts" do
8
+ facts = Puppet::Node::Facts.new('foo')
9
+ request = Puppet::Indirector::Request.new(:facts, :save, facts)
10
+
11
+ Net::HTTP.any_instance.stubs(:put).raises(Errno::ECONNREFUSED)
12
+
13
+ Puppet.expects(:warning).with do |msg|
14
+ msg =~ /Could not upload facts for foo to inventory service/
15
+ end
16
+
17
+ expect {
18
+ subject.save(request)
19
+ }.should_not raise_error
20
+ end
21
+ end
22
+
@@ -30,9 +30,9 @@ describe Puppet::FileBucketFile::File do
30
30
  describe "when servicing a save request" do
31
31
  describe "when supplying a path" do
32
32
  it "should store the path if not already stored" do
33
- checksum = save_bucket_file("stuff", "/foo/bar")
34
- dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a"
35
- File.read("#{dir_path}/contents").should == "stuff"
33
+ checksum = save_bucket_file("stuff\r\n", "/foo/bar")
34
+ dir_path = "#{Puppet[:bucketdir]}/f/c/7/7/7/c/0/b/fc777c0bc467e1ab98b4c6915af802ec"
35
+ Puppet::Util.binread("#{dir_path}/contents").should == "stuff\r\n"
36
36
  File.read("#{dir_path}/paths").should == "foo/bar\n"
37
37
  end
38
38
 
@@ -241,33 +241,30 @@ HERE
241
241
  end
242
242
 
243
243
  describe "when verifying identical files" do
244
- before do
245
- # this is the default from spec_helper, but it keeps getting reset at odd times
246
- Puppet[:bucketdir] = make_absolute("/dev/null/bucket")
247
-
248
- @digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
249
- @checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
250
- @dir = make_absolute('/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0')
251
-
252
- @contents = "file contents"
253
-
254
- @bucket = stub "bucket file"
255
- @bucket.stubs(:bucket_path)
256
- @bucket.stubs(:checksum).returns(@checksum)
257
- @bucket.stubs(:checksum_data).returns(@digest)
258
- @bucket.stubs(:path).returns(nil)
259
- @bucket.stubs(:contents).returns("file contents")
244
+ let(:contents) { "file\r\n contents" }
245
+ let(:digest) { "8b3702ad1aed1ace7e32bde76ffffb2d" }
246
+ let(:checksum) { "{md5}#{@digest}" }
247
+ let(:bucketdir) { tmpdir('file_bucket_file') }
248
+ let(:destdir) { "#{bucketdir}/8/b/3/7/0/2/a/d/8b3702ad1aed1ace7e32bde76ffffb2d" }
249
+ let(:bucket) { Puppet::FileBucket::File.new(contents) }
250
+
251
+ before :each do
252
+ Puppet[:bucketdir] = bucketdir
253
+ FileUtils.mkdir_p(destdir)
260
254
  end
261
255
 
262
256
  it "should raise an error if the files don't match" do
263
- File.expects(:read).with("#{@dir}/contents").returns("corrupt contents")
264
- lambda{ Puppet::FileBucketFile::File.new.send(:verify_identical_file!, @bucket) }.should raise_error(Puppet::FileBucket::BucketError)
257
+ File.open(File.join(destdir, 'contents'), 'wb') { |f| f.print "corrupt contents" }
258
+
259
+ lambda{
260
+ Puppet::FileBucketFile::File.new.send(:verify_identical_file!, bucket)
261
+ }.should raise_error(Puppet::FileBucket::BucketError)
265
262
  end
266
263
 
267
264
  it "should do nothing if the files match" do
268
- File.expects(:read).with("#{@dir}/contents").returns("file contents")
269
- Puppet::FileBucketFile::File.new.send(:verify_identical_file!, @bucket)
270
- end
265
+ File.open(File.join(destdir, 'contents'), 'wb') { |f| f.print contents }
271
266
 
267
+ Puppet::FileBucketFile::File.new.send(:verify_identical_file!, bucket)
268
+ end
272
269
  end
273
270
  end