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.
- data/Gemfile +13 -11
- data/README.md +9 -7
- data/README_DEVELOPER.md +21 -30
- data/bin/extlookup2hiera +0 -0
- data/conf/auth.conf +42 -26
- data/conf/fileserver.conf +41 -0
- data/conf/tagmail.conf +16 -0
- data/examples/hiera/modules/data/manifests/common.pp +2 -1
- data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
- data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
- data/examples/hiera/modules/users/manifests/common.pp +2 -1
- data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
- data/examples/hiera/modules/users/manifests/development.pp +2 -1
- data/examples/hiera/site.pp +1 -1
- data/ext/debian/fileserver.conf +39 -15
- data/ext/envpuppet +2 -0
- data/ext/gentoo/puppet/fileserver.conf +41 -12
- data/ext/ips/puppet-agent +1 -6
- data/ext/ips/puppetagent.xml +0 -4
- data/ext/osx/postflight.erb +109 -0
- data/ext/project_data.yaml +2 -2
- data/ext/redhat/fileserver.conf +41 -12
- data/ext/redhat/puppet.spec.erb +8 -13
- data/install.rb +2 -5
- data/lib/puppet.rb +30 -13
- data/lib/puppet/application.rb +34 -16
- data/lib/puppet/application/agent.rb +4 -4
- data/lib/puppet/application/master.rb +25 -5
- data/lib/puppet/defaults.rb +11 -7
- data/lib/puppet/dsl.rb +7 -3
- data/lib/puppet/dsl/actions.rb +283 -0
- data/lib/puppet/dsl/blank_slate.rb +55 -0
- data/lib/puppet/dsl/context.rb +393 -0
- data/lib/puppet/dsl/parser.rb +57 -0
- data/lib/puppet/dsl/resource_decorator.rb +56 -0
- data/lib/puppet/dsl/resource_reference.rb +95 -0
- data/lib/puppet/dsl/type_reference.rb +102 -0
- data/lib/puppet/error.rb +1 -1
- data/lib/puppet/face/help.rb +2 -4
- data/lib/puppet/face/man.rb +8 -2
- data/lib/puppet/feature/pson.rb +1 -3
- data/lib/puppet/indirector/catalog/active_record.rb +3 -0
- data/lib/puppet/indirector/catalog/compiler.rb +1 -2
- data/lib/puppet/indirector/catalog/queue.rb +4 -0
- data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
- data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
- data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
- data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
- data/lib/puppet/indirector/certificate_status/file.rb +4 -0
- data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
- data/lib/puppet/indirector/facts/active_record.rb +3 -0
- data/lib/puppet/indirector/facts/couch.rb +3 -0
- data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
- data/lib/puppet/indirector/facts/store_configs.rb +3 -0
- data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
- data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
- data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
- data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
- data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
- data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
- data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
- data/lib/puppet/indirector/node/active_record.rb +3 -0
- data/lib/puppet/indirector/node/rest.rb +2 -2
- data/lib/puppet/indirector/node/store_configs.rb +3 -0
- data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
- data/lib/puppet/indirector/queue.rb +0 -1
- data/lib/puppet/indirector/request.rb +1 -2
- data/lib/puppet/indirector/resource/active_record.rb +4 -0
- data/lib/puppet/indirector/resource/ral.rb +3 -0
- data/lib/puppet/indirector/resource/rest.rb +3 -0
- data/lib/puppet/indirector/resource/store_configs.rb +3 -0
- data/lib/puppet/indirector/run/local.rb +3 -0
- data/lib/puppet/indirector/ssl_file.rb +16 -14
- data/lib/puppet/indirector/status/local.rb +3 -0
- data/lib/puppet/indirector/status/rest.rb +4 -0
- data/lib/puppet/interface.rb +78 -3
- data/lib/puppet/interface/action.rb +39 -3
- data/lib/puppet/interface/action_builder.rb +74 -1
- data/lib/puppet/interface/action_manager.rb +33 -3
- data/lib/puppet/interface/documentation.rb +116 -5
- data/lib/puppet/interface/face_collection.rb +6 -7
- data/lib/puppet/interface/option.rb +10 -1
- data/lib/puppet/interface/option_builder.rb +29 -1
- data/lib/puppet/interface/option_manager.rb +21 -6
- data/lib/puppet/metatype/manager.rb +47 -9
- data/lib/puppet/module_tool.rb +0 -1
- data/lib/puppet/network/formats.rb +0 -2
- data/lib/puppet/node.rb +2 -3
- data/lib/puppet/node/environment.rb +14 -1
- data/lib/puppet/parameter.rb +309 -44
- data/lib/puppet/parameter/package_options.rb +5 -0
- data/lib/puppet/parameter/path.rb +26 -3
- data/lib/puppet/parameter/value.rb +30 -6
- data/lib/puppet/parameter/value_collection.rb +82 -20
- data/lib/puppet/parser.rb +3 -0
- data/lib/puppet/parser/ast/definition.rb +2 -5
- data/lib/puppet/parser/ast/hostclass.rb +2 -3
- data/lib/puppet/parser/ast/node.rb +2 -5
- data/lib/puppet/parser/ast/resourceparam.rb +1 -1
- data/lib/puppet/parser/compiler.rb +10 -0
- data/lib/puppet/parser/functions.rb +111 -7
- data/lib/puppet/parser/functions/create_resources.rb +23 -2
- data/lib/puppet/parser/functions/defined.rb +1 -1
- data/lib/puppet/parser/functions/extlookup.rb +2 -1
- data/lib/puppet/parser/functions/fail.rb +1 -1
- data/lib/puppet/parser/functions/file.rb +1 -1
- data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
- data/lib/puppet/parser/functions/generate.rb +1 -1
- data/lib/puppet/parser/functions/hiera.rb +1 -1
- data/lib/puppet/parser/functions/hiera_array.rb +1 -1
- data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/include.rb +1 -1
- data/lib/puppet/parser/functions/inline_template.rb +1 -1
- data/lib/puppet/parser/functions/md5.rb +1 -1
- data/lib/puppet/parser/functions/realize.rb +1 -1
- data/lib/puppet/parser/functions/regsubst.rb +54 -57
- data/lib/puppet/parser/functions/require.rb +1 -0
- data/lib/puppet/parser/functions/search.rb +1 -1
- data/lib/puppet/parser/functions/sha1.rb +1 -1
- data/lib/puppet/parser/functions/shellquote.rb +1 -1
- data/lib/puppet/parser/functions/split.rb +1 -2
- data/lib/puppet/parser/functions/sprintf.rb +7 -10
- data/lib/puppet/parser/functions/tag.rb +1 -1
- data/lib/puppet/parser/functions/tagged.rb +1 -1
- data/lib/puppet/parser/functions/template.rb +1 -1
- data/lib/puppet/parser/functions/versioncmp.rb +1 -5
- data/lib/puppet/parser/parser_support.rb +11 -27
- data/lib/puppet/parser/scope.rb +48 -4
- data/lib/puppet/parser/type_loader.rb +31 -7
- data/lib/puppet/property.rb +304 -70
- data/lib/puppet/property/ensure.rb +14 -1
- data/lib/puppet/property/keyvalue.rb +17 -8
- data/lib/puppet/property/list.rb +3 -0
- data/lib/puppet/property/ordered_list.rb +7 -0
- data/lib/puppet/provider.rb +275 -53
- data/lib/puppet/provider/augeas/augeas.rb +17 -3
- data/lib/puppet/provider/confiner.rb +30 -1
- data/lib/puppet/provider/group/pw.rb +2 -2
- data/lib/puppet/provider/package/pip.rb +0 -1
- data/lib/puppet/provider/package/pkgin.rb +2 -0
- data/lib/puppet/provider/service/bsd.rb +1 -1
- data/lib/puppet/provider/service/freebsd.rb +10 -6
- data/lib/puppet/provider/service/init.rb +1 -1
- data/lib/puppet/provider/service/service.rb +1 -1
- data/lib/puppet/provider/user/pw.rb +2 -2
- data/lib/puppet/provider/user/useradd.rb +2 -3
- data/lib/puppet/reference/configuration.rb +6 -0
- data/lib/puppet/reports.rb +44 -4
- data/lib/puppet/reports/tagmail.rb +1 -1
- data/lib/puppet/resource.rb +38 -25
- data/lib/puppet/resource/type.rb +14 -6
- data/lib/puppet/settings.rb +66 -142
- data/lib/puppet/settings/config_file.rb +99 -0
- data/lib/puppet/settings/file_setting.rb +92 -24
- data/lib/puppet/settings/value_translator.rb +15 -0
- data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
- data/lib/puppet/test/test_helper.rb +8 -3
- data/lib/puppet/transaction.rb +1 -2
- data/lib/puppet/transaction/report.rb +122 -13
- data/lib/puppet/type.rb +763 -150
- data/lib/puppet/type/augeas.rb +4 -0
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/group.rb +1 -1
- data/lib/puppet/type/file/mode.rb +2 -0
- data/lib/puppet/type/file/selcontext.rb +1 -0
- data/lib/puppet/type/group.rb +12 -0
- data/lib/puppet/type/mount.rb +2 -2
- data/lib/puppet/type/notify.rb +1 -1
- data/lib/puppet/type/router.rb +1 -1
- data/lib/puppet/type/service.rb +1 -0
- data/lib/puppet/type/ssh_authorized_key.rb +3 -1
- data/lib/puppet/type/user.rb +8 -1
- data/lib/puppet/util.rb +8 -0
- data/lib/puppet/util/autoload.rb +7 -10
- data/lib/puppet/util/classgen.rb +58 -33
- data/lib/puppet/util/command_line.rb +120 -77
- data/lib/puppet/util/constant_inflector.rb +2 -0
- data/lib/puppet/util/execution.rb +63 -33
- data/lib/puppet/util/filetype.rb +1 -1
- data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
- data/lib/puppet/util/methodhelper.rb +19 -0
- data/lib/puppet/util/monkey_patches.rb +46 -0
- data/lib/puppet/util/plugins.rb +2 -2
- data/lib/puppet/util/provider_features.rb +24 -8
- data/lib/puppet/util/rubygems.rb +8 -1
- data/lib/puppet/util/zaml.rb +1 -1
- data/lib/puppet/version.rb +74 -3
- data/spec/integration/application/apply_spec.rb +1 -1
- data/spec/integration/defaults_spec.rb +1 -0
- data/spec/integration/dsl/classes_spec.rb +191 -0
- data/spec/integration/dsl/defaults_spec.rb +38 -0
- data/spec/integration/dsl/definitions_spec.rb +73 -0
- data/spec/integration/dsl/functions_spec.rb +95 -0
- data/spec/integration/dsl/nodes_spec.rb +96 -0
- data/spec/integration/dsl/params_spec.rb +146 -0
- data/spec/integration/dsl/relationships_spec.rb +46 -0
- data/spec/integration/dsl/resources_spec.rb +202 -0
- data/spec/integration/dsl/type_loading_spec.rb +64 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
- data/spec/integration/network/formats_spec.rb +32 -45
- data/spec/integration/parser/collector_spec.rb +105 -25
- data/spec/integration/parser/scope_spec.rb +64 -1
- data/spec/integration/resource/catalog_spec.rb +2 -4
- data/spec/integration/type/package_spec.rb +1 -1
- data/spec/lib/matchers/catalog.rb +50 -0
- data/spec/lib/puppet_spec/compiler.rb +11 -0
- data/spec/lib/puppet_spec/dsl.rb +29 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/unit/application/agent_spec.rb +0 -1
- data/spec/unit/application/apply_spec.rb +1 -1
- data/spec/unit/application/face_base_spec.rb +11 -4
- data/spec/unit/application/indirection_base_spec.rb +4 -8
- data/spec/unit/application/kick_spec.rb +5 -2
- data/spec/unit/application/master_spec.rb +0 -6
- data/spec/unit/application_spec.rb +38 -14
- data/spec/unit/dsl/actions_spec.rb +402 -0
- data/spec/unit/dsl/blank_slate_spec.rb +27 -0
- data/spec/unit/dsl/context_spec.rb +678 -0
- data/spec/unit/dsl/parser_spec.rb +56 -0
- data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
- data/spec/unit/dsl/resource_reference_spec.rb +150 -0
- data/spec/unit/dsl/type_reference_spec.rb +164 -0
- data/spec/unit/face/help_spec.rb +5 -7
- data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
- data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
- data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
- data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
- data/spec/unit/indirector/hiera_spec.rb +3 -1
- data/spec/unit/indirector/queue_spec.rb +1 -7
- data/spec/unit/indirector/ssl_file_spec.rb +66 -39
- data/spec/unit/module_spec.rb +1 -1
- data/spec/unit/network/authstore_spec.rb +22 -1
- data/spec/unit/network/formats_spec.rb +1 -1
- data/spec/unit/node/environment_spec.rb +13 -0
- data/spec/unit/parser/collector_spec.rb +1 -1
- data/spec/unit/parser/compiler_spec.rb +26 -0
- data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
- data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
- data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_spec.rb +1 -1
- data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
- data/spec/unit/parser/functions/split_spec.rb +4 -4
- data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
- data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
- data/spec/unit/parser/functions_spec.rb +51 -1
- data/spec/unit/parser/parser_spec.rb +0 -14
- data/spec/unit/parser/type_loader_spec.rb +15 -1
- data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
- data/spec/unit/provider/package/apt_spec.rb +0 -2
- data/spec/unit/provider/package/pip_spec.rb +12 -2
- data/spec/unit/provider/service/freebsd_spec.rb +8 -0
- data/spec/unit/provider/service/gentoo_spec.rb +20 -20
- data/spec/unit/provider/service/openrc_spec.rb +20 -20
- data/spec/unit/provider/service/src_spec.rb +4 -4
- data/spec/unit/provider/service/systemd_spec.rb +0 -8
- data/spec/unit/provider/service/windows_spec.rb +1 -1
- data/spec/unit/provider/user/useradd_spec.rb +2 -9
- data/spec/unit/relationship_spec.rb +2 -2
- data/spec/unit/resource/catalog_spec.rb +2 -2
- data/spec/unit/resource/type_spec.rb +49 -25
- data/spec/unit/resource_spec.rb +34 -2
- data/spec/unit/settings/config_file_spec.rb +100 -0
- data/spec/unit/settings/file_setting_spec.rb +87 -84
- data/spec/unit/settings/value_translator_spec.rb +77 -0
- data/spec/unit/settings_spec.rb +96 -29
- data/spec/unit/type/file/ensure_spec.rb +75 -36
- data/spec/unit/type/file_spec.rb +0 -68
- data/spec/unit/type/group_spec.rb +10 -0
- data/spec/unit/util/autoload_spec.rb +6 -0
- data/spec/unit/util/command_line_spec.rb +54 -62
- data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
- data/spec/unit/util/metric_spec.rb +0 -9
- data/spec/unit/util/posix_spec.rb +0 -4
- data/spec/unit/util/rdoc_spec.rb +0 -12
- data/spec/unit/util/zaml_spec.rb +188 -130
- data/spec/unit/version_spec.rb +42 -0
- metadata +123 -90
- data/README_HIERA.md +0 -148
- data/conf/epm.list +0 -8
- data/conf/namespaceauth.conf +0 -20
- data/conf/puppet-queue.conf +0 -10
- data/examples/allatonce +0 -13
- data/examples/assignments +0 -11
- data/examples/components +0 -73
- data/examples/etc/init.d/sleeper +0 -70
- data/examples/etc/otherfile +0 -0
- data/examples/etc/puppet/fileserver.conf +0 -13
- data/examples/etc/puppet/namespaceauth.conf +0 -20
- data/examples/etc/puppet/puppet.conf +0 -10
- data/examples/etc/puppet/tagmail.conf +0 -1
- data/examples/execs +0 -16
- data/examples/file.bl +0 -11
- data/examples/filedefaults +0 -10
- data/examples/fileparsing +0 -116
- data/examples/filerecursion +0 -15
- data/examples/functions +0 -3
- data/examples/groups +0 -7
- data/examples/head +0 -30
- data/examples/importing +0 -8
- data/examples/mac_dscl.pp +0 -28
- data/examples/mac_dscl_revert.pp +0 -26
- data/examples/mac_pkgdmg.pp +0 -7
- data/examples/modules/sample_module.pp +0 -10
- data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
- data/examples/modules/sample_module/manifests/init.pp +0 -12
- data/examples/modules/sample_module/templates/sample.erb +0 -5
- data/examples/nodes +0 -20
- data/examples/one +0 -8
- data/examples/relationships +0 -34
- data/examples/selectors +0 -28
- data/examples/simpletests +0 -11
- data/examples/svncommit +0 -13
- data/lib/puppet/dsl/resource_api.rb +0 -120
- data/lib/puppet/dsl/resource_type_api.rb +0 -34
- data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
- data/spec/unit/dsl/resource_api_spec.rb +0 -180
- data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -1,120 +0,0 @@
|
|
1
|
-
# This module adds functionality to a resource to make it
|
2
|
-
# capable of evaluating the DSL resource type block and also
|
3
|
-
# hooking into the scope system.
|
4
|
-
require 'puppet/resource/type_collection_helper'
|
5
|
-
|
6
|
-
class Puppet::DSL::ResourceAPI
|
7
|
-
include Puppet::Resource::TypeCollectionHelper
|
8
|
-
|
9
|
-
FUNCTION_MAP = {:acquire => :include}
|
10
|
-
|
11
|
-
attr_reader :scope, :resource, :block
|
12
|
-
|
13
|
-
def environment
|
14
|
-
scope.environment
|
15
|
-
end
|
16
|
-
|
17
|
-
def evaluate
|
18
|
-
set_instance_variables
|
19
|
-
instance_eval(&block)
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(resource, scope, block)
|
23
|
-
@scope = scope
|
24
|
-
@resource = resource
|
25
|
-
@block = block
|
26
|
-
end
|
27
|
-
|
28
|
-
# Try to convert a missing method into a resource type or a function.
|
29
|
-
def method_missing(name, *args)
|
30
|
-
raise "MethodMissing loop when searching for #{name} with #{args.inspect}" if searching_for_method?
|
31
|
-
@searching_for_method = true
|
32
|
-
return create_resource(name, args[0], args[1]) if valid_type?(name)
|
33
|
-
|
34
|
-
name = map_function(name)
|
35
|
-
|
36
|
-
return call_function(name, args) if Puppet::Parser::Functions.function(name)
|
37
|
-
|
38
|
-
super
|
39
|
-
ensure
|
40
|
-
@searching_for_method = false
|
41
|
-
end
|
42
|
-
|
43
|
-
def set_instance_variables
|
44
|
-
resource.eachparam do |param|
|
45
|
-
instance_variable_set("@#{param.name}", param.value)
|
46
|
-
end
|
47
|
-
@title = resource.title
|
48
|
-
@name ||= resource.title
|
49
|
-
end
|
50
|
-
|
51
|
-
def create_resource(type, names, arguments = nil)
|
52
|
-
names = [names] unless names.is_a?(Array)
|
53
|
-
|
54
|
-
arguments ||= {}
|
55
|
-
raise ArgumentError, "Resource arguments must be provided as a hash" unless arguments.is_a?(Hash)
|
56
|
-
|
57
|
-
names.collect do |name|
|
58
|
-
resource = Puppet::Parser::Resource.new(type, name, :scope => scope)
|
59
|
-
arguments.each do |param, value|
|
60
|
-
resource[param] = value
|
61
|
-
end
|
62
|
-
|
63
|
-
resource.exported = true if exporting?
|
64
|
-
resource.virtual = true if virtualizing?
|
65
|
-
scope.compiler.add_resource(scope, resource)
|
66
|
-
resource
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def call_function(name, args)
|
71
|
-
return false unless method = Puppet::Parser::Functions.function(name)
|
72
|
-
scope.send(method, *args)
|
73
|
-
end
|
74
|
-
|
75
|
-
def export(resources = nil, &block)
|
76
|
-
if resources
|
77
|
-
resources.each { |resource| resource.exported = true }
|
78
|
-
return resources
|
79
|
-
end
|
80
|
-
@exporting = true
|
81
|
-
instance_eval(&block)
|
82
|
-
ensure
|
83
|
-
@exporting = false
|
84
|
-
end
|
85
|
-
|
86
|
-
def virtual(resources = nil, &block)
|
87
|
-
if resources
|
88
|
-
resources.each { |resource| resource.virtual = true }
|
89
|
-
return resources
|
90
|
-
end
|
91
|
-
@virtualizing = true
|
92
|
-
instance_eval(&block)
|
93
|
-
ensure
|
94
|
-
@virtualizing = false
|
95
|
-
end
|
96
|
-
|
97
|
-
def valid_type?(name)
|
98
|
-
return true if [:class, :node].include?(name)
|
99
|
-
return true if Puppet::Type.type(name)
|
100
|
-
return(known_resource_types.definition(name) ? true : false)
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
def exporting?
|
106
|
-
@exporting
|
107
|
-
end
|
108
|
-
|
109
|
-
def map_function(name)
|
110
|
-
FUNCTION_MAP[name] || name
|
111
|
-
end
|
112
|
-
|
113
|
-
def searching_for_method?
|
114
|
-
@searching_for_method
|
115
|
-
end
|
116
|
-
|
117
|
-
def virtualizing?
|
118
|
-
@virtualizing
|
119
|
-
end
|
120
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'puppet/resource/type'
|
2
|
-
|
3
|
-
# Type of the objects inside of which pure ruby manifest files are
|
4
|
-
# executed. Provides methods for creating defines, hostclasses, and
|
5
|
-
# nodes.
|
6
|
-
class Puppet::DSL::ResourceTypeAPI
|
7
|
-
def initialize
|
8
|
-
@__created_ast_objects__ = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def define(name, *args, &block)
|
12
|
-
args = args.inject([]) do |result, item|
|
13
|
-
if item.is_a?(Hash)
|
14
|
-
item.each { |p, v| result << [p, v] }
|
15
|
-
else
|
16
|
-
result << item
|
17
|
-
end
|
18
|
-
result
|
19
|
-
end
|
20
|
-
@__created_ast_objects__.push Puppet::Parser::AST::Definition.new(name, {:arguments => args}, &block)
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def hostclass(name, options = {}, &block)
|
25
|
-
@__created_ast_objects__.push Puppet::Parser::AST::Hostclass.new(name, options, &block)
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def node(name, options = {}, &block)
|
30
|
-
name = [name] unless name.is_a?(Array)
|
31
|
-
@__created_ast_objects__.push Puppet::Parser::AST::Node.new(name, options, &block)
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'tempfile'
|
5
|
-
require 'puppet_spec/files'
|
6
|
-
|
7
|
-
describe "Pure ruby manifests" do
|
8
|
-
include PuppetSpec::Files
|
9
|
-
|
10
|
-
before do
|
11
|
-
@node = Puppet::Node.new "testnode"
|
12
|
-
|
13
|
-
@scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]'
|
14
|
-
@scope = stub 'scope', :resource => @scope_resource, :source => mock("source")
|
15
|
-
@test_dir = tmpdir('ruby_manifest_test')
|
16
|
-
end
|
17
|
-
|
18
|
-
after do
|
19
|
-
Puppet.settings.clear
|
20
|
-
end
|
21
|
-
|
22
|
-
def write_file(name, contents)
|
23
|
-
path = File.join(@test_dir, name)
|
24
|
-
File.open(path, "w") { |f| f.write(contents) }
|
25
|
-
path
|
26
|
-
end
|
27
|
-
|
28
|
-
def compile(contents)
|
29
|
-
Puppet[:code] = contents
|
30
|
-
Dir.chdir(@test_dir) do
|
31
|
-
Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should allow classes" do
|
36
|
-
write_file('foo.rb', ["hostclass 'one' do notify('one_notify') end",
|
37
|
-
"hostclass 'two' do notify('two_notify') end"].join("\n"))
|
38
|
-
catalog = compile("import 'foo'\ninclude one")
|
39
|
-
catalog.resource("Notify[one_notify]").should_not be_nil
|
40
|
-
catalog.resource("Notify[two_notify]").should be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should allow defines" do
|
44
|
-
write_file('foo.rb', 'define "bar", :arg do notify("bar_#{@name}_#{@arg}") end')
|
45
|
-
catalog = compile("import 'foo'\nbar { instance: arg => 'xyz' }")
|
46
|
-
catalog.resource("Notify[bar_instance_xyz]").should_not be_nil
|
47
|
-
catalog.resource("Bar[instance]").should_not be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should allow node declarations" do
|
51
|
-
write_file('foo.rb', "node 'mynode' do notify('mynode') end")
|
52
|
-
catalog = compile("import 'foo'")
|
53
|
-
node_declaration = catalog.resource("Notify[mynode]")
|
54
|
-
node_declaration.should_not be_nil
|
55
|
-
node_declaration.title.should == 'mynode'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should allow access to the environment" do
|
59
|
-
write_file('foo.rb', ["hostclass 'bar' do",
|
60
|
-
" if environment.is_a? Puppet::Node::Environment",
|
61
|
-
" notify('success')",
|
62
|
-
" end",
|
63
|
-
"end"].join("\n"))
|
64
|
-
compile("import 'foo'\ninclude bar").resource("Notify[success]").should_not be_nil
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should allow creation of resources of built-in types" do
|
68
|
-
write_file('foo.rb', "hostclass 'bar' do file 'test_file', :owner => 'root', :mode => '644' end")
|
69
|
-
catalog = compile("import 'foo'\ninclude bar")
|
70
|
-
file = catalog.resource("File[test_file]")
|
71
|
-
file.should be_a(Puppet::Resource)
|
72
|
-
file.type.should == 'File'
|
73
|
-
file.title.should == 'test_file'
|
74
|
-
file.exported.should_not be
|
75
|
-
file.virtual.should_not be
|
76
|
-
file[:owner].should == 'root'
|
77
|
-
file[:mode].should == '644'
|
78
|
-
file[:stage].should be_nil # TODO: is this correct behavior?
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should allow calling user-defined functions" do
|
82
|
-
write_file('foo.rb', "hostclass 'bar' do user_func 'name', :arg => 'xyz' end")
|
83
|
-
catalog = compile(['define user_func($arg) { notify {"n_$arg": } }',
|
84
|
-
'import "foo"',
|
85
|
-
'include bar'].join("\n"))
|
86
|
-
catalog.resource("Notify[n_xyz]").should_not be_nil
|
87
|
-
catalog.resource("User_func[name]").should_not be_nil
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should be properly cached for multiple compiles" do
|
91
|
-
# Note: we can't test this by calling compile() twice, because
|
92
|
-
# that sets Puppet[:code], which clears out all cached
|
93
|
-
# environments.
|
94
|
-
Puppet[:filetimeout] = 1000
|
95
|
-
write_file('foo.rb', "hostclass 'bar' do notify('success') end")
|
96
|
-
Puppet[:code] = "import 'foo'\ninclude bar"
|
97
|
-
|
98
|
-
# Compile the catalog and check it
|
99
|
-
catalog = Dir.chdir(@test_dir) do
|
100
|
-
Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
|
101
|
-
end
|
102
|
-
catalog.resource("Notify[success]").should_not be_nil
|
103
|
-
|
104
|
-
# Secretly change the file to make it invalid. This change
|
105
|
-
# shouldn't be noticed because the we've set a high
|
106
|
-
# Puppet[:filetimeout].
|
107
|
-
write_file('foo.rb', "raise 'should not be executed'")
|
108
|
-
|
109
|
-
# Compile the catalog a second time and make sure it's still ok.
|
110
|
-
catalog = Dir.chdir(@test_dir) do
|
111
|
-
Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
|
112
|
-
end
|
113
|
-
catalog.resource("Notify[success]").should_not be_nil
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should be properly reloaded when stale" do
|
117
|
-
Puppet[:filetimeout] = -1 # force stale check to happen all the time
|
118
|
-
write_file('foo.rb', "hostclass 'bar' do notify('version1') end")
|
119
|
-
catalog = compile("import 'foo'\ninclude bar")
|
120
|
-
catalog.resource("Notify[version1]").should_not be_nil
|
121
|
-
sleep 1 # so that timestamp will change forcing file reload
|
122
|
-
write_file('foo.rb', "hostclass 'bar' do notify('version2') end")
|
123
|
-
catalog = compile("import 'foo'\ninclude bar")
|
124
|
-
catalog.resource("Notify[version1]").should be_nil
|
125
|
-
catalog.resource("Notify[version2]").should_not be_nil
|
126
|
-
end
|
127
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'puppet/dsl/resource_api'
|
5
|
-
|
6
|
-
describe Puppet::DSL::ResourceAPI do
|
7
|
-
before do
|
8
|
-
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
|
9
|
-
@scope = Puppet::Parser::Scope.new(@compiler, :source => "foo")
|
10
|
-
@resource = Puppet::Parser::Resource.new(:mytype, "myresource", :scope => @scope)
|
11
|
-
@api = Puppet::DSL::ResourceAPI.new(@resource, @scope, proc { })
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should include the resource type collection helper" do
|
15
|
-
Puppet::DSL::ResourceAPI.ancestors.should be_include(Puppet::Resource::TypeCollectionHelper)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should use the scope's environment as its environment" do
|
19
|
-
@scope.expects(:environment).returns "myenv"
|
20
|
-
@api.environment.should == "myenv"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should be able to set all of its parameters as instance variables" do
|
24
|
-
@resource["foo"] = "myval"
|
25
|
-
@api.set_instance_variables
|
26
|
-
@api.instance_variable_get("@foo").should == "myval"
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "when calling a function" do
|
30
|
-
it "should return false if the function does not exist" do
|
31
|
-
Puppet::Parser::Functions.expects(:function).with("myfunc").returns nil
|
32
|
-
@api.call_function("myfunc", "foo").should be_false
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should use the scope the call the provided function with the provided arguments and return the results" do
|
36
|
-
scope = stub 'scope'
|
37
|
-
@api.stubs(:scope).returns scope
|
38
|
-
Puppet::Parser::Functions.expects(:function).with("myfunc").returns "myfunc_method"
|
39
|
-
|
40
|
-
scope.expects(:myfunc_method).with("one", "two")
|
41
|
-
@api.call_function("myfunc", ["one", "two"])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should call 'include' when asked to call 'acquire'" do
|
45
|
-
scope = stub 'scope'
|
46
|
-
@api.stubs(:scope).returns scope
|
47
|
-
@api.stubs(:valid_type?).returns false
|
48
|
-
|
49
|
-
scope.expects(:function_include).with("one", "two")
|
50
|
-
@api.acquire("one", "two")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "when determining if a provided name is a valid type" do
|
55
|
-
it "should be valid if it's :class" do
|
56
|
-
@api.should be_valid_type(:class)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be valid if it's :node" do
|
60
|
-
@api.should be_valid_type(:node)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should be valid if it's a builtin type" do
|
64
|
-
Puppet::Type.expects(:type).with(:mytype).returns "whatever"
|
65
|
-
@api.should be_valid_type(:mytype)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should be valid if it's a defined resource type in the environment's known resource types" do
|
69
|
-
collection = stub 'collection'
|
70
|
-
@api.stubs(:known_resource_types).returns collection
|
71
|
-
collection.expects(:definition).with(:mytype).returns "whatever"
|
72
|
-
@api.should be_valid_type(:mytype)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not be valid unless it's a node, class, builtin type, or defined resource" do
|
76
|
-
collection = stub 'collection'
|
77
|
-
@api.stubs(:known_resource_types).returns collection
|
78
|
-
collection.expects(:definition).returns nil
|
79
|
-
Puppet::Type.expects(:type).returns nil
|
80
|
-
@api.should_not be_valid_type(:mytype)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "when creating a resource" do
|
85
|
-
before do
|
86
|
-
@api.scope.stubs(:source).returns stub("source")
|
87
|
-
@api.scope.compiler.stubs(:add_resource)
|
88
|
-
@created_resource = Puppet::Parser::Resource.new("yay", "eh", :scope => @api.scope)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should create and return a resource of the type specified" do
|
92
|
-
Puppet::Parser::Resource.expects(:new).with { |type, title, args| type == "mytype" }.returns @created_resource
|
93
|
-
@api.create_resource("mytype", "myname", {:foo => "bar"}).should == [@created_resource]
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should use the name from the first element of the provided argument array" do
|
97
|
-
Puppet::Parser::Resource.expects(:new).with { |type, title, args| title == "myname" }.returns @created_resource
|
98
|
-
@api.create_resource("mytype", "myname", {:foo => "bar"})
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should create multiple resources if the first element of the argument array is an array" do
|
102
|
-
second_resource = Puppet::Parser::Resource.new('yay', "eh", :scope => @api.scope)
|
103
|
-
Puppet::Parser::Resource.expects(:new).with { |type, title, args| title == "first" }.returns @created_resource
|
104
|
-
Puppet::Parser::Resource.expects(:new).with { |type, title, args| title == "second" }.returns @created_resource
|
105
|
-
@api.create_resource("mytype", ["first", "second"], {:foo => "bar"})
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should provide its scope as the scope" do
|
109
|
-
Puppet::Parser::Resource.expects(:new).with { |type, title, args| args[:scope] == @api.scope }.returns @created_resource
|
110
|
-
@api.create_resource("mytype", "myname", {:foo => "bar"})
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should set each provided argument as a parameter on the created resource" do
|
114
|
-
result = @api.create_resource("mytype", "myname", {"foo" => "bar", "biz" => "baz"}).shift
|
115
|
-
result["foo"].should == "bar"
|
116
|
-
result["biz"].should == "baz"
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should add the resource to the scope's copmiler" do
|
120
|
-
Puppet::Parser::Resource.expects(:new).returns @created_resource
|
121
|
-
@api.scope.compiler.expects(:add_resource).with(@api.scope, @created_resource)
|
122
|
-
@api.create_resource("mytype", "myname", {:foo => "bar"})
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should fail if the resource parameters are not a hash" do
|
126
|
-
lambda { @api.create_resource("mytype", "myname", %w{foo bar}) }.should raise_error(ArgumentError)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "when an unknown method is called" do
|
131
|
-
it "should create a resource if the method name is a valid type" do
|
132
|
-
@api.expects(:valid_type?).with(:mytype).returns true
|
133
|
-
@api.expects(:create_resource).with(:mytype, "myname", {:foo => "bar"}).returns true
|
134
|
-
|
135
|
-
@api.mytype("myname", :foo => "bar")
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should call any function whose name matches the undefined method if the name is not a valid type" do
|
139
|
-
@api.expects(:valid_type?).with(:myfunc).returns false
|
140
|
-
@api.expects(:create_resource).never
|
141
|
-
|
142
|
-
Puppet::Parser::Functions.expects(:function).with(:myfunc).returns true
|
143
|
-
|
144
|
-
@api.expects(:call_function).with(:myfunc, %w{foo bar})
|
145
|
-
|
146
|
-
@api.myfunc("foo", "bar")
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should raise a method missing error if the method is neither a type nor a function" do
|
150
|
-
@api.expects(:valid_type?).with(:myfunc).returns false
|
151
|
-
@api.expects(:create_resource).never
|
152
|
-
|
153
|
-
Puppet::Parser::Functions.expects(:function).with(:myfunc).returns false
|
154
|
-
|
155
|
-
@api.expects(:call_function).never
|
156
|
-
|
157
|
-
lambda { @api.myfunc("foo", "bar") }.should raise_error(NoMethodError)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should mark the specified resource as exported when creating a single exported resource" do
|
162
|
-
resources = @api.export @api.file("/my/file", :ensure => :present)
|
163
|
-
resources[0].should be_exported
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should mark all created resources as exported when creating exported resources using a block" do
|
167
|
-
@compiler.expects(:add_resource).with { |s, res| res.exported == true }
|
168
|
-
@api.export { file "/my/file", :ensure => :present }
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should mark the specified resource as virtual when creating a single virtual resource" do
|
172
|
-
resources = @api.virtual @api.file("/my/file", :ensure => :present)
|
173
|
-
resources[0].should be_virtual
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should mark all created resources as virtual when creating virtual resources using a block" do
|
177
|
-
@compiler.expects(:add_resource).with { |s, res| res.virtual == true }
|
178
|
-
@api.virtual { file "/my/file", :ensure => :present }
|
179
|
-
end
|
180
|
-
end
|