puppet 2.7.11 → 2.7.12

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 (220) hide show
  1. data/CHANGELOG +188 -0
  2. data/conf/osx/createpackage.sh +1 -0
  3. data/conf/redhat/puppet.spec +12 -9
  4. data/conf/suse/puppet.spec +4 -1
  5. data/install.rb +9 -22
  6. data/lib/puppet.rb +1 -31
  7. data/lib/puppet/agent.rb +3 -5
  8. data/lib/puppet/agent/locker.rb +15 -1
  9. data/lib/puppet/application.rb +7 -4
  10. data/lib/puppet/application/agent.rb +4 -25
  11. data/lib/puppet/application/apply.rb +3 -3
  12. data/lib/puppet/application/device.rb +2 -16
  13. data/lib/puppet/application/doc.rb +2 -2
  14. data/lib/puppet/application/face_base.rb +22 -5
  15. data/lib/puppet/application/filebucket.rb +2 -0
  16. data/lib/puppet/application/inspect.rb +2 -1
  17. data/lib/puppet/application/kick.rb +25 -9
  18. data/lib/puppet/application/queue.rb +0 -23
  19. data/lib/puppet/configurer.rb +1 -0
  20. data/lib/puppet/configurer/downloader.rb +7 -3
  21. data/lib/puppet/defaults.rb +34 -29
  22. data/lib/puppet/face/ca.rb +1 -1
  23. data/lib/puppet/face/catalog.rb +1 -0
  24. data/lib/puppet/face/file/store.rb +1 -1
  25. data/lib/puppet/face/module/list.rb +23 -3
  26. data/lib/puppet/face/module/search.rb +21 -32
  27. data/lib/puppet/face/module/uninstall.rb +56 -15
  28. data/lib/puppet/file_bucket/dipper.rb +2 -2
  29. data/lib/puppet/file_serving/base.rb +6 -5
  30. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  31. data/lib/puppet/file_serving/content.rb +1 -1
  32. data/lib/puppet/forge.rb +153 -0
  33. data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
  34. data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
  35. data/lib/puppet/indirector/exec.rb +1 -1
  36. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
  37. data/lib/puppet/interface/action.rb +6 -2
  38. data/lib/puppet/module.rb +70 -10
  39. data/lib/puppet/module_tool.rb +2 -38
  40. data/lib/puppet/module_tool/applications.rb +15 -11
  41. data/lib/puppet/module_tool/applications/application.rb +2 -5
  42. data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
  43. data/lib/puppet/module_tool/applications/installer.rb +10 -45
  44. data/lib/puppet/module_tool/applications/searcher.rb +2 -26
  45. data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
  46. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +1 -1
  48. data/lib/puppet/network/authconfig.rb +1 -1
  49. data/lib/puppet/network/handler/fileserver.rb +1 -1
  50. data/lib/puppet/network/http/handler.rb +4 -1
  51. data/lib/puppet/network/http/webrick.rb +4 -2
  52. data/lib/puppet/node/environment.rb +32 -6
  53. data/lib/puppet/parameter/path.rb +0 -4
  54. data/lib/puppet/parser/ast/relationship.rb +3 -16
  55. data/lib/puppet/parser/collector.rb +5 -3
  56. data/lib/puppet/parser/compiler.rb +2 -1
  57. data/lib/puppet/parser/functions/file.rb +1 -1
  58. data/lib/puppet/parser/functions/generate.rb +8 -2
  59. data/lib/puppet/parser/grammar.ra +16 -15
  60. data/lib/puppet/parser/parser.rb +959 -881
  61. data/lib/puppet/parser/relationship.rb +32 -15
  62. data/lib/puppet/parser/resource.rb +0 -1
  63. data/lib/puppet/parser/type_loader.rb +1 -2
  64. data/lib/puppet/provider/augeas/augeas.rb +17 -29
  65. data/lib/puppet/provider/exec/windows.rb +25 -3
  66. data/lib/puppet/provider/file/posix.rb +1 -1
  67. data/lib/puppet/provider/file/windows.rb +1 -1
  68. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  69. data/lib/puppet/provider/package/aix.rb +1 -1
  70. data/lib/puppet/provider/package/appdmg.rb +1 -1
  71. data/lib/puppet/provider/package/dpkg.rb +1 -1
  72. data/lib/puppet/provider/package/gem.rb +21 -23
  73. data/lib/puppet/provider/package/macports.rb +1 -1
  74. data/lib/puppet/provider/package/msi.rb +7 -1
  75. data/lib/puppet/provider/package/openbsd.rb +13 -16
  76. data/lib/puppet/provider/package/pacman.rb +1 -1
  77. data/lib/puppet/provider/package/pip.rb +3 -0
  78. data/lib/puppet/provider/package/pkg.rb +1 -1
  79. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  80. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  81. data/lib/puppet/provider/package/portage.rb +2 -2
  82. data/lib/puppet/provider/package/rpm.rb +1 -1
  83. data/lib/puppet/provider/package/sun.rb +1 -1
  84. data/lib/puppet/provider/package/zypper.rb +35 -3
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
  86. data/lib/puppet/provider/selmodule/semodule.rb +2 -2
  87. data/lib/puppet/provider/service/base.rb +1 -1
  88. data/lib/puppet/provider/service/launchd.rb +4 -0
  89. data/lib/puppet/provider/service/src.rb +2 -2
  90. data/lib/puppet/provider/service/upstart.rb +1 -1
  91. data/lib/puppet/provider/service/windows.rb +5 -4
  92. data/lib/puppet/provider/user/aix.rb +3 -3
  93. data/lib/puppet/provider/user/pw.rb +6 -0
  94. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  95. data/lib/puppet/resource/catalog.rb +6 -6
  96. data/lib/puppet/resource/type.rb +2 -0
  97. data/lib/puppet/ssl/certificate_request.rb +0 -70
  98. data/lib/puppet/transaction.rb +1 -1
  99. data/lib/puppet/transaction/report.rb +3 -2
  100. data/lib/puppet/type.rb +1 -1
  101. data/lib/puppet/type/cron.rb +5 -2
  102. data/lib/puppet/type/exec.rb +8 -0
  103. data/lib/puppet/type/file.rb +27 -18
  104. data/lib/puppet/type/file/checksum.rb +2 -2
  105. data/lib/puppet/type/file/content.rb +14 -9
  106. data/lib/puppet/type/file/ensure.rb +5 -4
  107. data/lib/puppet/type/file/group.rb +10 -2
  108. data/lib/puppet/type/file/mode.rb +46 -18
  109. data/lib/puppet/type/file/owner.rb +10 -2
  110. data/lib/puppet/type/file/source.rb +27 -40
  111. data/lib/puppet/type/file/target.rb +6 -6
  112. data/lib/puppet/type/group.rb +13 -9
  113. data/lib/puppet/type/k5login.rb +1 -1
  114. data/lib/puppet/type/package.rb +24 -8
  115. data/lib/puppet/type/scheduled_task.rb +77 -131
  116. data/lib/puppet/type/service.rb +22 -8
  117. data/lib/puppet/type/user.rb +29 -9
  118. data/lib/puppet/util.rb +24 -33
  119. data/lib/puppet/util/colors.rb +98 -0
  120. data/lib/puppet/util/diff.rb +3 -1
  121. data/lib/puppet/util/log.rb +5 -1
  122. data/lib/puppet/util/log/destinations.rb +37 -44
  123. data/lib/puppet/util/monkey_patches.rb +32 -0
  124. data/lib/puppet/util/pidlock.rb +70 -21
  125. data/lib/puppet/util/rdoc/parser.rb +4 -2
  126. data/lib/puppet/util/selinux.rb +1 -1
  127. data/lib/puppet/util/suidmanager.rb +2 -12
  128. data/lib/puppet/util/windows.rb +2 -0
  129. data/lib/puppet/util/windows/process.rb +33 -0
  130. data/lib/puppet/util/windows/security.rb +6 -4
  131. data/lib/puppet/util/windows/user.rb +44 -0
  132. data/lib/semver.rb +55 -4
  133. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
  134. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
  135. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
  136. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
  137. data/spec/integration/defaults_spec.rb +10 -0
  138. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  139. data/spec/integration/module_tool_spec.rb +10 -12
  140. data/spec/integration/parser/compiler_spec.rb +147 -0
  141. data/spec/integration/type/file_spec.rb +1 -1
  142. data/spec/integration/util/windows/user_spec.rb +59 -0
  143. data/spec/lib/puppet/face/basetest.rb +5 -0
  144. data/spec/lib/puppet_spec/modules.rb +26 -0
  145. data/spec/spec_helper.rb +25 -0
  146. data/spec/unit/agent/locker_spec.rb +12 -0
  147. data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
  148. data/spec/unit/agent_spec.rb +28 -8
  149. data/spec/unit/application/agent_spec.rb +4 -36
  150. data/spec/unit/application/device_spec.rb +55 -10
  151. data/spec/unit/application/face_base_spec.rb +32 -10
  152. data/spec/unit/application/filebucket_spec.rb +5 -0
  153. data/spec/unit/application/kick_spec.rb +6 -0
  154. data/spec/unit/application_spec.rb +8 -1
  155. data/spec/unit/configurer/downloader_spec.rb +4 -5
  156. data/spec/unit/face/ca_spec.rb +15 -4
  157. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  158. data/spec/unit/file_serving/base_spec.rb +60 -42
  159. data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
  160. data/spec/unit/file_serving/content_spec.rb +26 -27
  161. data/spec/unit/file_serving/metadata_spec.rb +22 -21
  162. data/spec/unit/forge/repository_spec.rb +86 -0
  163. data/spec/unit/forge_spec.rb +114 -0
  164. data/spec/unit/indirector/exec_spec.rb +8 -6
  165. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
  166. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  167. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  168. data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
  169. data/spec/unit/interface/action_builder_spec.rb +7 -5
  170. data/spec/unit/module_spec.rb +228 -9
  171. data/spec/unit/module_tool/application_spec.rb +3 -3
  172. data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
  173. data/spec/unit/module_tool_spec.rb +0 -33
  174. data/spec/unit/network/authconfig_spec.rb +22 -21
  175. data/spec/unit/network/http/webrick_spec.rb +13 -9
  176. data/spec/unit/node/environment_spec.rb +159 -66
  177. data/spec/unit/parser/collector_spec.rb +16 -8
  178. data/spec/unit/parser/functions/generate_spec.rb +60 -18
  179. data/spec/unit/parser/resource_spec.rb +44 -0
  180. data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
  181. data/spec/unit/provider/confine/feature_spec.rb +3 -5
  182. data/spec/unit/provider/package/dpkg_spec.rb +4 -2
  183. data/spec/unit/provider/package/gem_spec.rb +59 -43
  184. data/spec/unit/provider/package/openbsd_spec.rb +114 -0
  185. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  186. data/spec/unit/provider/package/pip_spec.rb +10 -4
  187. data/spec/unit/provider/package/zypper_spec.rb +56 -14
  188. data/spec/unit/provider/selmodule_spec.rb +3 -3
  189. data/spec/unit/provider/service/launchd_spec.rb +22 -21
  190. data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
  191. data/spec/unit/provider/user/pw_spec.rb +19 -0
  192. data/spec/unit/resource/catalog_spec.rb +3 -3
  193. data/spec/unit/semver_spec.rb +117 -24
  194. data/spec/unit/transaction/report_spec.rb +11 -1
  195. data/spec/unit/type/cron_spec.rb +200 -213
  196. data/spec/unit/type/exec_spec.rb +7 -0
  197. data/spec/unit/type/file/content_spec.rb +2 -2
  198. data/spec/unit/type/file_spec.rb +12 -9
  199. data/spec/unit/type/package_spec.rb +25 -0
  200. data/spec/unit/type/schedule_spec.rb +31 -31
  201. data/spec/unit/util/diff_spec.rb +30 -0
  202. data/spec/unit/util/execution_stub_spec.rb +1 -2
  203. data/spec/unit/util/log/destinations_spec.rb +51 -0
  204. data/spec/unit/util/log_spec.rb +17 -1
  205. data/spec/unit/util/monkey_patches_spec.rb +119 -0
  206. data/spec/unit/util/rdoc/parser_spec.rb +25 -1
  207. data/spec/unit/util/selinux_spec.rb +2 -2
  208. data/spec/unit/util/suidmanager_spec.rb +6 -51
  209. data/spec/unit/util_spec.rb +82 -24
  210. data/test/lib/puppettest/certificates.rb +16 -0
  211. data/test/lib/puppettest/servertest.rb +4 -0
  212. data/test/util/pidlock.rb +125 -0
  213. metadata +23 -14
  214. data/ext/puppetstoredconfigclean.rb +0 -103
  215. data/lib/puppet/agent/disabler.rb +0 -27
  216. data/lib/puppet/util/anonymous_filelock.rb +0 -36
  217. data/spec/unit/agent/disabler_spec.rb +0 -60
  218. data/spec/unit/module_tool/repository_spec.rb +0 -52
  219. data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
  220. data/spec/unit/util/pidlock_spec.rb +0 -208
