puppet 4.4.2-x86-mingw32 → 4.5.0-x86-mingw32

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 (218) hide show
  1. data/CONTRIBUTING.md +5 -5
  2. data/Gemfile +2 -2
  3. data/LICENSE +2 -2
  4. data/README.md +5 -0
  5. data/ext/project_data.yaml +2 -0
  6. data/lib/hiera_puppet.rb +6 -14
  7. data/lib/puppet/application/agent.rb +2 -3
  8. data/lib/puppet/data_providers/hiera_config.rb +2 -4
  9. data/lib/puppet/data_providers/hiera_interpolate.rb +12 -154
  10. data/lib/puppet/data_providers/json_data_provider_factory.rb +0 -7
  11. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -8
  12. data/lib/puppet/defaults.rb +70 -7
  13. data/lib/puppet/functions.rb +69 -0
  14. data/lib/puppet/functions/dig.rb +39 -0
  15. data/lib/puppet/functions/lest.rb +53 -0
  16. data/lib/puppet/functions/lookup.rb +40 -27
  17. data/lib/puppet/functions/new.rb +502 -0
  18. data/lib/puppet/functions/regsubst.rb +11 -10
  19. data/lib/puppet/functions/then.rb +74 -0
  20. data/lib/puppet/functions/type.rb +4 -4
  21. data/lib/puppet/functions/with.rb +1 -1
  22. data/lib/puppet/indirector/catalog/compiler.rb +2 -0
  23. data/lib/puppet/indirector/resource_type/parser.rb +5 -0
  24. data/lib/puppet/indirector/rest.rb +5 -1
  25. data/lib/puppet/loaders.rb +2 -0
  26. data/lib/puppet/metatype/manager.rb +19 -2
  27. data/lib/puppet/module_tool/applications/application.rb +1 -1
  28. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +6 -2
  29. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +19 -4
  30. data/lib/puppet/module_tool/skeleton/templates/generator/{tests → examples}/init.pp.erb +1 -1
  31. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -1
  32. data/lib/puppet/network/http/api/master/v3/environment.rb +6 -2
  33. data/lib/puppet/parser/ast/pops_bridge.rb +20 -3
  34. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +24 -2
  35. data/lib/puppet/parser/e4_parser_adapter.rb +13 -12
  36. data/lib/puppet/parser/environment_compiler.rb +2 -2
  37. data/lib/puppet/parser/resource.rb +14 -5
  38. data/lib/puppet/parser/scope.rb +18 -15
  39. data/lib/puppet/plugins/data_providers/data_provider.rb +19 -8
  40. data/lib/puppet/pops.rb +6 -0
  41. data/lib/puppet/pops/adapters.rb +5 -1
  42. data/lib/puppet/pops/evaluator/access_operator.rb +52 -14
  43. data/lib/puppet/pops/evaluator/compare_operator.rb +34 -4
  44. data/lib/puppet/pops/evaluator/evaluator_impl.rb +75 -22
  45. data/lib/puppet/pops/evaluator/literal_evaluator.rb +7 -6
  46. data/lib/puppet/pops/evaluator/runtime3_converter.rb +13 -1
  47. data/lib/puppet/pops/evaluator/runtime3_support.rb +14 -4
  48. data/lib/puppet/pops/functions/dispatcher.rb +1 -1
  49. data/lib/puppet/pops/issues.rb +18 -2
  50. data/lib/puppet/pops/loader/base_loader.rb +48 -7
  51. data/lib/puppet/pops/loader/dependency_loader.rb +27 -2
  52. data/lib/puppet/pops/loader/loader.rb +12 -0
  53. data/lib/puppet/pops/loader/predefined_loader.rb +29 -0
  54. data/lib/puppet/pops/loader/runtime3_type_loader.rb +57 -0
  55. data/lib/puppet/pops/loader/static_loader.rb +92 -5
  56. data/lib/puppet/pops/loader/type_definition_instantiator.rb +25 -3
  57. data/lib/puppet/pops/loaders.rb +84 -14
  58. data/lib/puppet/pops/lookup/explainer.rb +38 -1
  59. data/lib/puppet/pops/lookup/interpolation.rb +115 -0
  60. data/lib/puppet/pops/lookup/sub_lookup.rb +86 -0
  61. data/lib/puppet/pops/model/ast_transformer.rb +8 -1
  62. data/lib/puppet/pops/model/factory.rb +31 -8
  63. data/lib/puppet/pops/model/model.rb +8 -0
  64. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  65. data/lib/puppet/pops/model/model_meta.rb +7 -1
  66. data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  67. data/lib/puppet/pops/parser/egrammar.ra +24 -7
  68. data/lib/puppet/pops/parser/eparser.rb +863 -798
  69. data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
  70. data/lib/puppet/pops/parser/locator.rb +8 -4
  71. data/lib/puppet/pops/pcore.rb +30 -0
  72. data/lib/puppet/pops/types/class_loader.rb +2 -4
  73. data/lib/puppet/pops/types/implementation_registry.rb +146 -0
  74. data/lib/puppet/pops/types/iterable.rb +4 -4
  75. data/lib/puppet/pops/types/p_object_type.rb +846 -0
  76. data/lib/puppet/pops/types/p_runtime_type.rb +102 -0
  77. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +164 -0
  78. data/lib/puppet/pops/types/p_sem_ver_type.rb +113 -0
  79. data/lib/puppet/pops/types/puppet_object.rb +21 -0
  80. data/lib/puppet/pops/types/ruby_generator.rb +258 -0
  81. data/lib/puppet/pops/types/string_converter.rb +922 -0
  82. data/lib/puppet/pops/types/type_calculator.rb +29 -5
  83. data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  84. data/lib/puppet/pops/types/type_factory.rb +49 -16
  85. data/lib/puppet/pops/types/type_formatter.rb +335 -112
  86. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -29
  87. data/lib/puppet/pops/types/type_parser.rb +205 -197
  88. data/lib/puppet/pops/types/types.rb +481 -103
  89. data/lib/puppet/pops/validation.rb +1 -1
  90. data/lib/puppet/pops/validation/checker4_0.rb +66 -4
  91. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  92. data/lib/puppet/pops/visitor.rb +3 -1
  93. data/lib/puppet/property.rb +1 -1
  94. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  95. data/lib/puppet/provider/package/pip.rb +64 -20
  96. data/lib/puppet/provider/package/rpm.rb +112 -0
  97. data/lib/puppet/provider/package/yum.rb +7 -68
  98. data/lib/puppet/provider/service/daemontools.rb +3 -3
  99. data/lib/puppet/provider/service/init.rb +4 -2
  100. data/lib/puppet/provider/service/runit.rb +3 -3
  101. data/lib/puppet/provider/service/smf.rb +6 -3
  102. data/lib/puppet/provider/service/systemd.rb +59 -73
  103. data/lib/puppet/reference/providers.rb +1 -2
  104. data/lib/puppet/resource.rb +54 -37
  105. data/lib/puppet/resource/catalog.rb +31 -29
  106. data/lib/puppet/resource/type_collection.rb +23 -8
  107. data/lib/puppet/settings.rb +4 -2
  108. data/lib/puppet/settings/base_setting.rb +9 -3
  109. data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  110. data/lib/puppet/test/test_helper.rb +0 -1
  111. data/lib/puppet/type.rb +9 -3
  112. data/lib/puppet/type/exec.rb +17 -17
  113. data/lib/puppet/type/file.rb +12 -0
  114. data/lib/puppet/type/file/content.rb +6 -6
  115. data/lib/puppet/type/file/ensure.rb +4 -4
  116. data/lib/puppet/type/file/source.rb +4 -4
  117. data/lib/puppet/type/file/target.rb +2 -2
  118. data/lib/puppet/type/mount.rb +18 -1
  119. data/lib/puppet/type/package.rb +3 -3
  120. data/lib/puppet/type/schedule.rb +4 -4
  121. data/lib/puppet/type/service.rb +15 -0
  122. data/lib/puppet/type/sshkey.rb +5 -3
  123. data/lib/puppet/type/tidy.rb +3 -3
  124. data/lib/puppet/type/zone.rb +5 -5
  125. data/lib/puppet/util/feature.rb +1 -1
  126. data/lib/puppet/util/monkey_patches.rb +8 -0
  127. data/lib/puppet/util/network_device/cisco/device.rb +16 -6
  128. data/lib/puppet/util/network_device/cisco/interface.rb +5 -6
  129. data/lib/puppet/util/plist.rb +3 -3
  130. data/lib/puppet/version.rb +1 -1
  131. data/spec/fixtures/unit/application/environments/production/data/common.yaml +13 -0
  132. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +2 -1
  133. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/manifests/init.pp +2 -1
  134. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/data/empty_key.json +1 -0
  135. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/hiera.yaml +5 -0
  136. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/manifests/init.pp +2 -0
  137. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/metadata.json +9 -0
  138. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/data/empty_key.yaml +1 -0
  139. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/hiera.yaml +5 -0
  140. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/manifests/init.pp +2 -0
  141. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/metadata.json +9 -0
  142. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  143. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/type/usee_type.rb +5 -0
  144. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +6 -0
  145. data/spec/fixtures/unit/provider/service/smf/svcs.out +4 -3
  146. data/spec/integration/module_tool/tar/mini_spec.rb +27 -27
  147. data/spec/integration/parser/catalog_spec.rb +14 -2
  148. data/spec/integration/parser/compiler_spec.rb +94 -3
  149. data/spec/integration/parser/resource_expressions_spec.rb +1 -1
  150. data/spec/integration/resource/type_collection_spec.rb +8 -0
  151. data/spec/lib/puppet_spec/compiler.rb +11 -4
  152. data/spec/shared_contexts/types_setup.rb +4 -0
  153. data/spec/unit/application/lookup_spec.rb +91 -9
  154. data/spec/unit/appmgmt_spec.rb +44 -35
  155. data/spec/unit/capability_spec.rb +33 -53
  156. data/spec/unit/data_providers/function_data_provider_spec.rb +19 -1
  157. data/spec/unit/data_providers/hiera_data_provider_spec.rb +1 -1
  158. data/spec/unit/defaults_spec.rb +18 -0
  159. data/spec/unit/functions/assert_type_spec.rb +1 -1
  160. data/spec/unit/functions/dig_spec.rb +58 -0
  161. data/spec/unit/functions/lest_spec.rb +34 -0
  162. data/spec/unit/functions/lookup_spec.rb +108 -2
  163. data/spec/unit/functions/new_spec.rb +543 -0
  164. data/spec/unit/functions/regsubst_spec.rb +8 -0
  165. data/spec/unit/functions/then_spec.rb +40 -0
  166. data/spec/unit/functions4_spec.rb +78 -10
  167. data/spec/unit/hiera_puppet_spec.rb +49 -8
  168. data/spec/unit/indirector/resource_type/parser_spec.rb +5 -0
  169. data/spec/unit/indirector/rest_spec.rb +12 -0
  170. data/spec/unit/network/http/api/master/v3/environment_spec.rb +60 -0
  171. data/spec/unit/node/environment_spec.rb +10 -0
  172. data/spec/unit/parser/compiler_spec.rb +20 -1
  173. data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
  174. data/spec/unit/parser/functions/shared.rb +1 -1
  175. data/spec/unit/parser/resource_spec.rb +8 -1
  176. data/spec/unit/parser/scope_spec.rb +45 -0
  177. data/spec/unit/pops/evaluator/access_ops_spec.rb +14 -0
  178. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +13 -5
  179. data/spec/unit/pops/loaders/static_loader_spec.rb +92 -1
  180. data/spec/unit/{data_providers/hiera_interpolation_spec.rb → pops/lookup/interpolation_spec.rb} +7 -5
  181. data/spec/unit/pops/parser/lexer2_spec.rb +2 -9
  182. data/spec/unit/pops/parser/parse_application_spec.rb +3 -8
  183. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +19 -0
  184. data/spec/unit/pops/parser/parse_capabilities_spec.rb +3 -10
  185. data/spec/unit/pops/parser/parse_site_spec.rb +19 -10
  186. data/spec/unit/pops/parser/parser_rspec_helper.rb +0 -4
  187. data/spec/unit/pops/types/enumeration_spec.rb +13 -12
  188. data/spec/unit/pops/types/iterable_spec.rb +2 -2
  189. data/spec/unit/pops/types/p_object_type_spec.rb +1060 -0
  190. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +285 -0
  191. data/spec/unit/pops/types/recursion_guard_spec.rb +19 -17
  192. data/spec/unit/pops/types/ruby_generator_spec.rb +261 -0
  193. data/spec/unit/pops/types/string_converter_spec.rb +904 -0
  194. data/spec/unit/pops/types/type_calculator_spec.rb +430 -406
  195. data/spec/unit/pops/types/type_factory_spec.rb +119 -104
  196. data/spec/unit/pops/types/type_formatter_spec.rb +73 -6
  197. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
  198. data/spec/unit/pops/types/type_parser_spec.rb +54 -15
  199. data/spec/unit/pops/types/types_spec.rb +113 -8
  200. data/spec/unit/pops/validator/validator_spec.rb +84 -10
  201. data/spec/unit/provider/package/pip3_spec.rb +9 -270
  202. data/spec/unit/provider/package/pip_spec.rb +85 -30
  203. data/spec/unit/provider/package/rpm_spec.rb +160 -3
  204. data/spec/unit/provider/package/yum_spec.rb +23 -134
  205. data/spec/unit/provider/service/smf_spec.rb +14 -2
  206. data/spec/unit/provider/service/systemd_spec.rb +33 -41
  207. data/spec/unit/resource/capability_finder_spec.rb +10 -2
  208. data/spec/unit/settings/file_setting_spec.rb +6 -0
  209. data/spec/unit/transaction/additional_resource_generator_spec.rb +80 -65
  210. data/spec/unit/type/mount_spec.rb +51 -10
  211. data/spec/unit/type/service_spec.rb +16 -0
  212. data/spec/unit/type_spec.rb +14 -0
  213. data/spec/unit/util/feature_spec.rb +1 -1
  214. data/spec/unit/util/monkey_patches_spec.rb +60 -0
  215. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  216. metadata +63 -11
  217. data/lib/puppet/pops/types/types_meta.rb +0 -0
  218. data/spec/integration/provider/package_spec.rb +0 -35
