puppet 2.6.6 → 2.6.7

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 (140) hide show
  1. data/CHANGELOG +107 -1
  2. data/README.queueing +1 -1
  3. data/Rakefile +1 -1
  4. data/conf/solaris/smf/svc-puppetd +0 -2
  5. data/conf/solaris/smf/svc-puppetmasterd +0 -2
  6. data/examples/etc/init.d/sleeper +0 -2
  7. data/examples/modules/sample-module/README.txt +2 -2
  8. data/ext/puppetstoredconfigclean.rb +1 -1
  9. data/install.rb +20 -25
  10. data/lib/puppet.rb +1 -1
  11. data/lib/puppet/application/agent.rb +2 -2
  12. data/lib/puppet/application/apply.rb +2 -2
  13. data/lib/puppet/application/cert.rb +27 -11
  14. data/lib/puppet/application/filebucket.rb +1 -1
  15. data/lib/puppet/application/inspect.rb +1 -1
  16. data/lib/puppet/application/kick.rb +2 -2
  17. data/lib/puppet/application/master.rb +1 -1
  18. data/lib/puppet/application/queue.rb +2 -2
  19. data/lib/puppet/configurer/downloader.rb +1 -0
  20. data/lib/puppet/configurer/plugin_handler.rb +8 -1
  21. data/lib/puppet/daemon.rb +1 -1
  22. data/lib/puppet/defaults.rb +18 -2
  23. data/lib/puppet/external/nagios.rb +0 -2
  24. data/lib/puppet/external/nagios/base.rb +0 -2
  25. data/lib/puppet/indirector/facts/inventory_active_record.rb +97 -0
  26. data/lib/puppet/indirector/facts/rest.rb +2 -0
  27. data/lib/puppet/indirector/facts/yaml.rb +75 -0
  28. data/lib/puppet/indirector/indirection.rb +1 -0
  29. data/lib/puppet/module.rb +1 -1
  30. data/lib/puppet/network/http/api/v1.rb +3 -4
  31. data/lib/puppet/network/http/compression.rb +4 -1
  32. data/lib/puppet/network/http/handler.rb +1 -1
  33. data/lib/puppet/network/rest_authconfig.rb +1 -1
  34. data/lib/puppet/node/facts.rb +29 -0
  35. data/lib/puppet/parser/ast/collection.rb +5 -4
  36. data/lib/puppet/parser/ast/leaf.rb +1 -1
  37. data/lib/puppet/parser/functions/regsubst.rb +7 -14
  38. data/lib/puppet/parser/functions/split.rb +7 -7
  39. data/lib/puppet/parser/grammar.ra +2 -4
  40. data/lib/puppet/parser/lexer.rb +4 -1
  41. data/lib/puppet/parser/parser.rb +2062 -1976
  42. data/lib/puppet/parser/parser_support.rb +3 -3
  43. data/lib/puppet/provider/computer/computer.rb +1 -3
  44. data/lib/puppet/provider/mount.rb +12 -16
  45. data/lib/puppet/provider/mount/parsed.rb +67 -8
  46. data/lib/puppet/provider/parsedfile.rb +3 -1
  47. data/lib/puppet/provider/service/daemontools.rb +6 -6
  48. data/lib/puppet/provider/service/gentoo.rb +0 -2
  49. data/lib/puppet/provider/service/launchd.rb +11 -8
  50. data/lib/puppet/provider/service/runit.rb +4 -4
  51. data/lib/puppet/provider/user/useradd.rb +6 -1
  52. data/lib/puppet/rails/database/004_add_inventory_service_tables.rb +36 -0
  53. data/lib/puppet/rails/database/schema.rb +17 -0
  54. data/lib/puppet/rails/fact_name.rb +0 -2
  55. data/lib/puppet/rails/fact_value.rb +0 -2
  56. data/lib/puppet/rails/inventory_fact.rb +5 -0
  57. data/lib/puppet/rails/inventory_node.rb +25 -0
  58. data/lib/puppet/reference/configuration.rb +1 -1
  59. data/lib/puppet/reference/metaparameter.rb +1 -1
  60. data/lib/puppet/reports/store.rb +4 -1
  61. data/lib/puppet/resource.rb +39 -25
  62. data/lib/puppet/type.rb +5 -5
  63. data/lib/puppet/type/augeas.rb +4 -4
  64. data/lib/puppet/type/computer.rb +5 -1
  65. data/lib/puppet/type/exec.rb +3 -1
  66. data/lib/puppet/type/file.rb +3 -1
  67. data/lib/puppet/type/file/content.rb +13 -15
  68. data/lib/puppet/type/file/ensure.rb +11 -17
  69. data/lib/puppet/type/file/selcontext.rb +16 -0
  70. data/lib/puppet/type/file/target.rb +14 -1
  71. data/lib/puppet/type/k5login.rb +0 -2
  72. data/lib/puppet/type/macauthorization.rb +4 -1
  73. data/lib/puppet/type/mcx.rb +4 -1
  74. data/lib/puppet/type/mount.rb +37 -21
  75. data/lib/puppet/type/package.rb +5 -1
  76. data/lib/puppet/type/schedule.rb +20 -20
  77. data/lib/puppet/type/selmodule.rb +3 -1
  78. data/lib/puppet/type/ssh_authorized_key.rb +5 -1
  79. data/lib/puppet/type/user.rb +14 -1
  80. data/lib/puppet/type/zfs.rb +3 -1
  81. data/lib/puppet/type/zone.rb +3 -1
  82. data/lib/puppet/type/zpool.rb +7 -5
  83. data/lib/puppet/util.rb +5 -0
  84. data/lib/puppet/util/command_line.rb +1 -1
  85. data/lib/puppet/util/execution.rb +4 -5
  86. data/lib/puppet/util/execution_stub.rb +26 -0
  87. data/lib/puppet/util/monkey_patches.rb +21 -0
  88. data/lib/puppet/util/rdoc/code_objects.rb +39 -0
  89. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +18 -0
  90. data/lib/puppet/util/rdoc/parser.rb +5 -3
  91. data/lib/puppet/util/settings.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +7 -0
  93. data/spec/integration/provider/mount_spec.rb +151 -0
  94. data/spec/integration/type/file_spec.rb +32 -29
  95. data/spec/spec_helper.rb +2 -0
  96. data/spec/unit/application/agent_spec.rb +3 -7
  97. data/spec/unit/application/apply_spec.rb +17 -2
  98. data/spec/unit/application/cert_spec.rb +54 -14
  99. data/spec/unit/application/filebucket_spec.rb +1 -1
  100. data/spec/unit/application/queue_spec.rb +1 -5
  101. data/spec/unit/configurer/downloader_spec.rb +22 -10
  102. data/spec/unit/daemon_spec.rb +1 -5
  103. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +163 -0
  104. data/spec/unit/indirector/facts/yaml_spec.rb +216 -2
  105. data/spec/unit/indirector/queue_spec.rb +3 -0
  106. data/spec/unit/module_spec.rb +2 -2
  107. data/spec/unit/network/handler/fileserver_spec.rb +1 -1
  108. data/spec/unit/network/http/api/v1_spec.rb +28 -0
  109. data/spec/unit/network/http/compression_spec.rb +1 -1
  110. data/spec/unit/network/http/handler_spec.rb +7 -4
  111. data/spec/unit/node/facts_spec.rb +24 -0
  112. data/spec/unit/parser/ast/collection_spec.rb +16 -12
  113. data/spec/unit/parser/lexer_spec.rb +16 -0
  114. data/spec/unit/parser/parser_spec.rb +35 -2
  115. data/spec/unit/provider/mount/parsed_spec.rb +199 -114
  116. data/spec/unit/provider/mount_spec.rb +54 -53
  117. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
  118. data/spec/unit/provider/user/user_role_add_spec.rb +1 -0
  119. data/spec/unit/provider/user/useradd_spec.rb +43 -3
  120. data/spec/unit/reports/store_spec.rb +1 -1
  121. data/spec/unit/resource_spec.rb +39 -13
  122. data/spec/unit/type/file/content_spec.rb +38 -137
  123. data/spec/unit/type/file/selinux_spec.rb +5 -0
  124. data/spec/unit/type/mount_spec.rb +167 -122
  125. data/spec/unit/type/user_spec.rb +4 -0
  126. data/spec/unit/type_spec.rb +12 -1
  127. data/spec/unit/util/execution_spec.rb +49 -0
  128. data/spec/unit/util/execution_stub_spec.rb +35 -0
  129. data/spec/unit/util/rdoc/parser_spec.rb +15 -3
  130. data/spec/unit/util/settings_spec.rb +11 -2
  131. data/tasks/rake/git_workflow.rake +1 -1
  132. data/test/Rakefile +0 -2
  133. data/test/data/providers/mount/parsed/aix.mount +7 -0
  134. data/test/data/providers/mount/parsed/darwin.mount +6 -0
  135. data/test/data/providers/mount/parsed/hpux.mount +17 -0
  136. data/test/data/providers/mount/parsed/linux.mount +5 -0
  137. data/test/data/providers/mount/parsed/solaris.mount +6 -0
  138. data/test/data/types/mount/linux.fstab +1 -0
  139. data/test/data/types/mount/solaris.fstab +1 -0
  140. metadata +18 -4