@@ -18,24 +18,22 @@ describe Puppet::Provider::Confine::Feature do
18
18
 
19
19
  describe "when testing values" do
20
20
  before do
21
- @features = mock 'features'
22
- Puppet.stubs(:features).returns @features
23
21
  @confine = Puppet::Provider::Confine::Feature.new("myfeature")
24
22
  @confine.label = "eh"
25
23
  end
26
24
 
27
25
  it "should use the Puppet features instance to test validity" do
28
- @features.expects(:myfeature?)
26
+ Puppet.features.expects(:myfeature?)
29
27
  @confine.valid?
30
28
  end
31
29
 
32
30
  it "should return true if the feature is present" do
33
- @features.expects(:myfeature?).returns true
31
+ Puppet.features.add(:myfeature) do true end
34
32
  @confine.pass?("myfeature").should be_true
35
33
  end
36
34
 
37
35
  it "should return false if the value is false" do
38
- @features.expects(:myfeature?).returns false
36
+ Puppet.features.add(:myfeature) do false end
39
37
  @confine.pass?("myfeature").should be_false
40
38
  end
41
39
 
@@ -30,7 +30,8 @@ describe provider do
30
30
 
31
31
  it "should create and return an instance with each parsed line from dpkg-query" do
32
32
  pipe = mock 'pipe'
