puppet 2.7.13 → 2.7.14

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 (215) hide show
  1. data/CHANGELOG +144 -1
  2. data/conf/osx/preflight +1 -1
  3. data/conf/redhat/puppet.spec +9 -5
  4. data/conf/suse/puppet.spec +4 -1
  5. data/conf/windows/eventlog/Rakefile +32 -0
  6. data/conf/windows/eventlog/puppetres.dll +0 -0
  7. data/conf/windows/eventlog/puppetres.mc +18 -0
  8. data/ext/rack/files/apache2.conf +3 -0
  9. data/install.rb +23 -1
  10. data/lib/puppet.rb +1 -1
  11. data/lib/puppet/agent.rb +1 -14
  12. data/lib/puppet/application/kick.rb +1 -1
  13. data/lib/puppet/application/module.rb +11 -0
  14. data/lib/puppet/daemon.rb +74 -3
  15. data/lib/puppet/defaults.rb +1 -1
  16. data/lib/puppet/face/certificate.rb +1 -1
  17. data/lib/puppet/face/help/man.erb +1 -1
  18. data/lib/puppet/face/module.rb +17 -0
  19. data/lib/puppet/face/module/build.rb +10 -4
  20. data/lib/puppet/face/module/changes.rb +5 -5
  21. data/lib/puppet/face/module/generate.rb +6 -4
  22. data/lib/puppet/face/module/install.rb +122 -32
  23. data/lib/puppet/face/module/list.rb +234 -33
  24. data/lib/puppet/face/module/search.rb +56 -23
  25. data/lib/puppet/face/module/uninstall.rb +33 -38
  26. data/lib/puppet/face/module/upgrade.rb +84 -0
  27. data/lib/puppet/feature/eventlog.rb +6 -0
  28. data/lib/puppet/forge.rb +67 -122
  29. data/lib/puppet/forge/cache.rb +1 -1
  30. data/lib/puppet/forge/repository.rb +6 -25
  31. data/lib/puppet/indirector/facts/network_device.rb +1 -1
  32. data/lib/puppet/interface/action.rb +1 -1
  33. data/lib/puppet/module.rb +79 -28
  34. data/lib/puppet/module_tool.rb +72 -34
  35. data/lib/puppet/module_tool/applications.rb +12 -14
  36. data/lib/puppet/module_tool/applications/application.rb +21 -19
  37. data/lib/puppet/module_tool/applications/builder.rb +4 -4
  38. data/lib/puppet/module_tool/applications/checksummer.rb +12 -3
  39. data/lib/puppet/module_tool/applications/generator.rb +1 -1
  40. data/lib/puppet/module_tool/applications/installer.rb +163 -34
  41. data/lib/puppet/module_tool/applications/searcher.rb +2 -3
  42. data/lib/puppet/module_tool/applications/uninstaller.rb +84 -36
  43. data/lib/puppet/module_tool/applications/unpacker.rb +4 -26
  44. data/lib/puppet/module_tool/applications/upgrader.rb +109 -0
  45. data/lib/puppet/module_tool/checksums.rb +2 -2
  46. data/lib/puppet/module_tool/contents_description.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +2 -2
  48. data/lib/puppet/module_tool/errors.rb +9 -0
  49. data/lib/puppet/module_tool/errors/base.rb +15 -0
  50. data/lib/puppet/module_tool/errors/installer.rb +90 -0
  51. data/lib/puppet/module_tool/errors/shared.rb +115 -0
  52. data/lib/puppet/module_tool/errors/uninstaller.rb +45 -0
  53. data/lib/puppet/module_tool/errors/upgrader.rb +72 -0
  54. data/lib/puppet/module_tool/metadata.rb +2 -2
  55. data/lib/puppet/module_tool/modulefile.rb +7 -7
  56. data/lib/puppet/module_tool/shared_behaviors.rb +161 -0
  57. data/lib/puppet/module_tool/skeleton.rb +1 -1
  58. data/lib/puppet/node/environment.rb +4 -2
  59. data/lib/puppet/parser/ast/leaf.rb +1 -1
  60. data/lib/puppet/parser/functions/create_resources.rb +3 -2
  61. data/lib/puppet/parser/scope.rb +44 -9
  62. data/lib/puppet/provider/augeas/augeas.rb +2 -2
  63. data/lib/puppet/provider/exec.rb +8 -3
  64. data/lib/puppet/provider/exec/shell.rb +1 -2
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +10 -4
  66. data/lib/puppet/provider/package/gem.rb +1 -1
  67. data/lib/puppet/provider/package/pkg.rb +10 -21
  68. data/lib/puppet/provider/selmodule/semodule.rb +1 -2
  69. data/lib/puppet/provider/service/upstart.rb +33 -17
  70. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  71. data/lib/puppet/rails/inventory_node.rb +7 -7
  72. data/lib/puppet/reports/http.rb +4 -1
  73. data/lib/puppet/reports/tagmail.rb +8 -1
  74. data/lib/puppet/resource/type.rb +1 -1
  75. data/lib/puppet/test/test_helper.rb +138 -0
  76. data/lib/puppet/type.rb +9 -1
  77. data/lib/puppet/type/file.rb +18 -10
  78. data/lib/puppet/type/package.rb +13 -9
  79. data/lib/puppet/type/resources.rb +1 -1
  80. data/lib/puppet/type/ssh_authorized_key.rb +3 -4
  81. data/lib/puppet/type/sshkey.rb +4 -4
  82. data/lib/puppet/type/user.rb +1 -0
  83. data/lib/puppet/type/vlan.rb +1 -1
  84. data/lib/puppet/util.rb +31 -14
  85. data/lib/puppet/util/autoload.rb +1 -1
  86. data/lib/puppet/util/command_line.rb +2 -6
  87. data/lib/puppet/util/instrumentation/indirection_probe.rb +1 -1
  88. data/lib/puppet/util/instrumentation/instrumentable.rb +1 -1
  89. data/lib/puppet/util/instrumentation/listeners/log.rb +1 -1
  90. data/lib/puppet/util/instrumentation/listeners/performance.rb +1 -1
  91. data/lib/puppet/util/log.rb +3 -1
  92. data/lib/puppet/util/log/destinations.rb +38 -0
  93. data/lib/puppet/util/monkey_patches.rb +45 -0
  94. data/lib/puppet/util/network_device/base.rb +1 -1
  95. data/lib/puppet/util/network_device/cisco.rb +1 -1
  96. data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
  97. data/lib/puppet/util/network_device/cisco/interface.rb +1 -1
  98. data/lib/puppet/util/network_device/config.rb +1 -1
  99. data/lib/puppet/util/network_device/ipcalc.rb +1 -1
  100. data/lib/puppet/util/network_device/transport.rb +1 -1
  101. data/lib/puppet/util/network_device/transport/base.rb +1 -1
  102. data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
  103. data/lib/puppet/util/settings.rb +2 -11
  104. data/lib/puppet/util/settings/file_setting.rb +3 -5
  105. data/lib/puppet/util/terminal.rb +16 -0
  106. data/lib/puppet/util/zaml.rb +3 -1
  107. data/lib/semver.rb +15 -7
  108. data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -1
  109. data/spec/fixtures/unit/parser/lexer/arithmetic_expression.pp +1 -1
  110. data/spec/fixtures/unit/provider/package/pkg/dummy +1 -0
  111. data/spec/fixtures/unit/provider/package/pkg/incomplete +1 -0
  112. data/spec/fixtures/unit/provider/package/pkg/publisher +2 -0
  113. data/spec/fixtures/unit/provider/package/pkg/simple +4 -0
  114. data/spec/fixtures/unit/reports/tagmail/tagmail_email.conf +2 -0
  115. data/spec/fixtures/yaml/report0.25.x.yaml +1 -1
  116. data/spec/fixtures/yaml/report2.6.x.yaml +1 -1
  117. data/spec/integration/faces/documentation_spec.rb +1 -1
  118. data/spec/integration/network/rest_authconfig_spec.rb +1 -1
  119. data/spec/lib/puppet_spec/compiler.rb +6 -0
  120. data/spec/lib/puppet_spec/database.rb +30 -0
  121. data/spec/lib/puppet_spec/files.rb +4 -2
  122. data/spec/shared_behaviours/path_parameters.rb +2 -29
  123. data/spec/shared_contexts/platform.rb +43 -0
  124. data/spec/spec_helper.rb +36 -65
  125. data/spec/unit/agent_spec.rb +0 -32
  126. data/spec/unit/application/kick_spec.rb +2 -2
  127. data/spec/unit/daemon_spec.rb +1 -17
  128. data/spec/unit/face/module/install_spec.rb +158 -0
  129. data/spec/unit/face/module/list_spec.rb +182 -0
  130. data/spec/unit/face/module/search_spec.rb +163 -0
  131. data/spec/unit/face/module/uninstall_spec.rb +77 -0
  132. data/spec/unit/face/module/upgrade_spec.rb +26 -0
  133. data/spec/unit/forge/repository_spec.rb +0 -30
  134. data/spec/unit/forge_spec.rb +28 -86
  135. data/spec/unit/indirector/catalog/active_record_spec.rb +45 -65
  136. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +5 -18
  137. data/spec/unit/indirector/resource/active_record_spec.rb +2 -11
  138. data/spec/unit/indirector/resource/ral_spec.rb +7 -2
  139. data/spec/unit/module_spec.rb +240 -107
  140. data/spec/unit/module_tool/application_spec.rb +3 -5
  141. data/spec/unit/module_tool/applications/application_spec.rb +19 -0
  142. data/spec/unit/module_tool/applications/installer_spec.rb +205 -0
  143. data/spec/unit/module_tool/applications/uninstaller_spec.rb +206 -0
  144. data/spec/unit/module_tool/applications/upgrader_spec.rb +37 -0
  145. data/spec/unit/module_tool/metadata_spec.rb +2 -2
  146. data/spec/unit/module_tool_spec.rb +109 -1
  147. data/spec/unit/node/environment_spec.rb +16 -1
  148. data/spec/unit/parser/ast/leaf_spec.rb +16 -1
  149. data/spec/unit/parser/collector_spec.rb +2 -12
  150. data/spec/unit/parser/functions/create_resources_spec.rb +135 -86
  151. data/spec/unit/parser/functions/generate_spec.rb +2 -10
  152. data/spec/unit/parser/scope_spec.rb +345 -16
  153. data/spec/unit/provider/augeas/augeas_spec.rb +19 -0
  154. data/spec/unit/provider/exec/shell_spec.rb +17 -14
  155. data/spec/unit/provider/exec/windows_spec.rb +1 -7
  156. data/spec/unit/provider/exec_spec.rb +35 -0
  157. data/spec/unit/provider/nameservice/directoryservice_spec.rb +10 -0
  158. data/spec/unit/provider/package/dpkg_spec.rb +2 -1
  159. data/spec/unit/provider/package/gem_spec.rb +15 -0
  160. data/spec/unit/provider/package/openbsd_spec.rb +5 -4
  161. data/spec/unit/provider/package/pacman_spec.rb +3 -2
  162. data/spec/unit/provider/package/pkg_spec.rb +56 -33
  163. data/spec/unit/provider/selmodule_spec.rb +11 -4
  164. data/spec/unit/provider/service/redhat_spec.rb +1 -3
  165. data/spec/unit/provider/service/smf_spec.rb +1 -3
  166. data/spec/unit/provider/service/upstart_spec.rb +38 -0
  167. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +28 -0
  168. data/spec/unit/rails/host_spec.rb +6 -12
  169. data/spec/unit/rails/param_value_spec.rb +3 -8
  170. data/spec/unit/rails/resource_spec.rb +2 -8
  171. data/spec/unit/reports/http_spec.rb +47 -31
  172. data/spec/unit/reports/tagmail_spec.rb +77 -0
  173. data/spec/unit/resource/type_spec.rb +2 -2
  174. data/spec/unit/resource_spec.rb +18 -20
  175. data/spec/unit/semver_spec.rb +31 -13
  176. data/spec/unit/type/exec_spec.rb +8 -15
  177. data/spec/unit/type/group_spec.rb +0 -9
  178. data/spec/unit/type/package_spec.rb +10 -0
  179. data/spec/unit/type/resources_spec.rb +4 -5
  180. data/spec/unit/type/ssh_authorized_key_spec.rb +4 -15
  181. data/spec/unit/type/sshkey_spec.rb +9 -11
  182. data/spec/unit/type/user_spec.rb +123 -127
  183. data/spec/unit/type_spec.rb +20 -0
  184. data/spec/unit/util/command_line_spec.rb +2 -2
  185. data/spec/unit/util/instrumentation/data_spec.rb +1 -1
  186. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +1 -1
  187. data/spec/unit/util/instrumentation/instrumentable_spec.rb +1 -1
  188. data/spec/unit/util/instrumentation/listener_spec.rb +1 -1
  189. data/spec/unit/util/instrumentation/listeners/log_spec.rb +1 -1
  190. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +1 -1
  191. data/spec/unit/util/instrumentation_spec.rb +1 -1
  192. data/spec/unit/util/log/destinations_spec.rb +4 -8
  193. data/spec/unit/util/log_spec.rb +47 -0
  194. data/spec/unit/util/reference_spec.rb +1 -1
  195. data/spec/unit/util/settings/file_setting_spec.rb +9 -0
  196. data/spec/unit/util/settings_spec.rb +0 -53
  197. data/spec/unit/util/terminal_spec.rb +42 -0
  198. data/spec/unit/util/zaml_spec.rb +7 -0
  199. data/spec/unit/util_spec.rb +63 -20
  200. data/tasks/rake/manpages.rake +1 -1
  201. data/test/data/snippets/arithmetic_expression.pp +1 -1
  202. data/test/other/puppet.rb +0 -1
  203. data/test/util/log.rb +6 -6
  204. metadata +41 -16
  205. data/lib/puppet/external/event-loop.rb +0 -1
  206. data/lib/puppet/external/event-loop/better-definers.rb +0 -367
  207. data/lib/puppet/external/event-loop/event-loop.rb +0 -355
  208. data/lib/puppet/external/event-loop/signal-system.rb +0 -218
  209. data/lib/puppet/face/module/clean.rb +0 -30
  210. data/lib/puppet/module_tool/applications/cleaner.rb +0 -16
  211. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json +0 -12
  212. data/lib/puppet/module_tool/utils.rb +0 -5
  213. data/lib/puppet/module_tool/utils/interrogation.rb +0 -25
  214. data/spec/integration/module_tool_spec.rb +0 -475
  215. data/spec/unit/module_tool/uninstaller_spec.rb +0 -124