@@ -104,6 +104,7 @@ describe provider_class do
104
104
  before :each do
105
105
  @resource = stub("resource", :name => "foo")
106
106
  @resource.stubs(:[]).returns "foo"
107
+ @resource.class.stubs(:key_attributes).returns( [:name] )
107
108
 
108
109
  @provider = provider_class.new(@resource)
109
110
  provider_class.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam)
@@ -115,6 +115,7 @@ describe provider_class do
115
115
  describe "when allow duplicate is enabled" do
116
116
  before do
117
117
  @resource.expects(:allowdupe?).returns true
118
+ @resource.stubs(:system?)
118
119
  @provider.stubs(:is_role?).returns(false)
119
120
  @provider.stubs(:execute)
120
121
  @provider.expects(:execute).with { |args| args.include?("-o") }
@@ -15,6 +15,7 @@ describe provider_class do
15
15
  # #1360
16
16
  it "should add -o when allowdupe is enabled and the user is being created" do
17
17
  @resource.expects(:allowdupe?).returns true
18
+ @resource.expects(:system?).returns true
18
19
  @provider.stubs(:execute)
19
20
  @provider.expects(:execute).with { |args| args.include?("-o") }
20
21
  @provider.create
@@ -27,6 +28,14 @@ describe provider_class do
27
28
  @provider.uid = 150