33
- pipe.expects(:each).yields @fakeresult
33
+ pipe.expects(:each).never
34
+ pipe.expects(:each_line).yields @fakeresult
34
35
  provider.expects(:execpipe).yields pipe
35
36
 
36
37
  asdf = mock 'pkg1'
@@ -41,7 +42,8 @@ describe provider do
41
42
 
42
43
  it "should warn on and ignore any lines it does not understand" do
43
44
  pipe = mock 'pipe'
44
- pipe.expects(:each).yields "foobar"
45
+ pipe.expects(:each).never
46
+ pipe.expects(:each_line).yields "foobar"
45
47
  provider.expects(:execpipe).yields pipe
46
48
 
47
49
  Puppet.expects(:warning)
@@ -4,93 +4,109 @@ require 'spec_helper'
4
4
  provider_class = Puppet::Type.type(:package).provider(:gem)
5
5
 
6
6
  describe provider_class do
7
- it "should have an install method" do
8
- @provider = provider_class.new
9
- @provider.should respond_to(:install)
7
+ let(:resource) do
8
+ Puppet::Type.type(:package).new(
9
+ :name => 'myresource',
10
+ :ensure => :installed
11
+ )
10
12
  end
11
13
 
12
- describe "when installing" do
13
- before do
14
- # Create a mock resource
15
- @resource = stub 'resource'
16
-
17
- # A catch all; no parameters set
18
- @resource.stubs(:[]).returns nil
19
-
20
- # We have to set a name, though
21
- @resource.stubs(:[]).with(:name).returns "myresource"
22
- @resource.stubs(:[]).with(:ensure).returns :installed
23
-
24
- @provider = provider_class.new
25
- @provider.stubs(:resource).returns @resource
26
- end
14
+ let(:provider) do
15
+ provider = provider_class.new
16
+ provider.resource = resource
17
+ provider
18
+ end
27
19
 