@@ -19,9 +19,9 @@ Puppet::Type.type(:service).provide :daemontools, :parent => :base do
19
19
 
20
20
  ...or this can be overriden in the resource's attributes:
21
21
 
22
- service { "myservice":
23
- provider => "daemontools",
24
- path => "/path/to/daemons",
22
+ service { 'myservice':
23
+ provider => 'daemontools',
24
+ path => '/path/to/daemons',
25
25
  }
26
26
 
27
27
  This provider supports out of the box:
@@ -17,9 +17,11 @@ Puppet::Type.type(:service).provide :init, :parent => :base do
17
17
  end
18
18
 
19
19
  # Debian and Ubuntu should use the Debian provider.
20
+ # RedHat systems should use the RedHat provider.
20
21
  confine :true => begin
21
- os = Facter.value(:operatingsystem).downcase
22
- !(os == 'debian' || os == 'ubuntu')
22
+ os = Facter.value(:operatingsystem).downcase
23
+ family = Facter.value(:osfamily).downcase
24
+ !(os == 'debian' || os == 'ubuntu' || family == 'redhat')
23
25
  end
24
26
 
25
27
  # We can't confine this here, because the init path can be overridden.
@@ -19,9 +19,9 @@ Puppet::Type.type(:service).provide :runit, :parent => :daemontools do
19
19
 
20
20
  or this can be overriden in the service resource parameters::
21
21
 
22
- service { "myservice":
23
- provider => "runit",
24
- path => "/path/to/daemons",
22
+ service { 'myservice':
23
+ provider => 'runit',
24
+ path => '/path/to/daemons',
25
25
  }
26
26
 
27
27
  This provider supports out of the box:
@@ -34,11 +34,12 @@ Puppet::Type.type(:service).provide :smf, :parent => :base do
34
34
  end
35
35
 
36
36
  def self.instances
37
- svcs("-H").split("\n").select{|l| l !~ /^legacy_run/ }.collect do |line|
38
- state,stime,fmri = line.split(/\s+/)
37
+ svcs("-H", "-o", "state,fmri" ).split("\n").select{|l| l !~ /^legacy_run/ }.collect do |line|
38
+ state,fmri = line.split(/\s+/)
39
39
  status = case state
40
40
  when /online/; :running
41
41
  when /maintenance/; :maintenance
42
+ when /degraded/; :degraded
42
43
  else :stopped
43
44
  end
44
45
  new({:name => fmri, :ensure => status})
@@ -69,7 +70,7 @@ Puppet::Type.type(:service).provide :smf, :parent => :base do
69
70
  def startcmd
70
71
  self.setupservice
71
72
  case self.status
72
- when :maintenance
73
+ when :maintenance, :degraded
73
74
  [command(:adm), :clear, @resource[:name]]
74
75
  else
75
76
  [command(:adm), :enable, "-s", @resource[:name]]
@@ -140,6 +141,8 @@ Puppet::Type.type(:service).provide :smf, :parent => :base do
140
141
  return :stopped
141
142
  when "maintenance"
142
143
  return :maintenance
144
+ when "degraded"
145
+ return :degraded
143
146
  when "legacy_run"
144
147
  raise Puppet::Error,
145
148
  "Cannot manage legacy services through SMF"
@@ -1,7 +1,11 @@
1
1
  # Manage systemd services using systemctl
2
2
 
3
3
  Puppet::Type.type(:service).provide :systemd, :parent => :base do
4
- desc "Manages `systemd` services using `systemctl`."
4
+ desc "Manages `systemd` services using `systemctl`.
5
+
6
+ Because `systemd` defaults to assuming the `.service` unit type, the suffix
7
+ may be omitted. Other unit types (such as `.path`) may be managed by
8
+ providing the proper suffix."
5
9
 
6
10
  commands :systemctl => "systemctl"
7
11
 
@@ -32,10 +36,21 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
32
36
  return []
33
37
  end
34
38
 
39
+ # This helper ensures that the enable state cache is always reset
40
+ # after a systemctl enable operation. A particular service state is not guaranteed
41
+ # after such an operation, so the cache must be emptied to prevent inconsistencies
42
+ # in the provider's believed state of the service and the actual state.
43
+ # @param action [String,Symbol] One of 'enable', 'disable', 'mask' or 'unmask'
44
+ def systemctl_change_enable(action)
45
+ output = systemctl(action, @resource[:name])
46
+ rescue
47
+ raise Puppet::Error, "Could not #{action} #{self.name}: #{output}", $!.backtrace
48
+ ensure
49
+ @cached_enabled = nil
50
+ end
51
+
35
52
  def disable
36
- output = systemctl(:disable, @resource[:name])
37
- rescue Puppet::ExecutionFailure
38
- raise Puppet::Error, "Could not disable #{self.name}: #{output}", $!.backtrace
53
+ systemctl_change_enable(:disable)
39
54
  end
40
55
 
41
56
  def get_start_link_count
@@ -49,38 +64,27 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
49
64
  Dir.glob("/etc/rc*.d/S??#{link_name}").length
50
65
  end
51
66
 
52
- def enabled?
53
- begin
54
- systemctl_info = systemctl(
55
- 'show',
56
- @resource[:name],
57
- '--property', 'LoadState',
58
- '--property', 'UnitFileState',
59
- '--no-pager'
60
- )
61
-
62
- svc_info = Hash.new
63
- systemctl_info.split.each do |svc|
64
- entry_pair = svc.split('=')
65
- svc_info[entry_pair.first.to_sym] = entry_pair.last
66
- end
67
+ def cached_enabled?
68
+ return @cached_enabled if @cached_enabled
69
+ cmd = [command(:systemctl), 'is-enabled', @resource[:name]]
70
+ @cached_enabled = execute(cmd, :failonfail => false).strip
71
+ end
67
72
 
68
- # The masked state is equivalent to the disabled state in terms of
69
- # comparison so we only care to check if it is masked if we want to keep
70
- # it masked.
71
- #
72
- # We only return :mask if we're trying to mask the service. This prevents
73
- # flapping when simply trying to disable a masked service.
74
- return :mask if (@resource[:enable] == :mask) && (svc_info[:LoadState] == 'masked')
75
- return :true if svc_info[:UnitFileState] == 'enabled'
76
- if Facter.value(:osfamily).downcase == 'debian'
77
- ret = debian_enabled?(svc_info)
78
- return ret if ret
79
- end
80
- rescue Puppet::ExecutionFailure
81
- # The execution of the systemd command can fail for quite a few reasons.
82
- # In all of these cases, the failure of the query indicates that the
83
- # service is disabled and therefore we simply return :false.
73
+ def enabled?
74
+ output = cached_enabled?
75
+
76
+ # The masked state is equivalent to the disabled state in terms of
77
+ # comparison so we only care to check if it is masked if we want to keep
78
+ # it masked.
79
+ #
80
+ # We only return :mask if we're trying to mask the service. This prevents
81
+ # flapping when simply trying to disable a masked service.
82
+ return :mask if (@resource[:enable] == :mask) && (output == 'masked')
83
+ return :true if ['static', 'enabled'].include? output
84
+ return :false if ['disabled', 'linked', 'indirect', 'masked'].include? output
85
+ if (output.empty?) && (Facter.value(:osfamily).downcase == 'debian')
86
+ ret = debian_enabled?
87
+ return ret if ret
84
88
  end
85
89
 
86
90
  return :false
@@ -91,60 +95,38 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
91
95
  # have a Systemd unit file, we need to go through the old init script to determine
92
96
  # whether it is enabled or not. See PUP-5016 for more details.
93
97
  #
94
- def debian_enabled?(svc_info)
95
- # If UnitFileState == UnitFileState then we query the older way.
96
- if svc_info[:UnitFileState] == 'UnitFileState'
97
- system("/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start")
98
- if [104, 106].include?($CHILD_STATUS.exitstatus)
98
+ def debian_enabled?
99
+ system("/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start")
100
+ if [104, 106].include?($CHILD_STATUS.exitstatus)
101
+ return :true
102
+ elsif [101, 105].include?($CHILD_STATUS.exitstatus)
103
+ # 101 is action not allowed, which means we have to do the check manually.
104
+ # 105 is unknown, which generally means the iniscript does not support query
105
+ # The debian policy states that the initscript should support methods of query
106
+ # For those that do not, peform the checks manually
107
+ # http://www.debian.org/doc/debian-policy/ch-opersys.html
108
+ if get_start_link_count >= 4
99
109
  return :true
100
- elsif [101, 105].include?($CHILD_STATUS.exitstatus)
101
- # 101 is action not allowed, which means we have to do the check manually.
102
- # 105 is unknown, which generally means the iniscript does not support query
103
- # The debian policy states that the initscript should support methods of query
104
- # For those that do not, peform the checks manually
105
- # http://www.debian.org/doc/debian-policy/ch-opersys.html
106
- if get_start_link_count >= 4
107
- return :true
108
- else
109
- return :false
110
- end
111
110
  else
112
111
  return :false
113
112
  end
113
+ else
114
+ return :false
114
115
  end
115
116
  end
116
117
 
117
- def status
118
- begin
119
- systemctl("is-active", @resource[:name])
120
- rescue Puppet::ExecutionFailure
121
- return :stopped
122
- end
123
- return :running
124
- end
125
-
126
118
  def enable
127
119
  self.unmask
128
- output = systemctl("enable", @resource[:name])
129
- rescue Puppet::ExecutionFailure
130
- raise Puppet::Error, "Could not enable #{self.name}: #{output}", $!.backtrace
120
+ systemctl_change_enable(:enable)
131
121
  end
132
122
 
133
123
  def mask
134
124
  self.disable
135
- begin
136
- output = systemctl("mask", @resource[:name])
137
- rescue Puppet::ExecutionFailure
138
- raise Puppet::Error, "Could not mask #{self.name}: #{output}", $!.backtrace
139
- end
125
+ systemctl_change_enable(:mask)
140
126
  end
141
127
 
142
128
  def unmask
143
- begin
144
- output = systemctl("unmask", @resource[:name])
145
- rescue Puppet::ExecutionFailure
146
- raise Puppet::Error, "Could not unmask #{self.name}: #{output}", $!.backtrace
147
- end
129
+ systemctl_change_enable(:unmask)
148
130
  end
149
131
 
150
132
  def restartcmd
@@ -159,5 +141,9 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
159
141
  def stopcmd
160
142
  [command(:systemctl), "stop", @resource[:name]]
161
143
  end
144
+
145
+ def statuscmd
146
+ [command(:systemctl), "is-active", @resource[:name]]
147
+ end
162
148
  end
163
149
 
@@ -1,9 +1,8 @@
1
- # This doesn't get stored in trac, since it changes every time.
2
1
  providers = Puppet::Util::Reference.newreference :providers, :title => "Provider Suitability Report", :depth => 1, :dynamic => true, :doc => "Which providers are valid for this machine" do
3
2
  types = []
4
3
  Puppet::Type.loadall
5
4
  Puppet::Type.eachtype do |klass|
6
- next unless klass.providers.length > 0
5
+ next unless klass && klass.providers.length > 0
7
6
  types << klass
8
7
  end
9
8
  types.sort! { |a,b| a.name.to_s <=> b.name.to_s }
@@ -21,7 +21,10 @@ class Puppet::Resource
21
21
  extend Puppet::Indirector
22
22
  indirects :resource, :terminus_class => :ral
23
23
 
24
- ATTRIBUTES = [:file, :line, :exported]
24
+ ATTRIBUTES = [:file, :line, :exported].freeze
25
+ TYPE_CLASS = 'Class'.freeze
26
+ TYPE_NODE = 'Node'.freeze
27
+ TYPE_SITE = 'Site'.freeze
25
28
 
26
29
  def self.from_data_hash(data)
27
30
  raise ArgumentError, "No resource type provided in serialized data" unless type = data['type']
@@ -162,7 +165,7 @@ class Puppet::Resource
162
165
  end
163
166
 
164
167
  def class?
165
- @is_class ||= @type == "Class"
168
+ @is_class ||= @type == TYPE_CLASS
166
169
  end
167
170
 
168
171
  def stage?
@@ -222,6 +225,11 @@ class Puppet::Resource
222
225
  self[p] = v
223
226
  end
224
227
  else
228
+ if type.is_a?(Hash)
229
+ raise ArgumentError, "Puppet::Resource.new does not take a hash as the first argument. "+
230
+ "Did you mean (#{(type[:type] || type["type"]).inspect}, #{(type[:title] || type["title"]).inspect }) ?"
231
+ end
232
+
225
233
  environment = attributes[:environment]
226
234
  if type.is_a?(Class) && type < Puppet::Type
227
235
  # Set the resource type to avoid an expensive `known_resource_types`
@@ -238,22 +246,15 @@ class Puppet::Resource
238
246
  send(attr.to_s + "=", value)
239
247
  end
240
248
 
241
- @type, @title = extract_type_and_title(type, title)
242
-
243
- @type = munge_type_name(@type)
244
-
245
- if self.class?
246
- @title = :main if @title == ""
247
- @title = munge_type_name(@title)
248
- end
249
+ @type, @title = self.class.type_and_title(type, title)
249
250
 
250
251
  if params = attributes[:parameters]
251
252
  extract_parameters(params)
252
253
  end
253
254
 
254
- if resource_type && resource_type.respond_to?(:deprecate_params)
255
+ if resource_type && resource_type.respond_to?(:deprecate_params)
255
256
  resource_type.deprecate_params(title, attributes[:parameters])
256
- end
257
+ end
257
258
 
258
259
  tag(self.type)
259
260
  tag_if_valid(self.title)
@@ -304,10 +305,17 @@ class Puppet::Resource
304
305
  # @return [Puppet::Type, Puppet::Resource::Type]
305
306
  # @api private
306
307
  def resource_type
307
- @rstype ||= case type
308
- when "Class"; environment.known_resource_types.hostclass(title == :main ? "" : title)
309
- when "Node"; environment.known_resource_types.node(title)
310
- when "Site"; environment.known_resource_types.site(nil)
308
+ @rstype ||= self.class.resource_type(type, title, environment)
309
+ end
310
+
311
+ # The resource's type implementation
312
+ # @return [Puppet::Type, Puppet::Resource::Type]
313
+ # @api private
314
+ def self.resource_type(type, title, environment)
315
+ case type
316
+ when TYPE_CLASS; environment.known_resource_types.hostclass(title == :main ? "" : title)
317
+ when TYPE_NODE; environment.known_resource_types.node(title)
318
+ when TYPE_SITE; environment.known_resource_types.site(nil)
311
319
  else
312
320
  result = Puppet::Type.type(type)
313
321
  if !result
@@ -516,6 +524,35 @@ class Puppet::Resource
516
524
  self
517
525
  end
518
526
 
527
+ # @api private
528
+ def self.type_and_title(type, title)
529
+ type, title = extract_type_and_title(type, title)
530
+ type = munge_type_name(type)
531
+ if type == TYPE_CLASS
532
+ title = title == '' ? :main : munge_type_name(title)
533
+ end
534
+ [type, title]
535
+ end
536
+
537
+
538
+ def self.extract_type_and_title(argtype, argtitle)
539
+ if (argtype.nil? || argtype == :component || argtype == :whit) &&
540
+ argtitle =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
541
+ elsif argtitle.nil? && argtype =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
542
+ elsif argtitle then [ argtype, argtitle ]
543
+ elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ]
544
+ else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
545
+ end
546
+ end
547
+ private_class_method :extract_type_and_title
548
+
549
+ def self.munge_type_name(value)
550
+ return :main if value == :main
551
+ return TYPE_CLASS if value == '' || value.nil? || value.to_s.casecmp('component') == 0
552
+ Puppet::Pops::Types::TypeFormatter.singleton.capitalize_segments(value.to_s)
553
+ end
554
+ private_class_method :munge_type_name
555
+
519
556
  private
520
557
 
521
558
  # Produce a canonical method name.
@@ -530,7 +567,7 @@ class Puppet::Resource
530
567
  # The namevar for our resource type. If the type doesn't exist,
531
568
  # always use :name.
532
569
  def namevar
533
- if builtin_type? and t = resource_type and t.key_attributes.length == 1
570
+ if builtin_type? && !(t = resource_type).nil? && t.key_attributes.length == 1
534
571
  t.key_attributes.first
535
572
  else
536
573
  :name
@@ -544,26 +581,6 @@ class Puppet::Resource
544
581
  end
545
582
  end
546
583
 
547
- def extract_type_and_title(argtype, argtitle)
548
- if (argtype.nil? || argtype == :component || argtype == :whit) &&
549
- argtitle =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
550
- elsif argtitle.nil? && argtype =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
551
- elsif argtitle then [ argtype, argtitle ]
552
- elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ]
553
- elsif argtype.is_a?(Hash) then
554
- raise ArgumentError, "Puppet::Resource.new does not take a hash as the first argument. "+
555
- "Did you mean (#{(argtype[:type] || argtype["type"]).inspect}, #{(argtype[:title] || argtype["title"]).inspect }) ?"
556
- else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
557
- end
558
- end
559
-
560
- def munge_type_name(value)
561
- return :main if value == :main
562
- return "Class" if value == "" or value.nil? or value.to_s.downcase == "component"
563
-
564
- value.to_s.split("::").collect { |s| s.capitalize }.join("::")
565
- end
566
-
567
584
  def parse_title