28
29
  end
29
30
 
31
+ it "should add -r when system is enabled" do
32
+ @resource.expects(:allowdupe?).returns true
33
+ @resource.expects(:system?).returns true
34
+ @provider.stubs(:execute)
35
+ @provider.expects(:execute).with { |args| args.include?("-r") }
36
+ @provider.create
37
+ end
38
+
30
39
  it "should set password age rules" do
31
40
  provider_class.has_feature :manages_password_age
32
41
  @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :useradd
@@ -53,6 +62,23 @@ describe provider_class do
53
62
  end
54
63
  end
55
64
 
65
+ describe "when checking to add system users" do
66
+ it "should check system users" do
67
+ @resource.expects(:system?)
68
+ @provider.check_system_users
69
+ end
70
+
71
+ it "should return an array with a flag if it's a system user" do
72
+ @resource.stubs(:system?).returns true
73
+ @provider.check_system_users.must == ["-r"]
74
+ end
75
+
76
+ it "should return an empty array if it's not a system user" do
77
+ @resource.stubs(:system?).returns false
78
+ @provider.check_system_users.must == []
79
+ end
80
+ end
81
+
56
82
  describe "when checking manage home" do
57
83
  it "should check manage home" do
58
84
  @resource.expects(:managehome?)
@@ -88,6 +114,7 @@ describe provider_class do
88
114
  before do
89
115
  @resource.stubs(:allowdupe?).returns true
90
116
  @resource.stubs(:managehome?).returns true
117
+ @resource.stubs(:system?).returns true
91
118
  end
92
119
 
93
120
  it "should call command with :add" do
@@ -115,20 +142,32 @@ describe provider_class do
115
142
  @provider.addcmd
116
143
  end
117
144
 
145
+ it "should return an array with -r if system? is true" do
146
+ resource = Puppet::Type.type(:user).new( :name => "bob", :system => true)
147
+
148
+ provider_class.new( resource ).addcmd.should include("-r")
149
+ end
150
+
151
+ it "should return an array without -r if system? is false" do
152
+ resource = Puppet::Type.type(:user).new( :name => "bob", :system => false)
153
+
154
+ provider_class.new( resource ).addcmd.should_not include("-r")
155
+ end
156
+
118
157
  it "should return an array with full command" do
119
158
  @provider.stubs(:command).with(:add).returns("useradd")
120
159
  @provider.stubs(:add_properties).returns(["-G", "somegroup"])
121
160
  @resource.stubs(:[]).with(:name).returns("someuser")
122
161
  @resource.stubs(:[]).with(:expiry).returns("somedate")
123
- @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", '-e somedate', "someuser"]
162
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", '-e somedate', "-r", "someuser"]
124
163
  end
125
164
 
126
- it "should return an array without -e if expery is undefined full command" do
165
+ it "should return an array without -e if expiry is undefined full command" do
127
166
  @provider.stubs(:command).with(:add).returns("useradd")
128
167
  @provider.stubs(:add_properties).returns(["-G", "somegroup"])
129
168
  @resource.stubs(:[]).with(:name).returns("someuser")
130
169
  @resource.stubs(:[]).with(:expiry).returns nil
131
- @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
170
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "-r", "someuser"]
132
171
  end
133
172
  end
134
173
 
@@ -136,6 +175,7 @@ describe provider_class do
136
175
  before do
137
176
  @resource.stubs(:allowdupe?).returns true
138
177
  @resource.stubs(:managehome?).returns true
178
+ @resource.stubs(:system?).returns true
139
179
  end
140
180
 
141
181
  it "should call command with :pass" do
@@ -11,7 +11,7 @@ describe processor do
11
11
  describe "#process" do
12
12
  include PuppetSpec::Files
13
13
  before :each do
14
- Puppet[:reportdir] = tmpdir('reports')
14
+ Puppet[:reportdir] = tmpdir('reports') << '/reports'
15
15
  @report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml')).extend processor
16
16
  end
17
17
 
@@ -99,11 +99,11 @@ describe Puppet::Resource do
99
99
  end
100
100
 
101
101
  it 'should fail if strict is set and type does not exist' do
102
- lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
102
+ lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
103
103
  end
104
104
 
105
105
  it 'should fail if strict is set and class does not exist' do
106
- lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
106
+ lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
107
107
  end
108
108
 
109
109
  it "should fail if the title is a hash and the type is not a valid resource reference string" do
@@ -463,6 +463,28 @@ describe Puppet::Resource do
463
463
  end
464
464
  end
465
465
 
466
+ describe "when loading 0.25.x storedconfigs YAML" do
467
+ before :each do
468
+ @old_storedconfig_yaml = %q{--- !ruby/object:Puppet::Resource::Reference
469
+ builtin_type:
470
+ title: /tmp/bar
471
+ type: File
472
+ }
473
+ end
474
+
475
+ it "should deserialize a Puppet::Resource::Reference without exceptions" do
476
+ lambda { YAML.load(@old_storedconfig_yaml) }.should_not raise_error
477
+ end
478
+
479
+ it "should deserialize as a Puppet::Resource::Reference as a Puppet::Resource" do
480
+ YAML.load(@old_storedconfig_yaml).class.should == Puppet::Resource
481
+ end
482
+
483
+ it "should to_hash properly" do
484
+ YAML.load(@old_storedconfig_yaml).to_hash.should == { :path => "/tmp/bar" }
485
+ end
486
+ end
487
+
466
488
  describe "when converting to a RAL resource" do