20
+ describe "when installing" do
28
21
  it "should use the path to the gem" do
29
22
  provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
30
- @provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns ""
31
- @provider.install
23
+ provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns ""
24
+ provider.install
32
25
  end
33
26
 
34
27
  it "should specify that the gem is being installed" do
35
- @provider.expects(:execute).with { |args| args[1] == "install" }.returns ""
36
- @provider.install
28
+ provider.expects(:execute).with { |args| args[1] == "install" }.returns ""
29
+ provider.install
37
30
  end
38
31
 
39
32
  it "should specify that dependencies should be included" do
40
- @provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns ""
41
- @provider.install
33
+ provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns ""
34
+ provider.install
42
35
  end
43
36
 
44
37
  it "should specify that documentation should not be included" do
45
- @provider.expects(:execute).with { |args| args[3] == "--no-rdoc" }.returns ""
46
- @provider.install
38
+ provider.expects(:execute).with { |args| args[3] == "--no-rdoc" }.returns ""
39
+ provider.install
47
40
  end
48
41
 
49
42
  it "should specify that RI should not be included" do
50
- @provider.expects(:execute).with { |args| args[4] == "--no-ri" }.returns ""
51
- @provider.install
43
+ provider.expects(:execute).with { |args| args[4] == "--no-ri" }.returns ""
44
+ provider.install
52
45
  end
