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
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+ require 'puppet/forge/repository'
4
+ require 'puppet/forge/cache'
5
+
6
+ describe Puppet::Forge::Repository do
7
+ describe 'instances' do
8
+
9
+ let(:repository) { Puppet::Forge::Repository.new('http://fake.com') }
10
+
11
+ describe '#make_http_request' do
12
+ before do
13
+ # Do a mock of the Proxy call so we can do proper expects for
14
+ # Net::HTTP
15
+ Net::HTTP.expects(:Proxy).returns(Net::HTTP)
16
+ Net::HTTP.expects(:start)
17
+ end
18
+ context "when not given an :authenticate option" do
19
+ it "should authenticate" do
20
+ repository.expects(:authenticate).never
21
+ repository.make_http_request(nil)
22
+ end
23
+ end
24
+ context "when given an :authenticate option" do
25
+ it "should authenticate" do
26
+ repository.expects(:authenticate)
27
+ repository.make_http_request(nil, :authenticate => true)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#authenticate' do
33
+ it "should set basic auth on the request" do
34
+ authenticated_request = stub
35
+ authenticated_request.expects(:basic_auth)
36
+ repository.expects(:prompt).twice
37
+ repository.authenticate(authenticated_request)
38
+ end
39
+ end
40
+
41
+ describe '#retrieve' do
42
+ before do
43
+ @uri = URI.parse('http://some.url.com')
44
+ end
45
+
46
+ it "should access the cache" do
47
+ repository.cache.expects(:retrieve).with(@uri)
48
+ repository.retrieve(@uri)
49
+ end
50
+ end
51
+
52
+ describe 'http_proxy support' do
53
+ before :each do
54
+ ENV["http_proxy"] = nil
55
+ end
56
+
57
+ after :each do
58
+ ENV["http_proxy"] = nil
59
+ end
60
+
61
+ it "should support environment variable for port and host" do
62
+ ENV["http_proxy"] = "http://test.com:8011"
63
+ repository.http_proxy_host.should == "test.com"
64
+ repository.http_proxy_port.should == 8011
65
+ end
66
+
67
+ it "should support puppet configuration for port and host" do
68
+ ENV["http_proxy"] = nil
69
+ Puppet.settings.stubs(:[]).with(:http_proxy_host).returns('test.com')
70
+ Puppet.settings.stubs(:[]).with(:http_proxy_port).returns(7456)
71
+
72
+ repository.http_proxy_port.should == 7456
73
+ repository.http_proxy_host.should == "test.com"
74
+ end
75
+
76
+ it "should use environment variable before puppet settings" do
77
+ ENV["http_proxy"] = "http://test1.com:8011"
78
+ Puppet.settings.stubs(:[]).with(:http_proxy_host).returns('test2.com')
79
+ Puppet.settings.stubs(:[]).with(:http_proxy_port).returns(7456)
80
+
81
+ repository.http_proxy_host.should == "test1.com"
82
+ repository.http_proxy_port.should == 8011
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require 'puppet/forge'
3
+ require 'net/http'
4
+
5
+ describe Puppet::Forge::Forge do
6
+ before do
7
+ Puppet::Forge::Repository.any_instance.stubs(:make_http_request).returns(response)
8
+ Puppet::Forge::Repository.any_instance.stubs(:retrieve).returns("/tmp/foo")
9
+ end
10
+
11
+ let(:forge) { forge = Puppet::Forge::Forge.new('http://forge.puppetlabs.com') }
12
+
13
+ describe "the behavior of the search method" do
14
+ context "when there are matches for the search term" do
15
+ before do
16
+ Puppet::Forge::Repository.any_instance.stubs(:make_http_request).returns(response)
17
+ end
18
+
19
+ let(:response) { stub(:body => response_body, :code => '200') }
20
+ let(:response_body) do
21
+ <<-EOF
22
+ [
23
+ {
24
+ "author": "puppetlabs",
25
+ "name": "bacula",
26
+ "tag_list": ["backup", "bacula"],
27
+ "releases": [{"version": "0.0.1"}, {"version": "0.0.2"}],
28
+ "full_name": "puppetlabs/bacula",
29
+ "version": "0.0.2",
30
+ "project_url": "http://github.com/puppetlabs/puppetlabs-bacula",
31
+ "desc": "bacula"
32
+ }
33
+ ]
34
+ EOF
35
+ end
36
+
37
+ it "should return a list of matches from the forge" do
38
+ forge.search('bacula').should == PSON.load(response_body)
39
+ end
40
+ end
41
+
42
+ context "when the connection to the forge fails" do
43
+ let(:response) { stub(:body => '[]', :code => '404') }
44
+
45
+ it "should raise an error" do
46
+ lambda { forge.search('bacula') }.should raise_error RuntimeError
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "the behavior of the get_release_package method" do
52
+
53
+ let(:response) do
54
+ response = mock()
55
+ response.stubs(:body).returns('{"file": "/system/releases/p/puppetlabs/puppetlabs-apache-0.0.3.tar.gz", "version": "0.0.3"}')
56
+ response
57
+ end
58
+
59
+ context "when source is not filesystem or repository" do
60
+ it "should raise an error" do
61
+ params = { :source => 'foo' }
62
+ lambda { forge.get_release_package(params) }.should
63
+ raise_error(ArgumentError, "Could not determine installation source")
64
+ end
65
+ end
66
+
67
+ context "when the source is a repository" do
68
+ let(:params) do
69
+ {
70
+ :source => :repository,
71
+ :author => 'fakeauthor',
72
+ :modname => 'fakemodule',
73
+ :version => '0.0.1'
74
+ }
75
+ end
76
+
77
+ it "should require author" do
78
+ params.delete(:author)
79
+ lambda { forge.get_release_package(params) }.should
80
+ raise_error(ArgumentError, ":author and :modename required")
81
+ end
82
+
83
+ it "should require modname" do
84
+ params.delete(:modname)
85
+ lambda { forge.get_release_package(params) }.should
86
+ raise_error(ArgumentError, ":author and :modename required")
87
+ end
88
+
89
+ it "should download the release package" do
90
+ forge.get_release_package(params).should == "/tmp/foo"
91
+ end
92
+ end
93
+
94
+ context "when the source is a filesystem" do
95
+ it "should require filename" do
96
+ params = { :source => :filesystem }
97
+ lambda { forge.get_release_package(params) }.should
98
+ raise_error(ArgumentError, ":filename required")
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "the behavior of the get_releases method" do
104
+ let(:response) do
105
+ response = mock()
106
+ response.stubs(:body).returns('{"releases": [{"version": "0.0.1"}, {"version": "0.0.2"}, {"version": "0.0.3"}]}')
107
+ response
108
+ end
109
+
110
+ it "should return a list of module releases" do
111
+ forge.get_releases('fakeauthor', 'fakemodule').should == ["0.0.1", "0.0.2", "0.0.3"]
112
+ end
113
+ end
114
+ end
@@ -14,15 +14,17 @@ describe Puppet::Indirector::Exec do
14
14
  end
