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
@@ -413,6 +413,25 @@ describe provider_class do
413
413
  @provider.should be_need_to_run
414
414
  end
415
415
 
416
+ # Workaround for Augeas bug #264 which reports filenames twice
417
+ it "should handle duplicate /augeas/events/saved filenames" do
418
+ file = "/etc/hosts"
419
+
420
+ @resource[:context] = "/files"
421
+ @resource[:changes] = ["set #{file}/foo bar"]
422
+
423
+ @augeas.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved[1]", "/augeas/events/saved[2]"])
424
+ @augeas.stubs(:get).with("/augeas/events/saved[1]").returns("/files#{file}")
425
+ @augeas.stubs(:get).with("/augeas/events/saved[2]").returns("/files#{file}")
426
+ @augeas.expects(:set).with("/augeas/save", "newfile")
427
+ @augeas.expects(:close)
428
+
429
+ File.expects(:delete).with(file + ".augnew").once()
430
+
431
+ @provider.expects(:diff).with("#{file}", "#{file}.augnew").returns("").once()
432
+ @provider.should be_need_to_run
433
+ end
434
+
416
435
  it "should fail with an error if saving fails" do
417
436
  file = "/etc/hosts"
418
437
 
@@ -1,50 +1,53 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
3
 
4
- provider_class = Puppet::Type.type(:exec).provider(:shell)
5
-
6
- describe provider_class, :unless => Puppet.features.microsoft_windows? do
7
- before :each do
8
- @resource = Puppet::Resource.new(:exec, 'foo')
9
- @provider = provider_class.new(@resource)
10
- end
4
+ describe Puppet::Type.type(:exec).provider(:shell), :unless => Puppet.features.microsoft_windows? do
5
+ let :resource do Puppet::Resource.new(:exec, 'foo') end
6
+ let :provider do described_class.new(resource) end
11
7
 
12
8
  describe "#run" do
13
9
  it "should be able to run builtin shell commands" do
14
- output, status = @provider.run("if [ 1 = 1 ]; then echo 'blah'; fi")
10
+ output, status = provider.run("if [ 1 = 1 ]; then echo 'blah'; fi")
15
11
  status.exitstatus.should == 0
16
12
  output.should == "blah\n"
17
13
  end
18
14
 
19
15
  it "should be able to run commands with single quotes in them" do
20
- output, status = @provider.run("echo 'foo bar'")
16
+ output, status = provider.run("echo 'foo bar'")
21
17
  status.exitstatus.should == 0
22
18
  output.should == "foo bar\n"
23
19
  end
24
20
 
25
21
  it "should be able to run commands with double quotes in them" do
26
- output, status = @provider.run('echo "foo bar"')
22
+ output, status = provider.run('echo "foo bar"')
27
23
  status.exitstatus.should == 0
28
24
  output.should == "foo bar\n"
29
25
  end
30
26
 
31
27
  it "should be able to run multiple commands separated by a semicolon" do
32
- output, status = @provider.run("echo 'foo' ; echo 'bar'")
28
+ output, status = provider.run("echo 'foo' ; echo 'bar'")
33
29
  status.exitstatus.should == 0
34
30
  output.should == "foo\nbar\n"
35
31
  end
36
32
 
37
33
  it "should be able to read values from the environment parameter" do
38
- @resource[:environment] = "FOO=bar"
39
- output, status = @provider.run("echo $FOO")
34
+ resource[:environment] = "FOO=bar"
35
+ output, status = provider.run("echo $FOO")
40
36
  status.exitstatus.should == 0
41
37
  output.should == "bar\n"
42
38
  end
39
+
40
+ it "#14060: should interpolate inside the subshell, not outside it" do
41
+ resource[:environment] = "foo=outer"
42
+ output, status = provider.run("foo=inner; echo \"foo is $foo\"")
43
+ status.exitstatus.should == 0
44
+ output.should == "foo is inner\n"
45
+ end
43
46
  end
44
47
 
45
48
  describe "#validatecmd" do