53
46
 
54
47
  it "should specify the package name" do
55
- @provider.expects(:execute).with { |args| args[5] == "myresource" }.returns ""
56
- @provider.install
48
+ provider.expects(:execute).with { |args| args[5] == "myresource" }.returns ""
49
+ provider.install
57
50
  end
58
51
 
59
52
  describe "when a source is specified" do
60
53
  describe "as a normal file" do
61
54
  it "should use the file name instead of the gem name" do
62
- @resource.stubs(:[]).with(:source).returns "/my/file"
63
- @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns ""
64
- @provider.install
55
+ resource[:source] = "/my/file"
56
+ provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns ""
57
+ provider.install
65
58
  end
66
59
  end
67
60
  describe "as a file url" do
68
61
  it "should use the file name instead of the gem name" do
69
- @resource.stubs(:[]).with(:source).returns "file:///my/file"
70
- @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns ""
71
- @provider.install
62
+ resource[:source] = "file:///my/file"
63
+ provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns ""
64
+ provider.install
72
65
  end
73
66
  end
74
67
  describe "as a puppet url" do
75
68
  it "should fail" do
76
- @resource.stubs(:[]).with(:source).returns "puppet://my/file"
77
- lambda { @provider.install }.should raise_error(Puppet::Error)
69
+ resource[:source] = "puppet://my/file"
70
+ lambda { provider.install }.should raise_error(Puppet::Error)
78
71
  end
79
72
  end
80
73
  describe "as a non-file and non-puppet url" do
81
74
  it "should treat the source as a gem repository" do
82
- @resource.stubs(:[]).with(:source).returns "http://host/my/file"
83
- @provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns ""
84
- @provider.install
75
+ resource[:source] = "http://host/my/file"
76
+ provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns ""
77
+ provider.install
85
78
  end
