puppet 3.0.2 → 3.1.0.rc1

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 (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -1,7 +1,12 @@
1
1
  require 'puppet/property'
2
2
 
3
- # This property will get automatically added to any type that responds
3
+ # This property is automatically added to any {Puppet::Type} that responds
4
4
  # to the methods 'exists?', 'create', and 'destroy'.
5
+ #
6
+ # Ensure defaults to having the wanted _(should)_ value `:present`.
7
+ #
8
+ # @api public
9
+ #
5
10
  class Puppet::Property::Ensure < Puppet::Property
6
11
  @name = :ensure
7
12
 
@@ -58,6 +63,14 @@ class Puppet::Property::Ensure < Puppet::Property
58
63
  end
59
64
  end
60
65
 
66
+ # Retrieves the _is_ value for the ensure property.
67
+ # The existence of the resource is checked by first consulting the provider (if it responds to
68
+ # `:exists`), and secondly the resource. A a value of `:present` or `:absent` is returned
69
+ # depending on if the managed entity exists or not.
70
+ #
71
+ # @return [Symbol] a value of `:present` or `:absent` depending on if it exists or not
72
+ # @raise [Puppet::DevError] if neither the provider nor the resource responds to `:exists`
73
+ #
61
74
  def retrieve
62
75
  # XXX This is a problem -- whether the object exists or not often
63
76
  # depends on the results of other properties, yet we're the first property
@@ -1,15 +1,16 @@
1
- #This subclass of property manages string key value pairs.
2
-
3
- #In order to use this property:
4
- # - the @should value must be an array of keyvalue pairs separated by the 'separator'
5
- # - the retrieve method should return a hash with the keys as symbols
6
- # IMPORTANT NOTE: In order for this property to work there must also be a 'membership' parameter
7
- # The class that inherits from property should override that method with the symbol for the membership
8
-
9
1
  require 'puppet/property'
10
2
 
11
3
  module Puppet
12
4
  class Property
5
+ # This subclass of {Puppet::Property} manages string key value pairs.
6
+ # In order to use this property:
7
+ #
8
+ # * the _should_ value must be an array of key-value pairs separated by the 'separator'
9
+ # * the retrieve method should return a hash with the keys as symbols
10
+ # @note **IMPORTANT**: In order for this property to work there must also be a 'membership' parameter
11
+ # The class that inherits from property should override that method with the symbol for the membership
12
+ # @todo The node with an important message is not very clear.
13
+ #
13
14
  class KeyValue < Property
14
15
 
15
16
  def hash_to_key_value_s(hash)
@@ -59,14 +60,19 @@ module Puppet
59
60
  current.merge(members)
60
61
  end
61
62
 
63
+ # @return [String] Returns a default separator of "="
62
64
  def separator
63
65
  "="
64
66
  end
65
67
 
68
+ # @return [String] Returns a default delimiter of ";"
66
69
  def delimiter
67
70
  ";"
68
71
  end
69
72
 
73
+ # Retrieves the key-hash from the provider by invoking it's method named the same as this property.
74
+ # @return [Hash] the hash from the provider, or `:absent`
75
+ #
70
76
  def retrieve
71
77
  #ok, some 'convention' if the keyvalue property is named properties, provider should implement a properties method
72
78
  if key_hash = provider.send(name) and key_hash != :absent
@@ -76,6 +82,9 @@ module Puppet
76
82
  end
77
83
  end
78
84
 
85
+ # Returns true if there is no _is_ value, else returns if _is_ is equal to _should_ using == as comparison.
86
+ # @return [Boolean] whether the property is in sync or not.
87
+ #
79
88
  def insync?(is)
80
89
  return true unless is
81
90
 
@@ -2,6 +2,9 @@ require 'puppet/property'
2
2
 
3
3
  module Puppet
4
4
  class Property
5
+ # This subclass of {Puppet::Property} manages an unordered list of values.
6
+ # For an ordered list see {Puppet::Property::OrderedList}.
7
+ #
5
8
  class List < Property
6
9
 
7
10
  def should_to_s(should_value)
@@ -2,6 +2,13 @@ require 'puppet/property/list'
2
2
 
3
3
  module Puppet
4
4
  class Property
5
+ # This subclass of {Puppet::Property} manages an ordered list of values.
6
+ # The maintained order is the order defined by the 'current' set of values (i.e. the
7
+ # original order is not disrupted). Any additions are added after the current values
8
+ # in their given order).
9
+ #
10
+ # For an unordered list see {Puppet::Property::List}.
11
+ #
5
12
  class OrderedList < List
6
13
 
7
14
  def add_should_with_current(should, current)
@@ -1,4 +1,40 @@
1
- # The container class for implementations.
1
+ # A Provider is an implementation of the actions that manage resources (of some type) on a system.
2
+ # This class is the base class for all implementation of a Puppet Provider.
3
+ #
4
+ # Concepts:
5
+ #--
6
+ # * **Confinement** - confinement restricts providers to only be applicable under certain conditions.
7
+ # It is possible to confine a provider several different ways:
8
+ # * the included {#confine} method which provides filtering on fact, feature, existence of files, or a free form
9
+ # predicate.
10
+ # * the {commands} method that filters on the availability of given system commands.
11
+ # * **Property hash** - the important instance variable `@property_hash` contains all current state values
12
+ # for properties (it is lazily built). It is important that these values are managed appropriately in the
13
+ # methods {instances}, {prefetch}, and in methods that alters the current state (those that change the
14
+ # lifecycle (creates, destroys), or alters some value reflected backed by a property).
15
+ # * **Flush** - is a hook that is called once per resource when everything has been applied. The intent is
16
+ # that an implementation may defer modification of the current state typically done in property setters
17
+ # and instead record information that allows flush to perform the changes more efficiently.
18
+ # * **Execution Methods** - The execution methods provides access to execution of arbitrary commands.
19
+ # As a convenience execution methods are available on both the instance and the class of a provider since a
20
+ # lot of provider logic switch between these contexts fairly freely.
21
+ # * **System Entity/Resource** - this documentation uses the term "system entity" for system resources to make
22
+ # it clear if talking about a resource on the system being managed (e.g. a file in the file system)
23
+ # or about a description of such a resource (e.g. a Puppet Resource).
24
+ # * **Resource Type** - this is an instance of Type that describes a classification of instances of Resource (e.g.
25
+ # the `File` resource type describes all instances of `file` resources).
26
+ # (The term is used to contrast with "type" in general, and specifically to contrast with the implementation
27
+ # class of Resource or a specific Type).
28
+ #
29
+ # @note An instance of a Provider is associated with one resource.
30
+ #
31
+ # @note Class level methods are only called once to configure the provider (when the type is created), and not
32
+ # for each resource the provider is operating on.
33
+ # The instance methods are however called for each resource.
34
+ #
35
+ #
36
+ # @api public
37
+ #
2
38
  class Puppet::Provider
3
39
  include Puppet::Util
4
40
  include Puppet::Util::Errors
@@ -16,53 +52,105 @@ class Puppet::Provider
16
52
  # Include the util module so we have access to things like 'which'
17
53
  include Puppet::Util, Puppet::Util::Docs
18
54
  include Puppet::Util::Logging
55
+
56
+ # @return [String] The name of the provider
19
57
  attr_accessor :name
20
58
 
21
- # The source parameter exists so that providers using the same
22
- # source can specify this, so reading doesn't attempt to read the
23
- # same package multiple times.
59
+ #
60
+ # @todo Original = _"The source parameter exists so that providers using the same
61
+ # source can specify this, so reading doesn't attempt to read the
62
+ # same package multiple times."_ This seems to be a package type specific attribute. Is this really
63
+ # used?
64
+ #
65
+ # @return [???] The source is WHAT?
24
66
  attr_writer :source
25
67
 
26
- # LAK 2007-05-09: Keep the model stuff around for backward compatibility
68
+ # @todo Original = _"LAK 2007-05-09: Keep the model stuff around for backward compatibility"_
69
+ # Is this really needed? The comment about backwards compatibility was made in 2007.
70
+ #
71
+ # @return [???] A model kept for backwards compatibility.
72
+ # @api private
73
+ # @deprecated This attribute is available for backwards compatibility reasons.
27
74
  attr_reader :model
75
+
76
+ # @todo What is this type? A reference to a Puppet::Type ?
77
+ # @return [Puppet::Type] the resource type (that this provider is ... WHAT?)
78
+ #
28
79
  attr_accessor :resource_type
80
+
81
+ # @!attribute [r] doc
82
+ # The (full) documentation for this provider class. The documentation for the provider class itself
83
+ # should be set with the DSL method {desc=}. Setting the documentation with with {doc=} has the same effect
84
+ # as setting it with {desc=} (only the class documentation part is set). In essence this means that
85
+ # there is no getter for the class documentation part (since the getter returns the full
86
+ # documentation when there are additional contributors).
87
+ #
88
+ # @return [String] Returns the full documentation for the provider.
89
+ # @see Puppet::Utils::Docs
90
+ # @comment This is puzzling ... a write only doc attribute??? The generated setter never seems to be
91
+ # used, instead the instance variable @doc is set in the `desc` method. This seems wrong. It is instead
92
+ # documented as a read only attribute (to get the full documentation). Also see doc below for
93
+ # desc.
94
+ # @!attribute [w] desc
95
+ # Sets the documentation of this provider class. (The full documentation is read via the
96
+ # {doc} attribute).
97
+ #
98
+ # @dsl type
99
+ #
100
+ #
29
101
  attr_writer :doc
102
+
30
103
  end
31
104
 
32
- # LAK 2007-05-09: Keep the model stuff around for backward compatibility
105
+ # @todo original = _"LAK 2007-05-09: Keep the model stuff around for backward compatibility"_, why is it
106
+ # both here (instance) and at class level? Is this a different model?
107
+ # @return [???] model is WHAT?
33
108
  attr_reader :model
109
+
110
+ # @return [???] This resource is what? Is an instance of a provider attached to one particular Puppet::Resource?
111
+ #
34
112
  attr_accessor :resource
35
113
 
36
- # Provide access to execution of arbitrary commands in providers. Execution methods are
37
- # available on both the instance and the class of a provider because it seems that a lot of
38
- # providers switch between these contexts fairly freely.
39
- #
40
- # @see Puppet::Util::Execution for how to use these methods
114
+ # Convenience methods - see class method with the same name.
115
+ # @see execute
116
+ # @return (see execute)
41
117
  def execute(*args)
42
118
  Puppet::Util::Execution.execute(*args)
43
119
  end
44
120
 
121
+ # (see Puppet::Util::Execution.execute)
45
122
  def self.execute(*args)
46
123
  Puppet::Util::Execution.execute(*args)
47
124
  end
48
125
 
126
+ # Convenience methods - see class method with the same name.
127
+ # @see execpipe
128
+ # @return (see execpipe)
49
129
  def execpipe(*args, &block)
50
130
  Puppet::Util::Execution.execpipe(*args, &block)
51
131
  end
52
132
 
133
+ # (see Puppet::Util::Execution.execpipe)
53
134
  def self.execpipe(*args, &block)
54
135
  Puppet::Util::Execution.execpipe(*args, &block)
55
136
  end
56
137
 
138
+ # Convenience methods - see class method with the same name.
139
+ # @see execfail
140
+ # @return (see execfail)
57
141
  def execfail(*args)
58
142
  Puppet::Util::Execution.execfail(*args)
59
143
  end
60
144
 
145
+ # (see Puppet::Util::Execution.execfail)
61
146
  def self.execfail(*args)
62
147
  Puppet::Util::Execution.execfail(*args)
63
148
  end
64
- #########
65
149
 
150
+ # Returns the absolute path to the executable for the command referenced by the given name.
151
+ # @raise [Puppet::DevError] if the name does not reference an existing command.
152
+ # @return [String] the absolute path to the found executable for the command
153
+ # @see which
66
154
  def self.command(name)
67
155
  name = name.intern
68
156
 
@@ -77,22 +165,33 @@ class Puppet::Provider
77
165
  which(command)
78
166
  end
79
167
 
80
- # Define commands that are not optional.
168
+ # Confines this provider to be suitable only on hosts where the given commands are present.
169
+ # Also see {Puppet::Provider::Confiner#confine} for other types of confinement of a provider by use of other types of
170
+ # predicates.
171
+ #
172
+ # @note It is preferred if the commands are not entered with absolute paths as this allows puppet
173
+ # to search for them using the PATH variable.
81
174
  #
82
- # @param [Hash{String => String}] command_specs Named commands that the provider will
175
+ # @param command_specs [Hash{String => String}] Map of name to command that the provider will
83
176
  # be executing on the system. Each command is specified with a name and the path of the executable.
84
- # (@see #has_command)
177
+ # @return [void]
178
+ # @see optional_commands
179
+ #
85
180
  def self.commands(command_specs)
86
181
  command_specs.each do |name, path|
87
182
  has_command(name, path)
88
183
  end
89
184
  end
90
185
 
91
- # Define commands that are optional.
92
- #
186
+ # Defines optional commands.
187
+ # Since Puppet 2.7.8 this is typically not needed as evaluation of provider suitability
188
+ # is lazy (when a resource is evaluated) and the absence of commands
189
+ # that will be present after other resources have been applied no longer needs to be specified as
190
+ # optional.
93
191
  # @param [Hash{String => String}] command_specs Named commands that the provider will
94
192
  # be executing on the system. Each command is specified with a name and the path of the executable.
95
193
  # (@see #has_command)
194
+ # @see commands
96
195
  def self.optional_commands(hash)
97
196
  hash.each do |name, target|
98
197
  has_command(name, target) do
@@ -101,27 +200,31 @@ class Puppet::Provider
101
200
  end
102
201
  end
103
202
 
104
- # Define a single command
105
- #
106
- # A method will be generated on the provider that allows easy execution of the command. The generated
107
- # method can take arguments that will be passed through to the executable as the command line arguments
108
- # when it is run.
203
+ # Creates a convenience method for invocation of a command.
109
204
  #
110
- # has_command(:echo, "/bin/echo")
111
- # def some_method
112
- # echo("arg 1", "arg 2")
113
- # end
205
+ # This generates a Provider method that allows easy execution of the command. The generated
206
+ # method may take arguments that will be passed through to the executable as the command line arguments
207
+ # when it is invoked.
114
208
  #
115
- # # or
209
+ # @example Use it like this:
210
+ # has_command(:echo, "/bin/echo")
211
+ # def some_method
212
+ # echo("arg 1", "arg 2")
213
+ # end
214
+ # @comment the . . . below is intentional to avoid the three dots to become an illegible ellipsis char.
215
+ # @example . . . or like this
216
+ # has_command(:echo, "/bin/echo") do
217
+ # is_optional
218
+ # environment :HOME => "/var/tmp", :PWD => "/tmp"
219
+ # end
116
220
  #
117
- # has_command(:echo, "/bin/echo") do
118
- # is_optional
119
- # environment :HOME => "/var/tmp", :PWD => "/tmp"
120
- # end
221
+ # @param name [Symbol] The name of the command (will become the name of the generated method that executes the command)
222
+ # @param path [String] The path to the executable for the command
223
+ # @yield [ ] A block that configures the command (see {Puppet::Provider::Command})
224
+ # @comment a yield [ ] produces {|| ...} in the signature, do not remove the space.
225
+ # @note the name ´has_command´ looks odd in an API context, but makes more sense when seen in the internal
226
+ # DSL context where a Provider is declaratively defined.
121
227
  #
122
- # @param [Symbol] name Name of the command (will be the name of the generated method to call the command)
123
- # @param [String] path The path to the executable for the command
124
- # @yield A block that configures the command (@see Puppet::Provider::Command)
125
228
  def self.has_command(name, path, &block)
126
229
  name = name.intern
127
230
  command = CommandDefiner.define(name, path, self, &block)
@@ -134,6 +237,8 @@ class Puppet::Provider
134
237
  end
135
238
  end
136
239
 
240
+ # Internal helper class when creating commands - undocumented.
241
+ # @api private
137
242
  class CommandDefiner
138
243
  private_class_method :new
139
244
 
@@ -168,13 +273,15 @@ class Puppet::Provider
168
273
  end
169
274
  end
170
275
 
171
- # Is the provided feature a declared feature?
276
+ # @return [Boolean] Return whether the given feature has been declared or not.
172
277
  def self.declared_feature?(name)
173
278
  defined?(@declared_features) and @declared_features.include?(name)
174
279
  end
175
280
 
176
- # Does this implementation match all of the default requirements? If
177
- # defaults are empty, we return false.
281
+ # @return [Boolean] Returns whether this implementation satisfies all of the default requirements or not.
282
+ # Returns false If defaults are empty.
283
+ # @see Provider.defaultfor
284
+ #
178
285
  def self.default?
179
286
  return false if @defaults.empty?
180
287
  if @defaults.find do |fact, values|
@@ -198,31 +305,79 @@ class Puppet::Provider
198
305
  end
199
306
  end
200
307
 
201
- # Store how to determine defaults.
308
+ # Sets a facts filter that determine which of several suitable providers should be picked by default.
309
+ # This selection only kicks in if there is more than one suitable provider.
310
+ # To filter on multiple facts the given hash may contain more than one fact name/value entry.
311
+ # The filter picks the provider if all the fact/value entries match the current set of facts. (In case
312
+ # there are still more than one provider after this filtering, the first found is picked).
313
+ # @param hash [Hash<{String => Object}>] hash of fact name to fact value.
314
+ # @return [void]
315
+ #
202
316
  def self.defaultfor(hash)
203
317
  hash.each do |d,v|
204
318
  @defaults[d] = v
205
319
  end
206
320
  end
207
321
 
322
+ # @return [Integer] Returns a numeric specificity for this provider based on how many requirements it has
323
+ # and number of _ancestors_. The higher the number the more specific the provider.
324
+ # The number of requirements is based on the number of defaults set up with {Provider.defaultfor}.
325
+ #
326
+ # The _ancestors_ is the Ruby Module::ancestors method and the number of classes returned is used
327
+ # to boost the score. The intent is that if two providers are equal, but one is more "derived" than the other
328
+ # (i.e. includes more classes), it should win because it is more specific).
329
+ # @note Because of how this value is
330
+ # calculated there could be surprising side effects if a provider included an excessive amount of classes.
331
+ #
208
332
  def self.specificity
333
+ # This strange piece of logic attempts to figure out how many parent providers there
334
+ # are to increase the score. What is will actually do is count all classes that Ruby Module::ancestors
335
+ # returns (which can be other classes than those the parent chain) - in a way, an odd measure of the
336
+ # complexity of a provider).
209
337
  (@defaults.length * 100) + ancestors.select { |a| a.is_a? Class }.length
210
338
  end
211
339
 
340
+ # Initializes defaults and commands (i.e. clears them).
341
+ # @return [void]
212
342
  def self.initvars
213
343
  @defaults = {}
214
344
  @commands = {}
215
345
  end
216
346
 
217
- # The method for returning a list of provider instances. Note that it returns providers, preferably with values already
218
- # filled in, not resources.
347
+ # Returns a list of system resources (entities) this provider may/can manage.
348
+ # This is a query mechanism that lists entities that the provider may manage on a given system. It is
349
+ # is directly used in query services, but is also the foundation for other services; prefetching, and
350
+ # purging.
351
+ #
352
+ # As an example, a package provider lists all installed packages. (In contrast, the File provider does
353
+ # not list all files on the file-system as that would make execution incredibly slow). An implementation
354
+ # of this method should be made if it is possible to quickly (with a single system call) provide all
355
+ # instances.
356
+ #
357
+ # An implementation of this method should only cache the values of properties
358
+ # if they are discovered as part of the process for finding existing resources.
359
+ # Resource properties that require additional commands (than those used to determine existence/identity)
360
+ # should be implemented in their respective getter method. (This is important from a performance perspective;
361
+ # it may be expensive to compute, as well as wasteful as all discovered resources may perhaps not be managed).
362
+ #
363
+ # An implementation may return an empty list (naturally with the effect that it is not possible to query
364
+ # for manageable entities).
365
+ #
366
+ # By implementing this method, it is possible to use the `resources´ resource type to specify purging
367
+ # of all non managed entities.
368
+ #
369
+ # @note The returned instances are instance of some subclass of Provider, not resources.
370
+ # @return [Array<Puppet::Provider>] a list of providers referencing the system entities
371
+ # @abstract this method must be implemented by a subclass and this super method should never be called as it raises an exception.
372
+ # @raise [Puppet::DevError] Error indicating that the method should have been implemented by subclass.
373
+ # @see prefetch
219
374
  def self.instances
220
375
  raise Puppet::DevError, "Provider #{self.name} has not defined the 'instances' class method"
221
376
  end
222
377
 
223
- # Create the methods for a given command.
224
- #
225
- # @deprecated Use {#commands}, {#optional_commands}, or {#has_command} instead. This was not meant to be part of a public API
378
+ # Creates the methods for a given command.
379
+ # @api private
380
+ # @deprecated Use {commands}, {optional_commands}, or {has_command} instead. This was not meant to be part of a public API
226
381
  def self.make_command_methods(name)
227
382
  Puppet.deprecation_warning "Provider.make_command_methods is deprecated; use Provider.commands or Provider.optional_commands instead for creating command methods"
228
383
 
@@ -245,9 +400,19 @@ class Puppet::Provider
245
400
  end
246
401
  end
247
402
 
248
- # Create getter/setter methods for each property our resource type supports.
249
- # They all get stored in @property_hash. This method is useful
250
- # for those providers that use prefetch and flush.
403
+ # Creates getter- and setter- methods for each property supported by the resource type.
404
+ # Call this method to generate simple accessors for all properties supported by the
405
+ # resource type. These simple accessors lookup and sets values in the property hash.
406
+ # The generated methods may be overridden by more advanced implementations if something
407
+ # else than a straight forward getter/setter pair of methods is required.
408
+ # (i.e. define such overriding methods after this method has been called)
409
+ #
410
+ # An implementor of a provider that makes use of `prefetch` and `flush` can use this method since it uses
411
+ # the internal `@property_hash` variable to store values. An implementation would then update the system
412
+ # state on a call to `flush` based on the current values in the `@property_hash`.
413
+ #
414
+ # @return [void]
415
+ #
251
416
  def self.mk_resource_methods
252
417
  [resource_type.validproperties, resource_type.parameters].flatten.each do |attr|
253
418
  attr = attr.intern
@@ -264,6 +429,10 @@ class Puppet::Provider
264
429
 
265
430
  self.initvars
266
431
 
432
+ # This method is used to generate a method for a command.
433
+ # @return [void]
434
+ # @api private
435
+ #
267
436
  def self.create_class_and_instance_method(name, &block)
268
437
  unless singleton_class.method_defined?(name)
269
438
  meta_def(name, &block)
@@ -277,12 +446,20 @@ class Puppet::Provider
277
446
  end
278
447
  private_class_method :create_class_and_instance_method
279
448
 
280
- # Retrieve the data source. Defaults to the provider name.
449
+ # @return [String] Returns the data source, which is the provider name if no other source has been set.
450
+ # @todo Unclear what "the source" is used for?
281
451
  def self.source
282
452
  @source ||= self.name
283
453
  end
284
454
 
285
- # Does this provider support the specified parameter?
455
+ # Returns true if the given attribute/parameter is supported by the provider.
456
+ # The check is made that the parameter is a valid parameter for the resource type, and then
457
+ # if all its required features (if any) are supported by the provider.
458
+ #
459
+ # @param param [Class, Puppet::Parameter] the parameter class, or a parameter instance
460
+ # @return [Boolean] Returns whether this provider supports the given parameter or not.
461
+ # @raise [Puppet::DevError] if the given parameter is not valid for the resource type
462
+ #
286
463
  def self.supports_parameter?(param)
287
464
  if param.is_a?(Class)
288
465
  klass = param
@@ -331,22 +508,34 @@ class Puppet::Provider
331
508
  end
332
509
  end
333
510
 
334
- # Remove the reference to the resource, so GC can clean up.
511
+ # Clears this provider instance to allow GC to clean up.
335
512
  def clear
336
513
  @resource = nil
337
514
  @model = nil
338
515
  end
339
516
 
340
- # Retrieve a named command.
517
+ # (see command)
341
518
  def command(name)
342
519
  self.class.command(name)
343
520
  end
344
521
 
345
- # Get a parameter value.
522
+ # Returns the value of a parameter value, or `:absent` if it is not defined.
523
+ # @param param [Puppet::Parameter] the parameter to obtain the value of
524
+ # @return [Object] the value of the parameter or `:absent` if not defined.
525
+ #
346
526
  def get(param)
347
527
  @property_hash[param.intern] || :absent
348
528
  end
349
529
 
530
+ # Creates a new provider that is optionally initialized from a resource or a hash of properties.
531
+ # If no argument is specified, a new non specific provider is initialized. If a resource is given
532
+ # it is remembered for further operations. If a hash is used it becomes the internal `@property_hash`
533
+ # structure of the provider - this hash holds the current state property values of system entities
534
+ # as they are being discovered by querying or other operations (typically getters).
535
+ #
536
+ # @todo The use of a hash as a parameter needs a better exaplanation; why is this done? What is the intent?
537
+ # @param resource [Puppet::Resource, Hash] optional resource or hash
538
+ #
350
539
  def initialize(resource = nil)
351
540
  if resource.is_a?(Hash)
352
541
  # We don't use a duplicate here, because some providers (ParsedFile, at least)
@@ -362,6 +551,10 @@ class Puppet::Provider
362
551
  end
363
552
  end
364
553
 
554
+ # Returns the name of the resource this provider is operating on.
555
+ # @return [String] the name of the resource instance (e.g. the file path of a File).
556
+ # @raise [Puppet::DevError] if no resource is set, or no name defined.
557
+ #
365
558
  def name
366
559
  if n = @property_hash[:name]
367
560
  return n
@@ -372,24 +565,53 @@ class Puppet::Provider
372
565
  end
373
566
  end
374
567
 
375
- # Set passed params as the current values.
568
+ # Sets the given parameters values as the current values for those parameters.
569
+ # Other parameters are unchanged.
570
+ # @param [Array<Puppet::Parameter] the parameters with values that should be set
571
+ # @return [void]
572
+ #
376
573
  def set(params)
377
574
  params.each do |param, value|
378
575
  @property_hash[param.intern] = value
379
576
  end
380
577
  end
381
578
 
579
+ # @return [String] Returns a human readable string with information about the resource and the provider.
382
580
  def to_s
383
581
  "#{@resource}(provider=#{self.class.name})"
384
582
  end
385
583
 
386
- # Make providers comparable.
584
+ # Makes providers comparable.
387
585
  include Comparable
586
+ # Compares this provider against another provider.
587
+ # Comparison is only possible with another provider (no other class).
588
+ # The ordering is based on the class name of the two providers.
589
+ #
590
+ # @return [-1,0,+1, nil] A comparison result -1, 0, +1 if this is before other, equal or after other. Returns
591
+ # nil oif not comparable to other.
592
+ # @see Comparable
388
593
  def <=>(other)
389
594
  # We can only have ordering against other providers.
390
595
  return nil unless other.is_a? Puppet::Provider
391
596
  # Otherwise, order by the providers class name.
392
597
  return self.class.name <=> other.class.name
393
598
  end
599
+
600
+ # @comment Document prefetch here as it does not exist anywhere else (called from transaction if implemented)
601
+ # @!method self.prefetch(resource_hash)
602
+ # @abstract A subclass may implement this - it is not implemented in the Provider class
603
+ # This method may be implemented by a provider in order to pre-fetch resource properties.
604
+ # If implemented it should set the provider instance of the managed resources to a provider with the
605
+ # fetched state (i.e. what is returned from the {instances} method).
606
+ # @param resources_hash [Hash<{String => Puppet::Resource}>] map from name to resource of resources to prefetch
607
+ # @return [void]
608
+
609
+ # @comment Document flush here as it does not exist anywhere (called from transaction if implemented)
610
+ # @!method flush()
611
+ # @abstract A subclass may implement this - it is not implemented in the Provider class
612
+ # This method may be implemented by a provider in order to flush properties that has not been individually
613
+ # applied to the managed entity's current state.
614
+ # @return [void]
615
+
394
616
  end
395
617