15
15
  end
16
16
 
17
+ let(:path) { File.expand_path('/echo') }
18
+
17
19
  before :each do
18
20
  @searcher = @exec_class.new
19
- @searcher.command = ["/echo"]
21
+ @searcher.command = [path]
20
22
 
21
23
  @request = stub 'request', :key => "foo"
22
24
  end
23
25
 
24
26
  it "should throw an exception if the command is not an array" do
25
- @searcher.command = "/usr/bin/echo"
27
+ @searcher.command = path
26
28
  proc { @searcher.find(@request) }.should raise_error(Puppet::DevError)
27
29
  end
28
30
 
@@ -32,22 +34,22 @@ describe Puppet::Indirector::Exec do
32
34
  end
33
35
 
34
36
  it "should execute the command with the object name as the only argument" do
35
- @searcher.expects(:execute).with(%w{/echo foo}, :combine => false)
37
+ @searcher.expects(:execute).with([path, 'foo'], :combine => false)
36
38
  @searcher.find(@request)
37
39
  end
38
40
 
39
41
  it "should return the output of the script" do
40
- @searcher.expects(:execute).with(%w{/echo foo}, :combine => false).returns("whatever")
42
+ @searcher.expects(:execute).with([path, 'foo'], :combine => false).returns("whatever")
41
43
  @searcher.find(@request).should == "whatever"