46
49
  it "should always return true because builtins don't need path or to be fully qualified" do
47
- @provider.validatecmd('whateverdoesntmatter').should == true
50
+ provider.validatecmd('whateverdoesntmatter').should == true
48
51
  end
49
52
  end
50
53
  end
@@ -2,18 +2,12 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Puppet::Type.type(:exec).provider(:windows) do
5
+ describe Puppet::Type.type(:exec).provider(:windows), :as_platform => :windows do
6
6
  include PuppetSpec::Files
7
7
 
8
8
  let(:resource) { Puppet::Type.type(:exec).new(:title => 'C:\foo', :provider => :windows) }
9
9
  let(:provider) { described_class.new(resource) }
10
10
 
11
- before :each do
12
- Facter.stubs(:value).with(:operatingsystem).returns 'Windows'
13
- Puppet.features.stubs(:microsoft_windows?).returns(true)
14
- Puppet.features.stubs(:posix?).returns(false)
15
- end
16
-
17
11
  after :all do
18
12
  # This provider may not be suitable on some machines, so we want to reset
19
13
  # the default so it isn't used by mistake in future specs.
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+ require 'puppet/provider/exec'
4
+
5
+ describe Puppet::Provider::Exec do
6
+ describe "#extractexe" do
7
+ it "should return the first element of an array" do
8
+ subject.extractexe(['one', 'two']).should == 'one'
9
+ end
10
+
11
+ {
12
+ # double-quoted commands
13
+ %q{"/has whitespace"} => "/has whitespace",
14
+ %q{"/no/whitespace"} => "/no/whitespace",
15
+ # singe-quoted commands
16
+ %q{'/has whitespace'} => "/has whitespace",
17
+ %q{'/no/whitespace'} => "/no/whitespace",
18
+ # combinations
19
+ %q{"'/has whitespace'"} => "'/has whitespace'",
20
+ %q{'"/has whitespace"'} => '"/has whitespace"',
21
+ %q{"/has 'special' characters"} => "/has 'special' characters",
22
+ %q{'/has "special" characters'} => '/has "special" characters',
23
+ # whitespace split commands
24
+ %q{/has whitespace} => "/has",
25
+ %q{/no/whitespace} => "/no/whitespace",
26
+ }.each do |base_command, exe|
27
+ ['', ' and args', ' "and args"', " 'and args'"].each do |args|
28
+ command = base_command + args
29
+ it "should extract #{exe.inspect} from #{command.inspect}" do
30
+ subject.extractexe(command).should == exe
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -155,6 +155,16 @@ describe 'DirectoryService password behavior' do
155
155
  Plist::Emit.expects(:save_plist).with(shadow_hash_data, plist_path)
156
156
  subject.set_password('jeff', 'uid', sha512_hash)
157
157
  end
158
+
159
+ it '[#13686] should handle an empty ShadowHashData field in the users plist' do
160
+ subject.expects(:convert_xml_to_binary).returns(binary_plist)
161
+ File.expects(:exists?).with(plist_path).once.returns(true)
162
+ Plist.expects(:parse_xml).returns({'ShadowHashData' => nil})
163
+ subject.expects(:plutil).with('-convert', 'xml1', '-o', '/dev/stdout', plist_path)
164
+ subject.expects(:plutil).with('-convert', 'binary1', plist_path)
165
+ Plist::Emit.expects(:save_plist)
166
+ subject.set_password('jeff', 'uid', sha512_hash)
167
+ end
158
168
  end
159
169
 
160
170
  describe '(#4855) directoryservice group resource failure' do
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
+ require 'stringio'
3
4
 
4
5
  provider = Puppet::Type.type(:package).provider(:dpkg)
5
6
 
@@ -23,7 +24,7 @@ describe provider do
23
24
 
24
25
  it "should use dpkg-query" do
25
26
  provider.expects(:command).with(:dpkgquery).returns "myquery"
26
- provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").returns @fakeresult
27
+ provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").yields StringIO.new(@fakeresult)
27
28
 
