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
@@ -34,6 +34,7 @@ describe provider_class do
34
34
  it "should use the default status command if none is specified" do
35
35
  resource = Puppet::Type.type(:service).new(:name => "foo", :provider => :upstart)
36
36
  provider = provider_class.new(resource)
37
+ provider.stubs(:is_upstart?).returns(true)
37
38
 
38
39
  provider.expects(:status_exec).with(["foo"]).returns("foo start/running, process 1000")
39
40
  Process::Status.any_instance.stubs(:exitstatus).returns(0)
@@ -43,10 +44,47 @@ describe provider_class do
43
44
  it "should properly handle services with 'start' in their name" do
44
45
  resource = Puppet::Type.type(:service).new(:name => "foostartbar", :provider => :upstart)
45
46
  provider = provider_class.new(resource)
47
+ provider.stubs(:is_upstart?).returns(true)
46
48
 
47
49
  provider.expects(:status_exec).with(["foostartbar"]).returns("foostartbar stop/waiting")
48
50
  Process::Status.any_instance.stubs(:exitstatus).returns(0)
49
51
  provider.status.should == :stopped
52
+ end
53
+ end
54
+ describe "inheritance" do
55
+ let :resource do
56
+ resource = Puppet::Type.type(:service).new(:name => "foo", :provider => :upstart)
57
+ end
58
+
59
+ let :provider do
60
+ provider = provider_class.new(resource)
50
61
  end
62
+
63
+ describe "when upstart job" do
64
+ before(:each) do
65
+ provider.stubs(:is_upstart?).returns(true)
66
+ end
67
+ ["start", "stop"].each do |command|
68
+ it "should return the #{command}cmd of its parent provider" do
69
+ provider.send("#{command}cmd".to_sym).should == [provider.command(command.to_sym), resource.name]
70
+ end
71
+ end
72
+ it "should return nil for the statuscmd" do
73
+ provider.statuscmd.should be_nil
74
+ end
75
+ end
76
+
77
+ describe "when init script" do
78
+ before(:each) do
79
+ provider.stubs(:is_upstart?).returns(false)
80
+ end
81
+ ["start", "stop", "status"].each do |command|
82
+ it "should return the #{command}cmd of its parent provider" do
83
+ provider.expects(:search).with('foo').returns("/etc/init.d/foo")
84
+ provider.send("#{command}cmd".to_sym).should == ["/etc/init.d/foo", command.to_sym]
85
+ end
86
+ end
87
+ end
88
+
51
89
  end
52
90
  end
@@ -80,6 +80,34 @@ describe provider_class, :unless => Puppet.features.microsoft_windows? do
80
80
 
81
81
  @provider_class.parse(line)[0][:name].should == ""
82
82
  end