42
44
  end
43
45
 
44
46
  it "should return nil when the command produces no output" do
45
- @searcher.expects(:execute).with(%w{/echo foo}, :combine => false).returns(nil)
47
+ @searcher.expects(:execute).with([path, 'foo'], :combine => false).returns(nil)
46
48
  @searcher.find(@request).should be_nil
47
49
  end
48
50
 
49
51
  it "should raise an exception if there's an execution failure" do
50
- @searcher.expects(:execute).with(%w{/echo foo}, :combine => false).raises(Puppet::ExecutionFailure.new("message"))
52
+ @searcher.expects(:execute).with([path, 'foo'], :combine => false).raises(Puppet::ExecutionFailure.new("message"))
51
53
 
52
54
  lambda {@searcher.find(@request)}.should raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
53
55
  end
@@ -34,7 +34,6 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => (Puppet.features.r
34
34
 
35
35
  after :each do
36
36
  Puppet::Rails.teardown
37
- ActiveRecord::Base.remove_connection
38
37
  end
39
38
 
40
39
  describe "#save" do
@@ -32,7 +32,7 @@ describe Puppet::FileBucketFile::File do
32
32
  it "should store the path if not already stored" do
33
33
  checksum = save_bucket_file("stuff\r\n", "/foo/bar")
34
34
  dir_path = "#{Puppet[:bucketdir]}/f/c/7/7/7/c/0/b/fc777c0bc467e1ab98b4c6915af802ec"
35
- Puppet::Util.binread("#{dir_path}/contents").should == "stuff\r\n"
35
+ IO.binread("#{dir_path}/contents").should == "stuff\r\n"
36
36
  File.read("#{dir_path}/paths").should == "foo/bar\n"
37
37
  end
38
38
 
@@ -6,7 +6,7 @@ require 'puppet/indirector/node/exec'
6
6
  describe Puppet::Node::Exec do
7
7
  before do
8
8
  @indirection = mock 'indirection'
9
- Puppet.settings.stubs(:value).with(:external_nodes).returns("/echo")
9
+ Puppet.settings.stubs(:value).with(:external_nodes).returns(File.expand_path("/echo"))
10
10
  @searcher = Puppet::Node::Exec.new
11
11
  end
12
12
 
@@ -20,10 +20,6 @@ describe "Puppet::Resource::ActiveRecord", :if => (Puppet.features.rails? and de
20
20
  Puppet[:storeconfigs] = true
21
21
  end
22
22
 
23
- after :each do
24
- ActiveRecord::Base.remove_connection
25
- end
26
-
27
23
  subject {
28
24
  require 'puppet/indirector/resource/active_record'
29
25
  Puppet::Resource.indirection.terminus(:active_record)
@@ -114,16 +114,18 @@ describe Puppet::Interface::ActionBuilder do
114
114
  when_invoked do |options| true end
115
115
  when_rendering :json do true end
116
116
  end
117
- }.to raise_error ArgumentError, /when_rendering methods take one argument, the result, not/
117
+ }.to raise_error ArgumentError,
118
+ /the puppet_interface_actionbuilder face foo action takes .* not/
118
119
  end
119
120
 
120
- it "should fail if the block takes more than one argument" do
121
+ it "should fail if the when_rendering block takes a different number of arguments than when_invoked" do
121
122
  expect {
122
123
  Puppet::Interface::ActionBuilder.build(face, :foo) do
123
124
  when_invoked do |options| true end
124
125
  when_rendering :json do |a, b, c| true end
125
126
  end
126
- }.to raise_error ArgumentError, /when_rendering methods take one argument, the result, not/
127
+ }.to raise_error ArgumentError,
128
+ /the puppet_interface_actionbuilder face foo action takes .* not 3/
127
129
  end