@@ -611,6 +611,26 @@ describe Puppet::Type, :fails_on_windows => true do
611
611
  end
612
612
  end
613
613
 
614
+ describe "::instances" do
615
+ it "should not fail if no suitable providers are found" do
616
+ fake_type = Puppet::Type.newtype(:type_spec_fake_type) do
617
+ newparam(:name) do
618
+ isnamevar
619
+ end
620
+ newproperty(:prop1) do
621
+ end
622
+
623
+ provide(:fake1) do
624
+ confine :exists => '/no/such/file'
625
+ mk_resource_methods
626
+ end
627
+ end
628
+
629
+ expect { fake_type.instances }.should_not raise_error
630
+ end
631
+ end
632
+
633
+
614
634
  describe "::ensurable?" do
615
635
  before :each do
616
636
  class TestEnsurableType < Puppet::Type
@@ -87,7 +87,7 @@ describe Puppet::Util::CommandLine do
87
87
  it "should find and invoke an executable with a hyphenated name" do
88
88
  commandline = Puppet::Util::CommandLine.new("puppet", ['whatever', 'argument'], @tty)
89
89
  Puppet::Util.expects(:which).with('puppet-whatever').returns('/dev/null/puppet-whatever')
90
- commandline.expects(:system).with('/dev/null/puppet-whatever', 'argument')
90
+ commandline.expects(:exec).with('/dev/null/puppet-whatever', 'argument')
91
91
 
