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
@@ -297,8 +297,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do
297
297
  saved_files = @aug.match("/augeas/events/saved")
298
298
  if saved_files.size > 0
299
299
  root = resource[:root].sub(/^\/$/, "")
300
- saved_files.each do |key|
301
- saved_file = @aug.get(key).sub(/^\/files/, root)
300
+ saved_files.map! {|key| @aug.get(key).sub(/^\/files/, root) }
301
+ saved_files.uniq.each do |saved_file|
302
302
  if Puppet[:show_diff]
303
303
  notice "\n" + diff(saved_file, saved_file + ".augnew")
304
304
  end
@@ -1,3 +1,6 @@
1
+ require 'puppet/provider'
2
+ require 'puppet/util/execution'
3
+
1
4
  class Puppet::Provider::Exec < Puppet::Provider
2
5
  include Puppet::Util::Execution
3
6
 
@@ -63,9 +66,11 @@ class Puppet::Provider::Exec < Puppet::Provider
63
66
  end
64
67
 
65
68
  def extractexe(command)
66
- # easy case: command was quoted
67
- if command =~ /^"([^"]+)"/
68
- $1
69
+ if command.is_a? Array
70
+ command.first
71
+ elsif match = /^"([^"]+)"|^'([^']+)'/.match(command)
72
+ # extract whichever of the two sides matched the content.
73
+ match[1] or match[2]
69
74
  else
70
75
  command.split(/ /)[0]
71
76
  end
@@ -16,8 +16,7 @@ Puppet::Type.type(:exec).provide :shell, :parent => :posix do
16
16
  EOT
17
17
 
18
18
  def run(command, check = false)
19
- command = %Q{/bin/sh -c "#{command.gsub(/"/,'\"')}"}
20
- super(command, check)
19
+ super(['/bin/sh', '-c', command], check)
21
20
  end
22
21
 
23
22
  def validatecmd(command)
@@ -323,9 +323,15 @@ class DirectoryService < Puppet::Provider::NameService
323
323
 
324
324
  # users_plist['ShadowHashData'][0].string is actually a binary plist
325
325
  # that's nested INSIDE the user's plist (which itself is a binary
326
- # plist).
327
- password_hash_plist = users_plist['ShadowHashData'][0].string
328
- converted_hash_plist = convert_binary_to_xml(password_hash_plist)
326
+ # plist). If we encounter a user plist that DOESN'T have a
327
+ # ShadowHashData field, create one.
328
+ if users_plist['ShadowHashData']
329
+ password_hash_plist = users_plist['ShadowHashData'][0].string
330
+ converted_hash_plist = convert_binary_to_xml(password_hash_plist)
331
+ else
332
+ users_plist['ShadowHashData'] = [StringIO.new]
333
+ converted_hash_plist = {'SALTED-SHA512' => StringIO.new}
334
+ end
329
335
 
330
336
  # converted_hash_plist['SALTED-SHA512'].string expects a Base64 encoded
331
337
  # string. The password_hash provided as a resource attribute is a
@@ -348,7 +354,7 @@ class DirectoryService < Puppet::Provider::NameService
348
354
  def self.get_password(guid, username)
349
355
  # Use Puppet::Util::Package.versioncmp() to catch the scenario where a
350
356
  # version '10.10' would be < '10.7' with simple string comparison. This
351
- # if-statement only executes if the current version is less-than 10.7
357
+ # if-statement only executes if the current version is less-than 10.7
352
358
  if (Puppet::Util::Package.versioncmp(get_macosx_version_major, '10.7') == -1)
353
359
  password_hash = nil
354
360
  password_hash_file = "#{@@password_hash_dir}/#{guid}"
@@ -104,7 +104,7 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d
104
104
  # This always gets the latest version available.
105
105
  hash = self.class.gemlist(:justme => resource[:name])
106
106
 
107
- hash[:ensure]
107
+ hash[:ensure][0]
108
108
  end
109
109
 
110
110
  def query
@@ -12,22 +12,17 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
12
12
  def self.instances
13
13
  packages = []
14
14
 