128
130
 
129
131
  it "should fail if the block takes a variable number of arguments" do
@@ -132,8 +134,8 @@ describe Puppet::Interface::ActionBuilder do
132
134
  when_invoked do |options| true end
133
135
  when_rendering :json do |*args| true end
134
136
  end
135
- }.to raise_error(ArgumentError,
136
- /when_rendering methods take one argument, the result, not/)
137
+ }.to raise_error ArgumentError,
138
+ /the puppet_interface_actionbuilder face foo action takes .* not/
137
139
  end
138
140
 
139
141
  it "should stash a rendering block" do
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
3
  require 'puppet_spec/files'
4
+ require 'puppet_spec/modules'
5
+ require 'puppet/module_tool/checksums'
4
6
 
5
7
  describe Puppet::Module do
6
8
  include PuppetSpec::Files
@@ -89,6 +91,153 @@ describe Puppet::Module do
89
91
  lambda { mod.validate_puppet_version }.should raise_error(Puppet::Module::IncompatibleModule)
90
92
  end
91
93
 
94
+ describe "when finding unmet dependencies" do
95
+ before do
96
+ @mod = Puppet::Module.new("mymod")
97
+ @mod.stubs(:dependencies).returns [
98
+ {
99
+ "version_requirement" => ">= 2.2.0",
100
+ "name" => "baz/foobar"
101
+ }
102
+ ]
103
+ end
104
+
105
+ it "should list modules that are missing" do
106
+ @mod.unmet_dependencies.should == [{
107
+ :name => 'baz/foobar',
108
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
109
+ Missing dependency `foobar`:
110
+ `mymod` () requires `baz/foobar` (>= 2.2.0)
111
+ HEREDOC
112
+ }]
113
+ end
114
+
115
+ it "should list modules with unmet version" do
116
+ foobar = Puppet::Module.new("foobar")
117
+ foobar.version = '2.0.0'
118
+ @mod.environment.expects(:module).with("foobar").returns foobar
119
+
120
+ @mod.unmet_dependencies.should == [{
121
+ :name => 'baz/foobar',
122
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
123
+ Version dependency mismatch `foobar` (2.0.0):
124
+ `mymod` () requires `baz/foobar` (>= 2.2.0)
125
+ HEREDOC
126
+ }]
127
+ end
128
+
129
+ it "should consider a dependency without a version requirement to be satisfied" do
130
+ mod = Puppet::Module.new("mymod")
131
+ mod.stubs(:dependencies).returns [{ "name" => "baz/foobar" }]
132
+
133
+ foobar = Puppet::Module.new("foobar")
134
+ mod.environment.expects(:module).with("foobar").returns foobar
135
+
136
+ mod.unmet_dependencies.should be_empty
137
+ end
138
+
139
+ it "should consider a dependency without a version to be unmet" do
140
+ foobar = Puppet::Module.new("foobar")
141
+ @mod.environment.expects(:module).with("foobar").returns foobar
142
+
143
+ @mod.unmet_dependencies.should == [{
144
+ :name => 'baz/foobar',
145
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
146
+ Unversioned dependency `foobar`:
147
+ `mymod` () requires `baz/foobar` (>= 2.2.0)
148
+ HEREDOC
149
+ }]
150
+ end
151
+
152
+ it "should consider a dependency without a semantic version to be unmet" do
153
+ foobar = Puppet::Module.new("foobar")
154
+ foobar.version = '5.1'
155
+ @mod.environment.expects(:module).with("foobar").returns foobar
156
+
157
+ @mod.unmet_dependencies.should == [{
158
+ :name => 'baz/foobar',
159
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
160
+ Non semantic version dependency `foobar` (5.1):
161
+ `mymod` () requires `baz/foobar` (>= 2.2.0)
162
+ HEREDOC
163
+ }]
164
+ end
165
+
166
+ it "should consider a dependency requirement without a semantic version to be unmet" do
167
+ foobar = Puppet::Module.new("foobar")
168
+ foobar.version = '5.1.0'
169
+
170
+ mod = Puppet::Module.new("mymod")
171
+ mod.stubs(:dependencies).returns [{ "name" => "baz/foobar", "version_requirement" => '> 2.0' }]
172
+ mod.environment.expects(:module).with("foobar").returns foobar
173
+
174
+ mod.unmet_dependencies.should == [{
175
+ :name => 'baz/foobar',
176
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
177
+ Non semantic version dependency `foobar` (5.1.0):
178
+ `mymod` () requires `baz/foobar` (> 2.0)
179
+ HEREDOC
180
+ }]
181
+ end
182
+
183
+ it "should have valid dependencies when no dependencies have been specified" do
184
+ mod = Puppet::Module.new("mymod")
185
+
186
+ mod.unmet_dependencies.should == []
187
+ end
188
+
189
+ it "should only list unmet dependencies" do
190
+ mod = Puppet::Module.new("mymod")
191
+ mod.stubs(:dependencies).returns [
192
+ {
193
+ "version_requirement" => ">= 2.2.0",
194
+ "name" => "baz/satisfied"
195
+ },
196
+ {
197
+ "version_requirement" => ">= 2.2.0",
198
+ "name" => "baz/notsatisfied"
199
+ }
200
+ ]
201
+
202
+ satisfied = Puppet::Module.new("satisfied")
203
+ satisfied.version = "3.3.0"
204
+
205
+ mod.environment.expects(:module).with("satisfied").returns satisfied
206
+ mod.environment.expects(:module).with("notsatisfied").returns nil
207
+
208
+ mod.unmet_dependencies.should == [{
209
+ :name => 'baz/notsatisfied',
210
+ :error => <<-HEREDOC.gsub(/^\s{10}/, '')
211
+ Missing dependency `notsatisfied`:
212
+ `mymod` () requires `baz/notsatisfied` (>= 2.2.0)
213
+ HEREDOC
214
+ }]
215
+ end
216
+
217
+ it "should be empty when all dependencies are met" do
218
+ mod = Puppet::Module.new("mymod")
219
+ mod.stubs(:dependencies).returns [
220
+ {
221
+ "version_requirement" => ">= 2.2.0",
222
+ "name" => "baz/satisfied"
223
+ },
224
+ {
225
+ "version_requirement" => "< 2.2.0",
226
+ "name" => "baz/alsosatisfied"
227
+ }
228
+ ]
229
+ satisfied = Puppet::Module.new("satisfied")
230
+ satisfied.version = "3.3.0"
231
+ alsosatisfied = Puppet::Module.new("alsosatisfied")
232
+ alsosatisfied.version = "2.1.0"
233
+
234
+ mod.environment.expects(:module).with("satisfied").returns satisfied
235
+ mod.environment.expects(:module).with("alsosatisfied").returns alsosatisfied
236
+
237
+ mod.unmet_dependencies.should be_empty
238
+ end
239
+ end
240
+
92
241
  describe "when managing supported platforms" do