467
489
  it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do
468
490
  resource = Puppet::Resource.new("file", @basepath+"/my/file")
@@ -486,19 +508,23 @@ describe Puppet::Resource do
486
508
 
487
509
  describe "when converting to puppet code" do
488
510
  before do
489
- @resource = Puppet::Resource.new("one::two", "/my/file", :parameters => {:noop => true, :foo => %w{one two}})
490
- end
491
-
492
- it "should print the type and title" do
493
- @resource.to_manifest.should be_include("one::two { '/my/file':\n")
494
- end
495
-
496
- it "should print each parameter, with the value single-quoted" do
497
- @resource.to_manifest.should be_include(" noop => 'true'")
511
+ @resource = Puppet::Resource.new("one::two", "/my/file",
512
+ :parameters => {
513
+ :noop => true,
514
+ :foo => %w{one two},
515
+ :ensure => 'present',
516
+ }
517
+ )
498
518
  end
499
519
 
500
- it "should print array values appropriately" do
501
- @resource.to_manifest.should be_include(" foo => ['one','two']")
520
+ it "should align, sort and add trailing commas to attributes with ensure first" do
521
+ @resource.to_manifest.should == <<-HEREDOC.gsub(/^\s{8}/, '').gsub(/\n$/, '')
522
+ one::two { '/my/file':
523
+ ensure => 'present',
524
+ foo => ['one', 'two'],
525
+ noop => 'true',
526
+ }
527
+ HEREDOC
502
528
  end
503
529
  end
504
530
 
@@ -4,15 +4,14 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
4
4
 
5
5
  content = Puppet::Type.type(:file).attrclass(:content)
6
6
  describe content do
7
+ include PuppetSpec::Files
7
8
  before do
8
- @resource = Puppet::Type.type(:file).new :path => "/foo/bar"
9
+ @filename = tmpfile('testfile')
10
+ @resource = Puppet::Type.type(:file).new :path => @filename
11
+ File.open(@filename, 'w') {|f| f.write "initial file content"}
9
12
  content.stubs(:standalone?).returns(false)
10
13
  end
11
14
 
12
- it "should be a subclass of Property" do
13
- content.superclass.must == Puppet::Property
14
- end
15
-
16
15
  describe "when determining the checksum type" do
17
16
  it "should use the type specified in the source checksum if a source is set" do
18
17
  @resource[:source] = "/foo"
@@ -249,10 +248,10 @@ describe content do
249
248
  describe "when writing" do
250
249
  before do
251
250
  @content = content.new(:resource => @resource)
252
- @fh = stub_everything
253
251
  end
254
252
 
255
253
  it "should attempt to read from the filebucket if no actual content nor source exists" do
254
+ @fh = File.open(@filename, 'w')
256
255
  @content.should = "{md5}foo"
257
256
  @content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo"
258
257
  @content.write(@fh)
@@ -302,166 +301,68 @@ describe content do
302
301
 
303
302
  describe "from local source" do
304
303
  before(:each) do
305
- @content.stubs(:actual_content).returns(nil)
306
- @source = stub_everything 'source', :local? => true, :full_path => "/path/to/source"
307
- @resource.stubs(:parameter).with(:source).returns @source
308
-
309
- @sum = stub_everything 'sum'
310
- @resource.stubs(:parameter).with(:checksum).returns(@sum)
311
-
312
- @digest = stub_everything 'digest'
313
- @sum.stubs(:sum_stream).yields(@digest)
314
-
315
- @file = stub_everything 'file'
316
- File.stubs(:open).yields(@file)
317
- @file.stubs(:read).with(8192).returns("chunk1").then.returns("chunk2").then.returns(nil)
318
- end
319
-
320
- it "should open the local file" do
321
- File.expects(:open).with("/path/to/source", "r")
322
- @content.write(@fh)
323
- end
304
+ @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false
305
+ @sourcename = tmpfile('source')
306
+ @source_content = "source file content"*10000
307
+ @sourcefile = File.open(@sourcename, 'w') {|f| f.write @source_content}
324
308
 
325
- it "should read the local file by chunks" do
326
- @file.expects(:read).with(8192).returns("chunk1").then.returns(nil)
327
- @content.write(@fh)
309
+ @content = @resource.newattr(:content)
310
+ @source = @resource.newattr(:source)
311
+ @source.stubs(:metadata).returns stub_everything('metadata', :source => @sourcename, :ftype => 'file')
328
312
  end
329
313
 
330
- it "should write each chunk to the file" do
331
- @fh.expects(:print).with("chunk1").then.with("chunk2")
332
- @content.write(@fh)
333
- end
334
-
335
- it "should pass each chunk to the current sum stream" do
336
- @digest.expects(:<<).with("chunk1").then.with("chunk2")
337
- @content.write(@fh)
314
+ it "should copy content from the source to the file" do
315
+ @resource.write(@source)
316
+ File.read(@filename).should == @source_content
338
317
  end
339
318
 
340
319
  it "should return the checksum computed" do