15
- cmd = "#{command(:pkg)} list -H"
16
- execpipe(cmd) do |process|
17
- hash = {}
18
-
15
+ pkg(:list, '-H').each_line do |line|
19
16
  # now turn each returned line into a package object
20
- process.each_line { |line|
21
- if hash = parse_line(line)
22
- packages << new(hash)
23
- end
24
- }
17
+ if hash = parse_line(line.chomp)
18
+ packages << new(hash)
19
+ end
25
20
  end
26
21
 
27
22
  packages
28
23
  end
29
24
 
30
- self::REGEX = %r{^(\S+)\s+(\S+)\s+(\S+)\s+}
25
+ self::REGEX = /^(\S+)(?:\s+\(.*?\))?\s+(\S+)\s+(\S+)\s+\S+$/
31
26
  self::FIELDS = [:name, :version, :status]
32
27
 
33
28
  def self.parse_line(line)
@@ -39,7 +34,6 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
39
34
  }
40
35
 
41
36
  hash[:provider] = self.name
42
- hash[:error] = "ok"
43
37
 
44
38
  if hash[:status] == "installed"
45
39
  hash[:ensure] = :present
@@ -47,7 +41,7 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
47
41
  hash[:ensure] = :absent
48
42
  end
49
43
  else
50
- Puppet.warning "Failed to match 'pkg list' line #{line.inspect}"
44
+ warning "Failed to match 'pkg list' line #{line.inspect}"
51
45
  return nil
52
46
  end
53
47
 
@@ -58,8 +52,8 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
58
52
  # TODO deal with multiple publishers
59
53
  def latest
60
54
  version = nil
61
- pkg(:list, "-Ha", @resource[:name]).split("\n").each do |line|
62
- v = line.split[2]
55
+ pkg(:list, "-Ha", @resource[:name]).each_line do |line|
56
+ v = parse_line(line.chomp)[:status]
63
57
  case v
64
58
  when "known"
65
59
  return v
@@ -93,15 +87,10 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
93
87
  output = pkg(:list, "-H", @resource[:name])
94
88
  rescue Puppet::ExecutionFailure
95
89
  # pkg returns 1 if the package is not found.
96
- return {:ensure => :absent, :status => 'missing',
97
- :name => @resource[:name], :error => 'ok'}
90
+ return {:ensure => :absent, :name => @resource[:name]}
98
91
  end
99
92
 
100
- hash = self.class.parse_line(output) ||
101
- {:ensure => :absent, :status => 'missing', :name => @resource[:name], :error => 'ok'}
102
-
103
- raise Puppet::Error.new( "Package #{hash[:name]}, version #{hash[:version]} is in error state: #{hash[:error]}") if hash[:error] != "ok"
104
-
93
+ hash = self.class.parse_line(output.chomp) || {:ensure => :absent, :name => @resource[:name]}
105
94
  hash
106
95
  end
107
96
  end
@@ -117,8 +117,7 @@ Puppet::Type.type(:selmodule).provide(:semodule) do
117
117
  lines = ()
118
118
  begin
119
119
  execpipe("#{command(:semodule)} --list") do |output|
120
- lines = output.readlines
121
- lines.each_line do |line|
120
+ output.each_line do |line|
122
121
  line.chomp!
123
122
  bits = line.split
124
123
  if bits[0] == @resource[:name]
@@ -1,4 +1,4 @@
1
- Puppet::Type.type(:service).provide :upstart, :parent => :init do
1
+ Puppet::Type.type(:service).provide :upstart, :parent => :debian do
2
2
  desc "Ubuntu service management with `upstart`.
3
3
 
4
4
  This provider manages `upstart` jobs, which have replaced `initd` services
@@ -6,6 +6,8 @@ Puppet::Type.type(:service).provide :upstart, :parent => :init do
6
6
  "
7
7
  # confine to :ubuntu for now because I haven't tested on other platforms
8
8
  confine :operatingsystem => :ubuntu #[:ubuntu, :fedora, :debian]
9
+
10
+ defaultfor :operatingsystem => :ubuntu
9
11
 
10
12
  commands :start => "/sbin/start",
11
13
  :stop => "/sbin/stop",