93
242
  it "should support specifying a supported platform" do
94
243
  mod = Puppet::Module.new("mymod")
@@ -385,13 +534,14 @@ describe Puppet::Module, "when finding matching manifests" do
385
534
  end
386
535
 
387
536
  describe Puppet::Module do
537
+ include PuppetSpec::Files
388
538
  before do
389
- Puppet::Module.any_instance.stubs(:path).returns "/my/mod/path"
390
- @module = Puppet::Module.new("foo")
539
+ @modpath = tmpdir('modpath')
540
+ @module = PuppetSpec::Modules.create('mymod', @modpath)
391
541
  end
392
542
 
393
543
  it "should use 'License' in its current path as its metadata file" do
394
- @module.license_file.should == "/my/mod/path/License"
544
+ @module.license_file.should == "#{@modpath}/mymod/License"
395
545
  end
396
546
 
397
547
  it "should return nil as its license file when the module has no path" do
@@ -400,13 +550,13 @@ describe Puppet::Module do
400
550
  end
401
551
 
402
552
  it "should cache the license file" do
403
- Puppet::Module.any_instance.expects(:path).once.returns nil
404
- mod = Puppet::Module.new("foo")
405
- mod.license_file.should == mod.license_file
553
+ @module.expects(:path).once.returns nil
554
+ @module.license_file
555
+ @module.license_file
406
556
  end