86
79
  end
87
80
  describe "with an invalid uri" do
88
81
  it "should fail" do
89
82
  URI.expects(:parse).raises(ArgumentError)
90
- @resource.stubs(:[]).with(:source).returns "http:::::uppet:/:/my/file"
91
- lambda { @provider.install }.should raise_error(Puppet::Error)
83
+ resource[:source] = "http:::::uppet:/:/my/file"
84
+ lambda { provider.install }.should raise_error(Puppet::Error)
92
85
  end
93
86
  end
94
87
  end
95
88
  end
89
+
90
+ describe "#instances" do
91
+ before do
92
+ provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
93
+ end
94
+
95
+ it "should return an empty array when no gems installed" do
96
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).returns("\n")
97
+ provider_class.instances.should == []
98
+ end
99
+
100
+ it "should return ensure values as an array of installed versions" do
101
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).returns <<-HEREDOC.gsub(/ /, '')
102
+ systemu (1.2.0)
103
+ vagrant (0.8.7, 0.6.9)
104
+ HEREDOC
105
+
106
+ provider_class.instances.map {|p| p.properties}.should == [
107
+ {:ensure => ["1.2.0"], :provider => :gem, :name => 'systemu'},
108
+ {:ensure => ["0.8.7", "0.6.9"], :provider => :gem, :name => 'vagrant'}
109
+ ]
110
+ end
111
+ end
96
112
  end
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ provider_class = Puppet::Type.type(:package).provider(:openbsd)
5
+
6
+ describe provider_class do
7
+ subject { provider_class }
8
+
9
+ def package(args = {})
10
+ defaults = { :name => 'bash', :provider => 'openbsd' }
11
+ Puppet::Type.type(:package).new(defaults.merge(args))
12
+ end
13
+
14
+ before :each do
15
+ # Stub some provider methods to avoid needing the actual software
16
+ # installed, so we can test on whatever platform we want.
17
+ provider_class.stubs(:command).with(:pkginfo).returns('/bin/pkg_info')
18
+ provider_class.stubs(:command).with(:pkgadd).returns('/bin/pkg_add')
19
+ provider_class.stubs(:command).with(:pkgdelete).returns('/bin/pkg_delete')
20
+ end
21
+
22
+ context "::instances" do
23
+ it "should return nil if execution failed" do
24
+ subject.expects(:execpipe).raises(Puppet::ExecutionFailure, 'wawawa')
25
+ subject.instances.should be_nil
26
+ end
27
+
28
+ 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.instances.should be_empty
31
+ end
32
+
33
+ it "should return all packages when invoked" do
34
+ fixture = File.read(my_fixture('pkginfo.list'))
35
+ subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(fixture)
36
+ subject.instances.map(&:name).sort.should ==
37
+ %w{bash bzip2 expat gettext libiconv lzo openvpn python vim wget}.sort
38
+ end
39
+ end
40
+
41
+ context "#install" do
42
+ it "should fail if the resource doesn't have a source" do
43
+ provider = subject.new(package())
44
+ expect { provider.install }.
45
+ to raise_error Puppet::Error, /must specify a package source/
46
+ end
47
+
48
+ it "should install correctly when given a directory-unlike source" do
49
+ ENV.should_not be_key 'PKG_PATH'
50
+
51
+ source = '/whatever.pkg'
52
+ provider = subject.new(package(:source => source))
53
+ provider.expects(:pkgadd).with do |name|
54
+ ENV.should_not be_key 'PKG_PATH'
55
+ name == source
56
+ end
57
+
58
+ provider.install
59
+ ENV.should_not be_key 'PKG_PATH'
60
+ end
61
+
62
+ it "should install correctly when given a directory-like source" do
63
+ ENV.should_not be_key 'PKG_PATH'
64
+
65
+ source = '/whatever/'
66
+ provider = subject.new(package(:source => source))
67
+ provider.expects(:pkgadd).with do |name|
68
+ ENV.should be_key 'PKG_PATH'
69
+ ENV['PKG_PATH'].should == source
70
+
71
+ name == provider.resource[:name]
72
+ end
73
+
74
+ provider.install
75
+ ENV.should_not be_key 'PKG_PATH'
76
+ end
77
+ end
78
+
79
+ context "#get_version" do
80
+ it "should return nil if execution fails" do
81
+ provider = subject.new(package)
82
+ provider.expects(:execpipe).raises(Puppet::ExecutionFailure, 'wawawa')
83
+ provider.get_version.should be_nil
84
+ end
85
+
86
+ it "should return the package version if in the output" do
87
+ fixture = File.read(my_fixture('pkginfo.list'))
88
+ provider = subject.new(package(:name => 'bash'))
89
+ provider.expects(:execpipe).with(%w{/bin/pkg_info -I bash}).yields(fixture)
90
+ provider.get_version.should == '3.1.17'
91
+ end
92
+
93
+ it "should return the empty string if the package is not present" do
94
+ provider = subject.new(package(:name => 'zsh'))
95
+ provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields('')
96
+ provider.get_version.should == ''
97
+ end
98
+ end
99
+
100
+ context "#query" do
101
+ it "should return the installed version if present" do
102
+ fixture = File.read(my_fixture('pkginfo.detail'))
103
+ provider = subject.new(package(:name => 'bash'))
104
+ provider.expects(:pkginfo).with('bash').returns(fixture)
105
+ provider.query.should == { :ensure => '3.1.17' }
106
+ end
107
+
108
+ it "should return nothing if not present" do
109
+ provider = subject.new(package(:name => 'zsh'))
110
+ provider.expects(:pkginfo).with('zsh').returns('')
111
+ provider.query.should be_nil
112
+ end
113
+ end
114
+ end
@@ -157,7 +157,7 @@ EOF
157
157
 