@@ -39,33 +41,47 @@ Puppet::Type.type(:service).provide :upstart, :parent => :init do
39
41
  end
40
42
 
41
43
  def startcmd
42
- [command(:start), @resource[:name]]
44
+ is_upstart? ? [command(:start), @resource[:name]] : super
43
45
  end
44
46
 
45
47
  def stopcmd
46
- [command(:stop), @resource[:name]]
48
+ is_upstart? ? [command(:stop), @resource[:name]] : super
47
49
  end
48
50
 
49
51
  def restartcmd
50
- (@resource[:hasrestart] == :true) && [command(:restart), @resource[:name]]
52
+ is_upstart? ? (@resource[:hasrestart] == :true) && [command(:restart), @resource[:name]] : super
51
53
  end
52
54
 
55
+ def statuscmd
56
+ is_upstart? ? nil : super #this is because upstart is broken with its return codes
57
+ end
58
+
53
59
  def status
54
- # allows user override of status command
55
60
  if @resource[:status]
56
- ucommand(:status, false)
57
- if $?.exitstatus == 0
58
- return :running
59
- else
60
- return :stopped
61
- end
61
+ is_upstart?(@resource[:status]) ? upstart_status(@resource[:status]) : normal_status
62
+ elsif is_upstart?
63
+ upstart_status
62
64
  else