28
29
  provider.instances
29
30
  end
@@ -87,6 +87,21 @@ describe provider_class do
87
87
  end
88
88
  end
89
89
 
90
+ describe "#latest" do
91
+ it "should return a single value for 'latest'" do
92
+ #gemlist is used for retrieving both local and remote version numbers, and there are cases
93
+ # (particularly local) where it makes sense for it to return an array. That doesn't make
94
+ # sense for '#latest', though.
95
+ provider.class.expects(:gemlist).with({ :justme => 'myresource'}).returns({
96
+ :name => 'myresource',
97
+ :ensure => ["3.0"],
98
+ :provider => :gem,
99
+ })
100
+ provider.latest.should == "3.0"
101
+ end
102
+ end
103
+
104
+
90
105
  describe "#instances" do
91
106
  before do
92
107
  provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
+ require 'stringio'
3
4
 
4
5
  provider_class = Puppet::Type.type(:package).provider(:openbsd)
5
6
 
@@ -26,12 +27,12 @@ describe provider_class do
26
27
  end
27
28
 
28
29
  it "should return the empty set if no packages are listed" do
29
- subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields('')
30
+ subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(StringIO.new(''))
30
31
  subject.instances.should be_empty
31
32
  end
32
33
 
33
34
  it "should return all packages when invoked" do
34
- fixture = File.read(my_fixture('pkginfo.list'))
35
+ fixture = File.new(my_fixture('pkginfo.list'))
35
36
  subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(fixture)
36
37
  subject.instances.map(&:name).sort.should ==
37
38
  %w{bash bzip2 expat gettext libiconv lzo openvpn python vim wget}.sort
@@ -84,7 +85,7 @@ describe provider_class do
84
85
  end
85
86
 
86
87
  it "should return the package version if in the output" do
87
- fixture = File.read(my_fixture('pkginfo.list'))
88
+ fixture = File.new(my_fixture('pkginfo.list'))
88
89
  provider = subject.new(package(:name => 'bash'))
89
90
  provider.expects(:execpipe).with(%w{/bin/pkg_info -I bash}).yields(fixture)
90
91
  provider.get_version.should == '3.1.17'
@@ -92,7 +93,7 @@ describe provider_class do
92
93
 
93
94
  it "should return the empty string if the package is not present" do
94
95
  provider = subject.new(package(:name => 'zsh'))
95
- provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields('')
96
+ provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields(StringIO.new(''))
96
97
  provider.get_version.should == ''
97
98
  end
98
99
  end
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
+ require 'stringio'
3
4
 
4
5
  provider = Puppet::Type.type(:package).provider(:pacman)
5
6
 
@@ -162,7 +163,7 @@ EOF
162
163
  end
163
164
 
164
165
  it "should return installed packages with their versions" do