568
585
  h = {}
569
586
  type = resource_type
@@ -167,14 +167,15 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
167
167
 
168
168
  # Create an alias for a resource.
169
169
  def alias(resource, key)
170
- resource.ref =~ /^(.+)\[/
170
+ ref = resource.ref
171
+ ref =~ /^(.+)\[/
171
172
  class_name = $1 || resource.class.name
172
173
 
173
174
  newref = [class_name, key].flatten
174
175
 
175
176
  if key.is_a? String
176
177
  ref_string = "#{class_name}[#{key}]"
177
- return if ref_string == resource.ref
178
+ return if ref_string == ref
178
179
  end
179
180
 
180
181
  # LAK:NOTE It's important that we directly compare the references,
@@ -185,12 +186,12 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
185
186
  return if existing == resource
186
187
  resource_declaration = " at #{resource.file}:#{resource.line}" if resource.file and resource.line
187
188
  existing_declaration = " at #{existing.file}:#{existing.line}" if existing.file and existing.line
188
- msg = "Cannot alias #{resource.ref} to #{key.inspect}#{resource_declaration}; resource #{newref.inspect} already declared#{existing_declaration}"
189
+ msg = "Cannot alias #{ref} to #{key.inspect}#{resource_declaration}; resource #{newref.inspect} already declared#{existing_declaration}"
189
190
  raise ArgumentError, msg
190
191
  end
191
192
  @resource_table[newref] = resource
192
- @aliases[resource.ref] ||= []
193
- @aliases[resource.ref] << newref
193
+ @aliases[ref] ||= []
194
+ @aliases[ref] << newref
194
195
  end
195
196
 
196
197
  # Apply our catalog to the local host.
@@ -332,11 +333,12 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
332
333
  # references to the resource instances.
333
334
  def remove_resource(*resources)
334
335
  resources.each do |resource|
335
- title_key = title_key_for_ref(resource.ref)
336
+ ref = resource.ref
337
+ title_key = title_key_for_ref(ref)
336
338
  @resource_table.delete(title_key)
337
- if aliases = @aliases[resource.ref]
339
+ if aliases = @aliases[ref]
338
340
  aliases.each { |res_alias| @resource_table.delete(res_alias) }
339
- @aliases.delete(resource.ref)
341
+ @aliases.delete(ref)
340
342
  end
341
343
  remove_vertex!(resource) if vertex?(resource)
342
344
  @relationship_graph.remove_vertex!(resource) if @relationship_graph and @relationship_graph.vertex?(resource)
@@ -348,27 +350,27 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
348
350
 
349
351
  # Look a resource up by its reference (e.g., File[/etc/passwd]).
350
352
  def resource(type, title = nil)
351
- # Always create a resource reference, so that it always
352
- # canonicalizes how we are referring to them.
353
- attributes = { :environment => environment_instance }
354
- if title
355
- res = Puppet::Resource.new(type, title, attributes)
356
- else
357
- # If they didn't provide a title, then we expect the first
358
- # argument to be of the form 'Class[name]', which our
359
- # Reference class canonicalizes for us.
360
- res = Puppet::Resource.new(nil, type, attributes)
361
- end
362
- res.catalog = self
363
- title_key = [res.type, res.title.to_s]
364
- uniqueness_key = [res.type, res.uniqueness_key].flatten
365
- result = @resource_table[title_key] || @resource_table[uniqueness_key]
366
- if ! result && res.resource_type && res.resource_type.is_capability?
367
- # @todo lutter 2015-03-10: this assumes that it is legal to just
368
- # mention a capability resource in code and have it automatically
369
- # made available, even if the current component does not require it
370
- result = Puppet::Resource::CapabilityFinder.find(environment, code_id, res)
371
- add_resource(result) if result
353
+ type, title = Puppet::Resource.type_and_title(type, title)
354
+ title_key = [type, title.to_s]
355
+ result = @resource_table[title_key]
356
+ if result.nil?
357
+ # an instance has to be created in order to construct the unique key used when
358
+ # searching for aliases.
359
+ unless @aliases.empty? && !Puppet[:app_management]
360
+ res = Puppet::Resource.new(type, title, { :environment => @environment_instance })
361
+ result = @resource_table[[type, res.uniqueness_key].flatten]
362
+ end
363
+
364
+ if result.nil? && Puppet[:app_management]
365
+ resource_type = res.resource_type
366
+ if resource_type && resource_type.is_capability?
367
+ # @todo lutter 2015-03-10: this assumes that it is legal to just
368
+ # mention a capability resource in code and have it automatically
369
+ # made available, even if the current component does not require it
370
+ result = Puppet::Resource::CapabilityFinder.find(environment, code_id, res)
371
+ add_resource(result) if result
372
+ end
373
+ end
372
374
  end
373
375
  result
374
376
  end