63
- output = status_exec(@resource[:name].split)
64
- if (! $?.nil?) && (output =~ /start\//)
65
- return :running
66
- else
67
- return :stopped
68
- end
65
+ super
69
66
  end
70
67
  end
68
+
69
+ def normal_status
70
+ ucommand(:status, false)
71
+ ($?.exitstatus == 0) ? :running : :stopped
72
+ end
73
+
74
+ def upstart_status(exec = @resource[:name])
75
+ output = status_exec(@resource[:name].split)
76
+ if (! $?.nil?) && (output =~ /start\//)
77
+ return :running
78
+ else
79
+ return :stopped
80
+ end
81
+ end
82
+
83
+ def is_upstart?(script = initscript)
84
+ File.symlink?(script) && File.readlink(script) == "/lib/init/upstart-job"
85
+ end
86
+
71
87
  end
@@ -17,7 +17,7 @@ require 'puppet/provider/parsedfile'
17
17
  :fields => %w{options type key name},
18
18
  :optional => %w{options},
19
19
  :rts => /^\s+/,
20
- :match => /^(?:(.+) )?(ssh-dss|ssh-rsa) ([^ ]+) ?(.*)$/,
20
+ :match => /^(?:(.+) )?(ssh-dss|ssh-rsa|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521) ([^ ]+) ?(.*)$/,
21
21
  :post_parse => proc { |h|
22
22
  h[:name] = "" if h[:name] == :absent
23
23
  h[:options] ||= [:absent]
@@ -3,21 +3,21 @@ require 'puppet/rails/inventory_fact'
3
3
  class Puppet::Rails::InventoryNode < ::ActiveRecord::Base
4
4
  has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :foreign_key => :node_id, :dependent => :delete_all
5
5
 
6
- if Puppet::Util.activerecord_version >= 3.0
7
- # Prevents "DEPRECATION WARNING: Base.named_scope has been deprecated, please use Base.scope instead"
8
- ActiveRecord::NamedScope::ClassMethods.module_eval { alias :named_scope :scope }
6
+ if Puppet::Util.activerecord_version < 3.0
7
+ # For backward compatibility, add the newer name to older implementations.
8
+ ActiveRecord::NamedScope::ClassMethods.module_eval { alias :scope :named_scope }
9
9
  end
10
10
 
11
- named_scope :has_fact_with_value, lambda { |name,value|
11
+ scope :has_fact_with_value, lambda { |name,value|
12
12
  {
13
- :conditions => ["inventory_facts.name = ? AND inventory_facts.value = ?", name, value],
13
+ :conditions => ["inventory_facts.name = ? AND inventory_facts.value = ?", name, value.to_s],
14
14
  :joins => :facts
15
15
  }
16
16
  }
17
17
 
18
- named_scope :has_fact_without_value, lambda { |name,value|
18
+ scope :has_fact_without_value, lambda { |name,value|
19
19
  {
20
- :conditions => ["inventory_facts.name = ? AND inventory_facts.value != ?", name, value],
20
+ :conditions => ["inventory_facts.name = ? AND inventory_facts.value != ?", name, value.to_s],
21
21
  :joins => :facts
22
22
  }
23
23
  }
@@ -16,7 +16,10 @@ Puppet::Reports.register_report(:http) do
16
16
  req.body = self.to_yaml
17
17
  req.content_type = "application/x-yaml"
18
18
  Net::HTTP.new(url.host, url.port).start {|http|
19
- http.request(req)
19
+ response = http.request(req)
20
+ unless response.kind_of?(Net::HTTPSuccess)
21
+ Puppet.err "Unable to submit report to #{Puppet[:reporturl].to_s} [#{response.code}] #{response.msg}"
22
+ end
20
23
  }
21
24
  end
22
25
  end
@@ -113,6 +113,13 @@ Puppet::Reports.register_report(:tagmail) do
113
113
  return
114
114
  end
115
115
 
116
+ metrics = raw_summary['resources'] || {} rescue {}
117
+
118
+ if metrics['out_of_sync'] == 0 && metrics['changed'] == 0
119
+ Puppet.notice "Not sending tagmail report; no changes"
120
+ return
121
+ end
122
+
116
123
  taglists = parse(File.read(Puppet[:tagmap]))
117
124
 
118
125
  # Now find any appropriately tagged messages.
@@ -123,7 +130,7 @@ Puppet::Reports.register_report(:tagmail) do
123
130
 
124
131
  # Send the email reports.
125
132
  def send(reports)
126
- pid = fork do
133
+ pid = Puppet::Util.safe_posix_fork do
127
134
  if Puppet[:smtpserver] != "none"
128
135
  begin
129
136
  Net::SMTP.start(Puppet[:smtpserver]) do |smtp|
@@ -66,7 +66,7 @@ class Puppet::Resource::Type
66
66
  static_parent = evaluate_parent_type(resource)
67
67
  scope = static_parent || resource.scope
68
68
 
69
- scope = scope.newscope(:namespace => namespace, :source => self, :resource => resource, :dynamic => !static_parent) unless resource.title == :main
69
+ scope = scope.newscope(:namespace => namespace, :source => self, :resource => resource) unless resource.title == :main
70
70
  scope.compiler.add_class(name) unless definition?
71
71
 
72
72
  set_resource_parameters(resource, scope)
@@ -0,0 +1,138 @@
1
+ module Puppet::Test
2
+ # This class is intended to provide an API to be used by external projects
3
+ # when they are running tests that depend on puppet core. This should
4
+ # allow us to vary the implementation details of managing puppet's state
5
+ # for testing, from one version of puppet to the next--without forcing
6
+ # the external projects to do any of that state management or be aware of
7
+ # the implementation details.
8
+ #
9
+ # For now, this consists of a few very simple signatures. The plan is
10
+ # that it should be the responsibility of the puppetlabs_spec_helper
11
+ # to broker between external projects and this API; thus, if any
12
+ # hacks are required (e.g. to determine whether or not a particular)
13
+ # version of puppet supports this API, those hacks will be consolidated in
14
+ # one place and won't need to be duplicated in every external project.
15
+ #
16
+ # This should also alleviate the anti-pattern that we've been following,
17
+ # wherein each external project starts off with a copy of puppet core's
18
+ # test_helper.rb and is exposed to risk of that code getting out of
19
+ # sync with core.
20
+ #
21
+ # Since this class will be "library code" that ships with puppet, it does
22
+ # not use API from any existing test framework such as rspec. This should
23
+ # theoretically allow it to be used with other unit test frameworks in the
24
+ # future, if desired.
25
+ #
26
+ # Note that in the future this API could potentially be expanded to handle
27
+ # other features such as "around_test", but we didn't see a compelling
28
+ # reason to deal with that right now.
29
+ class TestHelper
30
+ # Call this method once, when beginning a test run--prior to running
31
+ # any individual tests.
32
+ # @return nil
33
+ def self.before_all_tests()
34
+
35
+ end
36
+
37
+ # Call this method once, at the end of a test run, when no more tests
38
+ # will be run.
39
+ # @return nil
40
+ def self.after_all_tests()
41
+
42
+ end
43
+
44
+ # Call this method once per test, prior to execution of each invididual test.
45
+ # @return nil
46
+ def self.before_each_test()
47
+ # We need to preserve the current state of all our indirection cache and
48
+ # terminus classes. This is pretty important, because changes to these
49
+ # are global and lead to order dependencies in our testing.
50
+ #
51
+ # We go direct to the implementation because there is no safe, sane public
52
+ # API to manage restoration of these to their default values. This
53
+ # should, once the value is proved, be moved to a standard API on the
54
+ # indirector.
55
+ #
56
+ # To make things worse, a number of the tests stub parts of the
57
+ # indirector. These stubs have very specific expectations that what
58
+ # little of the public API we could use is, well, likely to explode
59
+ # randomly in some tests. So, direct access. --daniel 2011-08-30
60
+ $saved_indirection_state = {}
61
+ indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections)
62
+ indirections.each do |indirector|
63
+ $saved_indirection_state[indirector.name] = {
64
+ :@terminus_class => indirector.instance_variable_get(:@terminus_class),
65
+ :@cache_class => indirector.instance_variable_get(:@cache_class)
66
+ }
67
+ end
68
+
69
+ initialize_settings_before_each()
70
+
71
+ # Longer keys are secure, but they sure make for some slow testing - both
72
+ # in terms of generating keys, and in terms of anything the next step down
73
+ # the line doing validation or whatever. Most tests don't care how long
74
+ # or secure it is, just that it exists, so these are better and faster
75
+ # defaults, in testing only.
76
+ #
77
+ # I would make these even shorter, but OpenSSL doesn't support anything
78
+ # below 512 bits. Sad, really, because a 0 bit key would be just fine.
79
+ Puppet[:req_bits] = 512
80
+ Puppet[:keylength] = 512
81
+
82
+ end
83
+
84
+ # Call this method once per test, after execution of each individual test.
85
+ # @return nil
86
+ def self.after_each_test()
87
+ clear_settings_after_each()
88
+
89
+ Puppet::Node::Environment.clear
90
+ Puppet::Util::Storage.clear
91
+ Puppet::Util::ExecutionStub.reset
92
+
93
+ # Restore the indirector configuration. See before hook.
94
+ indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections)
95
+ indirections.each do |indirector|
96
+ $saved_indirection_state.fetch(indirector.name, {}).each do |variable, value|
97
+ indirector.instance_variable_set(variable, value)
98
+ end
99
+ end
100
+ $saved_indirection_state = nil
101
+
102
+
103
+ # Some tests can cause us to connect, in which case the lingering
104
+ # connection is a resource that can cause unexpected failure in later
105
+ # tests, as well as sharing state accidentally.
106
+ # We're testing if ActiveRecord::Base is defined because some test cases
107
+ # may stub Puppet.features.rails? which is how we should normally
108
+ # introspect for this functionality.
109
+ ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
110
+
111
+ end
112
+
113
+
114
+ #########################################################################################
115
+ # PRIVATE METHODS (not part of the public TestHelper API--do not call these from outside
116
+ # of this class!)
117
+ #########################################################################################
118
+
119
+ def self.initialize_settings_before_each()
120
+ # these globals are set by Application
121
+ $puppet_application_mode = nil
122
+ $puppet_application_name = nil
123
+ # Set the confdir and vardir to gibberish so that tests
124
+ # have to be correctly mocked.
125
+ Puppet[:confdir] = "/dev/null"
126
+ Puppet[:vardir] = "/dev/null"
127
+
128
+ # Avoid opening ports to the outside world
129
+ Puppet[:bindaddress] = "127.0.0.1"
130
+ end
131
+ private_class_method :initialize_settings_before_each
132
+
133
+ def self.clear_settings_after_each()
134
+ Puppet.settings.clear
135
+ end
136
+ private_class_method :clear_settings_after_each
137
+ end
138
+ end