83
+
84
+ ['ssh-dss', 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521'].each do |keytype|
85
+ it "should be able to parse a #{keytype} key entry" do
86
+ # use some real world examples generated with ssh-keygen
87
+ key = case keytype
88
+ when 'ssh-dss' # ssh-keygen -t dsa -b 1024
89
+ 'AAAAB3NzaC1kc3MAAACBANGTefWMXS780qLMMgysq3GNMKzg55LXZODif6Tqv1vtTh4Wuk3J5X5u644jTyNdAIn1RiBI9MnwnZMZ6nXKvucMcMQWMibYS9W2MhkRj3oqsLWMMsdGXJL18SWM5A6oC3oIRC4JHJZtkm0OctR2trKxmX+MGhdCd+Xpsh9CNK8XAAAAFQD4olFiwv+QQUFdaZbWUy1CLEG9xQAAAIByCkXKgoriZF8bQ0OX1sKuR69M/6n5ngmQGVBKB7BQkpUjbK/OggB6iJgst5utKkDcaqYRnrTYG9q3jJ/flv7yYePuoSreS0nCMMx9gpEYuq+7Sljg9IecmN/IHrNd9qdYoASy5iuROQMvEZM7KFHA8vBv0tWdBOsp4hZKyiL1DAAAAIEAjkZlOps9L+cD/MTzxDj7toYYypdLOvjlcPBaglkPZoFZ0MAKTI0zXlVX1cWAnkd0Yfo4EpP+6XAjlZkod+QXKXM4Tb4PnR34ASMeU6sEjM61Na24S7JD3gpPKataFU/oH3hzXsBdK2ttKYmoqvf61h32IA/3Z5PjCCD9pPLPpAY'
90
+ when 'ssh-rsa' # ssh-keygen -t rsa -b 2048
91
+ 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDYtEaWa1mlxaAh9vtiz6RCVKDiJHDY15nsqqWU7F7A1+U1498+sWDyRDkZ8vXWQpzyOMBzBSHIxhsprlKhkjomy8BuJP+bHDBIKx4zgSFDrklrPIf467Iuug8J0qqDLxO4rOOjeAiLEyC0t2ZGnsTEea+rmat0bJ2cv3g5L4gH/OFz2pI4ZLp1HGN83ipl5UH8CjXQKwo3Db1E3WJCqKgszVX0Z4/qjnBRxFMoqky/1mGb/mX1eoT9JyQ8OhU9uENZOShkksSpgUqjlrjpj0Yd14hBlnE3M18pE4ivxjzectA/XRKNZaxOL1YREtU8sXusAwmlEY4aJ64aR0JrXfgx'
92
+ when 'ecdsa-sha2-nistp256' # ssh-keygen -t ecdsa -b 256
93
+ 'AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBO5PfBf0c2jAuqD+Lj3j+SuXOXNT2uqESLVOn5jVQfEF9GzllOw+CMOpUvV1CiOOn+F1ET15vcsfmD7z05WUTA='
94
+ when 'ecdsa-sha2-nistp384' # ssh-keygen -t ecdsa -b 384
95
+ 'AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBJIfxNoVK4FX3RuMlkHOwwxXwAh6Fqx5uAp4ftXrJ+64qYuIzb+/zSAkJV698Sre1b1lb0G4LyDdVAvXwaYK9kN25vy8umV3WdfZeHKXJGCcrplMCbbOERWARlpiPNEblg=='
96
+ when 'ecdsa-sha2-nistp521' #ssh-keygen -t ecdsa -b 521
97
+ 'AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBADLK+u12xwB0JOwpmaxYXv8KnPK4p+SE2405qoo+vpAQ569fMwPMgKzltd770amdeuFogw/MJu17PN9LDdrD3o0uwHMjWee6TpHQDkuEetaxiou6K0WAzgbxx9QsY0MsJgXf1BuMLqdK+xT183wOSXwwumv99G7T32dOJZ5tYrH0y4XMw=='
98
+ else
99
+ pending("No sample key for #{keytype} yet")
100
+ end
101
+ comment = 'sample_key'
102
+
103
+ record = @provider_class.parse_line("#{keytype} #{key} #{comment}")
104
+ record.should_not be_nil
105
+ record[:name].should == comment
106
+ record[:key].should == key
107
+ record[:type].should == keytype
108
+ end
109
+ end
110
+
83
111
  end
84
112
 
85
113
  describe provider_class, :unless => Puppet.features.microsoft_windows? do
@@ -3,16 +3,10 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet/node/environment'
5
5
 
6
- describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
7
- def column(name, type)
8
- ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
9
- end
10
-
6
+ describe "Puppet::Rails::Host", :if => can_use_scratch_database? do
11
7
  before do
12
8
  require 'puppet/rails/host'
13
-
14
- # Stub this so we don't need access to the DB.
15
- Puppet::Rails::Host.stubs(:columns).returns([column("name", "string"), column("environment", "string"), column("ip", "string")])
9
+ setup_scratch_database
16
10
 
17
11
  @node = Puppet::Node.new("foo")
18
12
  @node.environment = "production"
@@ -96,7 +90,7 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
96
90
 
97
91
  describe "when merging catalog resources and database resources" do
98
92
  before :each do
99
- Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(false)
93
+ Puppet[:thin_storeconfigs] = false
100
94
  @resource1 = stub_everything 'res1'
101
95
  @resource2 = stub_everything 'res2'
102
96
  @resources = [ @resource1, @resource2 ]
@@ -131,7 +125,7 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
131
125
  end
132
126
 
133
127
  it "should compare only exported resources in thin_storeconfigs mode" do
134
- Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(true)
128
+ Puppet[:thin_storeconfigs] = true
135
129
  @resource1.stubs(:exported?).returns(true)
136
130
 
137
131
  @host.expects(:compare_to_catalog).with(@dbresources, [ @resource1 ])
@@ -142,7 +136,7 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
142
136
 
143
137
  describe "when searching the database for host resources" do
144
138
  before :each do
145
- Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(false)
139
+ Puppet[:thin_storeconfigs] = false
146
140
  @resource1 = stub_everything 'res1', :id => 1
147
141
  @resource2 = stub_everything 'res2', :id => 2
148
142
  @resources = [ @resource1, @resource2 ]
@@ -159,7 +153,7 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do
159
153
  end
160
154
 
161
155
  it "should return a hash keyed by id of only exported resources in thin_storeconfigs mode" do
162
- Puppet.settings.stubs(:[]).with(:thin_storeconfigs).returns(true)
156
+ Puppet[:thin_storeconfigs] = true
163
157
  @dbresources.expects(:find).with { |*h| h[1][:conditions] == { :exported => true } }.returns([])
164
158
 
165
159
  @host.find_resources
@@ -2,18 +2,13 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet/rails'
4
4
 
5
- describe "Puppet::Rails::ParamValue", :if => Puppet.features.rails? do
6
- def column(name, type)
7
- ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
8
- end
9
-
5
+ describe "Puppet::Rails::ParamValue", :if => can_use_scratch_database? do
10
6
  before do
11
7
  require 'puppet/rails/param_value'
12
-
13
- name = stub 'param_name', :name => "foo"
8
+ setup_scratch_database
14
9
 
15
10
  # Stub this so we don't need access to the DB.
16
- Puppet::Rails::ParamValue.stubs(:columns).returns([column("value", "string")])
11
+ name = stub 'param_name', :name => "foo"
17
12
  Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(name)
18
13
  end
19
14
 
@@ -2,16 +2,10 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet/rails'
4
4
 
5
- describe "Puppet::Rails::Resource", :if => Puppet.features.rails? do
6
- def column(name, type)
7
- ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
8
- end
9
-
5
+ describe "Puppet::Rails::Resource", :if => can_use_scratch_database? do
10
6
  before do
11
7
  require 'puppet/rails/resource'
12
-
13
- # Stub this so we don't need access to the DB.
14
- Puppet::Rails::Resource.stubs(:columns).returns([column("title", "string"), column("restype", "string"), column("exported", "boolean")])
8
+ setup_scratch_database
15
9
  end
16
10
 
17
11
  describe "when creating initial resource arguments" do
@@ -1,55 +1,71 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
-
4
3
  require 'puppet/reports'
5
4
 
6
- # FakeHTTP fakes the behavior of Net::HTTP#request and acts as a sensor for an
7
- # otherwise difficult to trace method call.
8
- #
9
- class FakeHTTP
10
- REQUESTS = {}
11
- def self.request(req)
12
- REQUESTS[req.path] = req
13
- end
14
- end
15
-
16
5
  processor = Puppet::Reports.report(:http)
17
6
 
18
7
  describe processor do
19
- before { Net::HTTP.any_instance.stubs(:start).yields(FakeHTTP) }
20
8
  subject { Puppet::Transaction::Report.new("apply").extend(processor) }
21
9
 
22
- it { should respond_to(:process) }
23
-
24
10
  it "should use the reporturl setting's host and port" do
25
11
  uri = URI.parse(Puppet[:reporturl])
26
12
  Net::HTTP.expects(:new).with(uri.host, uri.port).returns(stub_everything('http'))
27
13
  subject.process
28
14
  end
29
15
 
30
- describe "request" do
31
- before { subject.process }
16
+ describe "when making a request" do
17
+ let(:http) { mock "http" }
18
+ let(:httpok) { Net::HTTPOK.new('1.1', 200, '') }
32
19
 
33
- describe "path" do
34
- it "should use the path specified by the 'reporturl' setting" do
35
- reports_request.path.should == URI.parse(Puppet[:reporturl]).path
36
- end
20
+ before :each do
21
+ Net::HTTP.any_instance.expects(:start).yields(http)
37
22
  end
38
23
 
39
- describe "body" do
40
- it "should be the report as YAML" do
41
- reports_request.body.should == subject.to_yaml
42
- end
24
+ it "should use the path specified by the 'reporturl' setting" do
25
+ http.expects(:request).with {|req|
26
+ req.path.should == URI.parse(Puppet[:reporturl]).path
27
+ }.returns(httpok)
28
+
29
+ subject.process
43
30
  end
44
31
 
45
- describe "content type" do
46
- it "should be 'application/x-yaml'" do
47
- reports_request.content_type.should == "application/x-yaml"
48
- end
32
+ it "should give the body as the report as YAML" do
33
+ http.expects(:request).with {|req|
34
+ req.body.should == subject.to_yaml
35
+ }.returns(httpok)
36
+
37
+ subject.process
49
38
  end
50
- end
51
39
 
52
- private
40
+ it "should set content-type to 'application/x-yaml'" do
41
+ http.expects(:request).with {|req|
42
+ req.content_type.should == "application/x-yaml"
43
+ }.returns(httpok)
53
44
 
54
- def reports_request; FakeHTTP::REQUESTS[URI.parse(Puppet[:reporturl]).path] end
45
+ subject.process
46
+ end
47
+
48
+ Net::HTTPResponse::CODE_TO_OBJ.each do |code, klass|
49
+ if code.to_i >= 200 and code.to_i < 300
50
+ it "should succeed on http code #{code}" do
51
+ response = klass.new('1.1', code, '')
52
+ http.expects(:request).returns(response)
53
+
54
+ Puppet.expects(:err).never
55
+ subject.process
56
+ end
57
+ end
58
+
59
+ if code.to_i >= 300
60
+ it "should log error on http code #{code}" do
61
+ response = klass.new('1.1', code, '')
62
+ http.expects(:request).returns(response)
63
+
64
+ Puppet.expects(:err)
65
+ subject.process
66
+ end
67
+ end
68
+ end
69
+
70
+ end
55
71
  end
@@ -88,4 +88,81 @@ describe tagmail do
88
88
  results.should be_nil
89
89
  end
90
90
  end
91
+
92
+ describe "the behavior of tagmail.process" do
93
+ before do
94
+ Puppet[:tagmap] = my_fixture "tagmail_email.conf"
95
+ end
96
+
97
+ let(:processor) do
98
+ processor = Puppet::Transaction::Report.new("apply")
99
+ processor.extend(Puppet::Reports.report(:tagmail))
100
+ processor
101
+ end
102
+
103
+ context "when any messages match a positive tag" do
104
+ before do
105
+ processor << log_entry
106
+ end
107
+
108
+ let(:log_entry) do
109
+ Puppet::Util::Log.new(
110
+ :level => :notice, :message => "Secure change", :tags => %w{secure})
111
+ end
112
+
113
+ let(:message) do
114
+ "#{log_entry.time} Puppet (notice): Secure change"
115
+ end
116
+
117
+ it "should send email if there are changes" do
118
+ processor.expects(:send).with([[['user@domain.com'], message]])
119
+ processor.expects(:raw_summary).returns({
120
+ "resources" => { "changed" => 1, "out_of_sync" => 0 }
121
+ })
122
+
123
+ processor.process
124
+ end
125
+
126
+ it "should send email if there are resources out of sync" do
127
+ processor.expects(:send).with([[['user@domain.com'], message]])
128
+ processor.expects(:raw_summary).returns({
129
+ "resources" => { "changed" => 0, "out_of_sync" => 1 }
130
+ })
131
+
132
+ processor.process
133
+ end
134
+
135
+ it "should not send email if no changes or resources out of sync" do
136
+ processor.expects(:send).never
137
+ processor.expects(:raw_summary).returns({
138
+ "resources" => { "changed" => 0, "out_of_sync" => 0 }
139
+ })
140
+
141
+ processor.process
142
+ end
143
+
144
+ it "should log a message if no changes or resources out of sync" do
145
+ processor.expects(:send).never
146
+ processor.expects(:raw_summary).returns({
147
+ "resources" => { "changed" => 0, "out_of_sync" => 0 }
148
+ })
149
+
150
+ Puppet.expects(:notice).with("Not sending tagmail report; no changes")
151
+ processor.process
152
+ end
153
+
154
+ it "should send email if raw_summary is not defined" do
155
+ processor.expects(:send).with([[['user@domain.com'], message]])
156
+ processor.expects(:raw_summary).returns(nil)
157
+ processor.process
158
+ end
159
+
160
+ it "should send email if there are no resource metrics" do
161
+ processor.expects(:send).with([[['user@domain.com'], message]])
162
+ processor.expects(:raw_summary).returns({'resources' => nil})
163
+ processor.process
164
+ end
165
+ end
166
+ end
91
167
  end
168
+
@@ -238,7 +238,7 @@ describe Puppet::Resource::Type do
238
238
 
239
239
  describe "when setting its parameters in the scope" do
240
240
  before do
241
- @scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source"))
241
+ @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo")), :source => stub("source"))
242
242
  @resource = Puppet::Parser::Resource.new(:foo, "bar", :scope => @scope)
243
243
  @type = Puppet::Resource::Type.new(:hostclass, "foo")
244
244
  end
@@ -435,7 +435,7 @@ describe Puppet::Resource::Type do
435
435
 
436
436
  it "should set all of its parameters in a subscope" do
437
437
  subscope = stub 'subscope', :compiler => @compiler
438
- @scope.expects(:newscope).with(:source => @type, :dynamic => true, :namespace => 'foo', :resource => @resource).returns subscope
438
+ @scope.expects(:newscope).with(:source => @type, :namespace => 'foo', :resource => @resource).returns subscope
439
439
  @type.expects(:set_resource_parameters).with(@resource, subscope)
440
440
 
441
441
  @type.evaluate_code(@resource)
@@ -5,9 +5,7 @@ require 'puppet/resource'
5
5
  describe Puppet::Resource do
6
6
  include PuppetSpec::Files
7
7
 
8
- before do
9
- @basepath = make_absolute("/somepath")
10
- end
8
+ let :basepath do make_absolute("/somepath") end
11
9
 
12
10
  [:catalog, :file, :line].each do |attr|
13
11
  it "should have an #{attr} attribute" do
@@ -87,27 +85,27 @@ describe Puppet::Resource do
87
85
  end
88
86
 
89
87
  it "should be able to extract its information from a Puppet::Type instance" do
90
- ral = Puppet::Type.type(:file).new :path => @basepath+"/foo"
88
+ ral = Puppet::Type.type(:file).new :path => basepath+"/foo"
91
89
  ref = Puppet::Resource.new(ral)
92
90
  ref.type.should == "File"
93
- ref.title.should == @basepath+"/foo"
91
+ ref.title.should == basepath+"/foo"
94
92
  end
95
93
 
96
94
 
97
95
  it "should fail if the title is nil and the type is not a valid resource reference string" do
98
- lambda { Puppet::Resource.new("foo") }.should raise_error(ArgumentError)
96
+ expect { Puppet::Resource.new("resource-spec-foo") }.should raise_error(ArgumentError)
99
97
  end
100
98
 
101
99
  it 'should fail if strict is set and type does not exist' do
102
- lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
100
+ expect { Puppet::Resource.new('resource-spec-foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type resource-spec-foo')
103
101
  end
104
102
 
105
103
  it 'should fail if strict is set and class does not exist' do
106
- lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
104
+ expect { Puppet::Resource.new('Class', 'resource-spec-foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class resource-spec-foo')
107
105
  end
108
106
 
109
107
  it "should fail if the title is a hash and the type is not a valid resource reference string" do
110
- expect { Puppet::Resource.new({:type => "foo", :title => "bar"}) }.
108
+ expect { Puppet::Resource.new({:type => "resource-spec-foo", :title => "bar"}) }.
111
109
  to raise_error ArgumentError, /Puppet::Resource.new does not take a hash/
112
110
  end
113
111
 
@@ -286,11 +284,11 @@ describe Puppet::Resource do
286
284
  end
287
285
 
288
286
  it "should fail if invalid parameters are used" do
289
- lambda { Puppet::Resource.new("file", "/path", :strict => true, :parameters => {:nosuchparam => "bar"}) }.should raise_error
287
+ expect { Puppet::Resource.new("file", "/path", :strict => true, :parameters => {:nosuchparam => "bar"}) }.should raise_error
290
288
  end
291
289
 
292
290
  it "should fail if the resource type cannot be resolved" do
293
- lambda { Puppet::Resource.new("nosuchtype", "/path", :strict => true) }.should raise_error
291
+ expect { Puppet::Resource.new("nosuchtype", "/path", :strict => true) }.should raise_error
294
292
  end
295
293
  end
296
294
 
@@ -355,7 +353,7 @@ describe Puppet::Resource do
355
353
  it "should be able to set the name for non-builtin types" do
356
354
  resource = Puppet::Resource.new(:foo, "bar")
357
355
  resource[:name] = "eh"
358
- lambda { resource[:name] = "eh" }.should_not raise_error
356
+ expect { resource[:name] = "eh" }.should_not raise_error
359
357
  end
360
358
 
361
359
  it "should be able to return the name for non-builtin types" do
@@ -472,7 +470,7 @@ type: File
472
470
  end
473
471
 
474
472
  it "should deserialize a Puppet::Resource::Reference without exceptions" do
475
- lambda { YAML.load(@old_storedconfig_yaml) }.should_not raise_error
473
+ expect { YAML.load(@old_storedconfig_yaml) }.should_not raise_error
476
474
  end
477
475
 
478
476
  it "should deserialize as a Puppet::Resource::Reference as a Puppet::Resource" do
@@ -486,10 +484,10 @@ type: File
486
484
 
487
485
  describe "when converting to a RAL resource" do
488
486
  it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do
489
- resource = Puppet::Resource.new("file", @basepath+"/my/file")
487
+ resource = Puppet::Resource.new("file", basepath+"/my/file")
490
488
  result = resource.to_ral
491
489
  result.should be_instance_of(Puppet::Type.type(:file))
492
- result[:path].should == @basepath+"/my/file"
490
+ result[:path].should == basepath+"/my/file"
493
491
  end
494
492
 
495
493
  it "should convert to a component instance if the resource type is not of a builtin type" do
@@ -526,7 +524,7 @@ type: File
526
524
  describe "when converting to a TransObject" do
527
525
  describe "and the resource is not an instance of a builtin type" do
528
526
  before do
529
- @resource = Puppet::Resource.new("foo", "bar")
527
+ @resource = Puppet::Resource.new("resource-spec-foo", "bar")
530
528
  end
531
529
 
532
530
  it "should return a simple TransBucket if it is not an instance of a builtin type" do
@@ -697,7 +695,7 @@ type: File
697
695
  before do
698
696
  @data = {
699
697
  'type' => "file",
700
- 'title' => @basepath+"/yay",
698
+ 'title' => basepath+"/yay",
701
699
  }
702
700
  end
703
701
 
@@ -706,7 +704,7 @@ type: File
706
704
  end
707
705
 
708
706
  it "should set its title to the provided title" do
709
- Puppet::Resource.from_pson(@data).title.should == @basepath+"/yay"
707
+ Puppet::Resource.from_pson(@data).title.should == basepath+"/yay"
710
708
  end
711
709
 
712
710
  it "should tag the resource with any provided tags" do
@@ -737,12 +735,12 @@ type: File
737
735
 
738
736
  it "should fail if no title is provided" do
739
737
  @data.delete('title')
740
- lambda { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
738
+ expect { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
741
739
  end
742
740
 
743
741
  it "should fail if no type is provided" do
744
742
  @data.delete('type')
745
- lambda { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
743
+ expect { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
746
744
  end
747
745
 
748
746
  it "should set each of the provided parameters" do