341
- @sum.stubs(:sum_stream).yields(@digest).returns("checksum")
342
- @content.write(@fh).should == "checksum"
320
+ File.open(@filename, 'w') do |file|
321
+ @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
322
+ end
343
323
  end
344
324
  end
345
325
 
346
326
  describe "from remote source" do
347
327
  before(:each) do
348
- @response = stub_everything 'mock response', :code => "404"
328
+ @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false
329
+ @response = stub_everything 'response', :code => "200"
330
+ @source_content = "source file content"*10000
331
+ @response.stubs(:read_body).multiple_yields(*(["source file content"]*10000))
332
+
349
333
  @conn = stub_everything 'connection'
350
334
  @conn.stubs(:request_get).yields(@response)
351
335
  Puppet::Network::HttpPool.stubs(:http_instance).returns @conn
352
336
 
353
- @content.stubs(:actual_content).returns(nil)
354
- @source = stub_everything 'source', :local? => false, :full_path => "/path/to/source", :server => "server", :port => 1234
355
- @resource.stubs(:parameter).with(:source).returns @source
356
-
357
- @sum = stub_everything 'sum'
358
- @resource.stubs(:parameter).with(:checksum).returns(@sum)
359
-
360
- @digest = stub_everything 'digest'
361
- @sum.stubs(:sum_stream).yields(@digest)
362
- end
363
-
364
- it "should open a network connection to source server and port" do
365
- Puppet::Network::HttpPool.expects(:http_instance).with("server", 1234).returns @conn
366
- @content.write(@fh)
367
- end
368
-
369
- it "should send the correct indirection uri" do
370
- @conn.expects(:request_get).with { |uri,headers| uri == "/production/file_content/path/to/source" }.yields(@response)
371
- @content.write(@fh)
337
+ @content = @resource.newattr(:content)
338
+ @sourcename = "puppet:///test/foo"
339
+ @source = @resource.newattr(:source)
340
+ @source.stubs(:metadata).returns stub_everything('metadata', :source => @sourcename, :ftype => 'file')
372
341
  end
373
342
 
374
- it "should return nil if source is not found" do
375
- @response.expects(:code).returns("404")
376
- @content.write(@fh).should == nil
343
+ it "should write the contents to the file" do
344
+ @resource.write(@source)
345
+ File.read(@filename).should == @source_content
377
346
  end
378
347
 
379
348
  it "should not write anything if source is not found" do
380
- @response.expects(:code).returns("404")
381
- @fh.expects(:print).never
382
- @content.write(@fh).should == nil
349
+ @response.stubs(:code).returns("404")
350
+ lambda {@resource.write(@source)}.should raise_error(Net::HTTPError) { |e| e.message =~ /404/ }
351
+ File.read(@filename).should == "initial file content"
383
352
  end
384
353
 
385
354
  it "should raise an HTTP error in case of server error" do
386
- @response.expects(:code).returns("500")
387
- lambda { @content.write(@fh) }.should raise_error
388
- end
389
-
390
- it "should write content by chunks" do
391
- @response.expects(:code).returns("200")
392
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
393
- @fh.expects(:print).with("chunk1").then.with("chunk2")
394
- @content.write(@fh)
395
- end
396
-
397
- it "should pass each chunk to the current sum stream" do
398
- @response.expects(:code).returns("200")
399
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
400
- @digest.expects(:<<).with("chunk1").then.with("chunk2")
401
- @content.write(@fh)
355
+ @response.stubs(:code).returns("500")
356
+ lambda { @content.write(@fh) }.should raise_error { |e| e.message.include? @source_content }
402
357
  end
403
358
 
404
359
  it "should return the checksum computed" do
405
- @response.expects(:code).returns("200")
406
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
407
- @sum.expects(:sum_stream).yields(@digest).returns("checksum")
408
- @content.write(@fh).should == "checksum"
409
- end
410
-
411
- it "should get the current accept encoding header value" do
412
- @content.expects(:add_accept_encoding)
413
- @content.write(@fh)
414
- end
415
-
416
- it "should uncompress body on error" do
417
- @response.expects(:code).returns("500")
418
- @response.expects(:body).returns("compressed body")
419
- @content.expects(:uncompress_body).with(@response).returns("uncompressed")
420
- lambda { @content.write(@fh) }.should raise_error { |e| e.message =~ /uncompressed/ }
421
- end
422
-
423
- it "should uncompress chunk by chunk" do
424
- uncompressor = stub_everything 'uncompressor'
425
- @content.expects(:uncompress).with(@response).yields(uncompressor)
426
- @response.expects(:code).returns("200")
427
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
428
-
429
- uncompressor.expects(:uncompress).with("chunk1").then.with("chunk2")
430
- @content.write(@fh)
431
- end
432
-
433
- it "should write uncompressed chunks to the file" do
434
- uncompressor = stub_everything 'uncompressor'
435
- @content.expects(:uncompress).with(@response).yields(uncompressor)
436
- @response.expects(:code).returns("200")
437
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
438
-
439
- uncompressor.expects(:uncompress).with("chunk1").returns("uncompressed1")
440
- uncompressor.expects(:uncompress).with("chunk2").returns("uncompressed2")
441
-
442
- @fh.expects(:print).with("uncompressed1")
443
- @fh.expects(:print).with("uncompressed2")
444
-
445
- @content.write(@fh)
446
- end
447
-
448
- it "should pass each uncompressed chunk to the current sum stream" do
449
- uncompressor = stub_everything 'uncompressor'
450
- @content.expects(:uncompress).with(@response).yields(uncompressor)
451
- @response.expects(:code).returns("200")
452
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
453
-
454
- uncompressor.expects(:uncompress).with("chunk1").returns("uncompressed1")
455
- uncompressor.expects(:uncompress).with("chunk2").returns("uncompressed2")
456
-
457
- @digest.expects(:<<).with("uncompressed1").then.with("uncompressed2")
458
- @content.write(@fh)
360
+ File.open(@filename, 'w') do |file|
361
+ @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
362
+ end
459
363
  end
