puppet 2.6.4 → 2.6.5
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.
- data/CHANGELOG +147 -0
- data/LICENSE +2 -2
- data/Rakefile +3 -4
- data/lib/puppet.rb +1 -1
- data/lib/puppet/application.rb +22 -5
- data/lib/puppet/application/apply.rb +2 -18
- data/lib/puppet/application/doc.rb +1 -4
- data/lib/puppet/application/inspect.rb +178 -0
- data/lib/puppet/configurer.rb +9 -11
- data/lib/puppet/configurer/plugin_handler.rb +0 -2
- data/lib/puppet/defaults.rb +12 -3
- data/lib/puppet/external/pson/pure/generator.rb +1 -22
- data/lib/puppet/file_bucket/dipper.rb +9 -3
- data/lib/puppet/file_bucket/file.rb +14 -94
- data/lib/puppet/indirector.rb +4 -0
- data/lib/puppet/indirector/catalog/active_record.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
- data/lib/puppet/indirector/indirection.rb +18 -8
- data/lib/puppet/indirector/resource/ral.rb +7 -2
- data/lib/puppet/indirector/rest.rb +19 -2
- data/lib/puppet/network/http/api/v1.rb +3 -0
- data/lib/puppet/network/http/handler.rb +16 -1
- data/lib/puppet/network/http/rack/rest.rb +1 -3
- data/lib/puppet/network/rest_authconfig.rb +4 -12
- data/lib/puppet/network/rights.rb +28 -14
- data/lib/puppet/parser/ast.rb +4 -0
- data/lib/puppet/parser/compiler.rb +18 -3
- data/lib/puppet/parser/functions/defined.rb +28 -6
- data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
- data/lib/puppet/parser/templatewrapper.rb +1 -0
- data/lib/puppet/property.rb +16 -1
- data/lib/puppet/property/keyvalue.rb +0 -2
- data/lib/puppet/property/list.rb +0 -2
- data/lib/puppet/provider/file/posix.rb +1 -3
- data/lib/puppet/provider/file/win32.rb +1 -3
- data/lib/puppet/provider/maillist/mailman.rb +3 -5
- data/lib/puppet/provider/mount.rb +2 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
- data/lib/puppet/provider/package/freebsd.rb +2 -2
- data/lib/puppet/provider/zone/solaris.rb +1 -1
- data/lib/puppet/reference/configuration.rb +2 -2
- data/lib/puppet/reference/function.rb +4 -0
- data/lib/puppet/relationship.rb +4 -0
- data/lib/puppet/reports/store.rb +1 -19
- data/lib/puppet/resource.rb +11 -2
- data/lib/puppet/resource/status.rb +24 -3
- data/lib/puppet/resource/type.rb +24 -16
- data/lib/puppet/resource/type_collection.rb +4 -1
- data/lib/puppet/simple_graph.rb +4 -0
- data/lib/puppet/transaction.rb +1 -28
- data/lib/puppet/transaction/event.rb +9 -4
- data/lib/puppet/transaction/report.rb +42 -22
- data/lib/puppet/transaction/resource_harness.rb +99 -71
- data/lib/puppet/type.rb +22 -9
- data/lib/puppet/type/cron.rb +1 -5
- data/lib/puppet/type/exec.rb +4 -34
- data/lib/puppet/type/file.rb +19 -26
- data/lib/puppet/type/file/checksum.rb +1 -1
- data/lib/puppet/type/file/content.rb +2 -1
- data/lib/puppet/type/file/ctime.rb +18 -0
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +10 -44
- data/lib/puppet/type/file/mtime.rb +17 -0
- data/lib/puppet/type/file/owner.rb +1 -1
- data/lib/puppet/type/file/source.rb +0 -1
- data/lib/puppet/type/file/target.rb +1 -1
- data/lib/puppet/type/file/type.rb +5 -12
- data/lib/puppet/type/host.rb +1 -1
- data/lib/puppet/type/mount.rb +2 -2
- data/lib/puppet/type/package.rb +0 -2
- data/lib/puppet/type/service.rb +11 -5
- data/lib/puppet/type/user.rb +7 -9
- data/lib/puppet/type/yumrepo.rb +2 -2
- data/lib/puppet/type/zpool.rb +0 -4
- data/lib/puppet/util/checksums.rb +24 -1
- data/lib/puppet/util/command_line.rb +6 -2
- data/lib/puppet/util/command_line/puppet +5 -1
- data/lib/puppet/util/command_line/puppetca +2 -2
- data/lib/puppet/util/command_line/puppetd +11 -9
- data/lib/puppet/util/command_line/puppetdoc +2 -2
- data/lib/puppet/util/command_line/puppetmasterd +5 -0
- data/lib/puppet/util/log.rb +15 -8
- data/lib/puppet/util/log/destinations.rb +2 -0
- data/lib/puppet/util/log_paths.rb +1 -1
- data/lib/puppet/util/logging.rb +1 -1
- data/lib/puppet/util/metric.rb +1 -0
- data/lib/puppet/util/reference.rb +1 -10
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/zaml.rb +30 -31
- data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
- data/spec/integration/application/apply_spec.rb +1 -2
- data/spec/integration/defaults_spec.rb +1 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
- data/spec/integration/indirector/report/rest_spec.rb +13 -17
- data/spec/integration/network/formats_spec.rb +2 -5
- data/spec/integration/network/server/mongrel_spec.rb +1 -2
- data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
- data/spec/integration/provider/package_spec.rb +1 -3
- data/spec/integration/provider/service/init_spec.rb +3 -9
- data/spec/integration/reference/providers_spec.rb +2 -2
- data/spec/integration/resource/catalog_spec.rb +1 -2
- data/spec/integration/transaction/report_spec.rb +1 -1
- data/spec/monkey_patches/alias_should_to_must.rb +2 -0
- data/spec/shared_behaviours/file_server_terminus.rb +1 -1
- data/spec/shared_behaviours/file_serving.rb +1 -1
- data/spec/shared_behaviours/memory_terminus.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/application/agent_spec.rb +1 -0
- data/spec/unit/application/apply_spec.rb +7 -7
- data/spec/unit/application/doc_spec.rb +2 -2
- data/spec/unit/application/filebucket_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +278 -0
- data/spec/unit/application/kick_spec.rb +1 -3
- data/spec/unit/application/master_spec.rb +1 -3
- data/spec/unit/application/queue_spec.rb +1 -0
- data/spec/unit/application_spec.rb +63 -5
- data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
- data/spec/unit/configurer_spec.rb +33 -49
- data/spec/unit/file_bucket/dipper_spec.rb +69 -77
- data/spec/unit/file_bucket/file_spec.rb +12 -127
- data/spec/unit/file_serving/fileset_spec.rb +1 -0
- data/spec/unit/file_serving/metadata_spec.rb +4 -4
- data/spec/unit/indirector/active_record_spec.rb +1 -0
- data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
- data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
- data/spec/unit/indirector/facts/couch_spec.rb +1 -2
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
- data/spec/unit/indirector/file_server_spec.rb +6 -7
- data/spec/unit/indirector/indirection_spec.rb +71 -2
- data/spec/unit/indirector/ldap_spec.rb +2 -6
- data/spec/unit/indirector/node/active_record_spec.rb +1 -3
- data/spec/unit/indirector/queue_spec.rb +1 -3
- data/spec/unit/indirector/rest_spec.rb +37 -1
- data/spec/unit/indirector/ssl_file_spec.rb +5 -5
- data/spec/unit/indirector_spec.rb +6 -1
- data/spec/unit/module_spec.rb +1 -3
- data/spec/unit/network/formats_spec.rb +2 -5
- data/spec/unit/network/http/api/v1_spec.rb +4 -0
- data/spec/unit/network/http/compression_spec.rb +1 -3
- data/spec/unit/network/http/handler_spec.rb +39 -0
- data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
- data/spec/unit/network/http/mongrel_spec.rb +3 -9
- data/spec/unit/network/http/rack/rest_spec.rb +1 -3
- data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
- data/spec/unit/network/http/rack_spec.rb +2 -3
- data/spec/unit/network/http/webrick_spec.rb +1 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/network/rights_spec.rb +43 -23
- data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
- data/spec/unit/parameter_spec.rb +1 -2
- data/spec/unit/parser/collector_spec.rb +3 -6
- data/spec/unit/parser/compiler_spec.rb +90 -5
- data/spec/unit/parser/lexer_spec.rb +3 -2
- data/spec/unit/parser/templatewrapper_spec.rb +1 -0
- data/spec/unit/property/keyvalue_spec.rb +5 -5
- data/spec/unit/property/list_spec.rb +7 -7
- data/spec/unit/provider/mount/parsed_spec.rb +1 -2
- data/spec/unit/provider/mount_spec.rb +8 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
- data/spec/unit/provider/package/freebsd_spec.rb +55 -0
- data/spec/unit/provider/service/init_spec.rb +2 -0
- data/spec/unit/rails/host_spec.rb +1 -3
- data/spec/unit/rails/param_value_spec.rb +2 -3
- data/spec/unit/rails/resource_spec.rb +2 -3
- data/spec/unit/rails_spec.rb +5 -15
- data/spec/unit/relationship_spec.rb +2 -6
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/reports/store_spec.rb +31 -0
- data/spec/unit/reports/tagmail_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +2 -6
- data/spec/unit/resource/status_spec.rb +53 -3
- data/spec/unit/resource/type_collection_spec.rb +0 -8
- data/spec/unit/resource/type_spec.rb +50 -4
- data/spec/unit/resource_spec.rb +10 -6
- data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
- data/spec/unit/transaction/event_spec.rb +21 -2
- data/spec/unit/transaction/report_spec.rb +91 -35
- data/spec/unit/transaction/resource_harness_spec.rb +289 -208
- data/spec/unit/transaction_spec.rb +1 -6
- data/spec/unit/type/augeas_spec.rb +1 -3
- data/spec/unit/type/file/content_spec.rb +63 -10
- data/spec/unit/type/file/ctime.rb +35 -0
- data/spec/unit/type/file/ensure_spec.rb +8 -7
- data/spec/unit/type/file/group_spec.rb +5 -5
- data/spec/unit/type/file/mtime.rb +35 -0
- data/spec/unit/type/file/owner_spec.rb +7 -7
- data/spec/unit/type/file/selinux_spec.rb +2 -2
- data/spec/unit/type/file/source_spec.rb +3 -3
- data/spec/unit/type/file/type.rb +20 -0
- data/spec/unit/type/file_spec.rb +131 -8
- data/spec/unit/type/mount_spec.rb +4 -4
- data/spec/unit/type/package_spec.rb +3 -3
- data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
- data/spec/unit/type/user_spec.rb +31 -3
- data/spec/unit/type/zpool_spec.rb +12 -12
- data/spec/unit/type_spec.rb +2 -2
- data/spec/unit/util/checksums_spec.rb +9 -1
- data/spec/unit/util/command_line_spec.rb +29 -0
- data/spec/unit/util/log/destinations_spec.rb +13 -0
- data/spec/unit/util/log_spec.rb +24 -12
- data/spec/unit/util/logging_spec.rb +1 -1
- data/spec/unit/util/metric_spec.rb +7 -7
- data/spec/unit/util/pson_spec.rb +15 -0
- data/spec/unit/util/queue/stomp_spec.rb +2 -6
- data/spec/unit/util/settings/file_setting_spec.rb +1 -3
- data/spec/unit/util/zaml_spec.rb +51 -0
- data/test/language/snippets.rb +3 -0
- data/test/lib/puppettest/fileparsing.rb +2 -0
- data/test/lib/puppettest/reporttesting.rb +1 -1
- data/test/lib/puppettest/support/utils.rb +1 -1
- data/test/network/server/mongrel_test.rb +0 -6
- data/test/other/report.rb +1 -1
- data/test/ral/providers/cron/crontab.rb +4 -1
- data/test/ral/type/file.rb +1 -1
- data/test/ral/type/filesources.rb +1 -4
- metadata +1119 -1113
- data/lib/puppet/transaction/change.rb +0 -87
- data/spec/Rakefile +0 -91
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
- data/spec/spec_specs/runnable_spec.rb +0 -95
- data/spec/unit/transaction/change_spec.rb +0 -193
@@ -180,18 +180,13 @@ class Puppet::Indirector::Indirection
|
|
180
180
|
request = request(:find, key, *args)
|
181
181
|
terminus = prepare(request)
|
182
182
|
|
183
|
-
|
184
|
-
|
185
|
-
return result
|
186
|
-
end
|
187
|
-
rescue => detail
|
188
|
-
puts detail.backtrace if Puppet[:trace]
|
189
|
-
Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}"
|
183
|
+
if result = find_in_cache(request)
|
184
|
+
return result
|
190
185
|
end
|
191
186
|
|
192
187
|
# Otherwise, return the result from the terminus, caching if appropriate.
|
193
188
|
if ! request.ignore_terminus? and result = terminus.find(request)
|
194
|
-
result.expiration ||= self.expiration
|
189
|
+
result.expiration ||= self.expiration if result.respond_to?(:expiration)
|
195
190
|
if cache? and request.use_cache?
|
196
191
|
Puppet.info "Caching #{self.name} for #{request.key}"
|
197
192
|
cache.save request(:save, result, *args)
|
@@ -203,6 +198,17 @@ class Puppet::Indirector::Indirection
|
|
203
198
|
nil
|
204
199
|
end
|
205
200
|
|
201
|
+
# Search for an instance in the appropriate terminus, and return a
|
202
|
+
# boolean indicating whether the instance was found.
|
203
|
+
def head(key, *args)
|
204
|
+
request = request(:head, key, *args)
|
205
|
+
terminus = prepare(request)
|
206
|
+
|
207
|
+
# Look in the cache first, then in the terminus. Force the result
|
208
|
+
# to be a boolean.
|
209
|
+
!!(find_in_cache(request) || terminus.head(request))
|
210
|
+
end
|
211
|
+
|
206
212
|
def find_in_cache(request)
|
207
213
|
# See if our instance is in the cache and up to date.
|
208
214
|
return nil unless cache? and ! request.ignore_cache? and cached = cache.find(request)
|
@@ -213,6 +219,10 @@ class Puppet::Indirector::Indirection
|
|
213
219
|
|
214
220
|
Puppet.debug "Using cached #{self.name} for #{request.key}"
|
215
221
|
cached
|
222
|
+
rescue => detail
|
223
|
+
puts detail.backtrace if Puppet[:trace]
|
224
|
+
Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}"
|
225
|
+
nil
|
216
226
|
end
|
217
227
|
|
218
228
|
# Remove something via the terminus.
|
@@ -34,12 +34,17 @@ class Puppet::Resource::Ral < Puppet::Indirector::Code
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
# {type,resource}_name: the resource name may contain slashes:
|
38
|
+
# File["/etc/hosts"]. To handle, assume the type name does
|
39
|
+
# _not_ have any slashes in it, and split only on the first.
|
40
|
+
|
37
41
|
def type_name( request )
|
38
|
-
request.key.split('/')[0]
|
42
|
+
request.key.split('/', 2)[0]
|
39
43
|
end
|
40
44
|
|
41
45
|
def resource_name( request )
|
42
|
-
request.key.split('/')[1]
|
46
|
+
name = request.key.split('/', 2)[1]
|
47
|
+
name unless name == ""
|
43
48
|
end
|
44
49
|
|
45
50
|
def type( request )
|
@@ -53,11 +53,15 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
|
|
53
53
|
end
|
54
54
|
else
|
55
55
|
# Raise the http error if we didn't get a 'success' of some kind.
|
56
|
-
|
57
|
-
raise Net::HTTPError.new(message, response)
|
56
|
+
raise convert_to_http_error(response)
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
60
|
+
def convert_to_http_error(response)
|
61
|
+
message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}"
|
62
|
+
Net::HTTPError.new(message, response)
|
63
|
+
end
|
64
|
+
|
61
65
|
# Provide appropriate headers.
|
62
66
|
def headers
|
63
67
|
add_accept_encoding({"Accept" => model.supported_formats.join(", ")})
|
@@ -73,6 +77,19 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
|
|
73
77
|
result
|
74
78
|
end
|
75
79
|
|
80
|
+
def head(request)
|
81
|
+
response = network(request).head(indirection2uri(request), headers)
|
82
|
+
case response.code
|
83
|
+
when "404"
|
84
|
+
return false
|
85
|
+
when /^2/
|
86
|
+
return true
|
87
|
+
else
|
88
|
+
# Raise the http error if we didn't get a 'success' of some kind.
|
89
|
+
raise convert_to_http_error(response)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
76
93
|
def search(request)
|
77
94
|
unless result = deserialize(network(request).get(indirection2uri(request), headers), true)
|
78
95
|
return []
|
@@ -109,7 +109,22 @@ module Puppet::Network::HTTP::Handler
|
|
109
109
|
format = format_to_use(request)
|
110
110
|
set_content_type(response, format)
|
111
111
|
|
112
|
-
|
112
|
+
if result.respond_to?(:render)
|
113
|
+
set_response(response, result.render(format))
|
114
|
+
else
|
115
|
+
set_response(response, result)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Execute our head.
|
120
|
+
def do_head(indirection_request, request, response)
|
121
|
+
unless indirection_request.model.head(indirection_request.key, indirection_request.to_hash)
|
122
|
+
Puppet.info("Could not find #{indirection_request.indirection_name} for '#{indirection_request.key}'")
|
123
|
+
return do_exception(response, "Could not find #{indirection_request.indirection_name} #{indirection_request.key}", 404)
|
124
|
+
end
|
125
|
+
|
126
|
+
# No need to set a response because no response is expected from a
|
127
|
+
# HEAD request. All we need to do is not die.
|
113
128
|
end
|
114
129
|
|
115
130
|
# Execute our search.
|
@@ -76,9 +76,7 @@ class Puppet::Network::HTTP::RackREST < Puppet::Network::HTTP::RackHttpHandler
|
|
76
76
|
# request.body has some limitiations, so we need to concat it back
|
77
77
|
# into a regular string, which is something puppet can use.
|
78
78
|
def body(request)
|
79
|
-
body
|
80
|
-
request.body.each { |part| body += part }
|
81
|
-
body
|
79
|
+
request.body.read
|
82
80
|
end
|
83
81
|
|
84
82
|
def extract_client_info(request)
|
@@ -38,14 +38,10 @@ module Puppet
|
|
38
38
|
# fail_on_deny could as well be called in the XMLRPC context
|
39
39
|
# with a ClientRequest.
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
:ip => request.ip,
|
46
|
-
:method => request.method,
|
47
|
-
:environment => request.environment,
|
48
|
-
:authenticated => request.authenticated)
|
41
|
+
if authorization_failure_exception = @rights.is_request_forbidden_and_why?(request)
|
42
|
+
Puppet.warning("Denying access: #{authorization_failure_exception}")
|
43
|
+
raise authorization_failure_exception
|
44
|
+
end
|
49
45
|
end
|
50
46
|
|
51
47
|
def initialize(file = nil, parsenow = true)
|
@@ -88,9 +84,5 @@ module Puppet
|
|
88
84
|
end
|
89
85
|
@rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil?
|
90
86
|
end
|
91
|
-
|
92
|
-
def build_uri(request)
|
93
|
-
"/#{request.indirection_name}/#{request.key}"
|
94
|
-
end
|
95
87
|
end
|
96
88
|
end
|
@@ -26,19 +26,34 @@ class Rights
|
|
26
26
|
|
27
27
|
# Check that name is allowed or not
|
28
28
|
def allowed?(name, *args)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
!is_forbidden_and_why?(name, :node => args[0], :ip => args[1])
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_request_forbidden_and_why?(request)
|
33
|
+
methods_to_check = if request.method == :head
|
34
|
+
# :head is ok if either :find or :save is ok.
|
35
|
+
[:find, :save]
|
36
|
+
else
|
37
|
+
[request.method]
|
38
|
+
end
|
39
|
+
authorization_failure_exceptions = methods_to_check.map do |method|
|
40
|
+
is_forbidden_and_why?("/#{request.indirection_name}/#{request.key}",
|
41
|
+
:node => request.node,
|
42
|
+
:ip => request.ip,
|
43
|
+
:method => method,
|
44
|
+
:environment => request.environment,
|
45
|
+
:authenticated => request.authenticated)
|
46
|
+
end
|
47
|
+
if authorization_failure_exceptions.include? nil
|
48
|
+
# One of the methods we checked is ok, therefore this request is ok.
|
49
|
+
nil
|
50
|
+
else
|
51
|
+
# Just need to return any of the failure exceptions.
|
52
|
+
authorization_failure_exceptions.first
|
37
53
|
end
|
38
|
-
true
|
39
54
|
end
|
40
55
|
|
41
|
-
def
|
56
|
+
def is_forbidden_and_why?(name, args = {})
|
42
57
|
res = :nomatch
|
43
58
|
right = @rights.find do |acl|
|
44
59
|
found = false
|
@@ -49,7 +64,7 @@ class Rights
|
|
49
64
|
args[:match] = match
|
50
65
|
if (res = acl.allowed?(args[:node], args[:ip], args)) != :dunno
|
51
66
|
# return early if we're allowed
|
52
|
-
return if res
|
67
|
+
return nil if res
|
53
68
|
# we matched, select this acl
|
54
69
|
found = true
|
55
70
|
end
|
@@ -70,13 +85,12 @@ class Rights
|
|
70
85
|
error.file = right.file
|
71
86
|
error.line = right.line
|
72
87
|
end
|
73
|
-
Puppet.warning("Denying access: #{error}")
|
74
88
|
else
|
75
89
|
# there were no rights allowing/denying name
|
76
90
|
# if name is not a path, let's throw
|
77
|
-
|
91
|
+
raise ArgumentError, "Unknown namespace right '#{name}'"
|
78
92
|
end
|
79
|
-
|
93
|
+
error
|
80
94
|
end
|
81
95
|
|
82
96
|
def initialize
|
data/lib/puppet/parser/ast.rb
CHANGED
@@ -139,12 +139,23 @@ class Puppet::Parser::Compiler
|
|
139
139
|
def evaluate_classes(classes, scope, lazy_evaluate = true)
|
140
140
|
raise Puppet::DevError, "No source for scope passed to evaluate_classes" unless scope.source
|
141
141
|
found = []
|
142
|
+
param_classes = nil
|
143
|
+
# if we are a param class, save the classes hash
|
144
|
+
# and transform classes to be the keys
|
145
|
+
if classes.class == Hash
|
146
|
+
param_classes = classes
|
147
|
+
classes = classes.keys
|
148
|
+
end
|
142
149
|
classes.each do |name|
|
143
150
|
# If we can find the class, then make a resource that will evaluate it.
|
144
151
|
if klass = scope.find_hostclass(name)
|
145
|
-
found << name and next if scope.class_scope(klass)
|
146
152
|
|
147
|
-
|
153
|
+
if param_classes
|
154
|
+
resource = klass.ensure_in_catalog(scope, param_classes[name] || {})
|
155
|
+
else
|
156
|
+
found << name and next if scope.class_scope(klass)
|
157
|
+
resource = klass.ensure_in_catalog(scope)
|
158
|
+
end
|
148
159
|
|
149
160
|
# If they've disabled lazy evaluation (which the :include function does),
|
150
161
|
# then evaluate our resource immediately.
|
@@ -432,7 +443,11 @@ class Puppet::Parser::Compiler
|
|
432
443
|
@resources = []
|
433
444
|
|
434
445
|
# Make sure any external node classes are in our class list
|
435
|
-
@
|
446
|
+
if @node.classes.class == Hash
|
447
|
+
@catalog.add_class(*@node.classes.keys)
|
448
|
+
else
|
449
|
+
@catalog.add_class(*@node.classes)
|
450
|
+
end
|
436
451
|
end
|
437
452
|
|
438
453
|
# Set the node's parameters into the top-scope as variables.
|
@@ -1,10 +1,32 @@
|
|
1
1
|
# Test whether a given class or definition is defined
|
2
|
-
Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether
|
3
|
+
a given class or resource type is defined. This function can also determine whether a
|
4
|
+
specific resource has been declared. Returns true or false. Accepts class names,
|
5
|
+
type names, and resource references.
|
6
|
+
|
7
|
+
The `defined` function checks both native and defined types, including types
|
8
|
+
provided as plugins via modules. Types and classes are both checked using their names:
|
9
|
+
|
10
|
+
defined(\"file\")
|
11
|
+
defined(\"customtype\")
|
12
|
+
defined(\"foo\")
|
13
|
+
defined(\"foo::bar\")
|
14
|
+
|
15
|
+
Resource declarations are checked using resource references, e.g.
|
16
|
+
`defined( File['/tmp/myfile'] )`. Checking whether a given resource
|
17
|
+
has been declared is, unfortunately, dependent on the parse order of
|
18
|
+
the configuration, and the following code will not work:
|
19
|
+
|
20
|
+
if defined(File['/tmp/foo']) {
|
21
|
+
notify(\"This configuration includes the /tmp/foo file.\")
|
22
|
+
}
|
23
|
+
file {\"/tmp/foo\":
|
24
|
+
ensure => present,
|
25
|
+
}
|
26
|
+
|
27
|
+
However, this order requirement refers to parse order only, and ordering of
|
28
|
+
resources in the configuration graph (e.g. with `before` or `require`) does not
|
29
|
+
affect the behavior of `defined`.") do |vals|
|
8
30
|
result = false
|
9
31
|
vals = [vals] unless vals.is_a?(Array)
|
10
32
|
vals.each do |val|
|
@@ -1,7 +1,10 @@
|
|
1
1
|
Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
|
2
|
-
"Generates random numbers based on the node's fqdn.
|
3
|
-
|
4
|
-
|
2
|
+
"Generates random numbers based on the node's fqdn. Generated random values
|
3
|
+
will be a range from 0 up to and excluding n, where n is the first parameter.
|
4
|
+
The second argument specifies a number to add to the seed and is optional, for example:
|
5
|
+
|
6
|
+
$random_number = fqdn_rand(30)
|
7
|
+
$random_number_seed = fqdn_rand(30,30)") do |args|
|
5
8
|
require 'md5'
|
6
9
|
max = args.shift
|
7
10
|
srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
|
data/lib/puppet/property.rb
CHANGED
@@ -152,9 +152,24 @@ class Puppet::Property < Puppet::Parameter
|
|
152
152
|
# since we cannot fix it. Otherwise, we expect our should value
|
153
153
|
# to be an array, and if @is matches any of those values, then
|
154
154
|
# we consider it to be in-sync.
|
155
|
-
|
155
|
+
#
|
156
|
+
# Don't override this method.
|
157
|
+
def safe_insync?(is)
|
158
|
+
# If there is no @should value, consider the property to be in sync.
|
156
159
|
return true unless @should
|
157
160
|
|
161
|
+
# Otherwise delegate to the (possibly derived) insync? method.
|
162
|
+
insync?(is)
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.method_added(sym)
|
166
|
+
raise "Puppet::Property#safe_insync? shouldn't be overridden; please override insync? instead" if sym == :safe_insync?
|
167
|
+
end
|
168
|
+
|
169
|
+
# This method should be overridden by derived classes if necessary
|
170
|
+
# to provide extra logic to determine whether the property is in
|
171
|
+
# sync.
|
172
|
+
def insync?(is)
|
158
173
|
self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array)
|
159
174
|
|
160
175
|
# an empty array is analogous to no should values
|
data/lib/puppet/property/list.rb
CHANGED
@@ -14,11 +14,9 @@ Puppet::Type.type(:maillist).provide(:mailman) do
|
|
14
14
|
|
15
15
|
# Return a list of existing mailman instances.
|
16
16
|
def self.instances
|
17
|
-
list_lists
|
18
|
-
|
19
|
-
|
20
|
-
new(:ensure => :present, :name => name, :description => description)
|
21
|
-
end
|
17
|
+
list_lists('--bare').
|
18
|
+
split("\n").
|
19
|
+
collect { |line| new(:ensure => :present, :name => line.strip) }
|
22
20
|
end
|
23
21
|
|
24
22
|
# Prefetch our list list, yo.
|