165
- provider.expects(:execpipe).yields("package1 1.23-4\npackage2 2.00\n")
166
+ provider.expects(:execpipe).yields(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
166
167
  packages = provider.instances
167
168
 
168
169
  packages.length.should == 2
@@ -186,7 +187,7 @@ EOF
186
187
  end
187
188
 
188
189
  it "should warn on invalid input" do
189
- provider.expects(:execpipe).yields("blah")
190
+ provider.expects(:execpipe).yields(StringIO.new("blah"))
190
191
  provider.expects(:warning).with("Failed to match line blah")
191
192
  provider.instances.should == []
192
193
  end
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
3
 
4
- provider = Puppet::Type.type(:package).provider(:pkg)
5
-
6
- describe provider do
7
- before do
8
- @resource = stub 'resource', :[] => "dummy"
9
- @provider = provider.new(@resource)
10
-
11
- @fakeresult = "install ok installed dummy 1.0\n"
4
+ describe Puppet::Type.type(:package).provider(:pkg) do
5
+ before :each do
6
+ @resource = Puppet::Resource.new(:package, 'dummy', :parameters => {:name => 'dummy', :ensure => :latest})
7
+ @provider = described_class.new(@resource)
12
8
  end
13
9
 
14
10
  def self.it_should_respond_to(*actions)
@@ -21,8 +17,8 @@ describe provider do
21
17
 
22
18
  it_should_respond_to :install, :uninstall, :update, :query, :latest
23
19
 
24
- it "should be versionable" do
25
- provider.should_not be_versionable
20
+ it "should not be versionable" do
21
+ described_class.should_not be_versionable
26
22
  end
27
23
 
28
24
  it "should use :install to update" do
@@ -30,33 +26,60 @@ describe provider do
30
26
  @provider.update
31
27
  end
32
28
 
33
- it "should parse a line correctly" do
34
- result = provider.parse_line("dummy 1.0@1.0-1.0 installed ----")
35
- result.should == {:name => "dummy", :version => "1.0@1.0-1.0",
36
- :ensure => :present, :status => "installed",
37
- :provider => :pkg, :error => "ok"}
38
- end
29
+ describe "when calling instances" do
30
+ it "should correctly parse lines with preferred publisher" do
31
+ described_class.expects(:pkg).with(:list,'-H').returns File.read(my_fixture('simple'))
32
+ @instances = described_class.instances.map { |p| Hash.new(:name => p.get(:name), :ensure => p.get(:ensure)) }
33
+ @instances.size.should == 4
34
+ @instances[0].should == Hash.new(:name => 'SUNPython', :ensure => :present)
35
+ @instances[1].should == Hash.new(:name => 'SUNWbind', :ensure => :present)
36
+ @instances[2].should == Hash.new(:name => 'SUNWdistro-license-copyright', :ensure => :present)
37
+ @instances[3].should == Hash.new(:name => 'SUNWfppd', :ensure => :present)
38
+ end
39
39
 
40
- it "should fail to parse an incorrect line" do
41
- result = provider.parse_line("foo")
42
- result.should be_nil
43
- end
40
+ it "should correctly parse lines with non preferred publisher" do
41
+ described_class.expects(:pkg).with(:list,'-H').returns File.read(my_fixture('publisher'))
42
+ @instances = described_class.instances.map { |p| Hash.new(:name => p.get(:name), :ensure => p.get(:ensure)) }
43
+ @instances.size.should == 2
44
+ @instances[0].should == Hash.new(:name => 'SUNWpcre', :ensure => :present)
45
+ @instances[1].should == Hash.new(:name => 'service/network/ssh', :ensure => :present)
46
+ end
44
47
 
45
- it "should fail to list a missing package" do
46
- @provider.expects(:pkg).with(:list, "-H", "dummy").returns "1"
47
- @provider.query.should == {:status=>"missing", :ensure=>:absent,
48
- :name=>"dummy", :error=>"ok"}
48
+ it "should warn about incorrect lines" do
49
+ fake_output = File.read(my_fixture('incomplete'))
50
+ error_line = fake_output.lines[0]
51
+ described_class.expects(:pkg).with(:list,'-H').returns fake_output
52
+ described_class.expects(:warning).with "Failed to match 'pkg list' line #{error_line.inspect}"
53
+ described_class.instances
54
+ end
49
55
  end
50
56
 
51
- it "should fail to list a package when it can't parse the output line" do
52
- @provider.expects(:pkg).with(:list, "-H", "dummy").returns "failed"
53
- @provider.query.should == {:status=>"missing", :ensure=>:absent, :name=>"dummy", :error=>"ok"}
54
- end
57
+ describe "when query a package" do
58
+ it "should find the package" do
59
+ @provider.stubs(:pkg).with(:list,'-H','dummy').returns File.read(my_fixture('dummy'))
60
+ @provider.query.should == {
61
+ :name => 'dummy',
62
+ :ensure => :present,
63
+ :version => '2.5.5-0.111',
64
+ :status => "installed",
65
+ :provider => :pkg,
66
+ }
67
+ end
68
+
69
+ it "should return :absent when the package is not found" do
70
+ # I dont know what the acutal error looks like, but according to type/pkg.rb we're just
71
+ # reacting on the Exception anyways
72
+ @provider.expects(:pkg).with(:list, "-H", "dummy").raises Puppet::ExecutionFailure, 'Not found'
73
+ @provider.query.should == {:ensure => :absent, :name => "dummy"}
74
+ end
55
75
 
56
- it "should list package correctly" do
57
- @provider.expects(:pkg).with(:list, "-H", "dummy").returns "dummy 1.0@1.0-1.0 installed ----"
58
- @provider.query.should == {:name => "dummy", :version => "1.0@1.0-1.0",
59
- :ensure => :present, :status => "installed",
60
- :provider => :pkg, :error => "ok"}
76
+ it "should return :absent when the packageline cannot be parsed" do
77
+ @provider.stubs(:pkg).with(:list,'-H','dummy').returns File.read(my_fixture('incomplete'))
78
+ @provider.query.should == {
79
+ :name => 'dummy',
80
+ :ensure => :absent
81
+ }
82
+ end
61
83
  end
84
+
62
85
  end
@@ -6,6 +6,7 @@
6
6
  # 256 bytes taken from /usr/share/selinux/targeted/nagios.pp on Fedora 9
7
7
 
8
8
  require 'spec_helper'
9
+ require 'stringio'
9
10
 
10
11
  provider_class = Puppet::Type.type(:selmodule).provider(:semodule)
11
12
 
@@ -19,19 +20,19 @@ describe provider_class do
19
20
  describe "exists? method" do
20
21
  it "should find a module if it is already loaded" do
21
22
  @provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
22
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields "bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n"
23
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n")
23
24
  @provider.exists?.should == :true
24
25
  end
25
26
 
26
27
  it "should return nil if not loaded" do
27
28
  @provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
28
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields "bar\t1.2.3\nbang\t1.0.0\n"
29
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nbang\t1.0.0\n")
29
30
  @provider.exists?.should be_nil
30
31
  end
31
32
 
32
33
  it "should return nil if no modules are loaded" do
33
34
  @provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
34
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields ""
35
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("")
35
36
  @provider.exists?.should be_nil
36
37
  end
37
38
  end
@@ -60,7 +61,13 @@ describe provider_class do
60
61
  @provider.expects(:selmodversion_loaded).returns nil
61
62
  @provider.syncversion.should == :false
62
63
  end
63
-
64
64
  end
65
65
 
66
+ describe "selmodversion_loaded" do
67
+ it "should return the version of a loaded module" do
68
+ @provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
69
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n")
70
+ @provider.selmodversion_loaded.should == "4.4.4"
71
+ end
72
+ end
66
73
  end
@@ -6,11 +6,9 @@ require 'spec_helper'
6
6
 
7
7
  provider_class = Puppet::Type.type(:service).provider(:redhat)
8
8
 
9
- describe provider_class do
9
+ describe provider_class, :as_platform => :posix do
10
10
 
11
11
  before :each do
12
- Puppet.features.stubs(:posix?).returns(true)
13
- Puppet.features.stubs(:microsoft_windows?).returns(false)
14
12
  @class = Puppet::Type.type(:service).provider(:redhat)
15
13
  @resource = stub 'resource'
16
14
  @resource.stubs(:[]).returns(nil)
@@ -8,11 +8,9 @@ require 'spec_helper'
8
8
 
9
9
  provider_class = Puppet::Type.type(:service).provider(:smf)
10
10
 
11
- describe provider_class do
11
+ describe provider_class, :as_platform => :posix do
12
12
 
13
13
  before(:each) do
14
- Puppet.features.stubs(:posix?).returns(true)
15
- Puppet.features.stubs(:microsoft_windows?).returns(false)
16
14
  # Create a mock resource
17
15
  @resource = Puppet::Type.type(:service).new(
18
16
  :name => "/system/myservice", :ensure => :running, :enable => :true)