158
158
  describe "when fetching a package list" do
159
159
  it "should query pacman" do
160
- provider.expects(:execpipe).with(["/usr/bin/pacman", ' -Q'])
160
+ provider.expects(:execpipe).with(["/usr/bin/pacman", '-Q'])
161
161
  provider.instances
162
162
  end
163
163
 
@@ -8,10 +8,10 @@ describe provider_class do
8
8
  before do
9
9
  @resource = Puppet::Resource.new(:package, "fake_package")
10
10
  @provider = provider_class.new(@resource)
11
- client = stub_everything('client')
12
- client.stubs(:call).with('package_releases', 'real_package').returns(["1.3", "1.2.5", "1.2.4"])
13
- client.stubs(:call).with('package_releases', 'fake_package').returns([])
14
- XMLRPC::Client.stubs(:new2).returns(client)
11
+ @client = stub_everything('client')
12
+ @client.stubs(:call).with('package_releases', 'real_package').returns(["1.3", "1.2.5", "1.2.4"])
13
+ @client.stubs(:call).with('package_releases', 'fake_package').returns([])
14
+ XMLRPC::Client.stubs(:new2).returns(@client)
15
15
  end
16
16
 
17
17
  describe "parse" do
@@ -86,6 +86,12 @@ describe provider_class do
86
86
  @provider.latest.should == nil
87
87
  end
88
88
 
89
+ it "should handle a timeout gracefully" do
90
+ @resource[:name] = "fake_package"
91
+ @client.stubs(:call).raises(Timeout::Error)
92
+ lambda { @provider.latest }.should raise_error(Puppet::Error)
93
+ end
94
+
89
95
  end
90
96
 
91
97
  describe "install" do
@@ -24,7 +24,7 @@ describe provider_class do
24
24
  @provider.should respond_to(:install)
25
25
  end
26
26
 
27
- it "should have a latest method" do
27
+ it "should have an uninstall method" do
28
28
  @provider = provider_class.new
29
29
  @provider.should respond_to(:uninstall)
30
30
  end