460
364
  end
461
365
 
462
- describe "from a filebucket" do
463
- end
464
-
465
366
  # These are testing the implementation rather than the desired behaviour; while that bites, there are a whole
466
367
  # pile of other methods in the File type that depend on intimate details of this implementation and vice-versa.
467
368
  # If these blow up, you are gonna have to review the callers to make sure they don't explode! --daniel 2011-02-01
@@ -66,6 +66,11 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
66
66
  @sel.default.must == expectedresult
67
67
  end
68
68
 
69
+ it "should return nil for defaults if selinux_ignore_defaults is true" do
70
+ @resource[:selinux_ignore_defaults] = :true
71
+ @sel.default.must be_nil
72
+ end
73
+
69
74
  it "should be able to set a new context" do
70
75
  stat = stub 'stat', :ftype => "foo"
71
76
  @sel.should = %w{newone}
@@ -11,10 +11,14 @@ describe Puppet::Type.type(:mount) do
11
11
  mount = Puppet::Type.type(:mount).new(:name => "yay")
12
12
  mount.should(:ensure).should be_nil
13
13
  end
14
+
15
+ it "should have :name as the only keyattribut" do
16
+ Puppet::Type.type(:mount).key_attributes.should == [:name]
17
+ end
14
18
  end
15
19
 
16
20
  describe Puppet::Type.type(:mount), "when validating attributes" do
17
- [:name, :remounts].each do |param|
21
+ [:name, :remounts, :provider].each do |param|
18
22
  it "should have a #{param} parameter" do
19
23
  Puppet::Type.type(:mount).attrtype(param).should == :param
20
24
  end
@@ -38,9 +42,16 @@ describe Puppet::Type.type(:mount)::Ensure, "when validating values" do
38
42
  mount.should(:ensure).should == :defined
39
43
  end
40
44
 
45
+ it "should support :present as a value to :ensure" do
46
+ Puppet::Type.type(:mount).new(:name => "yay", :ensure => :present)
47
+ end
48
+
49
+ it "should support :defined as a value to :ensure" do
50
+ Puppet::Type.type(:mount).new(:name => "yay", :ensure => :defined)
51
+ end
52
+
41
53
  it "should support :unmounted as a value to :ensure" do
42
- mount = Puppet::Type.type(:mount).new(:name => "yay", :ensure => :unmounted)
43
- mount.should(:ensure).should == :unmounted
54
+ Puppet::Type.type(:mount).new(:name => "yay", :ensure => :unmounted)
44
55
  end
45
56
 
46
57
  it "should support :absent as a value to :ensure" do
@@ -54,7 +65,8 @@ end
54
65
 
55
66
  describe Puppet::Type.type(:mount)::Ensure do
56
67
  before :each do
57
- @provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock
68
+ provider_properties = {}
69
+ @provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock, :property_hash => provider_properties
58
70
  Puppet::Type.type(:mount).defaultprovider.stubs(:new).returns(@provider)
59
71
  @mount = Puppet::Type.type(:mount).new(:name => "yay", :check => :ensure)
60
72
 
@@ -74,134 +86,150 @@ describe Puppet::Type.type(:mount)::Ensure do
74
86
  end
75
87
  end
76
88
 
77
- describe Puppet::Type.type(:mount)::Ensure, "when retrieving its current state" do
78
-
79
- it "should return the provider's value if it is :absent" do
80
- @provider.expects(:ensure).returns(:absent)
81
- @ensure.retrieve.should == :absent
82
- end
83
-
84
- it "should return :mounted if the provider indicates it is mounted and the value is not :absent" do
85
- @provider.expects(:ensure).returns(:present)
86
- @provider.expects(:mounted?).returns(true)
87
- @ensure.retrieve.should == :mounted
88
- end
89
-
90
- it "should return :unmounted if the provider indicates it is not mounted and the value is not :absent" do
91
- @provider.expects(:ensure).returns(:present)
92
- @provider.expects(:mounted?).returns(false)
93
- @ensure.retrieve.should == :unmounted
94
- end
95
- end
96
-
97
89
  describe Puppet::Type.type(:mount)::Ensure, "when changing the host" do
98
90
 