92
92
  commandline.execute
93
93
  end
@@ -96,7 +96,7 @@ describe Puppet::Util::CommandLine do
96
96
  it "should abort and show the usage message" do
97
97
  commandline = Puppet::Util::CommandLine.new("puppet", ['whatever', 'argument'], @tty)
98
98
  Puppet::Util.expects(:which).with('puppet-whatever').returns(nil)
99
- commandline.expects(:system).never
99
+ commandline.expects(:exec).never
100
100
 
101
101
  expect {
102
102
  commandline.execute
@@ -41,4 +41,4 @@ describe Puppet::Util::Instrumentation::Data do
41
41
  it "should return a hash containing data when unserializing from pson" do
42
42
  Puppet::Util::Instrumentation::Data.from_pson({:name => "name"}).should == {:name => "name"}
43
43
  end
44
- end
44
+ end
@@ -16,4 +16,4 @@ describe Puppet::Util::Instrumentation::IndirectionProbe do
16
16
  probe = Puppet::Util::Instrumentation::IndirectionProbe.new("probe")
17
17
  probe.should set_json_attribute('name').to("probe")
18
18
  end
19
- end
19
+ end
@@ -183,4 +183,4 @@ describe Puppet::Util::Instrumentation::Instrumentable do
183
183
  Puppet::Util::Instrumentation::Instrumentable.enable_probes
184
184
  ProbeTest2.new.should respond_to(:instrumented_mymethod)
185
185
  end
186
- end
186
+ end
@@ -97,4 +97,4 @@ describe Puppet::Util::Instrumentation::Listener do
97
97
  Puppet::Util::Instrumentation::Listener.from_pson({"name" => "listener", "enabled" => true})
98
98
  end
99
99
  end
100
- end
100
+ end
@@ -31,4 +31,4 @@ describe log do
31
31
  25.times { @log.notify(:test, :stop, { :started => Time.at(123456789), :finished => Time.at(123456790)}) }
32
32
  @log.data[:test].size.should == 20
33
33
  end
34
- end
34
+ end
@@ -33,4 +33,4 @@ describe performance do
33
33
  @performance.notify(:test, :start, { :started => Time.at(123456789)})
34
34
  @performance.data.should be_empty
35
35
  end
36
- end
36
+ end
@@ -178,4 +178,4 @@ describe Puppet::Util::Instrumentation do
178
178
  end
179
179
  end
180
180
  end
181
- end
181
+ end
@@ -29,8 +29,8 @@ describe Puppet::Util::Log.desttypes[:file] do
29
29
  @class = Puppet::Util::Log.desttypes[:file]
30
30
  end
31
31
 
32
- it "should default to autoflush false" do
33
- @class.new('/tmp/log').autoflush.should == false
32
+ it "should default to automatically flush log output" do
33
+ @class.new('/tmp/log').autoflush.should == true
34
34
  end
35
35
 
36
36
  describe "when matching" do
@@ -44,18 +44,14 @@ describe Puppet::Util::Log.desttypes[:file] do
44
44
  end
45
45
  end
46
46
 
47
- describe "on POSIX systems" do
48
- before :each do Puppet.features.stubs(:microsoft_windows?).returns false end
49
-
47
+ describe "on POSIX systems", :as_platform => :posix do
50
48
  let (:abspath) { '/tmp/log' }
51
49
  let (:relpath) { 'log' }
52
50
 
53
51
  it_behaves_like "file destination"
54
52
  end
55
53
 
56
- describe "on Windows systems" do
57
- before :each do Puppet.features.stubs(:microsoft_windows?).returns true end
58
-
54
+ describe "on Windows systems", :as_platform => :windows do
59
55
  let (:abspath) { 'C:\\temp\\log.txt' }
60
56
  let (:relpath) { 'log.txt' }
61
57
 
@@ -22,8 +22,17 @@ describe Puppet::Util::Log do
22
22
  Puppet::Util::Log.setup_default
23
23
  end
24
24
 
25
+ it "should fall back to :eventlog" do
26
+ Puppet.features.stubs(:syslog?).returns(false)
27
+ Puppet.features.stubs(:eventlog?).returns(true)
28
+ Puppet::Util::Log.expects(:newdestination).with(:eventlog)
29
+
30
+ Puppet::Util::Log.setup_default
31
+ end
32
+
25
33
  it "should fall back to :file" do
26
34
  Puppet.features.stubs(:syslog?).returns(false)
35
+ Puppet.features.stubs(:eventlog?).returns(false)
27
36
  Puppet::Util::Log.expects(:newdestination).with(Puppet[:puppetdlog])
28
37
 
29
38
  Puppet::Util::Log.setup_default
@@ -72,6 +81,44 @@ describe Puppet::Util::Log do
72
81
  end
73
82
  end
74
83
 
84
+ describe Puppet::Util::Log::DestEventlog, :if => Puppet.features.eventlog? do
85
+ before :each do
86
+ Win32::EventLog.stubs(:open).returns(mock 'mylog')
87
+ Win32::EventLog.stubs(:report_event)
88
+ Win32::EventLog.stubs(:close)
89
+ Puppet.features.stubs(:eventlog?).returns(true)
90
+ end
91
+
92
+ it "should restrict its suitability" do
93
+ Puppet.features.expects(:eventlog?).returns(false)
94
+
95
+ Puppet::Util::Log::DestEventlog.suitable?('whatever').should == false
96
+ end
97
+
98
+ it "should open the 'Application' event log" do
99
+ Win32::EventLog.expects(:open).with('Application')
100
+
101
+ Puppet::Util::Log.newdestination(:eventlog)
102
+ end
103
+
104
+ it "should close the event log" do
105
+ log = mock('myeventlog')
106
+ log.expects(:close)
107
+ Win32::EventLog.expects(:open).returns(log)
108
+
109
+ Puppet::Util::Log.newdestination(:eventlog)
110
+ Puppet::Util::Log.close(:eventlog)
111
+ end
112
+
113
+ it "should handle each puppet log level" do
114
+ log = Puppet::Util::Log::DestEventlog.new
115
+
116
+ Puppet::Util::Log.eachlevel do |level|
117
+ log.to_native(level).should be_is_a(Array)
118
+ end
119
+ end
120
+ end
121
+
75
122
  describe "instances" do
76
123
  before do
77
124
  Puppet::Util::Log.stubs(:newmessage)
@@ -36,4 +36,4 @@ A term
36
36
  EOT
37
37
  end
38
38
 
39
- end
39
+ end
@@ -286,5 +286,14 @@ describe Puppet::Util::Settings::FileSetting do
286
286
  @file.to_resource[:links].should == :follow
287
287
  end
288
288
  end
289
+
290
+ describe "when munging a filename" do
291
+ it "should preserve trailing slashes" do
292
+ settings = mock 'settings'
293
+ file = Puppet::Util::Settings::FileSetting.new(:settings => settings, :desc => "eh", :name => :mydir, :section => "mysect")
294
+ path = @basepath + '/'
295
+ file.munge(path).should == path
296
+ end
297
+ end
289
298
  end
290
299
 
@@ -411,13 +411,6 @@ describe Puppet::Util::Settings do
411
411
  @settings.parse
412
412
  end
413
413
 
414
- it "should set a timer that triggers reparsing, even if the file does not exist" do
415
- FileTest.expects(:exist?).returns false
416
- @settings.expects(:set_filetimeout_timer)
417
-
418
- @settings.parse
419
- end
420
-
421
414
  it "should return values set in the configuration file" do
422
415
  text = "[main]
423
416
  one = fileval
@@ -559,12 +552,6 @@ describe Puppet::Util::Settings do
559
552
  File.expects(:expand_path).with(somefile).returns somefile
560
553
  @settings[:config] = somefile
561
554
  end
562
-
563
- it "should not set a timer" do
564
- EventLoop::Timer.expects(:new).never
565
-
566
- @settings.parse
567
- end
568
555
  end
569
556
  end
570
557
 
@@ -1057,46 +1044,6 @@ describe Puppet::Util::Settings do
1057
1044
  end
1058
1045
  end
1059
1046
 
1060
- describe "when setting a timer to trigger configuration file reparsing" do
1061
- before do
1062
- @settings = Puppet::Util::Settings.new
1063
- @settings.setdefaults :foo, :filetimeout => [5, "eh"]
1064
- end
1065
-
1066
- it "should do nothing if no filetimeout setting is available" do
1067
- @settings.expects(:value).with(:filetimeout).returns nil
1068
- EventLoop::Timer.expects(:new).never
1069
- @settings.set_filetimeout_timer
1070
- end
1071
-
1072
- it "should always convert the timer interval to an integer" do
1073
- @settings.expects(:value).with(:filetimeout).returns "10"
1074
- EventLoop::Timer.expects(:new).with(:interval => 10, :start? => true, :tolerance => 1)
1075
- @settings.set_filetimeout_timer
1076
- end
1077
-
1078
- it "should do nothing if the filetimeout setting is not greater than 0" do
1079
- @settings.expects(:value).with(:filetimeout).returns -2
1080
- EventLoop::Timer.expects(:new).never
1081
- @settings.set_filetimeout_timer
1082
- end
1083
-
1084
- it "should create a timer with its interval set to the filetimeout, start? set to true, and a tolerance of 1" do
1085
- @settings.expects(:value).with(:filetimeout).returns 5
1086
- EventLoop::Timer.expects(:new).with(:interval => 5, :start? => true, :tolerance => 1)
1087
-
1088
- @settings.set_filetimeout_timer
1089
- end
1090
-
1091
- it "should reparse when the timer goes off" do
1092
- EventLoop::Timer.expects(:new).with(:interval => 5, :start? => true, :tolerance => 1).yields
1093
-
1094
- @settings.expects(:reparse)
1095
-
1096
- @settings.set_filetimeout_timer
1097
- end
1098
- end
1099
-
1100
1047
  describe "when determining if the service user is available" do
1101
1048
  it "should return false if there is no user setting" do
1102
1049
  Puppet::Util::Settings.new.should_not be_service_user_available
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+ require 'puppet/util/terminal'
4
+
5
+ describe Puppet::Util::Terminal do
6
+ describe '.width' do
7
+ before { Puppet.features.stubs(:posix?).returns(true) }
8
+
9
+ it 'should invoke `stty` and return the width' do
10
+ height, width = 100, 200
11
+ subject.expects(:`).with('stty size 2>/dev/null').returns("#{height} #{width}\n")
12
+ subject.width.should == width
13
+ end
14
+
15
+ it 'should use `tput` if `stty` is unavailable' do
16
+ width = 200
17
+ subject.expects(:`).with('stty size 2>/dev/null').returns("\n")
18
+ subject.expects(:`).with('tput cols 2>/dev/null').returns("#{width}\n")
19
+ subject.width.should == width
20
+ end
21
+
22
+ it 'should default to 80 columns if `tput` and `stty` are unavailable' do
23
+ width = 80
24
+ subject.expects(:`).with('stty size 2>/dev/null').returns("\n")
25
+ subject.expects(:`).with('tput cols 2>/dev/null').returns("\n")
26
+ subject.width.should == width
27
+ end
28
+
29
+ it 'should default to 80 columns if `tput` or `stty` raise exceptions' do
30
+ width = 80
31
+ subject.expects(:`).with('stty size 2>/dev/null').raises()
32
+ subject.stubs(:`).with('tput cols 2>/dev/null').returns("#{width + 1000}\n")
33
+ subject.width.should == width
34
+ end
35
+
36
+ it 'should default to 80 columns if not in a POSIX environment' do
37
+ width = 80
38
+ Puppet.features.stubs(:posix?).returns(false)
39
+ subject.width.should == width
40
+ end
41
+ end
42
+ end
@@ -19,6 +19,13 @@ describe "Pure ruby yaml implementation" do
19
19
  {
20
20
  7 => "--- 7",
21
21
  3.14159 => "--- 3.14159",
22
+ "3.14159" => '--- "3.14159"',
23
+ "+3.14159" => '--- "+3.14159"',
24
+ "0x123abc" => '--- "0x123abc"',
25
+ "-0x123abc" => '--- "-0x123abc"',
26
+ "-0x123" => '--- "-0x123"',
27
+ "+0x123" => '--- "+0x123"',
28
+ "0x123.456" => "--- 0x123.456",
22
29
  'test' => "--- test",
23
30
  [] => "--- []",
24
31
  :symbol => "--- !ruby/sym symbol",
@@ -30,18 +30,18 @@ describe Puppet::Util do
30
30
  end
31
31
 
32
32
  describe "#absolute_path?" do
33
- it "should default to the platform of the local system" do
34
- Puppet.features.stubs(:posix?).returns(true)
35
- Puppet.features.stubs(:microsoft_windows?).returns(false)
36
-
37
- Puppet::Util.should be_absolute_path('/foo')
38
- Puppet::Util.should_not be_absolute_path('C:/foo')
39
-
40
- Puppet.features.stubs(:posix?).returns(false)
41
- Puppet.features.stubs(:microsoft_windows?).returns(true)
33
+ describe "on posix systems", :as_platform => :posix do
34
+ it "should default to the platform of the local system" do
35
+ Puppet::Util.should be_absolute_path('/foo')
36
+ Puppet::Util.should_not be_absolute_path('C:/foo')
37
+ end
38
+ end
42
39
 
43
- Puppet::Util.should be_absolute_path('C:/foo')
44
- Puppet::Util.should_not be_absolute_path('/foo')
40
+ describe "on windows", :as_platform => :windows do
41
+ it "should default to the platform of the local system" do
42
+ Puppet::Util.should be_absolute_path('C:/foo')
43
+ Puppet::Util.should_not be_absolute_path('/foo')
44
+ end
45
45
  end
46
46
 
47
47
  describe "when using platform :posix" do
@@ -223,15 +223,6 @@ describe Puppet::Util do
223
223
  Puppet::Util.execute_posix('test command', {}, @stdin, @stdout, @stderr)
224
224
  end
225
225
 
226
- it "should close all open file descriptors except stdin/stdout/stderr" do
227
- # This is ugly, but I can't really think of a better way to do it without
228
- # letting it actually close fds, which seems risky
229
- (0..2).each {|n| IO.expects(:new).with(n).never}
230
- (3..256).each {|n| IO.expects(:new).with(n).returns mock('io', :close) }
231
-
232
- Puppet::Util.execute_posix('test command', {}, @stdin, @stdout, @stderr)
233
- end
234
-
235
226
  it "should permanently change to the correct user and group if specified" do
236
227
  Puppet::Util::SUIDManager.expects(:change_group).with(55, true)
237
228
  Puppet::Util::SUIDManager.expects(:change_user).with(50, true)
@@ -487,6 +478,38 @@ describe Puppet::Util do
487
478
  }.not_to raise_error
488
479
  end
489
480
  end
481
+
482
+ describe "safe_posix_fork" do
483
+ before :each do
484
+ # Most of the things this method does are bad to do during specs. :/
485
+ Kernel.stubs(:fork).returns(pid).yields
486
+
487
+ $stdin.stubs(:reopen)
488
+ $stdout.stubs(:reopen)
489
+ $stderr.stubs(:reopen)
490
+ end
491
+
492
+ it "should close all open file descriptors except stdin/stdout/stderr" do
493
+ # This is ugly, but I can't really think of a better way to do it without
494
+ # letting it actually close fds, which seems risky
495
+ (0..2).each {|n| IO.expects(:new).with(n).never}
496
+ (3..256).each {|n| IO.expects(:new).with(n).returns mock('io', :close) }
497
+
498
+ Puppet::Util.safe_posix_fork
499
+ end
500
+
501
+ it "should fork a child process to execute the block" do
502
+ Kernel.expects(:fork).returns(pid).yields
503
+
504
+ Puppet::Util.safe_posix_fork do
505
+ message = "Fork this!"
506
+ end
507
+ end
508
+
509
+ it "should return the pid of the child process" do
510
+ Puppet::Util.safe_posix_fork.should == pid
511
+ end
512
+ end
490
513
  end
491
514
 
492
515
  describe "#execpipe" do
@@ -637,6 +660,26 @@ describe Puppet::Util do
637
660
  end
638
661
  end
639
662
 
663
+ describe "hash symbolizing functions" do
664
+ let (:myhash) { { "foo" => "bar", :baz => "bam" } }
665
+ let (:resulthash) { { :foo => "bar", :baz => "bam" } }
666
+
667
+ describe "#symbolizehash" do
668
+ it "should return a symbolized hash" do
669
+ newhash = Puppet::Util.symbolizehash(myhash)
670
+ newhash.should == resulthash
671
+ end
672
+ end
673
+
674
+ describe "#symbolizehash!" do
675
+ it "should symbolize the hash in place" do
676
+ localhash = myhash
677
+ Puppet::Util.symbolizehash!(localhash)
678
+ localhash.should == resulthash
679
+ end
680
+ end
681
+ end
682
+
640
683
  context "#replace_file" do
641
684
  describe "on POSIX platforms", :if => Puppet.features.posix? do
642
685
  subject { Puppet::Util }