@@ -39,17 +39,64 @@ describe provider_class do
39
39
  @provider.should respond_to(:latest)
40
40
  end
41
41
 
42
- describe "when installing" do
42
+ describe "when installing with zypper version >= 1.0" do
43
+ it "should use a command-line with versioned package'" do
44
+ @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
45
+ @provider.stubs(:zypper_version).returns "1.2.8"
46
+
47
+ @provider.expects(:zypper).with('--quiet', :install,
48
+ '--auto-agree-with-licenses', '--no-confirm', 'mypackage-1.2.3-4.5.6')
49
+ @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
50
+ @provider.install
51
+ end
52
+
53
+ it "should use a command-line without versioned package" do
54
+ @resource.stubs(:should).with(:ensure).returns :latest
55
+ @provider.stubs(:zypper_version).returns "1.2.8"
56
+ @provider.expects(:zypper).with('--quiet', :install,
57
+ '--auto-agree-with-licenses', '--no-confirm', 'mypackage')
58
+ @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
59
+ @provider.install
60
+ end
61
+ end
62
+
63
+ describe "when installing with zypper version = 0.6.104" do
43
64
  it "should use a command-line with versioned package'" do
44
65
  @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
45
- @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage-1.2.3-4.5.6')
66
+ @provider.stubs(:zypper_version).returns "0.6.104"
67
+
68
+ @provider.expects(:zypper).with('--terse', :install,
69
+ '--auto-agree-with-licenses', '--no-confirm', 'mypackage-1.2.3-4.5.6')
46
70
  @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
47
71
  @provider.install
48
72
  end
49
73
 
50
74
  it "should use a command-line without versioned package" do
51
75
  @resource.stubs(:should).with(:ensure).returns :latest
52
- @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage')
76
+ @provider.stubs(:zypper_version).returns "0.6.104"
77
+ @provider.expects(:zypper).with('--terse', :install,
78
+ '--auto-agree-with-licenses', '--no-confirm', 'mypackage')
79
+ @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
80
+ @provider.install
81
+ end
82
+ end
83
+
84
+ describe "when installing with zypper version = 0.6.13" do
85
+ it "should use a command-line with versioned package'" do
86
+ @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
87
+ @provider.stubs(:zypper_version).returns "0.6.13"
88
+
89
+ @provider.expects(:zypper).with('--terse', :install,
90
+ '--no-confirm', 'mypackage-1.2.3-4.5.6')
91
+ @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
92
+ @provider.install
93
+ end
94
+
95
+ it "should use a command-line without versioned package" do
96
+ @resource.stubs(:should).with(:ensure).returns :latest
97
+ @provider.stubs(:zypper_version).returns "0.6.13"
98
+ @provider.expects(:zypper).with('--terse', :install,
99
+ '--no-confirm', 'mypackage')
53
100
  @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
54
101
  @provider.install
55
102
  end
@@ -63,17 +110,12 @@ describe provider_class do
63
110
  end
64
111
 
65
112
  describe "when getting latest version" do
66
- it "should return a version string" do
67
-
68
- fake_data = "Loading repository data...
69
- Reading installed packages...
70
- S | Repository | Name | Version | Arch
71
- --+----------------+-----------------------+-----------------+-------
72
- v | SLES11-Updates | cups | 1.1.1 | x86_64
73
- v | SLES11-Updates | mypackage | 1.3.9h-8.20.1 | x86_64"
113
+ it "should return a version string with valid list-updates data from SLES11sp1" do
114
+ fake_data = File.read(my_fixture('zypper-list-updates-SLES11sp1.out'))
74
115
 
75
- @provider.expects(:zypper).with("list-updates").returns fake_data
76
- @provider.latest.should == "1.3.9h-8.20.1"
116
+ @resource.stubs(:[]).with(:name).returns "at"
117
+ @provider.expects(:zypper).with("list-updates").returns fake_data
118
+ @provider.latest.should == "3.1.8-1069.18.2"
77
119
  end
78
120
  end
79
121