puppet 2.7.1 → 2.7.3

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 (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -62,13 +62,30 @@ class Puppet::Parser::Resource < Puppet::Resource
62
62
  scope.environment
63
63
  end
64
64
 
65
+ # Process the stage metaparameter for a class. A containment edge
66
+ # is drawn from the class to the stage. The stage for containment
67
+ # defaults to main, if none is specified.
68
+ def add_edge_to_stage
69
+ return unless self.type.to_s.downcase == "class"
70
+
71
+ unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main)
72
+ raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}"
73
+ end
74
+
75
+ self[:stage] ||= stage.title unless stage.title == :main
76
+ catalog.add_edge(stage, self)
77
+ end
78
+
65
79
  # Retrieve the associated definition and evaluate it.
66
80
  def evaluate
67
81
  return if evaluated?
68
82
  @evaluated = true
69
83
  if klass = resource_type and ! builtin_type?
70
84
  finish
71
- return klass.evaluate_code(self)
85
+ evaluated_code = klass.evaluate_code(self)
86
+ add_edge_to_stage
87
+
88
+ return evaluated_code
72
89
  elsif builtin?
73
90
  devfail "Cannot evaluate a builtin type (#{type})"
74
91
  else
@@ -101,7 +101,7 @@ class Puppet::Parser::Scope
101
101
 
102
102
  # Remove this when rebasing
103
103
  def environment
104
- compiler.environment
104
+ compiler ? compiler.environment : nil
105
105
  end
106
106
 
107
107
  def find_hostclass(name)
@@ -443,6 +443,6 @@ class Puppet::Parser::Scope
443
443
 
444
444
  def extend_with_functions_module
445
445
  extend Puppet::Parser::Functions.environment_module(Puppet::Node::Environment.root)
446
- extend Puppet::Parser::Functions.environment_module(compiler ? environment : nil)
446
+ extend Puppet::Parser::Functions.environment_module(environment)
447
447
  end
448
448
  end
@@ -15,9 +15,12 @@
15
15
 
16
16
  require 'augeas' if Puppet.features.augeas?
17
17
  require 'strscan'
18
+ require 'puppet/util'
19
+ require 'puppet/util/diff'
18
20
 
19
21
  Puppet::Type.type(:augeas).provide(:augeas) do
20
22
  include Puppet::Util
23
+ include Puppet::Util::Diff
21
24
 
22
25
  confine :true => Puppet.features.augeas?
23
26
 
@@ -25,6 +28,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do
25
28
 
26
29
  SAVE_NOOP = "noop"
27
30
  SAVE_OVERWRITE = "overwrite"
31
+ SAVE_NEWFILE = "newfile"
32
+ SAVE_BACKUP = "backup"
28
33
 