99
- it "should destroy itself if it should be absent" do
100
- @provider.stubs(:mounted?).returns(false)
101
- @provider.expects(:destroy)
102
- @ensure.should = :absent
103
- @ensure.sync
104
- end
105
-
106
- it "should unmount itself before destroying if it is mounted and should be absent" do
107
- @provider.expects(:mounted?).returns(true)
108
- @provider.expects(:unmount)
109
- @provider.expects(:destroy)
110
- @ensure.should = :absent
111
- @ensure.sync
112
- end
113
-
114
- it "should create itself if it is absent and should be defined" do
115
- @provider.stubs(:ensure).returns(:absent)
116
- @provider.stubs(:mounted?).returns(true)
117
-
118
- @provider.stubs(:mounted?).returns(false)
119
- @provider.expects(:create)
120
- @ensure.should = :defined
121
- @ensure.sync
122
- end
123
-
124
- it "should not unmount itself if it is mounted and should be defined" do
125
- @provider.stubs(:ensure).returns(:mounted)
126
- @provider.stubs(:mounted?).returns(true)
127
-
128
- @provider.stubs(:create)
129
- @provider.expects(:mount).never
130
- @provider.expects(:unmount).never
131
- @ensure.should = :defined
132
- @ensure.sync
133
- end
134
-
135
- it "should not mount itself if it is unmounted and should be defined" do
136
- @provider.stubs(:ensure).returns(:unmounted)
137
- @provider.stubs(:mounted?).returns(false)
138
-
139
- @ensure.stubs(:syncothers)
140
- @provider.stubs(:create)
91
+ def test_ensure_change(options)
92
+ @provider.stubs(:get).with(:ensure).returns options[:from]
93
+ @provider.stubs(:ensure).returns options[:from]
94
+ @provider.stubs(:mounted?).returns([:mounted,:ghost].include? options[:from])
95
+ @provider.expects(:create).times(options[:create] || 0)
96
+ @provider.expects(:destroy).times(options[:destroy] || 0)
141
97
  @provider.expects(:mount).never
142
- @provider.expects(:unmount).never
143
- @ensure.should = :present
144
- @ensure.sync
145
- end
146
-
147
- it "should unmount itself if it is mounted and should be unmounted" do
148
- @provider.stubs(:ensure).returns(:present)
149
- @provider.stubs(:mounted?).returns(true)
150
-
98
+ @provider.expects(:unmount).times(options[:unmount] || 0)
151
99
  @ensure.stubs(:syncothers)
152
- @provider.expects(:unmount)
153
- @ensure.should = :unmounted
100
+ @ensure.should = options[:to]
154
101
  @ensure.sync
155
- end
102
+ (!!@provider.property_hash[:needs_mount]).should == (!!options[:mount])
103
+ end
104
+
105
+ it "should create itself when changing from :ghost to :present" do
106
+ test_ensure_change(:from => :ghost, :to => :present, :create => 1)
107
+ end
108
+
109
+ it "should create itself when changing from :absent to :present" do
110
+ test_ensure_change(:from => :absent, :to => :present, :create => 1)
111
+ end
156
112
 
157
- it "should create and mount itself if it does not exist and should be mounted" do
158
- @provider.stubs(:ensure).returns(:absent)
159
- @provider.stubs(:mounted?).returns(false)
160
- @provider.expects(:create)
161
- @ensure.stubs(:syncothers)
162
- @provider.expects(:mount)
163
- @ensure.should = :mounted
164
- @ensure.sync
165
- end
113
+ it "should create itself and unmount when changing from :ghost to :unmounted" do
114
+ test_ensure_change(:from => :ghost, :to => :unmounted, :create => 1, :unmount => 1)
115
+ end
116
+
117
+ it "should unmount resource when changing from :mounted to :unmounted" do
118
+ test_ensure_change(:from => :mounted, :to => :unmounted, :unmount => 1)
119
+ end
120
+
121
+ it "should create itself when changing from :absent to :unmounted" do
122
+ test_ensure_change(:from => :absent, :to => :unmounted, :create => 1)
123
+ end
124
+
125
+ it "should unmount resource when changing from :ghost to :absent" do
126
+ test_ensure_change(:from => :ghost, :to => :absent, :unmount => 1)
127
+ end
128
+
129
+ it "should unmount and destroy itself when changing from :mounted to :absent" do
130
+ test_ensure_change(:from => :mounted, :to => :absent, :destroy => 1, :unmount => 1)
131
+ end
132
+
133
+ it "should destroy itself when changing from :unmounted to :absent" do
134
+ test_ensure_change(:from => :unmounted, :to => :absent, :destroy => 1)
135
+ end
136
+
137
+ it "should create itself when changing from :ghost to :mounted" do
138
+ test_ensure_change(:from => :ghost, :to => :mounted, :create => 1)
139
+ end
140
+
141
+ it "should create itself and mount when changing from :absent to :mounted" do
142
+ test_ensure_change(:from => :absent, :to => :mounted, :create => 1, :mount => 1)
143
+ end
144
+
145
+ it "should mount resource when changing from :unmounted to :mounted" do
146
+ test_ensure_change(:from => :unmounted, :to => :mounted, :mount => 1)
147
+ end
148
+
149
+
150
+ it "should be in sync if it is :absent and should be :absent" do
151
+ @ensure.should = :absent
152
+ @ensure.safe_insync?(:absent).should == true
153
+ end
154
+
155
+ it "should be out of sync if it is :absent and should be :defined" do
156
+ @ensure.should = :defined
157
+ @ensure.safe_insync?(:absent).should == false
158
+ end
159
+
160
+ it "should be out of sync if it is :absent and should be :mounted" do
161
+ @ensure.should = :mounted
162
+ @ensure.safe_insync?(:absent).should == false
163
+ end
164
+
165
+ it "should be out of sync if it is :absent and should be :unmounted" do
166
+ @ensure.should = :unmounted
167
+ @ensure.safe_insync?(:absent).should == false
168
+ end
169
+
170
+ it "should be out of sync if it is :mounted and should be :absent" do
171
+ @ensure.should = :absent
172
+ @ensure.safe_insync?(:mounted).should == false
173
+ end
174
+
175
+ it "should be in sync if it is :mounted and should be :defined" do
176
+ @ensure.should = :defined
177
+ @ensure.safe_insync?(:mounted).should == true
178
+ end
179
+
180
+ it "should be in sync if it is :mounted and should be :mounted" do
181
+ @ensure.should = :mounted
182
+ @ensure.safe_insync?(:mounted).should == true
183
+ end
184
+
185
+ it "should be out in sync if it is :mounted and should be :unmounted" do
186
+ @ensure.should = :unmounted
187
+ @ensure.safe_insync?(:mounted).should == false
188
+ end
189
+
190
+
191
+ it "should be out of sync if it is :unmounted and should be :absent" do
192
+ @ensure.should = :absent
193
+ @ensure.safe_insync?(:unmounted).should == false
194
+ end
195
+
196
+ it "should be in sync if it is :unmounted and should be :defined" do
197
+ @ensure.should = :defined
198
+ @ensure.safe_insync?(:unmounted).should == true
199
+ end
200
+
201
+ it "should be out of sync if it is :unmounted and should be :mounted" do
202
+ @ensure.should = :mounted
203
+ @ensure.safe_insync?(:unmounted).should == false
204
+ end
205
+
206
+ it "should be in sync if it is :unmounted and should be :unmounted" do
207
+ @ensure.should = :unmounted
208
+ @ensure.safe_insync?(:unmounted).should == true
209
+ end
166
210
 
