puppet 3.2.4 → 3.3.0.rc2
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/COMMITTERS.md +101 -42
- data/Gemfile +15 -4
- data/README.md +5 -1
- data/README_DEVELOPER.md +117 -54
- data/Rakefile +4 -0
- data/ext/build_defaults.yaml +3 -2
- data/ext/debian/puppet-common.manpages +33 -1
- data/ext/gentoo/init.d/puppet +1 -1
- data/ext/gentoo/init.d/puppetmaster +1 -1
- data/ext/redhat/puppet.spec.erb +0 -1
- data/install.rb +2 -1
- data/lib/hiera/backend/puppet_backend.rb +1 -1
- data/lib/puppet/application.rb +10 -9
- data/lib/puppet/application/agent.rb +87 -93
- data/lib/puppet/application/apply.rb +0 -2
- data/lib/puppet/application/device.rb +3 -3
- data/lib/puppet/application/kick.rb +2 -2
- data/lib/puppet/application/master.rb +41 -19
- data/lib/puppet/application/queue.rb +5 -3
- data/lib/puppet/bindings.rb +147 -0
- data/lib/puppet/configurer.rb +25 -15
- data/lib/puppet/configurer/fact_handler.rb +2 -9
- data/lib/puppet/daemon.rb +44 -33
- data/lib/puppet/defaults.rb +57 -26
- data/lib/puppet/error.rb +1 -1
- data/lib/puppet/external/dot.rb +2 -2
- data/lib/puppet/external/nagios/base.rb +1 -6
- data/lib/puppet/external/pson/common.rb +2 -2
- data/lib/puppet/external/pson/pure/generator.rb +2 -2
- data/lib/puppet/external/pson/pure/parser.rb +1 -1
- data/lib/puppet/face/ca.rb +1 -1
- data/lib/puppet/face/config.rb +1 -1
- data/lib/puppet/face/help.rb +2 -2
- data/lib/puppet/face/module/list.rb +2 -2
- data/lib/puppet/feature/rails.rb +1 -1
- data/lib/puppet/file_bucket/dipper.rb +0 -1
- data/lib/puppet/file_serving/base.rb +1 -1
- data/lib/puppet/file_serving/configuration/parser.rb +20 -14
- data/lib/puppet/forge.rb +0 -32
- data/lib/puppet/forge/cache.rb +1 -1
- data/lib/puppet/forge/errors.rb +3 -3
- data/lib/puppet/forge/repository.rb +7 -42
- data/lib/puppet/graph.rb +11 -0
- data/lib/puppet/graph/key.rb +26 -0
- data/lib/puppet/graph/prioritizer.rb +29 -0
- data/lib/puppet/graph/random_prioritizer.rb +16 -0
- data/lib/puppet/{rb_tree_map.rb → graph/rb_tree_map.rb} +3 -3
- data/lib/puppet/graph/relationship_graph.rb +246 -0
- data/lib/puppet/graph/sequential_prioritizer.rb +31 -0
- data/lib/puppet/{simple_graph.rb → graph/simple_graph.rb} +22 -3
- data/lib/puppet/graph/title_hash_prioritizer.rb +16 -0
- data/lib/puppet/indirector.rb +2 -2
- data/lib/puppet/indirector/catalog/compiler.rb +10 -7
- data/lib/puppet/indirector/catalog/static_compiler.rb +50 -0
- data/lib/puppet/indirector/certificate/rest.rb +1 -1
- data/lib/puppet/indirector/exec.rb +1 -1
- data/lib/puppet/indirector/facts/facter.rb +2 -2
- data/lib/puppet/indirector/facts/inventory_active_record.rb +0 -1
- data/lib/puppet/indirector/facts/network_device.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +0 -1
- data/lib/puppet/indirector/indirection.rb +2 -2
- data/lib/puppet/indirector/memory.rb +9 -0
- data/lib/puppet/indirector/node/ldap.rb +2 -4
- data/lib/puppet/indirector/report/processor.rb +1 -2
- data/lib/puppet/indirector/report/rest.rb +1 -1
- data/lib/puppet/indirector/request.rb +32 -10
- data/lib/puppet/indirector/resource/rest.rb +1 -1
- data/lib/puppet/indirector/resource_type/parser.rb +31 -12
- data/lib/puppet/interface.rb +1 -1
- data/lib/puppet/interface/documentation.rb +7 -11
- data/lib/puppet/interface/option.rb +1 -1
- data/lib/puppet/interface/option_builder.rb +1 -1
- data/lib/puppet/metatype/manager.rb +2 -2
- data/lib/puppet/module.rb +7 -1
- data/lib/puppet/module_tool.rb +1 -1
- data/lib/puppet/module_tool/applications/application.rb +10 -0
- data/lib/puppet/module_tool/applications/installer.rb +6 -3
- data/lib/puppet/module_tool/dependency.rb +2 -0
- data/lib/puppet/module_tool/errors/upgrader.rb +1 -1
- data/lib/puppet/module_tool/metadata.rb +25 -13
- data/lib/puppet/module_tool/modulefile.rb +7 -7
- data/lib/puppet/module_tool/shared_behaviors.rb +4 -2
- data/lib/puppet/module_tool/skeleton.rb +1 -1
- data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +5 -5
- data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +5 -4
- data/lib/puppet/network/auth_config_parser.rb +3 -0
- data/lib/puppet/network/authconfig.rb +0 -1
- data/lib/puppet/network/authorization.rb +1 -1
- data/lib/puppet/network/authstore.rb +2 -2
- data/lib/puppet/network/format_handler.rb +25 -114
- data/lib/puppet/network/format_support.rb +106 -0
- data/lib/puppet/network/formats.rb +10 -4
- data/lib/puppet/network/http/compression.rb +1 -1
- data/lib/puppet/network/http/connection.rb +76 -32
- data/lib/puppet/network/http/handler.rb +122 -61
- data/lib/puppet/network/http/rack/rest.rb +1 -1
- data/lib/puppet/network/http/webrick/rest.rb +9 -3
- data/lib/puppet/network/http_pool.rb +2 -2
- data/lib/puppet/network/resolver.rb +1 -0
- data/lib/puppet/network/server.rb +5 -81
- data/lib/puppet/node/environment.rb +256 -13
- data/lib/puppet/node/facts.rb +28 -2
- data/lib/puppet/parameter.rb +27 -18
- data/lib/puppet/parameter/boolean.rb +20 -0
- data/lib/puppet/parameter/path.rb +1 -1
- data/lib/puppet/parameter/value.rb +1 -1
- data/lib/puppet/parameter/value_collection.rb +1 -1
- data/lib/puppet/parser/ast/arithmetic_operator.rb +8 -0
- data/lib/puppet/parser/ast/casestatement.rb +0 -3
- data/lib/puppet/parser/ast/lambda.rb +25 -6
- data/lib/puppet/parser/ast/leaf.rb +10 -3
- data/lib/puppet/parser/ast/nop.rb +1 -1
- data/lib/puppet/parser/ast/resource_override.rb +0 -2
- data/lib/puppet/parser/compiler.rb +92 -34
- data/lib/puppet/parser/files.rb +0 -5
- data/lib/puppet/parser/functions/create_resources.rb +23 -46
- data/lib/puppet/parser/functions/each.rb +0 -2
- data/lib/puppet/parser/functions/extlookup.rb +2 -2
- data/lib/puppet/parser/functions/foreach.rb +0 -2
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/lookup.rb +44 -0
- data/lib/puppet/parser/functions/slice.rb +1 -1
- data/lib/puppet/parser/grammar.ra +0 -1
- data/lib/puppet/parser/lexer.rb +0 -1
- data/lib/puppet/parser/parser.rb +0 -1
- data/lib/puppet/parser/parser_factory.rb +3 -2
- data/lib/puppet/parser/parser_support.rb +1 -1
- data/lib/puppet/parser/relationship.rb +1 -1
- data/lib/puppet/parser/scope.rb +49 -24
- data/lib/puppet/parser/type_loader.rb +13 -18
- data/lib/puppet/pops.rb +45 -0
- data/lib/puppet/pops/adaptable.rb +2 -2
- data/lib/puppet/pops/adapters.rb +4 -0
- data/lib/puppet/pops/binder/binder.rb +421 -0
- data/lib/puppet/pops/binder/binder_issues.rb +142 -0
- data/lib/puppet/pops/binder/bindings_checker.rb +217 -0
- data/lib/puppet/pops/binder/bindings_composer.rb +241 -0
- data/lib/puppet/pops/binder/bindings_factory.rb +847 -0
- data/lib/puppet/pops/binder/bindings_label_provider.rb +46 -0
- data/lib/puppet/pops/binder/bindings_loader.rb +79 -0
- data/lib/puppet/pops/binder/bindings_model.rb +215 -0
- data/lib/puppet/pops/binder/bindings_model_dumper.rb +205 -0
- data/lib/puppet/pops/binder/bindings_validator_factory.rb +28 -0
- data/lib/puppet/pops/binder/config/binder_config.rb +139 -0
- data/lib/puppet/pops/binder/config/binder_config_checker.rb +183 -0
- data/lib/puppet/pops/binder/config/diagnostic_producer.rb +32 -0
- data/lib/puppet/pops/binder/config/issues.rb +106 -0
- data/lib/puppet/pops/binder/hiera2.rb +10 -0
- data/lib/puppet/pops/binder/hiera2/bindings_provider.rb +148 -0
- data/lib/puppet/pops/binder/hiera2/config.rb +69 -0
- data/lib/puppet/pops/binder/hiera2/config_checker.rb +68 -0
- data/lib/puppet/pops/binder/hiera2/diagnostic_producer.rb +36 -0
- data/lib/puppet/pops/binder/hiera2/issues.rb +67 -0
- data/lib/puppet/pops/binder/hiera2/json_backend.rb +18 -0
- data/lib/puppet/pops/binder/hiera2/yaml_backend.rb +21 -0
- data/lib/puppet/pops/binder/injector.rb +688 -0
- data/lib/puppet/pops/binder/injector_entry.rb +53 -0
- data/lib/puppet/pops/binder/key_factory.rb +61 -0
- data/lib/puppet/pops/binder/producers.rb +829 -0
- data/lib/puppet/pops/binder/scheme_handler/confdir_hiera_scheme.rb +67 -0
- data/lib/puppet/pops/binder/scheme_handler/confdir_scheme.rb +34 -0
- data/lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb +92 -0
- data/lib/puppet/pops/binder/scheme_handler/module_scheme.rb +84 -0
- data/lib/puppet/pops/binder/scheme_handler/symbolic_scheme.rb +54 -0
- data/lib/puppet/pops/binder/system_bindings.rb +72 -0
- data/lib/puppet/pops/issue_reporter.rb +75 -0
- data/lib/puppet/pops/issues.rb +9 -5
- data/lib/puppet/pops/model/ast_transformer.rb +4 -4
- data/lib/puppet/pops/model/ast_tree_dumper.rb +1 -1
- data/lib/puppet/pops/model/factory.rb +25 -13
- data/lib/puppet/pops/model/model.rb +1 -1
- data/lib/puppet/pops/model/tree_dumper.rb +2 -2
- data/lib/puppet/pops/parser/egrammar.ra +0 -1
- data/lib/puppet/pops/parser/eparser.rb +1 -2
- data/lib/puppet/pops/parser/evaluating_parser.rb +162 -0
- data/lib/puppet/pops/parser/lexer.rb +8 -6
- data/lib/puppet/pops/types/class_loader.rb +118 -0
- data/lib/puppet/pops/types/type_calculator.rb +557 -0
- data/lib/puppet/pops/types/type_factory.rb +147 -0
- data/lib/puppet/pops/types/type_parser.rb +117 -0
- data/lib/puppet/pops/types/types.rb +132 -0
- data/lib/puppet/pops/validation.rb +146 -17
- data/lib/puppet/pops/validation/checker3_1.rb +1 -1
- data/lib/puppet/pops/validation/validator_factory_3_1.rb +6 -16
- data/lib/puppet/property.rb +3 -3
- data/lib/puppet/property/keyvalue.rb +1 -1
- data/lib/puppet/provider.rb +2 -2
- data/lib/puppet/provider/aixobject.rb +19 -21
- data/lib/puppet/provider/augeas/augeas.rb +3 -1
- data/lib/puppet/provider/command.rb +2 -2
- data/lib/puppet/provider/group/aix.rb +1 -1
- data/lib/puppet/provider/group/ldap.rb +1 -1
- data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
- data/lib/puppet/provider/mailalias/aliases.rb +3 -8
- data/lib/puppet/provider/mcx/mcxcontent.rb +7 -1
- data/lib/puppet/provider/mount.rb +8 -3
- data/lib/puppet/provider/nameservice.rb +1 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +5 -5
- data/lib/puppet/provider/package/appdmg.rb +1 -1
- data/lib/puppet/provider/package/apt.rb +0 -1
- data/lib/puppet/provider/package/dpkg.rb +86 -32
- data/lib/puppet/provider/package/fink.rb +0 -2
- data/lib/puppet/provider/package/freebsd.rb +0 -2
- data/lib/puppet/provider/package/openbsd.rb +57 -10
- data/lib/puppet/provider/package/opkg.rb +0 -1
- data/lib/puppet/provider/package/pacman.rb +0 -1
- data/lib/puppet/provider/package/pip.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +17 -6
- data/lib/puppet/provider/package/pkgutil.rb +1 -1
- data/lib/puppet/provider/package/portage.rb +9 -1
- data/lib/puppet/provider/package/ports.rb +2 -2
- data/lib/puppet/provider/package/rpm.rb +29 -12
- data/lib/puppet/provider/package/rug.rb +1 -1
- data/lib/puppet/provider/package/urpmi.rb +11 -15
- data/lib/puppet/provider/package/windows/exe_package.rb +1 -1
- data/lib/puppet/provider/package/windows/package.rb +1 -26
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/package/zypper.rb +22 -3
- data/lib/puppet/provider/parsedfile.rb +1 -12
- data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +1 -1
- data/lib/puppet/provider/service/base.rb +1 -1
- data/lib/puppet/provider/service/daemontools.rb +3 -3
- data/lib/puppet/provider/service/debian.rb +1 -1
- data/lib/puppet/provider/service/init.rb +14 -20
- data/lib/puppet/provider/service/openrc.rb +3 -1
- data/lib/puppet/provider/service/redhat.rb +5 -8
- data/lib/puppet/provider/service/runit.rb +3 -2
- data/lib/puppet/provider/service/systemd.rb +1 -1
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
- data/lib/puppet/provider/sshkey/parsed.rb +0 -2
- data/lib/puppet/provider/user/aix.rb +25 -12
- data/lib/puppet/provider/user/directoryservice.rb +4 -7
- data/lib/puppet/provider/user/ldap.rb +0 -1
- data/lib/puppet/provider/user/user_role_add.rb +2 -0
- data/lib/puppet/provider/user/useradd.rb +1 -1
- data/lib/puppet/provider/zone/solaris.rb +1 -2
- data/lib/puppet/reference/metaparameter.rb +1 -1
- data/lib/puppet/reference/type.rb +1 -1
- data/lib/puppet/reports/rrdgraph.rb +1 -1
- data/lib/puppet/reports/tagmail.rb +1 -1
- data/lib/puppet/resource.rb +16 -4
- data/lib/puppet/resource/catalog.rb +111 -173
- data/lib/puppet/resource/status.rb +42 -3
- data/lib/puppet/resource/type.rb +33 -46
- data/lib/puppet/resource/type_collection.rb +19 -15
- data/lib/puppet/run.rb +5 -1
- data/lib/puppet/scheduler/scheduler.rb +14 -15
- data/lib/puppet/settings.rb +78 -41
- data/lib/puppet/settings/boolean_setting.rb +0 -2
- data/lib/puppet/settings/config_file.rb +0 -2
- data/lib/puppet/settings/directory_setting.rb +0 -2
- data/lib/puppet/settings/duration_setting.rb +0 -2
- data/lib/puppet/settings/enum_setting.rb +16 -0
- data/lib/puppet/settings/file_setting.rb +0 -2
- data/lib/puppet/settings/path_setting.rb +0 -2
- data/lib/puppet/settings/string_setting.rb +0 -3
- data/lib/puppet/settings/terminus_setting.rb +0 -2
- data/lib/puppet/ssl/certificate_authority.rb +102 -9
- data/lib/puppet/test/test_helper.rb +1 -0
- data/lib/puppet/transaction.rb +130 -292
- data/lib/puppet/transaction/additional_resource_generator.rb +126 -0
- data/lib/puppet/transaction/event.rb +16 -1
- data/lib/puppet/transaction/report.rb +34 -14
- data/lib/puppet/transaction/resource_harness.rb +16 -19
- data/lib/puppet/type.rb +59 -53
- data/lib/puppet/type/component.rb +0 -2
- data/lib/puppet/type/cron.rb +13 -2
- data/lib/puppet/type/exec.rb +5 -7
- data/lib/puppet/type/file.rb +9 -32
- data/lib/puppet/type/file/content.rb +4 -1
- data/lib/puppet/type/file/ctime.rb +3 -1
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +0 -1
- data/lib/puppet/type/file/mtime.rb +2 -1
- data/lib/puppet/type/group.rb +7 -9
- data/lib/puppet/type/host.rb +1 -2
- data/lib/puppet/type/mcx.rb +0 -1
- data/lib/puppet/type/mount.rb +38 -6
- data/lib/puppet/type/package.rb +2 -2
- data/lib/puppet/type/resources.rb +5 -4
- data/lib/puppet/type/schedule.rb +1 -4
- data/lib/puppet/type/selmodule.rb +1 -1
- data/lib/puppet/type/service.rb +1 -3
- data/lib/puppet/type/tidy.rb +3 -3
- data/lib/puppet/type/user.rb +9 -13
- data/lib/puppet/type/yumrepo.rb +11 -7
- data/lib/puppet/util.rb +14 -7
- data/lib/puppet/util/autoload.rb +0 -1
- data/lib/puppet/util/backups.rb +1 -3
- data/lib/puppet/util/classgen.rb +1 -1
- data/lib/puppet/util/command_line/puppet_option_parser.rb +1 -3
- data/lib/puppet/util/command_line/trollop.rb +1 -1
- data/lib/puppet/util/constant_inflector.rb +1 -2
- data/lib/puppet/util/errors.rb +1 -0
- data/lib/puppet/util/file_watcher.rb +28 -0
- data/lib/puppet/util/fileparsing.rb +1 -3
- data/lib/puppet/util/filetype.rb +0 -1
- data/lib/puppet/util/http_proxy.rb +38 -0
- data/lib/puppet/util/ldap/manager.rb +1 -2
- data/lib/puppet/util/log.rb +31 -10
- data/lib/puppet/util/log/destinations.rb +0 -50
- data/lib/puppet/util/metric.rb +8 -1
- data/lib/puppet/util/monkey_patches.rb +14 -148
- data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
- data/lib/puppet/util/network_device/config.rb +6 -9
- data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
- data/lib/puppet/util/pidlock.rb +3 -0
- data/lib/puppet/util/posix.rb +1 -1
- data/lib/puppet/util/profiler.rb +1 -1
- data/lib/puppet/util/rdoc.rb +1 -1
- data/lib/puppet/util/rdoc/generators/puppet_generator.rb +0 -1
- data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +50 -42
- data/lib/puppet/util/retryaction.rb +0 -1
- data/lib/puppet/util/symbolic_file_mode.rb +5 -1
- data/lib/puppet/util/tagging.rb +0 -2
- data/lib/puppet/util/warnings.rb +3 -0
- data/lib/puppet/util/watched_file.rb +37 -0
- data/lib/puppet/util/watcher.rb +17 -0
- data/lib/puppet/util/watcher/change_watcher.rb +33 -0
- data/lib/puppet/util/watcher/periodic_watcher.rb +37 -0
- data/lib/puppet/util/watcher/timer.rb +19 -0
- data/lib/puppet/util/windows/user.rb +1 -1
- data/lib/puppet/version.rb +1 -1
- data/lib/puppetx.rb +109 -0
- data/lib/puppetx/puppet/bindings_scheme_handler.rb +130 -0
- data/lib/puppetx/puppet/hiera2_backend.rb +31 -0
- data/lib/puppetx/puppet/syntax_checker.rb +91 -0
- data/lib/puppetx/puppetlabs/syntax_checkers/json.rb +39 -0
- data/lib/semver.rb +1 -1
- data/man/man8/puppet-kick.8 +1 -1
- data/spec/fixtures/integration/provider/cron/crontab/unspecialized +15 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/binder_config.yaml +18 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/hiera.yaml +10 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/binder_config.yaml +19 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/hiera.yaml +11 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/localhost.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/common.yaml +3 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/hiera.yaml +13 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppet/bindings/awesome/default.rb +4 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppetx/awesome/echo_backend.rb +11 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppetx/awesome/echo_scheme_handler.rb +18 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/localhost.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/common.yaml +3 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/hiera_config.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/common.yaml +2 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/hiera.yaml +11 -0
- data/spec/fixtures/unit/pops/binder/config/binder_config/ok/binder_config.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/hiera.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.json +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.yaml +5 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/bad_syntax/hiera.yaml +10 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/malformed_hierarchy/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/missing/foo.txt +1 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/no_backends/hiera.yaml +7 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/no_hierarchy/hiera.yaml +4 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/not_a_hash/hiera.yaml +2 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/ok/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/empty/common.yaml +0 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/invalid/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/ok/common.yaml +2 -0
- data/spec/fixtures/unit/provider/package/openbsd/pkginfo_flavors.list +2 -0
- data/spec/integration/agent/logging_spec.rb +178 -0
- data/spec/integration/configurer_spec.rb +1 -1
- data/spec/integration/defaults_spec.rb +0 -6
- data/spec/integration/network/authconfig_spec.rb +19 -0
- data/spec/integration/network/server/webrick_spec.rb +10 -11
- data/spec/integration/parser/catalog_spec.rb +85 -0
- data/spec/integration/provider/cron/crontab_spec.rb +11 -0
- data/spec/integration/provider/mount_spec.rb +1 -0
- data/spec/integration/transaction_spec.rb +8 -8
- data/spec/integration/type/file_spec.rb +1 -1
- data/spec/integration/util/settings_spec.rb +58 -11
- data/spec/lib/matchers/include_in_order.rb +21 -0
- data/spec/lib/matchers/include_in_order_spec.rb +30 -0
- data/spec/lib/matchers/relationship_graph_matchers.rb +48 -0
- data/spec/lib/puppet_spec/compiler.rb +24 -0
- data/spec/lib/puppet_spec/pops.rb +16 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/application/agent_spec.rb +145 -145
- data/spec/unit/application/apply_spec.rb +1 -1
- data/spec/unit/application/doc_spec.rb +1 -1
- data/spec/unit/application/face_base_spec.rb +3 -3
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/master_spec.rb +0 -15
- data/spec/unit/application/queue_spec.rb +6 -12
- data/spec/unit/application/resource_spec.rb +1 -1
- data/spec/unit/configurer/fact_handler_spec.rb +19 -50
- data/spec/unit/configurer_spec.rb +23 -7
- data/spec/unit/daemon_spec.rb +97 -121
- data/spec/unit/defaults_spec.rb +44 -0
- data/spec/unit/face/node_spec.rb +2 -2
- data/spec/unit/file_serving/configuration/parser_spec.rb +23 -33
- data/spec/unit/file_serving/configuration_spec.rb +2 -2
- data/spec/unit/file_serving/mount/file_spec.rb +4 -4
- data/spec/unit/forge/repository_spec.rb +9 -29
- data/spec/unit/graph/key_spec.rb +41 -0
- data/spec/unit/{rb_tree_map_spec.rb → graph/rb_tree_map_spec.rb} +7 -7
- data/spec/unit/graph/relationship_graph_spec.rb +393 -0
- data/spec/unit/graph/sequential_prioritizer_spec.rb +32 -0
- data/spec/unit/{simple_graph_spec.rb → graph/simple_graph.rb} +42 -254
- data/spec/unit/graph/title_hash_prioritizer_spec.rb +49 -0
- data/spec/unit/hiera_puppet_spec.rb +1 -1
- data/spec/unit/indirector/catalog/active_record_spec.rb +4 -2
- data/spec/unit/indirector/catalog/compiler_spec.rb +20 -26
- data/spec/unit/indirector/face_spec.rb +1 -1
- data/spec/unit/indirector/facts/facter_spec.rb +11 -1
- data/spec/unit/indirector/facts/network_device_spec.rb +11 -1
- data/spec/unit/indirector/hiera_spec.rb +1 -1
- data/spec/unit/indirector/instrumentation_data/local_spec.rb +1 -1
- data/spec/unit/indirector/instrumentation_listener/local_spec.rb +1 -1
- data/spec/unit/indirector/request_spec.rb +92 -39
- data/spec/unit/indirector/rest_spec.rb +1 -0
- data/spec/unit/indirector_spec.rb +2 -2
- data/spec/unit/interface/option_builder_spec.rb +1 -0
- data/spec/unit/interface/option_spec.rb +1 -0
- data/spec/unit/interface_spec.rb +2 -2
- data/spec/unit/module_tool/applications/installer_spec.rb +49 -2
- data/spec/unit/module_tool/metadata_spec.rb +13 -0
- data/spec/unit/network/authstore_spec.rb +1 -1
- data/spec/unit/network/format_handler_spec.rb +33 -282
- data/spec/unit/network/format_support_spec.rb +199 -0
- data/spec/unit/network/formats_spec.rb +2 -2
- data/spec/unit/network/http/connection_spec.rb +88 -7
- data/spec/unit/network/http/handler_spec.rb +271 -249
- data/spec/unit/network/http/rack/rest_spec.rb +1 -1
- data/spec/unit/network/http/webrick/rest_spec.rb +73 -22
- data/spec/unit/network/http_pool_spec.rb +40 -0
- data/spec/unit/network/server_spec.rb +18 -207
- data/spec/unit/node/facts_spec.rb +68 -17
- data/spec/unit/other/selinux_spec.rb +24 -20
- data/spec/unit/parameter/boolean_spec.rb +25 -0
- data/spec/unit/parameter/value_collection_spec.rb +7 -7
- data/spec/unit/parameter_spec.rb +10 -13
- data/spec/unit/parser/ast/function_spec.rb +4 -4
- data/spec/unit/parser/ast/leaf_spec.rb +45 -6
- data/spec/unit/parser/collector_spec.rb +3 -3
- data/spec/unit/parser/compiler_spec.rb +4 -3
- data/spec/unit/parser/functions/create_resources_spec.rb +9 -25
- data/spec/unit/parser/functions/extlookup_spec.rb +2 -2
- data/spec/unit/parser/functions/hiera_include_spec.rb +12 -0
- data/spec/unit/parser/functions/lookup_spec.rb +96 -0
- data/spec/unit/parser/functions/regsubst_spec.rb +2 -2
- data/spec/unit/parser/functions/split_spec.rb +2 -2
- data/spec/unit/parser/functions/sprintf_spec.rb +1 -1
- data/spec/unit/parser/functions/versioncmp_spec.rb +2 -2
- data/spec/unit/parser/functions_spec.rb +7 -7
- data/spec/unit/parser/lexer_spec.rb +1 -1
- data/spec/unit/parser/methods/collect_spec.rb +43 -0
- data/spec/unit/parser/resource_spec.rb +9 -9
- data/spec/unit/parser/scope_spec.rb +45 -2
- data/spec/unit/parser/type_loader_spec.rb +159 -175
- data/spec/unit/pops/binder/binder_spec.rb +62 -0
- data/spec/unit/pops/binder/bindings_checker_spec.rb +196 -0
- data/spec/unit/pops/binder/bindings_composer_spec.rb +89 -0
- data/spec/unit/pops/binder/bindings_validator_factory_spec.rb +18 -0
- data/spec/unit/pops/binder/config/binder_config_spec.rb +48 -0
- data/spec/unit/pops/binder/hiera2/bindings_provider_spec.rb +74 -0
- data/spec/unit/pops/binder/hiera2/config_spec.rb +61 -0
- data/spec/unit/pops/binder/hiera2/yaml_backend_spec.rb +33 -0
- data/spec/unit/pops/binder/injector_spec.rb +789 -0
- data/spec/unit/pops/containment_spec.rb +1 -0
- data/spec/unit/pops/issues_spec.rb +1 -1
- data/spec/unit/pops/parser/evaluating_parser_spec.rb +88 -0
- data/spec/unit/pops/parser/lexer_spec.rb +1 -1
- data/spec/unit/pops/parser/parse_calls_spec.rb +4 -0
- data/spec/unit/pops/parser/parser_spec.rb +1 -1
- data/spec/unit/pops/types/type_calculator_spec.rb +484 -0
- data/spec/unit/pops/types/type_factory_spec.rb +65 -0
- data/spec/unit/pops/types/type_parser_spec.rb +93 -0
- data/spec/unit/property/list_spec.rb +1 -1
- data/spec/unit/property/ordered_list_spec.rb +1 -1
- data/spec/unit/provider/aixobject_spec.rb +101 -0
- data/spec/unit/provider/augeas/augeas_spec.rb +14 -3
- data/spec/unit/provider/mcx/mcxcontent_spec.rb +52 -16
- data/spec/unit/provider/mount/parsed_spec.rb +44 -56
- data/spec/unit/provider/mount_spec.rb +11 -2
- data/spec/unit/provider/naginator_spec.rb +8 -0
- data/spec/unit/provider/package/apt_spec.rb +5 -1
- data/spec/unit/provider/package/aptitude_spec.rb +9 -5
- data/spec/unit/provider/package/aptrpm_spec.rb +2 -2
- data/spec/unit/provider/package/dpkg_spec.rb +274 -99
- data/spec/unit/provider/package/openbsd_spec.rb +84 -1
- data/spec/unit/provider/package/opkg_spec.rb +3 -3
- data/spec/unit/provider/package/pip_spec.rb +16 -0
- data/spec/unit/provider/package/pkgdmg_spec.rb +62 -7
- data/spec/unit/provider/package/rpm_spec.rb +112 -21
- data/spec/unit/provider/package/urpmi.rb +80 -0
- data/spec/unit/provider/package/windows/exe_package_spec.rb +1 -1
- data/spec/unit/provider/package/yum_spec.rb +85 -0
- data/spec/unit/provider/package/zypper_spec.rb +25 -6
- data/spec/unit/provider/parsedfile_spec.rb +3 -2
- data/spec/unit/provider/service/init_spec.rb +10 -10
- data/spec/unit/provider/service/openrc_spec.rb +16 -0
- data/spec/unit/provider/service/openwrt_spec.rb +1 -1
- data/spec/unit/provider/service/redhat_spec.rb +7 -0
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +2 -2
- data/spec/unit/provider/user/aix_spec.rb +89 -0
- data/spec/unit/provider/user/directoryservice_spec.rb +11 -4
- data/spec/unit/provider/user/user_role_add_spec.rb +18 -0
- data/spec/unit/provider_spec.rb +2 -13
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +23 -97
- data/spec/unit/resource/resource_type.json +34 -0
- data/spec/unit/resource/status_spec.rb +56 -0
- data/spec/unit/resource/type_collection_spec.rb +6 -6
- data/spec/unit/resource/type_spec.rb +25 -5
- data/spec/unit/resource_spec.rb +68 -24
- data/spec/unit/run_spec.rb +16 -0
- data/spec/unit/scheduler/scheduler_spec.rb +14 -27
- data/spec/unit/semver_spec.rb +5 -0
- data/spec/unit/settings/enum_setting_spec.rb +27 -0
- data/spec/unit/settings_spec.rb +53 -44
- data/spec/unit/ssl/certificate_authority_spec.rb +155 -19
- data/spec/unit/transaction/additional_resource_generator_spec.rb +419 -0
- data/spec/unit/transaction/event_manager_spec.rb +2 -2
- data/spec/unit/transaction/event_spec.rb +57 -0
- data/spec/unit/transaction/report_spec.rb +66 -0
- data/spec/unit/transaction/resource_harness_spec.rb +27 -20
- data/spec/unit/transaction_spec.rb +182 -390
- data/spec/unit/type/augeas_spec.rb +3 -3
- data/spec/unit/type/component_spec.rb +0 -9
- data/spec/unit/type/computer_spec.rb +1 -1
- data/spec/unit/type/cron_spec.rb +2 -2
- data/spec/unit/type/exec_spec.rb +4 -2
- data/spec/unit/type/file/content_spec.rb +11 -0
- data/spec/unit/type/file/group_spec.rb +1 -1
- data/spec/unit/type/file_spec.rb +16 -8
- data/spec/unit/type/mount_spec.rb +445 -259
- data/spec/unit/type/package_spec.rb +4 -4
- data/spec/unit/type/resources_spec.rb +30 -1
- data/spec/unit/type/user_spec.rb +26 -3
- data/spec/unit/type/yumrepo_spec.rb +7 -27
- data/spec/unit/type/zone_spec.rb +4 -1
- data/spec/unit/type_spec.rb +66 -33
- data/spec/unit/util/backups_spec.rb +3 -3
- data/spec/unit/util/http_proxy_spec.rb +83 -0
- data/spec/unit/util/log_spec.rb +79 -8
- data/spec/unit/util/metric_spec.rb +12 -0
- data/spec/unit/util/monkey_patches_spec.rb +6 -0
- data/spec/unit/util/network_device/config_spec.rb +26 -64
- data/spec/unit/util/pidlock_spec.rb +4 -1
- data/spec/unit/util/tagging_spec.rb +5 -9
- data/spec/unit/util/warnings_spec.rb +1 -1
- data/spec/unit/util/watched_file_spec.rb +52 -0
- data/spec/unit/util/watcher/periodic_watcher_spec.rb +52 -0
- data/spec/unit/util/watcher_spec.rb +56 -0
- data/spec/unit/util_spec.rb +16 -0
- metadata +2767 -2576
- data/ext/debian/puppet.manpages +0 -32
- data/ext/osx/PackageInfo.plist +0 -36
- data/ext/osx/createpackage.sh +0 -187
- data/ext/redhat/rundir-perms.patch +0 -28
- data/lib/puppet/external/base64.rb +0 -19
- data/lib/puppet/util/graph.rb +0 -27
- data/lib/puppet/util/loadedfile.rb +0 -61
- data/lib/puppet/util/log_paths.rb +0 -22
- data/lib/puppet/util/subclass_loader.rb +0 -78
- data/spec/monkey_patches/publicize_methods.rb +0 -11
- data/spec/unit/util/loadedfile_spec.rb +0 -71
@@ -0,0 +1,557 @@
|
|
1
|
+
# The TypeCalculator can answer questions about puppet types.
|
2
|
+
#
|
3
|
+
# The Puppet type system is primarily based on sub-classing. When asking the type calculator to infer types from Ruby in general, it
|
4
|
+
# may not provide the wanted answer; it does not for instance take module inclusions and extensions into account. In general the type
|
5
|
+
# system should be unsurprising for anyone being exposed to the notion of type. The type `Data` may require a bit more explanation; this
|
6
|
+
# is an abstract type that includes all literal types, as well as Array with an element type compatible with Data, and Hash with key
|
7
|
+
# compatible with Literal and elements compatible with Data. Expressed differently; Data is what you typically express using JSON (with
|
8
|
+
# the exception that the Puppet type system also includes Pattern (regular expression) as a literal.
|
9
|
+
#
|
10
|
+
# Inference
|
11
|
+
# ---------
|
12
|
+
# The `infer(o)` method infers a Puppet type for literal Ruby objects, and for Arrays and Hashes.
|
13
|
+
#
|
14
|
+
# Assignability
|
15
|
+
# -------------
|
16
|
+
# The `assignable?(t1, t2)` method answers if t2 conforms to t1. The type t2 may be an instance, in which case
|
17
|
+
# its type is inferred, or a type.
|
18
|
+
#
|
19
|
+
# Instance?
|
20
|
+
# ---------
|
21
|
+
# The `instance?(t, o)` method answers if the given object (instance) is an instance that is assignable to the given type.
|
22
|
+
#
|
23
|
+
# String
|
24
|
+
# ------
|
25
|
+
# Creates a string representation of a type.
|
26
|
+
#
|
27
|
+
# Creation of Type instances
|
28
|
+
# --------------------------
|
29
|
+
# Instance of the classes in the {Puppet::Pops::Types type model} are used to denote a specific type. It is most convenient
|
30
|
+
# to use the {Puppet::Pops::Types::TypeFactory TypeFactory} when creating instances.
|
31
|
+
#
|
32
|
+
# @note
|
33
|
+
# In general, new instances of the wanted type should be created as they are assigned to models using containment, and a
|
34
|
+
# contained object can only be in one container at a time. Also, the type system may include more details in each type
|
35
|
+
# instance, such as if it may be nil, be empty, contain a certain count etc. Or put differently, the puppet types are not
|
36
|
+
# singletons.
|
37
|
+
#
|
38
|
+
# Equality and Hash
|
39
|
+
# -----------------
|
40
|
+
# Type instances are equal in terms of Ruby eql? and `==` if they describe the same type, but they are not `equal?` if they are not
|
41
|
+
# the same type instance. Two types that describe the same type have identical hash - this makes them usable as hash keys.
|
42
|
+
#
|
43
|
+
# Types and Subclasses
|
44
|
+
# --------------------
|
45
|
+
# In general, the type calculator should be used to answer questions if a type is a subtype of another (using {#assignable?}, or
|
46
|
+
# {#instance?} if the question is if a given object is an instance of a given type (or is a subtype thereof).
|
47
|
+
# Many of the types also have a Ruby subtype relationship; e.g. PHashType and PArrayType are both subtypes of PCollectionType, and
|
48
|
+
# PIntegerType, PFloatType, PStringType,... are subtypes of PLiteralType. Even if it is possible to answer certain questions about
|
49
|
+
# type by looking at the Ruby class of the types this is considered an implementation detail, and such checks should in general
|
50
|
+
# be performed by the type_calculator which implements the type system semantics.
|
51
|
+
#
|
52
|
+
# The PRubyType
|
53
|
+
# -------------
|
54
|
+
# The PRubyType corresponds to a Ruby Class, except for the puppet types that are specialized (i.e. PRubyType should not be
|
55
|
+
# used for Integer, String, etc. since there are specialized types for those).
|
56
|
+
# When the type calculator deals with PRubyTypes and checks for assignability, it determines the "common ancestor class" of two classes.
|
57
|
+
# This check is made based on the superclasses of the two classes being compared. In order to perform this, the classes must be present
|
58
|
+
# (i.e. they are resolved from the string form in the PRubyType to a loaded, instantiated Ruby Class). In general this is not a problem,
|
59
|
+
# since the question to produce the common super type for two objects means that the classes must be present or there would have been
|
60
|
+
# no instances present in the first place. If however the classes are not present, the type calculator will fall back and state that
|
61
|
+
# the two types at least have Object in common.
|
62
|
+
#
|
63
|
+
# @see Puppet::Pops::Types::TypeFactory TypeFactory for how to create instances of types
|
64
|
+
# @see Puppet::Pops::Types::TypeParser TypeParser how to construct a type instance from a String
|
65
|
+
# @see Puppet::Pops::Types Types for details about the type model
|
66
|
+
#
|
67
|
+
# @api public
|
68
|
+
#
|
69
|
+
class Puppet::Pops::Types::TypeCalculator
|
70
|
+
|
71
|
+
Types = Puppet::Pops::Types
|
72
|
+
|
73
|
+
# @api public
|
74
|
+
#
|
75
|
+
def initialize
|
76
|
+
@@assignable_visitor ||= Puppet::Pops::Visitor.new(nil,"assignable",1,1)
|
77
|
+
@@infer_visitor ||= Puppet::Pops::Visitor.new(nil,"infer",0,0)
|
78
|
+
@@string_visitor ||= Puppet::Pops::Visitor.new(nil,"string",0,0)
|
79
|
+
|
80
|
+
da = Types::PArrayType.new()
|
81
|
+
da.element_type = Types::PDataType.new()
|
82
|
+
@data_array = da
|
83
|
+
|
84
|
+
h = Types::PHashType.new()
|
85
|
+
h.element_type = Types::PDataType.new()
|
86
|
+
h.key_type = Types::PLiteralType.new()
|
87
|
+
@data_hash = h
|
88
|
+
|
89
|
+
@data_t = Types::PDataType.new()
|
90
|
+
@literal_t = Types::PLiteralType.new()
|
91
|
+
@numeric_t = Types::PNumericType.new()
|
92
|
+
@t = Types::PObjectType.new()
|
93
|
+
end
|
94
|
+
|
95
|
+
# Convenience method to get a data type for comparisons
|
96
|
+
# @api private the returned value may not be contained in another element
|
97
|
+
#
|
98
|
+
def data
|
99
|
+
@data_t
|
100
|
+
end
|
101
|
+
|
102
|
+
# Answers the question 'is it possible to inject an instance of the given class'
|
103
|
+
# A class is injectable if it has a special *assisted inject* class method called `inject` taking
|
104
|
+
# an injector and a scope as argument, or if it has a zero args `initialize` method.
|
105
|
+
#
|
106
|
+
# @param klazz [Class, PRubyType] the class/type to check if it is injectable
|
107
|
+
# @return [Class, nil] the injectable Class, or nil if not injectable
|
108
|
+
# @api public
|
109
|
+
#
|
110
|
+
def injectable_class(klazz)
|
111
|
+
# Handle case when we get a PType instead of a class
|
112
|
+
if klazz.is_a?(Types::PRubyType)
|
113
|
+
klazz = Puppet::Pops::Types::ClassLoader.provide(klazz)
|
114
|
+
end
|
115
|
+
|
116
|
+
# data types can not be injected (check again, it is not safe to assume that given RubyType klazz arg was ok)
|
117
|
+
return false unless type(klazz).is_a?(Types::PRubyType)
|
118
|
+
if (klazz.respond_to?(:inject) && klazz.method(:inject).arity() == -4) || klazz.instance_method(:initialize).arity() == 0
|
119
|
+
klazz
|
120
|
+
else
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Answers 'can an instance of type t2 be assigned to a variable of type t'
|
126
|
+
# @api public
|
127
|
+
#
|
128
|
+
def assignable?(t, t2)
|
129
|
+
# nil is assignable to anything
|
130
|
+
if is_pnil?(t2)
|
131
|
+
return true
|
132
|
+
end
|
133
|
+
|
134
|
+
if t.is_a?(Class)
|
135
|
+
t = type(t)
|
136
|
+
end
|
137
|
+
|
138
|
+
if t2.is_a?(Class)
|
139
|
+
t2 = type(t2)
|
140
|
+
end
|
141
|
+
|
142
|
+
@@assignable_visitor.visit_this(self, t, t2)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Answers 'what is the Puppet Type corresponding to the given Ruby class'
|
146
|
+
# @param c [Class] the class for which a puppet type is wanted
|
147
|
+
# @api public
|
148
|
+
#
|
149
|
+
def type(c)
|
150
|
+
raise ArgumentError, "Argument must be a Class" unless c.is_a? Class
|
151
|
+
|
152
|
+
# Can't use a visitor here since we don't have an instance of the class
|
153
|
+
case
|
154
|
+
when c <= Integer
|
155
|
+
type = Types::PIntegerType.new()
|
156
|
+
when c == Float
|
157
|
+
type = Types::PFloatType.new()
|
158
|
+
when c == Numeric
|
159
|
+
type = Types::PNumericType.new()
|
160
|
+
when c == String
|
161
|
+
type = Types::PStringType.new()
|
162
|
+
when c == Regexp
|
163
|
+
type = Types::PPatternType.new()
|
164
|
+
when c == NilClass
|
165
|
+
type = Types::PNilType.new()
|
166
|
+
when c == FalseClass, c == TrueClass
|
167
|
+
type = Types::PBooleanType.new()
|
168
|
+
when c == Class
|
169
|
+
type = Types::PType.new()
|
170
|
+
when c == Array
|
171
|
+
# Assume array of data values
|
172
|
+
type = Types::PArrayType.new()
|
173
|
+
type.element_type = Types::PDataType.new()
|
174
|
+
when c == Hash
|
175
|
+
# Assume hash with literal keys and data values
|
176
|
+
type = Types::PHashType.new()
|
177
|
+
type.key_type = Types::PLiteralType.new()
|
178
|
+
type.element_type = Types::PDataType.new()
|
179
|
+
else
|
180
|
+
type = Types::PRubyType.new()
|
181
|
+
type.ruby_class = c.name
|
182
|
+
end
|
183
|
+
type
|
184
|
+
end
|
185
|
+
|
186
|
+
# Answers 'what is the Puppet Type of o'
|
187
|
+
# @api public
|
188
|
+
#
|
189
|
+
def infer(o)
|
190
|
+
@@infer_visitor.visit_this(self, o)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Answers 'is o an instance of type t'
|
194
|
+
# @api public
|
195
|
+
#
|
196
|
+
def instance?(t, o)
|
197
|
+
assignable?(t, infer(o))
|
198
|
+
end
|
199
|
+
|
200
|
+
# Answers if t is a puppet type
|
201
|
+
# @api public
|
202
|
+
#
|
203
|
+
def is_ptype?(t)
|
204
|
+
return t.is_a?(Types::PObjectType)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Answers if t represents the puppet type PNilType
|
208
|
+
# @api public
|
209
|
+
#
|
210
|
+
def is_pnil?(t)
|
211
|
+
return t.nil? || t.is_a?(Types::PNilType)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Answers, 'What is the common type of t1 and t2?'
|
215
|
+
# @api public
|
216
|
+
#
|
217
|
+
def common_type(t1, t2)
|
218
|
+
raise ArgumentError, 'two types expected' unless (is_ptype?(t1) || is_pnil?(t1)) && (is_ptype?(t2) || is_pnil?(t2))
|
219
|
+
|
220
|
+
# if either is nil, the common type is the other
|
221
|
+
if is_pnil?(t1)
|
222
|
+
return t2
|
223
|
+
elsif is_pnil?(t2)
|
224
|
+
return t1
|
225
|
+
end
|
226
|
+
|
227
|
+
# Simple case, one is assignable to the other
|
228
|
+
if assignable?(t1, t2)
|
229
|
+
return t1
|
230
|
+
elsif assignable?(t2, t1)
|
231
|
+
return t2
|
232
|
+
end
|
233
|
+
|
234
|
+
# when both are arrays, return an array with common element type
|
235
|
+
if t1.is_a?(Types::PArrayType) && t2.is_a?(Types::PArrayType)
|
236
|
+
type = Types::PArrayType.new()
|
237
|
+
type.element_type = common_type(t1.element_type, t2.element_type)
|
238
|
+
return type
|
239
|
+
end
|
240
|
+
|
241
|
+
# when both are hashes, return a hash with common key- and element type
|
242
|
+
if t1.is_a?(Types::PHashType) && t2.is_a?(Types::PHashType)
|
243
|
+
type = Types::PHashType.new()
|
244
|
+
type.key_type = common_type(t1.key_type, t2.key_type)
|
245
|
+
type.element_type = common_type(t1.element_type, t2.element_type)
|
246
|
+
return type
|
247
|
+
end
|
248
|
+
|
249
|
+
# Common abstract types, from most specific to most general
|
250
|
+
if common_numeric?(t1, t2)
|
251
|
+
return Types::PNumericType.new()
|
252
|
+
end
|
253
|
+
|
254
|
+
if common_literal?(t1, t2)
|
255
|
+
return Types::PLiteralType.new()
|
256
|
+
end
|
257
|
+
|
258
|
+
if common_data?(t1,t2)
|
259
|
+
return Types::PDataType.new()
|
260
|
+
end
|
261
|
+
|
262
|
+
if t1.is_a?(Types::PRubyType) && t2.is_a?(Types::PRubyType)
|
263
|
+
if t1.ruby_class == t2.ruby_class
|
264
|
+
return t1
|
265
|
+
end
|
266
|
+
# finding the common super class requires that names are resolved to class
|
267
|
+
c1 = Types::ClassLoader.provide_from_type(t1)
|
268
|
+
c2 = Types::ClassLoader.provide_from_type(t2)
|
269
|
+
if c1 && c2
|
270
|
+
c2_superclasses = superclasses(c2)
|
271
|
+
superclasses(c1).each do|c1_super|
|
272
|
+
c2_superclasses.each do |c2_super|
|
273
|
+
if c1_super == c2_super
|
274
|
+
result = Types::PRubyType.new()
|
275
|
+
result.ruby_class = c1_super.name
|
276
|
+
return result
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
# If both are RubyObjects
|
283
|
+
|
284
|
+
if common_pobject?(t1, t2)
|
285
|
+
return Types::PObjectType.new()
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Produces the superclasses of the given class, including the class
|
290
|
+
def superclasses(c)
|
291
|
+
result = [c]
|
292
|
+
while s = c.superclass
|
293
|
+
result << s
|
294
|
+
c = s
|
295
|
+
end
|
296
|
+
result
|
297
|
+
end
|
298
|
+
# Produces a string representing the type
|
299
|
+
# @api public
|
300
|
+
#
|
301
|
+
def string(t)
|
302
|
+
@@string_visitor.visit_this(self, t)
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
# Reduces an enumerable of types to a single common type.
|
307
|
+
# @api public
|
308
|
+
#
|
309
|
+
def reduce_type(enumerable)
|
310
|
+
enumerable.reduce(nil) {|memo, t| common_type(memo, t) }
|
311
|
+
end
|
312
|
+
|
313
|
+
# Reduce an enumerable of objects to a single common type
|
314
|
+
# @api public
|
315
|
+
#
|
316
|
+
def infer_and_reduce_type(enumerable)
|
317
|
+
reduce_type(enumerable.collect() {|o| infer(o) })
|
318
|
+
end
|
319
|
+
|
320
|
+
# The type of all classes is PType
|
321
|
+
# @api private
|
322
|
+
#
|
323
|
+
def infer_Class(o)
|
324
|
+
Types::PType.new()
|
325
|
+
end
|
326
|
+
|
327
|
+
# @api private
|
328
|
+
def infer_Object(o)
|
329
|
+
type = Types::PRubyType.new()
|
330
|
+
type.ruby_class = o.class.name
|
331
|
+
type
|
332
|
+
end
|
333
|
+
|
334
|
+
# The type of all types is PType
|
335
|
+
# @api private
|
336
|
+
#
|
337
|
+
def infer_PObjectType(o)
|
338
|
+
Types::PType.new()
|
339
|
+
end
|
340
|
+
|
341
|
+
# The type of all types is PType
|
342
|
+
# This is the metatype short circuit.
|
343
|
+
# @api private
|
344
|
+
#
|
345
|
+
def infer_PType(o)
|
346
|
+
Types::PType.new()
|
347
|
+
end
|
348
|
+
|
349
|
+
# @api private
|
350
|
+
def infer_String(o)
|
351
|
+
Types::PStringType.new()
|
352
|
+
end
|
353
|
+
|
354
|
+
# @api private
|
355
|
+
def infer_Float(o)
|
356
|
+
Types::PFloatType.new()
|
357
|
+
end
|
358
|
+
|
359
|
+
# @api private
|
360
|
+
def infer_Integer(o)
|
361
|
+
Types::PIntegerType.new()
|
362
|
+
end
|
363
|
+
|
364
|
+
# @api private
|
365
|
+
def infer_Regexp(o)
|
366
|
+
Types::PPatternType.new()
|
367
|
+
end
|
368
|
+
|
369
|
+
# @api private
|
370
|
+
def infer_NilClass(o)
|
371
|
+
Types::PNilType.new()
|
372
|
+
end
|
373
|
+
|
374
|
+
# @api private
|
375
|
+
def infer_TrueClass(o)
|
376
|
+
Types::PBooleanType.new()
|
377
|
+
end
|
378
|
+
|
379
|
+
# @api private
|
380
|
+
def infer_FalseClass(o)
|
381
|
+
Types::PBooleanType.new()
|
382
|
+
end
|
383
|
+
|
384
|
+
# @api private
|
385
|
+
def infer_Array(o)
|
386
|
+
type = Types::PArrayType.new()
|
387
|
+
type.element_type = if o.empty?
|
388
|
+
Types::PNilType.new()
|
389
|
+
else
|
390
|
+
infer_and_reduce_type(o)
|
391
|
+
end
|
392
|
+
type
|
393
|
+
end
|
394
|
+
|
395
|
+
# @api private
|
396
|
+
def infer_Hash(o)
|
397
|
+
type = Types::PHashType.new()
|
398
|
+
if o.empty?
|
399
|
+
ktype = Types::PNilType.new()
|
400
|
+
etype = Types::PNilType.new()
|
401
|
+
else
|
402
|
+
ktype = infer_and_reduce_type(o.keys())
|
403
|
+
etype = infer_and_reduce_type(o.values())
|
404
|
+
end
|
405
|
+
type.key_type = ktype
|
406
|
+
type.element_type = etype
|
407
|
+
type
|
408
|
+
end
|
409
|
+
|
410
|
+
# False in general type calculator
|
411
|
+
# @api private
|
412
|
+
def assignable_Object(t, t2)
|
413
|
+
false
|
414
|
+
end
|
415
|
+
|
416
|
+
# @api private
|
417
|
+
def assignable_PObjectType(t, t2)
|
418
|
+
t2.is_a?(Types::PObjectType)
|
419
|
+
end
|
420
|
+
|
421
|
+
# @api private
|
422
|
+
def assignable_PLiteralType(t, t2)
|
423
|
+
t2.is_a?(Types::PLiteralType)
|
424
|
+
end
|
425
|
+
|
426
|
+
# @api private
|
427
|
+
def assignable_PNumericType(t, t2)
|
428
|
+
t2.is_a?(Types::PNumericType)
|
429
|
+
end
|
430
|
+
|
431
|
+
# @api private
|
432
|
+
def assignable_PIntegerType(t, t2)
|
433
|
+
t2.is_a?(Types::PIntegerType)
|
434
|
+
end
|
435
|
+
|
436
|
+
# @api private
|
437
|
+
def assignable_PStringType(t, t2)
|
438
|
+
t2.is_a?(Types::PStringType)
|
439
|
+
end
|
440
|
+
|
441
|
+
# @api private
|
442
|
+
def assignable_PFloatType(t, t2)
|
443
|
+
t2.is_a?(Types::PFloatType)
|
444
|
+
end
|
445
|
+
|
446
|
+
# @api private
|
447
|
+
def assignable_PBooleanType(t, t2)
|
448
|
+
t2.is_a?(Types::PBooleanType)
|
449
|
+
end
|
450
|
+
|
451
|
+
# @api private
|
452
|
+
def assignable_PPatternType(t, t2)
|
453
|
+
t2.is_a?(Types::PPatternType)
|
454
|
+
end
|
455
|
+
|
456
|
+
# @api private
|
457
|
+
def assignable_PCollectionType(t, t2)
|
458
|
+
t2.is_a?(Types::PCollectionType)
|
459
|
+
end
|
460
|
+
|
461
|
+
# Array is assignable if t2 is an Array and t2's element type is assignable
|
462
|
+
# @api private
|
463
|
+
def assignable_PArrayType(t, t2)
|
464
|
+
return false unless t2.is_a?(Types::PArrayType)
|
465
|
+
assignable?(t.element_type, t2.element_type)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Hash is assignable if t2 is a Hash and t2's key and element types are assignable
|
469
|
+
# @api private
|
470
|
+
def assignable_PHashType(t, t2)
|
471
|
+
return false unless t2.is_a?(Types::PHashType)
|
472
|
+
assignable?(t.key_type, t2.key_type) && assignable?(t.element_type, t2.element_type)
|
473
|
+
end
|
474
|
+
|
475
|
+
# Data is assignable by other Data and by Array[Data] and Hash[Literal, Data]
|
476
|
+
# @api private
|
477
|
+
def assignable_PDataType(t, t2)
|
478
|
+
t2.is_a?(Types::PDataType) || assignable?(@data_array, t2) || assignable?(@data_hash, t2)
|
479
|
+
end
|
480
|
+
|
481
|
+
# Assignable if t2's ruby class is same or subclass of t1's ruby class
|
482
|
+
# @api private
|
483
|
+
def assignable_PRubyType(t1, t2)
|
484
|
+
return false unless t2.is_a?(Types::PRubyType)
|
485
|
+
c1 = class_from_string(t1.ruby_class)
|
486
|
+
c2 = class_from_string(t2.ruby_class)
|
487
|
+
return false unless c1.is_a?(Class) && c2.is_a?(Class)
|
488
|
+
!!(c2 <= c1)
|
489
|
+
end
|
490
|
+
|
491
|
+
# @api private
|
492
|
+
def string_PType(t) ; "Type" ; end
|
493
|
+
|
494
|
+
# @api private
|
495
|
+
def string_PObjectType(t) ; "Object" ; end
|
496
|
+
|
497
|
+
# @api private
|
498
|
+
def string_PBooleanType(t) ; "Boolean" ; end
|
499
|
+
|
500
|
+
# @api private
|
501
|
+
def string_PLiteralType(t) ; "Literal" ; end
|
502
|
+
|
503
|
+
# @api private
|
504
|
+
def string_PDataType(t) ; "Data" ; end
|
505
|
+
|
506
|
+
# @api private
|
507
|
+
def string_PNumericType(t) ; "Numeric" ; end
|
508
|
+
|
509
|
+
# @api private
|
510
|
+
def string_PIntegerType(t) ; "Integer" ; end
|
511
|
+
|
512
|
+
# @api private
|
513
|
+
def string_PFloatType(t) ; "Float" ; end
|
514
|
+
|
515
|
+
# @api private
|
516
|
+
def string_PPatternType(t) ; "Pattern" ; end
|
517
|
+
|
518
|
+
# @api private
|
519
|
+
def string_PStringType(t) ; "String" ; end
|
520
|
+
|
521
|
+
# @api private
|
522
|
+
def string_PRubyType(t) ; "Ruby[#{t.ruby_class}]" ; end
|
523
|
+
|
524
|
+
# @api private
|
525
|
+
def string_PArrayType(t)
|
526
|
+
"Array[#{string(t.element_type)}]"
|
527
|
+
end
|
528
|
+
|
529
|
+
# @api private
|
530
|
+
def string_PHashType(t)
|
531
|
+
"Hash[#{string(t.key_type)}, #{string(t.element_type)}]"
|
532
|
+
end
|
533
|
+
|
534
|
+
private
|
535
|
+
|
536
|
+
def class_from_string(str)
|
537
|
+
str.split('::').inject(Object) do |memo, name_segment|
|
538
|
+
memo.const_get(name_segment)
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
def common_data?(t1, t2)
|
543
|
+
assignable?(@data_t, t1) && assignable?(@data_t, t2)
|
544
|
+
end
|
545
|
+
|
546
|
+
def common_literal?(t1, t2)
|
547
|
+
assignable?(@literal_t, t1) && assignable?(@literal_t, t2)
|
548
|
+
end
|
549
|
+
|
550
|
+
def common_numeric?(t1, t2)
|
551
|
+
assignable?(@numeric_t, t1) && assignable?(@numeric_t, t2)
|
552
|
+
end
|
553
|
+
|
554
|
+
def common_pobject?(t1, t2)
|
555
|
+
assignable?(@t, t1) && assignable?(@t, t2)
|
556
|
+
end
|
557
|
+
end
|