407
557
 
408
558
  it "should use 'metadata.json' in its current path as its metadata file" do
409
- @module.metadata_file.should == "/my/mod/path/metadata.json"
559
+ @module.metadata_file.should == "#{@modpath}/mymod/metadata.json"
410
560
  end
411
561
 
412
562
  it "should return nil as its metadata file when the module has no path" do
@@ -469,14 +619,15 @@ describe Puppet::Module do
469
619
  Puppet::Module.new("yay")
470
620
  end
471
621
 
472
- describe "when loading the medatada file", :if => Puppet.features.pson? do
622
+ describe "when loading the metadata file", :if => Puppet.features.pson? do
473
623
  before do
474
624
  @data = {
475
625
  :license => "GPL2",
476
626
  :author => "luke",
477
627
  :version => "1.0",
478
628
  :source => "http://foo/",
479
- :puppetversion => "0.25"
629
+ :puppetversion => "0.25",
630
+ :dependencies => []
480
631
  }
481
632
  @text = @data.to_pson
482
633
 
@@ -509,4 +660,72 @@ describe Puppet::Module do
509
660
 
510
661
  it "should fail if the discovered name is different than the metadata name"
511
662
  end
663
+
664
+ it "should be able to tell if there are local changes" do
665
+ modpath = tmpdir('modpath')
666
+ foo_checksum = 'acbd18db4cc2f85cedef654fccc4a4d8'
667
+ checksummed_module = PuppetSpec::Modules.create(
668
+ 'changed',
669
+ modpath,
670
+ :metadata => {
671
+ :checksums => {
672
+ "foo" => foo_checksum,
673
+ }
674
+ }
675
+ )
676
+
677
+ foo_path = Pathname.new(File.join(checksummed_module.path, 'foo'))
678
+
679
+ IO.binwrite(foo_path, 'notfoo')
680
+ Puppet::Module::Tool::Checksums.new(foo_path).checksum(foo_path).should_not == foo_checksum
681
+ checksummed_module.has_local_changes?.should be_true
682
+
683
+ IO.binwrite(foo_path, 'foo')
684
+
685
+ Puppet::Module::Tool::Checksums.new(foo_path).checksum(foo_path).should == foo_checksum
686
+ checksummed_module.has_local_changes?.should be_false
687
+ end
688
+
689
+ it "should know what other modules require it" do
690
+ Puppet.settings[:modulepath] = @modpath
691
+ dependable = PuppetSpec::Modules.create(
692
+ 'dependable',
693
+ @modpath,
694
+ :metadata => {:author => 'puppetlabs'}
695
+ )
696
+ PuppetSpec::Modules.create(
697
+ 'needy',
698
+ @modpath,
699
+ :metadata => {
700
+ :author => 'beggar',
701
+ :dependencies => [{
702
+ "version_requirement" => ">= 2.2.0",
703
+ "name" => "puppetlabs/dependable"
704
+ }]
705
+ }
706
+ )
707
+ PuppetSpec::Modules.create(
708
+ 'wantit',
709
+ @modpath,
710
+ :metadata => {
711
+ :author => 'spoiled',
712
+ :dependencies => [{
713
+ "version_requirement" => "< 5.0.0",
714
+ "name" => "puppetlabs/dependable"
715
+ }]
716
+ }
717
+ )
718
+ dependable.required_by.should =~ [
719
+ {
720
+ "name" => "beggar/needy",
721
+ "version" => "9.9.9",
722
+ "version_requirement" => ">= 2.2.0"
723
+ },
724
+ {
725
+ "name" => "spoiled/wantit",
726
+ "version" => "9.9.9",
727
+ "version_requirement" => "< 5.0.0"
728
+ }
729
+ ]
730
+ end
512
731
  end