29
34
  COMMANDS = {
30
35
  "set" => [ :path, :string ],
@@ -254,11 +259,6 @@ Puppet::Type.type(:augeas).provide(:augeas) do
254
259
  @aug.set("/augeas/save", mode)
255
260
  end
256
261
 
257
- def files_changed?
258
- saved_files = @aug.match("/augeas/events/saved")
259
- saved_files.size > 0
260
- end
261
-
262
262
  # Determines if augeas acutally needs to run.
263
263
  def need_to_run?
264
264
  force = resource[:force]
@@ -287,20 +287,33 @@ Puppet::Type.type(:augeas).provide(:augeas) do
287
287
  # actually do the save.
288
288
  if return_value and get_augeas_version >= "0.3.6"
289
289
  debug("Will attempt to save and only run if files changed")
290
- set_augeas_save_mode(SAVE_NOOP)
290
+ set_augeas_save_mode(SAVE_NEWFILE)
291
291
  do_execute_changes
292
292
  save_result = @aug.save
293
293
  saved_files = @aug.match("/augeas/events/saved")
294
- if save_result and not files_changed?
295
- debug("Skipping because no files were changed")
296
- return_value = false
297
- else
294
+ if save_result and saved_files.size > 0
295
+ root = resource[:root].sub(/^\/$/, "")
296
+ saved_files.each do |key|
297
+ saved_file = @aug.get(key).to_s.sub(/^\/files/, root)
298
+ if Puppet[:show_diff]
299
+ print diff(saved_file, saved_file + ".augnew")
300
+ end
301
+ if resource.noop?
302
+ File.delete(saved_file + ".augnew")
303
+ end
304
+ end
298
305
  debug("Files changed, should execute")
306
+ return_value = true
307
+ else
308
+ debug("Skipping because no files were changed or save failed")
309
+ return_value = false
299
310
  end
300
311
  end
301
312
  end
302
313
  ensure
303
- close_augeas
314
+ if not return_value or resource.noop?
315
+ close_augeas
316
+ end
304
317
  end
305
318
  return_value
306
319
  end
@@ -309,12 +322,24 @@ Puppet::Type.type(:augeas).provide(:augeas) do
309
322
  # Re-connect to augeas, and re-execute the changes
310
323
  begin
311
324
  open_augeas
312
- set_augeas_save_mode(SAVE_OVERWRITE) if get_augeas_version >= "0.3.6"
313
-
314
- do_execute_changes
315
-
316
- success = @aug.save
317
- fail("Save failed with return code #{success}") if success != true
325
+ saved_files = @aug.match("/augeas/events/saved")
326
+ if saved_files
327
+ saved_files.each do |key|
328
+ root = resource[:root].sub(/^\/$/, "")
329
+ saved_file = @aug.get(key).to_s.sub(/^\/files/, root)
330
+ if File.exists?(saved_file + ".augnew")
331
+ success = File.rename(saved_file + ".augnew", saved_file)
332
+ debug(saved_file + ".augnew moved to " + saved_file)
333
+ fail("Rename failed with return code #{success}") if success != 0
334
+ end
335
+ end
336
+ else
337
+ debug("No saved files, re-executing augeas")
338
+ set_augeas_save_mode(SAVE_OVERWRITE) if get_augeas_version >= "0.3.6"
339
+ do_execute_changes
340
+ success = @aug.save
341
+ fail("Save failed with return code #{success}") if success != true
342
+ end
318
343
  ensure
319
344
  close_augeas
320
345
  end
@@ -18,7 +18,7 @@ Puppet::Type.type(:mount).provide(
18
18
 
19
19
  commands :mountcmd => "mount", :umount => "umount"
20
20
 
21
- case Facter["operatingsystem"]
21
+ case Facter.value(:operatingsystem)
22
22
  when "Solaris"
23
23
  @fields = [:device, :blockdevice, :name, :fstype, :pass, :atboot, :options]
24
24
  else
@@ -47,6 +47,24 @@ Puppet::Type.type(:mount).provide(
47
47
  end
48
48
  end
49
49
 
50
+ def self.instances
51
+ providers = super
52
+ mounts = mountinstances.dup
53
+
54
+ # Update fstab entries that are mounted
55
+ providers.each do |prov|
56
+ if mounts.delete({:name => prov.get(:name), :mounted => :yes}) then
57
+ prov.set(:ensure => :mounted)
58
+ end
59
+ end
60
+
61
+ # Add mounts that are not in fstab but mounted
62
+ mounts.each do |mount|
63
+ providers << new(:ensure => :ghost, :name => mount[:name])
64
+ end
65
+ providers
66
+ end
67
+
50
68
  def self.prefetch(resources = nil)
51
69
  # Get providers for all resources the user defined and that match
52
70
  # a record in /etc/fstab.
@@ -30,7 +30,15 @@ class Puppet::Provider::Naginator < Puppet::Provider::ParsedFile
30
30
  end
31
31
 
32
32
  def self.to_file(records)
33
- header + records.collect { |record| record.to_s }.join("\n").gsub("_naginator_name", NAME_STRING)
33
+ header + records.collect { |record|
34
+ # Remap the TYPE_name or _naginator_name params to the
35
+ # name if the record is a template (register == 0)
36
+ if record.to_s =~ /register\s+0/
37
+ record.to_s.sub("_naginator_name", "name").sub(record.type.to_s + "_name", "name")
38
+ else
39
+ record.to_s.sub("_naginator_name", NAME_STRING)
40
+ end
41
+ }.join("\n")
34
42
  end
35
43
 
36
44
  def self.skip_record?(record)
@@ -221,11 +221,12 @@ class DirectoryService < Puppet::Provider::NameService
221
221
  # have a lot of choice. Ultimately this should all be done using Ruby
222
222
  # to access the DirectoryService APIs directly, but that's simply not
223
223
  # feasible for a while yet.
224
- case self.get_macosx_version_major
225
- when "10.4"
226
- dscl_plist = self.parse_dscl_url_data(dscl_output)
227
- when "10.5", "10.6"
224
+ if self.get_macosx_version_major > "10.4"
228
225
  dscl_plist = self.parse_dscl_plist_data(dscl_output)
226
+ elsif self.get_macosx_version_major == "10.4"
227
+ dscl_plist = self.parse_dscl_url_data(dscl_output)
228
+ else
229
+ fail("Puppet does not support OS X versions < 10.4")
229
230
  end
230
231
 
231
232
  self.generate_attribute_hash(dscl_plist, *type_properties)
@@ -243,12 +244,14 @@ class DirectoryService < Puppet::Provider::NameService
243
244
  # different format for the -url output with objects with spaces in
244
245
  # their values. *sigh*. Use -url for 10.4 in the hope this can be
245
246
  # deprecated one day, and use -plist for 10.5 and higher.
246
- case self.get_macosx_version_major
247
- when "10.4"
248
- command_vector = [ command(:dscl), "-url", "." ]
249
- when "10.5", "10.6"
247
+ if self.get_macosx_version_major > "10.4"
250
248
  command_vector = [ command(:dscl), "-plist", "." ]
249
+ elsif self.get_macosx_version_major == "10.4"
250
+ command_vector = [ command(:dscl), "-url", "." ]
251
+ else
252
+ fail("Puppet does not support OS X versions < 10.4")
251
253
  end
254
+
252
255
  # JJM: The actual action to perform. See "man dscl"
253
256
  # Common actiosn: -create, -delete, -merge, -append, -passwd
254
257
  command_vector << ds_action
@@ -65,4 +65,4 @@ class Puppet::Provider::NetworkDevice < Puppet::Provider
65
65
  def properties
66
66
  @property_hash.dup
67
67
  end
68
- end
68
+ end
@@ -12,6 +12,7 @@ Puppet::Type.type(:package).provide :aptitude, :parent => :apt, :source => :dpkg
12
12
  args.flatten!
13
13
  # Apparently aptitude hasn't always supported a -q flag.
14
14
  args.delete("-q") if args.include?("-q")
15
+ args.delete("--force-yes") if args.include?("--force-yes")
15
16
  output = aptitude(*args)
16
17
 
17
18
  # Yay, stupid aptitude doesn't throw an error when the package is missing.
@@ -0,0 +1,94 @@
1
+ require 'puppet/provider/package'
2
+
3
+ Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do
4
+ desc "Support for the Package Manager Utility (pacman) used in Archlinux."
5
+
6
+ commands :pacman => "/usr/bin/pacman"
7
+ defaultfor :operatingsystem => :archlinux
8
+ confine :operatingsystem => :archlinux
9
+ has_feature :upgradeable
10
+
11
+ # Install a package using 'pacman'.
12
+ # Installs quietly, without confirmation or progressbar, updates package
13
+ # list from servers defined in pacman.conf.
14
+ def install
15
+ pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]
16
+
17
+ unless self.query
18
+ raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name)
19
+ end
20
+ end
21
+
22
+ def self.listcmd
23
+ [command(:pacman), " -Q"]
24
+ end
25
+
26
+ # Fetch the list of packages currently installed on the system.
27
+ def self.instances
28
+ packages = []
29
+ begin
30
+ execpipe(listcmd()) do |process|
31
+ # pacman -Q output is 'packagename version-rel'
32
+ regex = %r{^(\S+)\s(\S+)}
33
+ fields = [:name, :ensure]
34
+ hash = {}
35
+
36
+ process.each_line { |line|
37
+ if match = regex.match(line)
38
+ fields.zip(match.captures) { |field,value|
39
+ hash[field] = value
40
+ }
41
+
42
+ name = hash[:name]
43
+ hash[:provider] = self.name
44
+
45
+ packages << new(hash)
46
+ hash = {}
47
+ else
48
+ warning("Failed to match line %s" % line)
49
+ end
50
+ }
51
+ end
52
+ rescue Puppet::ExecutionFailure
53
+ return nil
54
+ end
55
+ packages
56
+ end
57
+
58
+ # Because Archlinux is a rolling release based distro, installing a package
59
+ # should always result in the newest release.
60
+ def update
61
+ # Install in pacman can be used for update, too
62
+ self.install
63
+ end
64
+
65
+ def latest
66
+ pacman "-Sy"
67
+ output = pacman "-Sp", "--print-format", "%v", @resource[:name]
68
+ output.chomp
69
+ end
70
+
71
+ # Querys the pacman master list for information about the package.
72
+ def query
73
+ begin
74
+ output = pacman("-Qi", @resource[:name])
75
+
76
+ if output =~ /Version.*:\s(.+)/
77
+ return { :ensure => $1 }
78
+ end
79
+ rescue Puppet::ExecutionFailure
80
+ return {
81
+ :ensure => :purged,
82
+ :status => 'missing',
83
+ :name => @resource[:name],
84
+ :error => 'ok',
85
+ }
86
+ end
87
+ nil
88
+ end
89
+
90
+ # Removes a package from the system.
91
+ def uninstall
92
+ pacman "--noconfirm", "--noprogressbar", "-R", @resource[:name]
93
+ end
94
+ end
@@ -42,12 +42,6 @@ require 'puppet/provider/parsedfile'
42
42
  0600
43
43
  end
44
44
 
45
- def target
46
- @resource.should(:target) || File.expand_path("~#{@resource.should(:user)}/.ssh/authorized_keys")
47
- rescue
48
- raise Puppet::Error, "Target not defined and/or specified user does not exist yet"
49
- end
50
-
51
45
  def user
52
46
  uid = File.stat(target).uid
53
47
  Etc.getpwuid(uid).name
@@ -1,3 +1,4 @@
1
+ require 'puppet/node/environment'
1
2
  require 'puppet/rails'
2
3
  require 'puppet/rails/resource'
3
4
  require 'puppet/rails/fact_name'
@@ -28,6 +29,12 @@ class Puppet::Rails::Host < ActiveRecord::Base
28
29
  host
29
30
  end
30
31
 
32
+ # Override the setter for environment to force it to be a string, lest it
33
+ # be YAML encoded. See #4487.
34
+ def environment=(value)
35
+ super value.to_s
36
+ end
37
+
31
38
  # returns a hash of fact_names.name => [ fact_values ] for this host.
32
39
  # Note that 'fact_values' is actually a list of the value instances, not
33
40
  # just actual values.
@@ -41,5 +41,20 @@ Puppet::Reports.register_report(:store) do
41
41
  # Only testing cares about the return value
42
42
  file
43
43
  end
44
+
45
+ # removes all reports for a given host
46
+ def self.destroy(host)
47
+ client = host.gsub("..",".")
48
+ dir = File.join(Puppet[:reportdir], client)
49
+
50
+ if File.exists?(dir)
51
+ Dir.entries(dir).each do |file|
52
+ next if ['.','..'].include?(file)
53
+ file = File.join(dir, file)
54
+ File.unlink(file) if File.file?(file)
55
+ end
56
+ Dir.rmdir(dir)
57
+ end
58
+ end
44
59
  end
45
60
 
@@ -94,7 +94,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
94
94
  resource.ref =~ /^(.+)\[/
95
95
  class_name = $1 || resource.class.name
96
96
 
97
- newref = [class_name, key]
97
+ newref = [class_name, key].flatten
98
98
 
99
99
  if key.is_a? String
100
100
  ref_string = "#{class_name}[#{key}]"
@@ -107,7 +107,10 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
107
107
  # isn't sufficient.
108
108
  if existing = @resource_table[newref]
109
109
  return if existing == resource
110
- raise(ArgumentError, "Cannot alias #{resource.ref} to #{key.inspect}; resource #{newref.inspect} already exists")
110
+ resource_definition = " at #{resource.file}:#{resource.line}" if resource.file and resource.line
111
+ existing_definition = " at #{existing.file}:#{existing.line}" if existing.file and existing.line
112
+ msg = "Cannot alias #{resource.ref} to #{key.inspect}#{resource_definition}; resource #{newref.inspect} already defined#{existing_definition}"
113
+ raise ArgumentError, msg
111
114
  end
112
115
  @resource_table[newref] = resource
113
116
  @aliases[resource.ref] ||= []
@@ -128,9 +131,10 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
128
131
  expire
129
132
 
130
133
  Puppet::Util::Storage.load if host_config?
131
- transaction = Puppet::Transaction.new(self)
132
134
 
133
- transaction.report = options[:report] if options[:report]
135
+ transaction = Puppet::Transaction.new(self, options[:report])
136
+ register_report = options[:report].nil?
137
+
134
138
  transaction.tags = options[:tags] if options[:tags]
135
139
  transaction.ignoreschedules = true if options[:ignoreschedules]
136
140
  transaction.for_network_device = options[:network_device]
@@ -138,7 +142,12 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
138
142
  transaction.add_times :config_retrieval => self.retrieval_duration || 0
139
143
 
140
144
  begin
141
- transaction.evaluate
145
+ Puppet::Util::Log.newdestination(transaction.report) if register_report
146
+ begin
147
+ transaction.evaluate
148
+ ensure
149
+ Puppet::Util::Log.close(transaction.report) if register_report
150
+ end
142
151
  rescue Puppet::Error => detail
143
152
  puts detail.backtrace if Puppet[:trace]
144
153
  Puppet.err "Could not apply complete catalog: #{detail}"
@@ -430,7 +439,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
430
439
  res = Puppet::Resource.new(nil, type)
431
440
  end
432
441
  title_key = [res.type, res.title.to_s]
433
- uniqueness_key = [res.type, res.uniqueness_key]
442
+ uniqueness_key = [res.type, res.uniqueness_key].flatten
434
443
  @resource_table[title_key] || @resource_table[uniqueness_key]
435
444
  end
436
445