167
- it "should mount itself if it is present and should be mounted" do
168
- @provider.stubs(:ensure).returns(:present)
169
- @provider.stubs(:mounted?).returns(false)
170
- @ensure.stubs(:syncothers)
171
- @provider.expects(:mount)
172
- @ensure.should = :mounted
173
- @ensure.sync
174
- end
175
211
 
176
- it "should create but not mount itself if it is absent and mounted and should be mounted" do
177
- @provider.stubs(:ensure).returns(:absent)
178
- @provider.stubs(:mounted?).returns(true)
179
- @ensure.stubs(:syncothers)
180
- @provider.expects(:create)
181
- @ensure.should = :mounted
182
- @ensure.sync
183
- end
184
-
185
- it "should be insync if it is mounted and should be defined" do
186
- @ensure.should = :defined
187
- @ensure.safe_insync?(:mounted).should == true
188
- end
189
-
190
- it "should be insync if it is unmounted and should be defined" do
191
- @ensure.should = :defined
192
- @ensure.safe_insync?(:unmounted).should == true
193
- end
212
+ it "should be out of sync if it is :ghost and should be :absent" do
213
+ @ensure.should = :absent
214
+ @ensure.safe_insync?(:ghost).should == false
215
+ end
194
216
 
195
- it "should be insync if it is mounted and should be present" do
196
- @ensure.should = :present
197
- @ensure.safe_insync?(:mounted).should == true
198
- end
217
+ it "should be out of sync if it is :ghost and should be :defined" do
218
+ @ensure.should = :defined
219
+ @ensure.safe_insync?(:ghost).should == false
220
+ end
221
+
222
+ it "should be out of sync if it is :ghost and should be :mounted" do
223
+ @ensure.should = :mounted
224
+ @ensure.safe_insync?(:ghost).should == false
225
+ end
226
+
227
+ it "should be out of sync if it is :ghost and should be :unmounted" do
228
+ @ensure.should = :unmounted
229
+ @ensure.safe_insync?(:ghost).should == false
230
+ end
199
231
 
200
- it "should be insync if it is unmounted and should be present" do
201
- @ensure.should = :present
202
- @ensure.safe_insync?(:unmounted).should == true
203
- end
204
- end
232
+ end
205
233
 
206
234
  describe Puppet::Type.type(:mount), "when responding to events" do
207
235
 
@@ -258,4 +286,21 @@ describe Puppet::Type.type(:mount), "when modifying an existing mount entry" do
258
286
 
259
287
  @catalog.apply
260
288
  end
289
+
290
+ it "should umount before flushing changes to disk" do
291
+ syncorder = sequence('syncorder')
292
+ @mount.provider.expects(:options).returns 'soft'
293
+ @mount.provider.expects(:ensure).returns :mounted
294
+
295
+ @mount.provider.expects(:unmount).in_sequence(syncorder)
296
+ @mount.provider.expects(:options=).in_sequence(syncorder).with 'hard'
297
+ @mount.expects(:flush).in_sequence(syncorder) # Call inside syncothers
298
+ @mount.expects(:flush).in_sequence(syncorder) # I guess transaction or anything calls flush again
299
+
300
+ @mount[:ensure] = :unmounted
301
+ @mount[:options] = 'hard'
302
+
303
+ @catalog.apply
304
+ end
305
+
261
306
  end