puppet 0.24.6 → 0.24.7
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 +115 -0
- data/Rakefile +43 -14
- data/bin/puppetca +6 -5
- data/bin/puppetdoc +109 -15
- data/bin/ralsh +3 -1
- data/conf/redhat/puppet.spec +74 -48
- data/examples/mcx_dock_absent.pp +4 -0
- data/examples/mcx_dock_default.pp +118 -0
- data/examples/mcx_dock_full.pp +125 -0
- data/examples/mcx_dock_invalid.pp +9 -0
- data/examples/mcx_nogroup.pp +118 -0
- data/examples/mcx_notexists_absent.pp +4 -0
- data/ext/emacs/puppet-mode.el +1 -1
- data/lib/puppet.rb +1 -1
- data/lib/puppet/external/nagios/base.rb +114 -71
- data/lib/puppet/feature/base.rb +6 -0
- data/lib/puppet/indirector/yaml.rb +12 -3
- data/lib/puppet/module.rb +1 -1
- data/lib/puppet/network/client/master.rb +1 -1
- data/lib/puppet/network/xmlrpc/client.rb +3 -1
- data/lib/puppet/parameter.rb +1 -1
- data/lib/puppet/parser/ast.rb +15 -0
- data/lib/puppet/parser/ast/astarray.rb +1 -2
- data/lib/puppet/parser/ast/casestatement.rb +2 -0
- data/lib/puppet/parser/ast/collection.rb +2 -0
- data/lib/puppet/parser/ast/comparison_operator.rb +4 -0
- data/lib/puppet/parser/ast/definition.rb +2 -0
- data/lib/puppet/parser/ast/else.rb +3 -0
- data/lib/puppet/parser/ast/function.rb +19 -12
- data/lib/puppet/parser/ast/hostclass.rb +9 -1
- data/lib/puppet/parser/ast/ifstatement.rb +3 -0
- data/lib/puppet/parser/ast/node.rb +3 -0
- data/lib/puppet/parser/ast/resource.rb +3 -0
- data/lib/puppet/parser/ast/resource_defaults.rb +2 -0
- data/lib/puppet/parser/ast/resource_override.rb +3 -0
- data/lib/puppet/parser/ast/vardef.rb +3 -0
- data/lib/puppet/parser/functions.rb +14 -0
- data/lib/puppet/parser/functions/inline_template.rb +21 -0
- data/lib/puppet/parser/functions/template.rb +3 -2
- data/lib/puppet/parser/lexer.rb +56 -7
- data/lib/puppet/parser/parser.rb +114 -98
- data/lib/puppet/parser/parser_support.rb +24 -4
- data/lib/puppet/parser/resource/reference.rb +4 -3
- data/lib/puppet/parser/templatewrapper.rb +30 -22
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/property/list.rb +7 -2
- data/lib/puppet/property/ordered_list.rb +22 -0
- data/lib/puppet/provider/augeas/augeas.rb +189 -0
- data/lib/puppet/provider/computer/computer.rb +22 -0
- data/lib/puppet/provider/confine.rb +4 -1
- data/lib/puppet/provider/confine/variable.rb +13 -2
- data/lib/puppet/provider/confine_collection.rb +4 -1
- data/lib/puppet/provider/confiner.rb +1 -1
- data/lib/puppet/provider/group/directoryservice.rb +6 -3
- data/lib/puppet/provider/group/groupadd.rb +5 -2
- data/lib/puppet/provider/group/ldap.rb +11 -9
- data/lib/puppet/provider/group/netinfo.rb +8 -4
- data/lib/puppet/provider/group/pw.rb +5 -1
- data/lib/puppet/provider/host/netinfo.rb +5 -2
- data/lib/puppet/provider/macauthorization/macauthorization.rb +315 -0
- data/lib/puppet/provider/mcx/mcxcontent.rb +201 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +210 -107
- data/lib/puppet/provider/nameservice/netinfo.rb +7 -2
- data/lib/puppet/provider/package/appdmg.rb +0 -3
- data/lib/puppet/provider/package/apt.rb +6 -0
- data/lib/puppet/provider/package/rpm.rb +2 -0
- data/lib/puppet/provider/package/yum.rb +5 -1
- data/lib/puppet/provider/package/yumhelper.py +9 -0
- data/lib/puppet/provider/service/base.rb +9 -6
- data/lib/puppet/provider/service/daemontools.rb +25 -15
- data/lib/puppet/provider/service/debian.rb +6 -2
- data/lib/puppet/provider/service/freebsd.rb +5 -2
- data/lib/puppet/provider/service/gentoo.rb +6 -3
- data/lib/puppet/provider/service/init.rb +31 -21
- data/lib/puppet/provider/service/launchd.rb +195 -0
- data/lib/puppet/provider/service/redhat.rb +5 -2
- data/lib/puppet/provider/service/runit.rb +30 -20
- data/lib/puppet/provider/service/smf.rb +7 -4
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +21 -1
- data/lib/puppet/provider/user/directoryservice.rb +1 -0
- data/lib/puppet/provider/user/netinfo.rb +9 -3
- data/lib/puppet/provider/user/user_role_add.rb +43 -6
- data/lib/puppet/provider/zfs/solaris.rb +45 -0
- data/lib/puppet/provider/zone/solaris.rb +8 -4
- data/lib/puppet/provider/zpool/solaris.rb +116 -0
- data/lib/puppet/rails/database/003_add_environment_to_host.rb +9 -0
- data/lib/puppet/rails/database/schema.rb +1 -0
- data/lib/puppet/rails/host.rb +4 -0
- data/lib/puppet/reference/configuration.rb +1 -1
- data/lib/puppet/reports/tagmail.rb +15 -6
- data/lib/puppet/transaction/change.rb +3 -5
- data/lib/puppet/transportable.rb +1 -0
- data/lib/puppet/type/augeas.rb +155 -0
- data/lib/puppet/type/computer.rb +62 -0
- data/lib/puppet/type/exec.rb +2 -1
- data/lib/puppet/type/file.rb +1 -1
- data/lib/puppet/type/file/ensure.rb +8 -5
- data/lib/puppet/type/file/mode.rb +0 -14
- data/lib/puppet/type/file/owner.rb +32 -64
- data/lib/puppet/type/file/selcontext.rb +3 -8
- data/lib/puppet/type/group.rb +27 -45
- data/lib/puppet/type/k5login.rb +1 -1
- data/lib/puppet/type/macauthorization.rb +141 -0
- data/lib/puppet/type/mcx.rb +115 -0
- data/lib/puppet/type/mount.rb +1 -1
- data/lib/puppet/type/nagios_hostdependency.rb +3 -0
- data/lib/puppet/type/ssh_authorized_key.rb +16 -0
- data/lib/puppet/type/tidy.rb +43 -14
- data/lib/puppet/type/user.rb +25 -1
- data/lib/puppet/type/zfs.rb +51 -0
- data/lib/puppet/type/zone.rb +8 -0
- data/lib/puppet/type/zpool.rb +93 -0
- data/lib/puppet/util.rb +17 -38
- data/lib/puppet/util/file_locking.rb +44 -0
- data/lib/puppet/util/filetype.rb +3 -3
- data/lib/puppet/util/log.rb +1 -16
- data/lib/puppet/util/metric.rb +0 -5
- data/lib/puppet/util/rdoc.rb +85 -0
- data/lib/puppet/util/rdoc/code_objects.rb +219 -0
- data/lib/puppet/util/rdoc/generators/puppet_generator.rb +829 -0
- data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +1051 -0
- data/lib/puppet/util/rdoc/parser.rb +437 -0
- data/lib/puppet/util/selinux.rb +135 -63
- data/lib/puppet/util/settings.rb +136 -126
- data/lib/puppet/util/storage.rb +4 -2
- data/spec/Rakefile +91 -0
- data/spec/integration/checksum.rb +47 -0
- data/spec/integration/defaults.rb +47 -0
- data/spec/integration/file_serving/configuration.rb +43 -0
- data/spec/integration/file_serving/content.rb +18 -0
- data/spec/integration/file_serving/metadata.rb +18 -0
- data/spec/integration/indirector/direct_file_server.rb +80 -0
- data/spec/integration/indirector/file_content/file_server.rb +18 -0
- data/spec/integration/indirector/file_metadata/file_server.rb +18 -0
- data/spec/integration/indirector/module_files.rb +57 -0
- data/spec/integration/indirector/node/ldap.rb +15 -0
- data/spec/integration/indirector/rest.rb +464 -0
- data/spec/integration/network/server/mongrel.rb +48 -0
- data/spec/integration/network/server/webrick.rb +48 -0
- data/spec/integration/node.rb +93 -0
- data/spec/integration/node/catalog.rb +54 -0
- data/spec/integration/node/facts.rb +45 -0
- data/spec/integration/provider/package.rb +26 -0
- data/spec/integration/provider/service/init.rb +32 -0
- data/spec/integration/reference/providers.rb +17 -0
- data/spec/integration/reports.rb +14 -0
- data/spec/integration/transaction/report.rb +26 -0
- data/spec/integration/type/package.rb +22 -0
- data/spec/integration/util/file_locking.rb +36 -0
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +46 -0
- data/spec/monkey_patches/alias_should_to_must.rb +5 -0
- data/spec/shared_behaviours/file_server_terminus.rb +42 -0
- data/spec/shared_behaviours/file_serving.rb +64 -0
- data/spec/shared_behaviours/memory_terminus.rb +32 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/unit/executables/client/certhandler.rb +122 -0
- data/spec/unit/file_serving/configuration.rb +224 -0
- data/spec/unit/file_serving/configuration/parser.rb +135 -0
- data/spec/unit/file_serving/content.rb +71 -0
- data/spec/unit/file_serving/file_base.rb +124 -0
- data/spec/unit/file_serving/fileset.rb +239 -0
- data/spec/unit/file_serving/indirection_hooks.rb +124 -0
- data/spec/unit/file_serving/metadata.rb +187 -0
- data/spec/unit/file_serving/mount.rb +143 -0
- data/spec/unit/file_serving/terminus_helper.rb +76 -0
- data/spec/unit/indirector.rb +152 -0
- data/spec/unit/indirector/catalog/compiler.rb +156 -0
- data/spec/unit/indirector/catalog/yaml.rb +25 -0
- data/spec/unit/indirector/checksum/file.rb +139 -0
- data/spec/unit/indirector/code.rb +33 -0
- data/spec/unit/indirector/direct_file_server.rb +89 -0
- data/spec/unit/indirector/envelope.rb +47 -0
- data/spec/unit/indirector/exec.rb +51 -0
- data/spec/unit/indirector/facts/facter.rb +76 -0
- data/spec/unit/indirector/facts/yaml.rb +26 -0
- data/spec/unit/indirector/file.rb +154 -0
- data/spec/unit/indirector/file_content/file.rb +18 -0
- data/spec/unit/indirector/file_content/file_server.rb +18 -0
- data/spec/unit/indirector/file_content/modules.rb +18 -0
- data/spec/unit/indirector/file_content/rest.rb +11 -0
- data/spec/unit/indirector/file_metadata/file.rb +52 -0
- data/spec/unit/indirector/file_metadata/file_server.rb +18 -0
- data/spec/unit/indirector/file_metadata/modules.rb +42 -0
- data/spec/unit/indirector/file_metadata/rest.rb +9 -0
- data/spec/unit/indirector/file_server.rb +184 -0
- data/spec/unit/indirector/indirection.rb +731 -0
- data/spec/unit/indirector/ldap.rb +143 -0
- data/spec/unit/indirector/memory.rb +29 -0
- data/spec/unit/indirector/module_files.rb +259 -0
- data/spec/unit/indirector/node/exec.rb +69 -0
- data/spec/unit/indirector/node/ldap.rb +424 -0
- data/spec/unit/indirector/node/memory.rb +19 -0
- data/spec/unit/indirector/node/plain.rb +19 -0
- data/spec/unit/indirector/node/rest.rb +13 -0
- data/spec/unit/indirector/node/yaml.rb +25 -0
- data/spec/unit/indirector/plain.rb +29 -0
- data/spec/unit/indirector/report/processor.rb +81 -0
- data/spec/unit/indirector/request.rb +87 -0
- data/spec/unit/indirector/rest.rb +372 -0
- data/spec/unit/indirector/ssl_rsa/file.rb +116 -0
- data/spec/unit/indirector/terminus.rb +245 -0
- data/spec/unit/indirector/yaml.rb +145 -0
- data/spec/unit/module.rb +247 -0
- data/spec/unit/network/client.rb +45 -0
- data/spec/unit/network/client/master.rb +442 -0
- data/spec/unit/network/handler/fileserver.rb +179 -0
- data/spec/unit/network/http.rb +35 -0
- data/spec/unit/network/http/mongrel.rb +117 -0
- data/spec/unit/network/http/mongrel/rest.rb +377 -0
- data/spec/unit/network/http/mongrel/xmlrpc.rb +0 -0
- data/spec/unit/network/http/webrick.rb +127 -0
- data/spec/unit/network/http/webrick/rest.rb +323 -0
- data/spec/unit/network/http/webrick/xmlrpc.rb +0 -0
- data/spec/unit/network/http_pool.rb +238 -0
- data/spec/unit/network/server.rb +316 -0
- data/spec/unit/network/xmlrpc/client.rb +13 -0
- data/spec/unit/node.rb +167 -0
- data/spec/unit/node/catalog.rb +864 -0
- data/spec/unit/node/environment.rb +37 -0
- data/spec/unit/node/facts.rb +44 -0
- data/spec/unit/other/checksum.rb +92 -0
- data/spec/unit/other/pgraph.rb +210 -0
- data/spec/unit/other/transaction.rb +33 -0
- data/spec/unit/other/transbucket.rb +172 -0
- data/spec/unit/other/transobject.rb +92 -0
- data/spec/unit/parameter.rb +24 -0
- data/spec/unit/parser/ast.rb +37 -0
- data/spec/unit/parser/ast/arithmetic_operator.rb +73 -0
- data/spec/unit/parser/ast/astarray.rb +66 -0
- data/spec/unit/parser/ast/boolean_operator.rb +53 -0
- data/spec/unit/parser/ast/collexpr.rb +92 -0
- data/spec/unit/parser/ast/comparison_operator.rb +92 -0
- data/spec/unit/parser/ast/definition.rb +195 -0
- data/spec/unit/parser/ast/function.rb +77 -0
- data/spec/unit/parser/ast/hostclass.rb +148 -0
- data/spec/unit/parser/ast/minus.rb +36 -0
- data/spec/unit/parser/ast/node.rb +125 -0
- data/spec/unit/parser/ast/nop.rb +20 -0
- data/spec/unit/parser/ast/not.rb +30 -0
- data/spec/unit/parser/ast/resource_override.rb +51 -0
- data/spec/unit/parser/ast/resource_reference.rb +63 -0
- data/spec/unit/parser/ast/vardef.rb +47 -0
- data/spec/unit/parser/collector.rb +426 -0
- data/spec/unit/parser/compiler.rb +561 -0
- data/spec/unit/parser/functions.rb +83 -0
- data/spec/unit/parser/functions/inline_template.rb +59 -0
- data/spec/unit/parser/functions/template.rb +62 -0
- data/spec/unit/parser/interpreter.rb +138 -0
- data/spec/unit/parser/lexer.rb +646 -0
- data/spec/unit/parser/parser.rb +228 -0
- data/spec/unit/parser/resource.rb +336 -0
- data/spec/unit/parser/resource/reference.rb +95 -0
- data/spec/unit/parser/scope.rb +87 -0
- data/spec/unit/parser/templatewrapper.rb +129 -0
- data/spec/unit/property.rb +35 -0
- data/spec/unit/property/keyvalue.rb +168 -0
- data/spec/unit/property/list.rb +156 -0
- data/spec/unit/property/ordered_list.rb +64 -0
- data/spec/unit/provider/augeas/augeas.rb +238 -0
- data/spec/unit/provider/confine.rb +78 -0
- data/spec/unit/provider/confine/exists.rb +81 -0
- data/spec/unit/provider/confine/false.rb +53 -0
- data/spec/unit/provider/confine/feature.rb +60 -0
- data/spec/unit/provider/confine/true.rb +53 -0
- data/spec/unit/provider/confine/variable.rb +107 -0
- data/spec/unit/provider/confine_collection.rb +134 -0
- data/spec/unit/provider/confiner.rb +63 -0
- data/spec/unit/provider/group/groupadd.rb +31 -0
- data/spec/unit/provider/group/ldap.rb +105 -0
- data/spec/unit/provider/ldap.rb +248 -0
- data/spec/unit/provider/macauthorization.rb +147 -0
- data/spec/unit/provider/mcx/mcxcontent.rb +175 -0
- data/spec/unit/provider/mount.rb +130 -0
- data/spec/unit/provider/mount/parsed.rb +185 -0
- data/spec/unit/provider/package/apt.rb +138 -0
- data/spec/unit/provider/package/dpkg.rb +163 -0
- data/spec/unit/provider/package/gem.rb +87 -0
- data/spec/unit/provider/package/hpux.rb +52 -0
- data/spec/unit/provider/selboolean.rb +37 -0
- data/spec/unit/provider/selmodule-example.pp +0 -0
- data/spec/unit/provider/selmodule.rb +66 -0
- data/spec/unit/provider/service/daemontools.rb +124 -0
- data/spec/unit/provider/service/launchd.rb +134 -0
- data/spec/unit/provider/service/runit.rb +117 -0
- data/spec/unit/provider/ssh_authorized_key/parsed.rb +102 -0
- data/spec/unit/provider/user/hpux.rb +25 -0
- data/spec/unit/provider/user/ldap.rb +279 -0
- data/spec/unit/provider/user/user_role_add.rb +249 -0
- data/spec/unit/provider/user/useradd.rb +115 -0
- data/spec/unit/provider/zfs/solaris.rb +87 -0
- data/spec/unit/provider/zone/solaris.rb +42 -0
- data/spec/unit/provider/zpool/solaris.rb +179 -0
- data/spec/unit/rails.rb +125 -0
- data/spec/unit/relationship.rb +149 -0
- data/spec/unit/reports.rb +61 -0
- data/spec/unit/resource_reference.rb +73 -0
- data/spec/unit/simple_graph.rb +280 -0
- data/spec/unit/transaction/change.rb +187 -0
- data/spec/unit/transaction/event.rb +25 -0
- data/spec/unit/transaction/report.rb +40 -0
- data/spec/unit/type.rb +64 -0
- data/spec/unit/type/augeas.rb +113 -0
- data/spec/unit/type/computer.rb +82 -0
- data/spec/unit/type/exec.rb +91 -0
- data/spec/unit/type/file.rb +155 -0
- data/spec/unit/type/file/ensure.rb +21 -0
- data/spec/unit/type/file/group.rb +118 -0
- data/spec/unit/type/file/owner.rb +132 -0
- data/spec/unit/type/file/selinux.rb +82 -0
- data/spec/unit/type/group.rb +40 -0
- data/spec/unit/type/macauthorization.rb +78 -0
- data/spec/unit/type/mcx.rb +108 -0
- data/spec/unit/type/mount.rb +219 -0
- data/spec/unit/type/nagios.rb +63 -0
- data/spec/unit/type/noop_metaparam.rb +38 -0
- data/spec/unit/type/package.rb +246 -0
- data/spec/unit/type/resources.rb +27 -0
- data/spec/unit/type/schedule.rb +339 -0
- data/spec/unit/type/selboolean.rb +47 -0
- data/spec/unit/type/selmodule.rb +18 -0
- data/spec/unit/type/service.rb +254 -0
- data/spec/unit/type/ssh_authorized_key.rb +106 -0
- data/spec/unit/type/tidy.rb +68 -0
- data/spec/unit/type/user.rb +260 -0
- data/spec/unit/type/zfs.rb +45 -0
- data/spec/unit/type/zone.rb +20 -0
- data/spec/unit/type/zpool.rb +110 -0
- data/spec/unit/util/checksums.rb +99 -0
- data/spec/unit/util/constant_inflector.rb +70 -0
- data/spec/unit/util/file_locking.rb +115 -0
- data/spec/unit/util/ldap/connection.rb +169 -0
- data/spec/unit/util/ldap/generator.rb +54 -0
- data/spec/unit/util/ldap/manager.rb +654 -0
- data/spec/unit/util/loadedfile.rb +65 -0
- data/spec/unit/util/log.rb +107 -0
- data/spec/unit/util/metric.rb +95 -0
- data/spec/unit/util/nagios_maker.rb +128 -0
- data/spec/unit/util/posix.rb +256 -0
- data/spec/unit/util/resource_template.rb +58 -0
- data/spec/unit/util/selinux.rb +219 -0
- data/spec/unit/util/settings.rb +847 -0
- data/spec/unit/util/storage.rb +248 -0
- data/spec/unit/util/tagging.rb +92 -0
- data/spec/unit/util/uri_helper.rb +41 -0
- data/spec/unit/util/user_attr.rb +47 -0
- data/spec/unit/util/warnings.rb +35 -0
- data/test/certmgr/support.rb +0 -6
- data/test/data/providers/ssh_authorized_key/parsed/authorized_keys +1 -0
- data/test/data/snippets/multilinecomments.pp +6 -0
- data/test/data/snippets/multipleclass.pp +9 -0
- data/test/language/functions.rb +11 -1
- data/test/language/snippets.rb +16 -0
- data/test/lib/puppettest/runnable_test.rb +1 -1
- data/test/network/handler/fileserver.rb +5 -0
- data/test/other/report.rb +0 -4
- data/test/ral/type/resources.rb +2 -19
- data/test/util/settings.rb +4 -4
- data/test/util/storage.rb +0 -24
- data/test/util/utiltest.rb +0 -33
- metadata +319 -26
- data/conf/debian/README.source +0 -2
- data/conf/debian/TODO.Debian +0 -1
- data/conf/debian/changelog +0 -257
- data/conf/debian/compat +0 -1
- data/conf/debian/control +0 -45
- data/conf/debian/copyright +0 -17
- data/conf/debian/docs +0 -1
- data/conf/debian/fileserver.conf +0 -12
- data/conf/debian/puppet.NEWS +0 -63
- data/conf/debian/puppet.conf +0 -8
- data/conf/debian/puppet.dirs +0 -7
- data/conf/debian/puppet.files +0 -6
- data/conf/debian/puppet.init +0 -64
- data/conf/debian/puppet.logrotate +0 -11
- data/conf/debian/puppet.postinst +0 -9
- data/conf/debian/puppet.postrm +0 -21
- data/conf/debian/puppet.preinst +0 -25
- data/conf/debian/puppetmaster.files +0 -4
- data/conf/debian/puppetmaster.init +0 -58
- data/conf/debian/rules +0 -115
- data/conf/debian/watch +0 -2
- data/lib/puppet/type/nagios_hostgroupescalation.rb +0 -3
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
require 'puppet/util/resource_template'
|
6
|
+
|
7
|
+
describe Puppet::Util::ResourceTemplate do
|
8
|
+
describe "when initializing" do
|
9
|
+
it "should fail if the template does not exist" do
|
10
|
+
FileTest.expects(:exist?).with("/my/template").returns false
|
11
|
+
lambda { Puppet::Util::ResourceTemplate.new("/my/template", mock('resource')) }.should raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not create the ERB template" do
|
15
|
+
ERB.expects(:new).never
|
16
|
+
FileTest.expects(:exist?).with("/my/template").returns true
|
17
|
+
Puppet::Util::ResourceTemplate.new("/my/template", mock('resource'))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when evaluating" do
|
22
|
+
before do
|
23
|
+
FileTest.stubs(:exist?).returns true
|
24
|
+
File.stubs(:read).returns "eh"
|
25
|
+
|
26
|
+
@template = stub 'template', :result => nil
|
27
|
+
ERB.stubs(:new).returns @template
|
28
|
+
|
29
|
+
@resource = mock 'resource'
|
30
|
+
@wrapper = Puppet::Util::ResourceTemplate.new("/my/template", @resource)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should set all of the resource's parameters as instance variables" do
|
34
|
+
@resource.expects(:to_hash).returns(:one => "uno", :two => "dos")
|
35
|
+
@template.expects(:result).with do |bind|
|
36
|
+
eval("@one", bind) == "uno" and eval("@two", bind) == "dos"
|
37
|
+
end
|
38
|
+
@wrapper.evaluate
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create a template instance with the contents of the file" do
|
42
|
+
File.expects(:read).with("/my/template").returns "yay"
|
43
|
+
ERB.expects(:new).with("yay", 0, "-").returns(@template)
|
44
|
+
|
45
|
+
@wrapper.stubs :set_resource_variables
|
46
|
+
|
47
|
+
@wrapper.evaluate
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return the result of the template" do
|
51
|
+
@wrapper.stubs :set_resource_variables
|
52
|
+
|
53
|
+
@wrapper.expects(:binding).returns "mybinding"
|
54
|
+
@template.expects(:result).with("mybinding").returns "myresult"
|
55
|
+
@wrapper.evaluate.should == "myresult"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
require 'puppet/util/selinux'
|
6
|
+
include Puppet::Util::SELinux
|
7
|
+
|
8
|
+
unless defined?(Selinux)
|
9
|
+
module Selinux
|
10
|
+
def self.is_selinux_enabled
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Puppet::Util::SELinux do
|
17
|
+
|
18
|
+
describe "selinux_support?" do
|
19
|
+
before do
|
20
|
+
end
|
21
|
+
it "should return :true if this system has SELinux enabled" do
|
22
|
+
Selinux.expects(:is_selinux_enabled).returns 1
|
23
|
+
selinux_support?.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return :false if this system lacks SELinux" do
|
27
|
+
Selinux.expects(:is_selinux_enabled).returns 0
|
28
|
+
selinux_support?.should be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "filesystem detection" do
|
33
|
+
before :each do
|
34
|
+
File.expects(:read).with("/proc/mounts").returns "rootfs / rootfs rw 0 0\n/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n/dev /dev tmpfs rw,relatime,mode=755 0 0\n/proc /proc proc rw,relatime 0 0\n/sys /sys sysfs rw,relatime 0 0\n192.168.1.1:/var/export /mnt/nfs nfs rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,nointr,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.1,mountvers=3,mountproto=udp,addr=192.168.1.1 0 0\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should parse the contents of /proc/mounts" do
|
38
|
+
read_mounts().should == {
|
39
|
+
'/' => 'ext3',
|
40
|
+
'/sys' => 'sysfs',
|
41
|
+
'/mnt/nfs' => 'nfs',
|
42
|
+
'/proc' => 'proc',
|
43
|
+
'/dev' => 'tmpfs' }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should match a path on / to ext3" do
|
47
|
+
find_fs('/etc/puppet/testfile').should == "ext3"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should match a path on /mnt/nfs to nfs" do
|
51
|
+
find_fs('/mnt/nfs/testfile/foobar').should == "nfs"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should reture true for a capable filesystem" do
|
55
|
+
selinux_label_support?('/etc/puppet/testfile').should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return false for a noncapable filesystem" do
|
59
|
+
selinux_label_support?('/mnt/nfs/testfile').should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "get_selinux_current_context" do
|
65
|
+
it "should return nil if no SELinux support" do
|
66
|
+
self.expects(:selinux_support?).returns false
|
67
|
+
get_selinux_current_context("/foo").should be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return a context" do
|
71
|
+
self.expects(:selinux_support?).returns true
|
72
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns [0, "user_u:role_r:type_t:s0"]
|
73
|
+
get_selinux_current_context("/foo").should == "user_u:role_r:type_t:s0"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return nil if lgetfilecon fails" do
|
77
|
+
self.expects(:selinux_support?).returns true
|
78
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns -1
|
79
|
+
get_selinux_current_context("/foo").should be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "get_selinux_default_context" do
|
84
|
+
it "should return nil if no SELinux support" do
|
85
|
+
self.expects(:selinux_support?).returns false
|
86
|
+
get_selinux_default_context("/foo").should be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return a context if a default context exists" do
|
90
|
+
self.expects(:selinux_support?).returns true
|
91
|
+
fstat = stub 'File::Stat', :mode => 0
|
92
|
+
File.expects(:lstat).with("/foo").returns fstat
|
93
|
+
self.expects(:find_fs).with("/foo").returns "ext3"
|
94
|
+
Selinux.expects(:matchpathcon).with("/foo", 0).returns [0, "user_u:role_r:type_t:s0"]
|
95
|
+
get_selinux_default_context("/foo").should == "user_u:role_r:type_t:s0"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return nil if matchpathcon returns failure" do
|
99
|
+
self.expects(:selinux_support?).returns true
|
100
|
+
fstat = stub 'File::Stat', :mode => 0
|
101
|
+
File.expects(:lstat).with("/foo").returns fstat
|
102
|
+
self.expects(:find_fs).with("/foo").returns "ext3"
|
103
|
+
Selinux.expects(:matchpathcon).with("/foo", 0).returns -1
|
104
|
+
get_selinux_default_context("/foo").should be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return nil if selinux_label_support returns false" do
|
108
|
+
self.expects(:selinux_support?).returns true
|
109
|
+
self.expects(:find_fs).with("/foo").returns "nfs"
|
110
|
+
get_selinux_default_context("/foo").should be_nil
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "parse_selinux_context" do
|
116
|
+
it "should return nil if no context is passed" do
|
117
|
+
parse_selinux_context(:seluser, nil).should be_nil
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return nil if the context is 'unlabeled'" do
|
121
|
+
parse_selinux_context(:seluser, "unlabeled").should be_nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return the user type when called with :seluser" do
|
125
|
+
parse_selinux_context(:seluser, "user_u:role_r:type_t:s0").should == "user_u"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return the role type when called with :selrole" do
|
129
|
+
parse_selinux_context(:selrole, "user_u:role_r:type_t:s0").should == "role_r"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return the type type when called with :seltype" do
|
133
|
+
parse_selinux_context(:seltype, "user_u:role_r:type_t:s0").should == "type_t"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return nil for :selrange when no range is returned" do
|
137
|
+
parse_selinux_context(:selrange, "user_u:role_r:type_t").should be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should return the range type when called with :selrange" do
|
141
|
+
parse_selinux_context(:selrange, "user_u:role_r:type_t:s0").should == "s0"
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "with a variety of SELinux range formats" do
|
145
|
+
['s0', 's0:c3', 's0:c3.c123', 's0:c3,c5,c8', 'TopSecret', 'TopSecret,Classified', 'Patient_Record'].each do |range|
|
146
|
+
it "should parse range '#{range}'" do
|
147
|
+
parse_selinux_context(:selrange, "user_u:role_r:type_t:#{range}").should == range
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "set_selinux_context" do
|
154
|
+
it "should return nil if there is no SELinux support" do
|
155
|
+
self.expects(:selinux_support?).returns false
|
156
|
+
set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should use lsetfilecon to set a context" do
|
160
|
+
self.expects(:selinux_support?).returns true
|
161
|
+
Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0").returns 0
|
162
|
+
set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_true
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should use lsetfilecon to set user_u user context" do
|
166
|
+
self.expects(:selinux_support?).returns true
|
167
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns [0, "foo:role_r:type_t:s0"]
|
168
|
+
Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0").returns 0
|
169
|
+
set_selinux_context("/foo", "user_u", :seluser).should be_true
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should use lsetfilecon to set role_r role context" do
|
173
|
+
self.expects(:selinux_support?).returns true
|
174
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns [0, "user_u:foo:type_t:s0"]
|
175
|
+
Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0").returns 0
|
176
|
+
set_selinux_context("/foo", "role_r", :selrole).should be_true
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should use lsetfilecon to set type_t type context" do
|
180
|
+
self.expects(:selinux_support?).returns true
|
181
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns [0, "user_u:role_r:foo:s0"]
|
182
|
+
Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0").returns 0
|
183
|
+
set_selinux_context("/foo", "type_t", :seltype).should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should use lsetfilecon to set s0:c3,c5 range context" do
|
187
|
+
self.expects(:selinux_support?).returns true
|
188
|
+
Selinux.expects(:lgetfilecon).with("/foo").returns [0, "user_u:role_r:type_t:s0"]
|
189
|
+
Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0:c3,c5").returns 0
|
190
|
+
set_selinux_context("/foo", "s0:c3,c5", :selrange).should be_true
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "set_selinux_default_context" do
|
195
|
+
it "should return nil if there is no SELinux support" do
|
196
|
+
self.expects(:selinux_support?).returns false
|
197
|
+
set_selinux_default_context("/foo").should be_nil
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should return nil if no default context exists" do
|
201
|
+
self.expects(:get_selinux_default_context).with("/foo").returns nil
|
202
|
+
set_selinux_default_context("/foo").should be_nil
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should do nothing and return nil if the current context matches the default context" do
|
206
|
+
self.expects(:get_selinux_default_context).with("/foo").returns "user_u:role_r:type_t"
|
207
|
+
self.expects(:get_selinux_current_context).with("/foo").returns "user_u:role_r:type_t"
|
208
|
+
set_selinux_default_context("/foo").should be_nil
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should set and return the default context if current and default do not match" do
|
212
|
+
self.expects(:get_selinux_default_context).with("/foo").returns "user_u:role_r:type_t"
|
213
|
+
self.expects(:get_selinux_current_context).with("/foo").returns "olduser_u:role_r:type_t"
|
214
|
+
self.expects(:set_selinux_context).with("/foo", "user_u:role_r:type_t").returns true
|
215
|
+
set_selinux_default_context("/foo").should == "user_u:role_r:type_t"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
@@ -0,0 +1,847 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Util::Settings do
|
6
|
+
describe "when specifying defaults" do
|
7
|
+
before do
|
8
|
+
@settings = Puppet::Util::Settings.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should start with no defined parameters" do
|
12
|
+
@settings.params.length.should == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow specification of default values associated with a section as an array" do
|
16
|
+
@settings.setdefaults(:section, :myvalue => ["defaultval", "my description"])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not allow duplicate parameter specifications" do
|
20
|
+
@settings.setdefaults(:section, :myvalue => ["a", "b"])
|
21
|
+
lambda { @settings.setdefaults(:section, :myvalue => ["c", "d"]) }.should raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow specification of default values associated with a section as a hash" do
|
25
|
+
@settings.setdefaults(:section, :myvalue => {:default => "defaultval", :desc => "my description"})
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should consider defined parameters to be valid" do
|
29
|
+
@settings.setdefaults(:section, :myvalue => ["defaultval", "my description"])
|
30
|
+
@settings.valid?(:myvalue).should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should require a description when defaults are specified with an array" do
|
34
|
+
lambda { @settings.setdefaults(:section, :myvalue => ["a value"]) }.should raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should require a description when defaults are specified with a hash" do
|
38
|
+
lambda { @settings.setdefaults(:section, :myvalue => {:default => "a value"}) }.should raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support specifying owner, group, and mode when specifying files" do
|
42
|
+
@settings.setdefaults(:section, :myvalue => {:default => "/some/file", :owner => "blah", :mode => "boo", :group => "yay", :desc => "whatever"})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should support specifying a short name" do
|
46
|
+
@settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fail when short names conflict" do
|
50
|
+
@settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"})
|
51
|
+
lambda { @settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :short => "m"}) }.should raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "when setting values" do
|
56
|
+
before do
|
57
|
+
@settings = Puppet::Util::Settings.new
|
58
|
+
@settings.setdefaults :main, :myval => ["val", "desc"]
|
59
|
+
@settings.setdefaults :main, :bool => [true, "desc"]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should provide a method for setting values from other objects" do
|
63
|
+
@settings[:myval] = "something else"
|
64
|
+
@settings[:myval].should == "something else"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should support a getopt-specific mechanism for setting values" do
|
68
|
+
@settings.handlearg("--myval", "newval")
|
69
|
+
@settings[:myval].should == "newval"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should support a getopt-specific mechanism for turning booleans off" do
|
73
|
+
@settings.handlearg("--no-bool")
|
74
|
+
@settings[:bool].should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should support a getopt-specific mechanism for turning booleans on" do
|
78
|
+
# Turn it off first
|
79
|
+
@settings[:bool] = false
|
80
|
+
@settings.handlearg("--bool")
|
81
|
+
@settings[:bool].should == true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should clear the cache when setting getopt-specific values" do
|
85
|
+
@settings.setdefaults :mysection, :one => ["whah", "yay"], :two => ["$one yay", "bah"]
|
86
|
+
@settings[:two].should == "whah yay"
|
87
|
+
@settings.handlearg("--one", "else")
|
88
|
+
@settings[:two].should == "else yay"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not clear other values when setting getopt-specific values" do
|
92
|
+
@settings[:myval] = "yay"
|
93
|
+
@settings.handlearg("--no-bool")
|
94
|
+
@settings[:myval].should == "yay"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should call passed blocks when values are set" do
|
98
|
+
values = []
|
99
|
+
@settings.setdefaults(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})
|
100
|
+
values.should == []
|
101
|
+
|
102
|
+
@settings[:hooker] = "something"
|
103
|
+
values.should == %w{something}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should provide an option to call passed blocks during definition" do
|
107
|
+
values = []
|
108
|
+
@settings.setdefaults(:section, :hooker => {:default => "yay", :desc => "boo", :call_on_define => true, :hook => lambda { |v| values << v }})
|
109
|
+
values.should == %w{yay}
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should pass the fully interpolated value to the hook when called on definition" do
|
113
|
+
values = []
|
114
|
+
@settings.setdefaults(:section, :one => ["test", "a"])
|
115
|
+
@settings.setdefaults(:section, :hooker => {:default => "$one/yay", :desc => "boo", :call_on_define => true, :hook => lambda { |v| values << v }})
|
116
|
+
values.should == %w{test/yay}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should munge values using the element-specific methods" do
|
120
|
+
@settings[:bool] = "false"
|
121
|
+
@settings[:bool].should == false
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should prefer cli values to values set in Ruby code" do
|
125
|
+
@settings.handlearg("--myval", "cliarg")
|
126
|
+
@settings[:myval] = "memarg"
|
127
|
+
@settings[:myval].should == "cliarg"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "when returning values" do
|
132
|
+
before do
|
133
|
+
@settings = Puppet::Util::Settings.new
|
134
|
+
@settings.setdefaults :section, :one => ["ONE", "a"], :two => ["$one TWO", "b"], :three => ["$one $two THREE", "c"], :four => ["$two $three FOUR", "d"]
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should provide a mechanism for returning set values" do
|
138
|
+
@settings[:one] = "other"
|
139
|
+
@settings[:one].should == "other"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should interpolate default values for other parameters into returned parameter values" do
|
143
|
+
@settings[:one].should == "ONE"
|
144
|
+
@settings[:two].should == "ONE TWO"
|
145
|
+
@settings[:three].should == "ONE ONE TWO THREE"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should interpolate default values that themselves need to be interpolated" do
|
149
|
+
@settings[:four].should == "ONE TWO ONE ONE TWO THREE FOUR"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should interpolate set values for other parameters into returned parameter values" do
|
153
|
+
@settings[:one] = "on3"
|
154
|
+
@settings[:two] = "$one tw0"
|
155
|
+
@settings[:three] = "$one $two thr33"
|
156
|
+
@settings[:four] = "$one $two $three f0ur"
|
157
|
+
@settings[:one].should == "on3"
|
158
|
+
@settings[:two].should == "on3 tw0"
|
159
|
+
@settings[:three].should == "on3 on3 tw0 thr33"
|
160
|
+
@settings[:four].should == "on3 on3 tw0 on3 on3 tw0 thr33 f0ur"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should not cache interpolated values such that stale information is returned" do
|
164
|
+
@settings[:two].should == "ONE TWO"
|
165
|
+
@settings[:one] = "one"
|
166
|
+
@settings[:two].should == "one TWO"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not cache values such that information from one environment is returned for another environment" do
|
170
|
+
text = "[env1]\none = oneval\n[env2]\none = twoval\n"
|
171
|
+
file = mock 'file'
|
172
|
+
file.stubs(:changed?).returns(true)
|
173
|
+
file.stubs(:file).returns("/whatever")
|
174
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
175
|
+
@settings.parse(file)
|
176
|
+
|
177
|
+
@settings.value(:one, "env1").should == "oneval"
|
178
|
+
@settings.value(:one, "env2").should == "twoval"
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should have a name determined by the 'name' parameter" do
|
182
|
+
@settings.setdefaults(:whatever, :name => ["something", "yayness"])
|
183
|
+
@settings.name.should == :something
|
184
|
+
@settings[:name] = :other
|
185
|
+
@settings.name.should == :other
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "when choosing which value to return" do
|
190
|
+
before do
|
191
|
+
@settings = Puppet::Util::Settings.new
|
192
|
+
@settings.setdefaults :section,
|
193
|
+
:one => ["ONE", "a"],
|
194
|
+
:name => ["myname", "w"]
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return default values if no values have been set" do
|
198
|
+
@settings[:one].should == "ONE"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should return values set on the cli before values set in the configuration file" do
|
202
|
+
text = "[main]\none = fileval\n"
|
203
|
+
file = mock 'file'
|
204
|
+
file.stubs(:changed?).returns(true)
|
205
|
+
file.stubs(:file).returns("/whatever")
|
206
|
+
@settings.stubs(:parse_file).returns(text)
|
207
|
+
@settings.handlearg("--one", "clival")
|
208
|
+
@settings.parse(file)
|
209
|
+
|
210
|
+
@settings[:one].should == "clival"
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should return values set on the cli before values set in Ruby" do
|
214
|
+
@settings[:one] = "rubyval"
|
215
|
+
@settings.handlearg("--one", "clival")
|
216
|
+
@settings[:one].should == "clival"
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should return values set in the executable-specific section before values set in the main section" do
|
220
|
+
text = "[main]\none = mainval\n[myname]\none = nameval\n"
|
221
|
+
file = mock 'file'
|
222
|
+
file.stubs(:changed?).returns(true)
|
223
|
+
file.stubs(:file).returns("/whatever")
|
224
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
225
|
+
@settings.parse(file)
|
226
|
+
|
227
|
+
@settings[:one].should == "nameval"
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should not return values outside of its search path" do
|
231
|
+
text = "[other]\none = oval\n"
|
232
|
+
file = "/some/file"
|
233
|
+
file = mock 'file'
|
234
|
+
file.stubs(:changed?).returns(true)
|
235
|
+
file.stubs(:file).returns("/whatever")
|
236
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
237
|
+
@settings.parse(file)
|
238
|
+
@settings[:one].should == "ONE"
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should return values in a specified environment" do
|
242
|
+
text = "[env]\none = envval\n"
|
243
|
+
file = "/some/file"
|
244
|
+
file = mock 'file'
|
245
|
+
file.stubs(:changed?).returns(true)
|
246
|
+
file.stubs(:file).returns("/whatever")
|
247
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
248
|
+
@settings.parse(file)
|
249
|
+
@settings.value(:one, "env").should == "envval"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should interpolate found values using the current environment" do
|
253
|
+
@settings.setdefaults :main, :myval => ["$environment/foo", "mydocs"]
|
254
|
+
|
255
|
+
@settings.value(:myval, "myenv").should == "myenv/foo"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should return values in a specified environment before values in the main or name sections" do
|
259
|
+
text = "[env]\none = envval\n[main]\none = mainval\n[myname]\none = nameval\n"
|
260
|
+
file = "/some/file"
|
261
|
+
file = mock 'file'
|
262
|
+
file.stubs(:changed?).returns(true)
|
263
|
+
file.stubs(:file).returns("/whatever")
|
264
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
265
|
+
@settings.parse(file)
|
266
|
+
@settings.value(:one, "env").should == "envval"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe "when parsing its configuration" do
|
271
|
+
before do
|
272
|
+
@settings = Puppet::Util::Settings.new
|
273
|
+
@settings.setdefaults :section, :one => ["ONE", "a"], :two => ["$one TWO", "b"], :three => ["$one $two THREE", "c"]
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should return values set in the configuration file" do
|
277
|
+
text = "[main]
|
278
|
+
one = fileval
|
279
|
+
"
|
280
|
+
file = "/some/file"
|
281
|
+
@settings.expects(:read_file).with(file).returns(text)
|
282
|
+
@settings.parse(file)
|
283
|
+
@settings[:one].should == "fileval"
|
284
|
+
end
|
285
|
+
|
286
|
+
#484 - this should probably be in the regression area
|
287
|
+
it "should not throw an exception on unknown parameters" do
|
288
|
+
text = "[main]\nnosuchparam = mval\n"
|
289
|
+
file = "/some/file"
|
290
|
+
@settings.expects(:read_file).with(file).returns(text)
|
291
|
+
lambda { @settings.parse(file) }.should_not raise_error
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should support an old parse method when per-executable configuration files still exist" do
|
295
|
+
# I'm not going to bother testing this method.
|
296
|
+
@settings.should respond_to(:old_parse)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should convert booleans in the configuration file into Ruby booleans" do
|
300
|
+
text = "[main]
|
301
|
+
one = true
|
302
|
+
two = false
|
303
|
+
"
|
304
|
+
file = "/some/file"
|
305
|
+
@settings.expects(:read_file).with(file).returns(text)
|
306
|
+
@settings.parse(file)
|
307
|
+
@settings[:one].should == true
|
308
|
+
@settings[:two].should == false
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should convert integers in the configuration file into Ruby Integers" do
|
312
|
+
text = "[main]
|
313
|
+
one = 65
|
314
|
+
"
|
315
|
+
file = "/some/file"
|
316
|
+
@settings.expects(:read_file).with(file).returns(text)
|
317
|
+
@settings.parse(file)
|
318
|
+
@settings[:one].should == 65
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should support specifying all metadata (owner, group, mode) in the configuration file" do
|
322
|
+
@settings.setdefaults :section, :myfile => ["/myfile", "a"]
|
323
|
+
|
324
|
+
text = "[main]
|
325
|
+
myfile = /other/file {owner = luke, group = luke, mode = 644}
|
326
|
+
"
|
327
|
+
file = "/some/file"
|
328
|
+
@settings.expects(:read_file).with(file).returns(text)
|
329
|
+
@settings.parse(file)
|
330
|
+
@settings[:myfile].should == "/other/file"
|
331
|
+
@settings.metadata(:myfile).should == {:owner => "luke", :group => "luke", :mode => "644"}
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should support specifying a single piece of metadata (owner, group, or mode) in the configuration file" do
|
335
|
+
@settings.setdefaults :section, :myfile => ["/myfile", "a"]
|
336
|
+
|
337
|
+
text = "[main]
|
338
|
+
myfile = /other/file {owner = luke}
|
339
|
+
"
|
340
|
+
file = "/some/file"
|
341
|
+
@settings.expects(:read_file).with(file).returns(text)
|
342
|
+
@settings.parse(file)
|
343
|
+
@settings[:myfile].should == "/other/file"
|
344
|
+
@settings.metadata(:myfile).should == {:owner => "luke"}
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should call hooks associated with values set in the configuration file" do
|
348
|
+
values = []
|
349
|
+
@settings.setdefaults :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
|
350
|
+
|
351
|
+
text = "[main]
|
352
|
+
mysetting = setval
|
353
|
+
"
|
354
|
+
file = "/some/file"
|
355
|
+
@settings.expects(:read_file).with(file).returns(text)
|
356
|
+
@settings.parse(file)
|
357
|
+
values.should == ["setval"]
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should not call the same hook for values set multiple times in the configuration file" do
|
361
|
+
values = []
|
362
|
+
@settings.setdefaults :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
|
363
|
+
|
364
|
+
text = "[main]
|
365
|
+
mysetting = setval
|
366
|
+
[puppet]
|
367
|
+
mysetting = other
|
368
|
+
"
|
369
|
+
file = "/some/file"
|
370
|
+
@settings.expects(:read_file).with(file).returns(text)
|
371
|
+
@settings.parse(file)
|
372
|
+
values.should == ["setval"]
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should pass the environment-specific value to the hook when one is available" do
|
376
|
+
values = []
|
377
|
+
@settings.setdefaults :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
|
378
|
+
@settings.setdefaults :section, :environment => ["yay", "a"]
|
379
|
+
@settings.setdefaults :section, :environments => ["yay,foo", "a"]
|
380
|
+
|
381
|
+
text = "[main]
|
382
|
+
mysetting = setval
|
383
|
+
[yay]
|
384
|
+
mysetting = other
|
385
|
+
"
|
386
|
+
file = "/some/file"
|
387
|
+
@settings.expects(:read_file).with(file).returns(text)
|
388
|
+
@settings.parse(file)
|
389
|
+
values.should == ["other"]
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should pass the interpolated value to the hook when one is available" do
|
393
|
+
values = []
|
394
|
+
@settings.setdefaults :section, :base => {:default => "yay", :desc => "a", :hook => proc { |v| values << v }}
|
395
|
+
@settings.setdefaults :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
|
396
|
+
|
397
|
+
text = "[main]
|
398
|
+
mysetting = $base/setval
|
399
|
+
"
|
400
|
+
file = "/some/file"
|
401
|
+
@settings.expects(:read_file).with(file).returns(text)
|
402
|
+
@settings.parse(file)
|
403
|
+
values.should == ["yay/setval"]
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should allow empty values" do
|
407
|
+
@settings.setdefaults :section, :myarg => ["myfile", "a"]
|
408
|
+
|
409
|
+
text = "[main]
|
410
|
+
myarg =
|
411
|
+
"
|
412
|
+
@settings.stubs(:read_file).returns(text)
|
413
|
+
@settings.parse("/some/file")
|
414
|
+
@settings[:myarg].should == ""
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
describe "when reparsing its configuration" do
|
419
|
+
before do
|
420
|
+
@settings = Puppet::Util::Settings.new
|
421
|
+
@settings.setdefaults :section, :one => ["ONE", "a"], :two => ["$one TWO", "b"], :three => ["$one $two THREE", "c"]
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should replace in-memory values with on-file values" do
|
425
|
+
# Init the value
|
426
|
+
text = "[main]\none = disk-init\n"
|
427
|
+
file = mock 'file'
|
428
|
+
file.stubs(:changed?).returns(true)
|
429
|
+
file.stubs(:file).returns("/test/file")
|
430
|
+
@settings[:one] = "init"
|
431
|
+
@settings.file = file
|
432
|
+
|
433
|
+
# Now replace the value
|
434
|
+
text = "[main]\none = disk-replace\n"
|
435
|
+
|
436
|
+
# This is kinda ridiculous - the reason it parses twice is that
|
437
|
+
# it goes to parse again when we ask for the value, because the
|
438
|
+
# mock always says it should get reparsed.
|
439
|
+
@settings.expects(:read_file).with(file).returns(text).times(2)
|
440
|
+
@settings.reparse
|
441
|
+
@settings[:one].should == "disk-replace"
|
442
|
+
end
|
443
|
+
|
444
|
+
it "should retain parameters set by cli when configuration files are reparsed" do
|
445
|
+
@settings.handlearg("--one", "clival")
|
446
|
+
|
447
|
+
text = "[main]\none = on-disk\n"
|
448
|
+
file = mock 'file'
|
449
|
+
file.stubs(:file).returns("/test/file")
|
450
|
+
@settings.stubs(:read_file).with(file).returns(text)
|
451
|
+
@settings.parse(file)
|
452
|
+
|
453
|
+
@settings[:one].should == "clival"
|
454
|
+
end
|
455
|
+
|
456
|
+
it "should remove in-memory values that are no longer set in the file" do
|
457
|
+
# Init the value
|
458
|
+
text = "[main]\none = disk-init\n"
|
459
|
+
file = mock 'file'
|
460
|
+
file.stubs(:changed?).returns(true)
|
461
|
+
file.stubs(:file).returns("/test/file")
|
462
|
+
@settings.expects(:read_file).with(file).returns(text)
|
463
|
+
@settings.parse(file)
|
464
|
+
@settings[:one].should == "disk-init"
|
465
|
+
|
466
|
+
# Now replace the value
|
467
|
+
text = "[main]\ntwo = disk-replace\n"
|
468
|
+
@settings.expects(:read_file).with(file).returns(text)
|
469
|
+
@settings.parse(file)
|
470
|
+
#@settings.reparse
|
471
|
+
|
472
|
+
# The originally-overridden value should be replaced with the default
|
473
|
+
@settings[:one].should == "ONE"
|
474
|
+
|
475
|
+
# and we should now have the new value in memory
|
476
|
+
@settings[:two].should == "disk-replace"
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
describe "when being used to manage the host machine" do
|
481
|
+
before do
|
482
|
+
@settings = Puppet::Util::Settings.new
|
483
|
+
@settings.setdefaults :main, :maindir => ["/maindir", "a"], :seconddir => ["/seconddir", "a"]
|
484
|
+
@settings.setdefaults :other, :otherdir => {:default => "/otherdir", :desc => "a", :owner => "luke", :group => "johnny", :mode => 0755}
|
485
|
+
@settings.setdefaults :third, :thirddir => ["/thirddir", "b"]
|
486
|
+
@settings.setdefaults :files, :myfile => {:default => "/myfile", :desc => "a", :mode => 0755}
|
487
|
+
end
|
488
|
+
|
489
|
+
after do
|
490
|
+
Puppet::Type.type(:file).clear
|
491
|
+
end
|
492
|
+
|
493
|
+
def stub_transaction
|
494
|
+
@bucket = mock 'bucket'
|
495
|
+
@config = mock 'config', :clear => nil
|
496
|
+
@trans = mock 'transaction'
|
497
|
+
|
498
|
+
@settings.expects(:to_transportable).with(:whatever).returns(@bucket)
|
499
|
+
@bucket.expects(:to_catalog).returns(@config)
|
500
|
+
@config.expects(:apply).yields(@trans)
|
501
|
+
@config.stubs(:host_config=)
|
502
|
+
end
|
503
|
+
|
504
|
+
it "should provide a method that writes files with the correct modes" do
|
505
|
+
pending "Not converted from test/unit yet"
|
506
|
+
end
|
507
|
+
|
508
|
+
it "should provide a method that creates directories with the correct modes" do
|
509
|
+
Puppet::Util::SUIDManager.expects(:asuser).with("luke", "johnny").yields
|
510
|
+
Dir.expects(:mkdir).with("/otherdir", 0755)
|
511
|
+
@settings.mkdir(:otherdir)
|
512
|
+
end
|
513
|
+
|
514
|
+
it "should be able to create needed directories in a single section" do
|
515
|
+
Dir.expects(:mkdir).with("/maindir")
|
516
|
+
Dir.expects(:mkdir).with("/seconddir")
|
517
|
+
@settings.use(:main)
|
518
|
+
end
|
519
|
+
|
520
|
+
it "should be able to create needed directories in multiple sections" do
|
521
|
+
Dir.expects(:mkdir).with("/maindir")
|
522
|
+
Dir.expects(:mkdir).with("/seconddir")
|
523
|
+
Dir.expects(:mkdir).with("/thirddir")
|
524
|
+
@settings.use(:main, :third)
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should provide a method to trigger enforcing of file modes on existing files and directories" do
|
528
|
+
pending "Not converted from test/unit yet"
|
529
|
+
end
|
530
|
+
|
531
|
+
it "should provide a method to convert the file mode enforcement into a Puppet manifest" do
|
532
|
+
pending "Not converted from test/unit yet"
|
533
|
+
end
|
534
|
+
|
535
|
+
it "should create files when configured to do so with the :create parameter"
|
536
|
+
|
537
|
+
it "should provide a method to convert the file mode enforcement into transportable resources" do
|
538
|
+
# Make it think we're root so it tries to manage user and group.
|
539
|
+
Puppet.features.stubs(:root?).returns(true)
|
540
|
+
File.stubs(:exist?).with("/myfile").returns(true)
|
541
|
+
trans = nil
|
542
|
+
trans = @settings.to_transportable
|
543
|
+
resources = []
|
544
|
+
trans.delve { |obj| resources << obj if obj.is_a? Puppet::TransObject }
|
545
|
+
%w{/maindir /seconddir /otherdir /myfile}.each do |path|
|
546
|
+
obj = resources.find { |r| r.type == "file" and r.name == path }
|
547
|
+
if path.include?("dir")
|
548
|
+
obj[:ensure].should == :directory
|
549
|
+
else
|
550
|
+
# Do not create the file, just manage mode
|
551
|
+
obj[:ensure].should be_nil
|
552
|
+
end
|
553
|
+
obj.should be_instance_of(Puppet::TransObject)
|
554
|
+
case path
|
555
|
+
when "/otherdir":
|
556
|
+
obj[:owner].should == "luke"
|
557
|
+
obj[:group].should == "johnny"
|
558
|
+
obj[:mode].should == 0755
|
559
|
+
when "/myfile":
|
560
|
+
obj[:mode].should == 0755
|
561
|
+
end
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should not try to manage user or group when not running as root" do
|
566
|
+
Puppet.features.stubs(:root?).returns(false)
|
567
|
+
trans = nil
|
568
|
+
trans = @settings.to_transportable(:other)
|
569
|
+
trans.delve do |obj|
|
570
|
+
next unless obj.is_a?(Puppet::TransObject)
|
571
|
+
obj[:owner].should be_nil
|
572
|
+
obj[:group].should be_nil
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
it "should add needed users and groups to the manifest when asked" do
|
577
|
+
# This is how we enable user/group management
|
578
|
+
@settings.setdefaults :main, :mkusers => [true, "w"]
|
579
|
+
Puppet.features.stubs(:root?).returns(false)
|
580
|
+
trans = nil
|
581
|
+
trans = @settings.to_transportable(:other)
|
582
|
+
resources = []
|
583
|
+
trans.delve { |obj| resources << obj if obj.is_a? Puppet::TransObject and obj.type != "file" }
|
584
|
+
|
585
|
+
user = resources.find { |r| r.type == "user" }
|
586
|
+
user.should be_instance_of(Puppet::TransObject)
|
587
|
+
user.name.should == "luke"
|
588
|
+
user[:ensure].should == :present
|
589
|
+
|
590
|
+
# This should maybe be a separate test, but...
|
591
|
+
group = resources.find { |r| r.type == "group" }
|
592
|
+
group.should be_instance_of(Puppet::TransObject)
|
593
|
+
group.name.should == "johnny"
|
594
|
+
group[:ensure].should == :present
|
595
|
+
end
|
596
|
+
|
597
|
+
it "should ignore tags and schedules when creating files and directories"
|
598
|
+
|
599
|
+
it "should apply all resources in debug mode to reduce logging"
|
600
|
+
|
601
|
+
it "should not try to manage absent files" do
|
602
|
+
# Make it think we're root so it tries to manage user and group.
|
603
|
+
Puppet.features.stubs(:root?).returns(true)
|
604
|
+
trans = nil
|
605
|
+
trans = @settings.to_transportable
|
606
|
+
file = nil
|
607
|
+
trans.delve { |obj| file = obj if obj.name == "/myfile" }
|
608
|
+
file.should be_nil
|
609
|
+
end
|
610
|
+
|
611
|
+
it "should not try to manage files in memory" do
|
612
|
+
main = Puppet::Type.type(:file).create(:path => "/maindir")
|
613
|
+
|
614
|
+
trans = @settings.to_transportable
|
615
|
+
|
616
|
+
lambda { trans.to_catalog }.should_not raise_error
|
617
|
+
end
|
618
|
+
|
619
|
+
it "should do nothing if a catalog cannot be created" do
|
620
|
+
bucket = mock 'bucket'
|
621
|
+
catalog = mock 'catalog'
|
622
|
+
|
623
|
+
@settings.expects(:to_transportable).returns bucket
|
624
|
+
bucket.expects(:to_catalog).raises RuntimeError
|
625
|
+
catalog.expects(:apply).never
|
626
|
+
|
627
|
+
@settings.use(:mysection)
|
628
|
+
end
|
629
|
+
|
630
|
+
it "should clear the catalog after applying" do
|
631
|
+
bucket = mock 'bucket'
|
632
|
+
catalog = mock 'catalog'
|
633
|
+
|
634
|
+
@settings.expects(:to_transportable).returns bucket
|
635
|
+
bucket.expects(:to_catalog).returns catalog
|
636
|
+
catalog.stubs(:host_config=)
|
637
|
+
catalog.stubs(:apply)
|
638
|
+
catalog.expects(:clear)
|
639
|
+
|
640
|
+
@settings.use(:mysection)
|
641
|
+
end
|
642
|
+
|
643
|
+
it "should clear the catalog even if there is an exception during applying" do
|
644
|
+
bucket = mock 'bucket'
|
645
|
+
catalog = mock 'catalog'
|
646
|
+
|
647
|
+
@settings.expects(:to_transportable).returns bucket
|
648
|
+
bucket.expects(:to_catalog).returns catalog
|
649
|
+
catalog.stubs(:host_config=)
|
650
|
+
catalog.expects(:apply).raises(ArgumentError)
|
651
|
+
catalog.expects(:clear)
|
652
|
+
|
653
|
+
# We don't care about the raised exception, we just care that
|
654
|
+
# we clear the catalog even with the exception
|
655
|
+
lambda { @settings.use(:mysection) }.should raise_error
|
656
|
+
end
|
657
|
+
|
658
|
+
it "should do nothing if all specified sections have already been used" do
|
659
|
+
bucket = mock 'bucket'
|
660
|
+
catalog = mock 'catalog'
|
661
|
+
|
662
|
+
@settings.expects(:to_transportable).once.returns(bucket)
|
663
|
+
bucket.expects(:to_catalog).returns catalog
|
664
|
+
catalog.stub_everything
|
665
|
+
|
666
|
+
@settings.use(:whatever)
|
667
|
+
|
668
|
+
@settings.use(:whatever)
|
669
|
+
end
|
670
|
+
|
671
|
+
it "should ignore file settings whose values are not strings" do
|
672
|
+
@settings[:maindir] = false
|
673
|
+
|
674
|
+
lambda { trans = @settings.to_transportable }.should_not raise_error
|
675
|
+
end
|
676
|
+
|
677
|
+
it "should be able to turn the current configuration into a parseable manifest"
|
678
|
+
|
679
|
+
it "should convert octal numbers correctly when producing a manifest"
|
680
|
+
|
681
|
+
it "should be able to provide all of its parameters in a format compatible with GetOpt::Long" do
|
682
|
+
pending "Not converted from test/unit yet"
|
683
|
+
end
|
684
|
+
|
685
|
+
it "should not attempt to manage files within /dev" do
|
686
|
+
pending "Not converted from test/unit yet"
|
687
|
+
end
|
688
|
+
|
689
|
+
it "should not modify the stored state database when managing resources" do
|
690
|
+
Puppet::Util::Storage.expects(:store).never
|
691
|
+
Puppet::Util::Storage.expects(:load).never
|
692
|
+
Dir.expects(:mkdir).with("/maindir")
|
693
|
+
Dir.expects(:mkdir).with("/seconddir")
|
694
|
+
@settings.use(:main)
|
695
|
+
end
|
696
|
+
|
697
|
+
it "should convert all relative paths to fully-qualified paths (#795)" do
|
698
|
+
@settings[:myfile] = "unqualified"
|
699
|
+
dir = Dir.getwd
|
700
|
+
@settings[:myfile].should == File.join(dir, "unqualified")
|
701
|
+
end
|
702
|
+
|
703
|
+
it "should support a method for re-using all currently used sections" do
|
704
|
+
Dir.expects(:mkdir).with("/thirddir").times(2)
|
705
|
+
@settings.use(:third)
|
706
|
+
@settings.reuse
|
707
|
+
end
|
708
|
+
|
709
|
+
it "should fail with an appropriate message if any resources fail" do
|
710
|
+
stub_transaction
|
711
|
+
@trans.expects(:any_failed?).returns(true)
|
712
|
+
report = mock 'report'
|
713
|
+
@trans.expects(:report).returns report
|
714
|
+
|
715
|
+
log = mock 'log', :to_s => "My failure", :level => :err
|
716
|
+
report.expects(:logs).returns [log]
|
717
|
+
|
718
|
+
@settings.expects(:raise).with { |msg| msg.include?("My failure") }
|
719
|
+
@settings.use(:whatever)
|
720
|
+
end
|
721
|
+
|
722
|
+
after { Puppet::Type.allclear }
|
723
|
+
end
|
724
|
+
|
725
|
+
describe "when dealing with printing configs" do
|
726
|
+
before do
|
727
|
+
@settings = Puppet::Util::Settings.new
|
728
|
+
#these are the magic default values
|
729
|
+
@settings.stubs(:value).with(:configprint).returns("")
|
730
|
+
@settings.stubs(:value).with(:genconfig).returns(false)
|
731
|
+
@settings.stubs(:value).with(:genmanifest).returns(false)
|
732
|
+
@settings.stubs(:value).with(:environment).returns(nil)
|
733
|
+
end
|
734
|
+
|
735
|
+
describe "when checking print_config?" do
|
736
|
+
it "should return false when the :configprint, :genconfig and :genmanifest are not set" do
|
737
|
+
@settings.print_configs?.should be_false
|
738
|
+
end
|
739
|
+
|
740
|
+
it "should return true when :configprint has a value" do
|
741
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
742
|
+
@settings.print_configs?.should be_true
|
743
|
+
end
|
744
|
+
|
745
|
+
it "should return true when :genconfig has a value" do
|
746
|
+
@settings.stubs(:value).with(:genconfig).returns(true)
|
747
|
+
@settings.print_configs?.should be_true
|
748
|
+
end
|
749
|
+
|
750
|
+
it "should return true when :genmanifest has a value" do
|
751
|
+
@settings.stubs(:value).with(:genmanifest).returns(true)
|
752
|
+
@settings.print_configs?.should be_true
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
describe "when printing configs" do
|
757
|
+
describe "when :configprint has a value" do
|
758
|
+
it "should call print_config_options" do
|
759
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
760
|
+
@settings.expects(:print_config_options)
|
761
|
+
@settings.print_configs
|
762
|
+
end
|
763
|
+
|
764
|
+
it "should get the value of the option using the environment" do
|
765
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
766
|
+
@settings.stubs(:include?).with("something").returns(true)
|
767
|
+
@settings.expects(:value).with(:environment).returns("env")
|
768
|
+
@settings.expects(:value).with("something", "env").returns("foo")
|
769
|
+
@settings.stubs(:puts).with("foo")
|
770
|
+
@settings.print_configs
|
771
|
+
end
|
772
|
+
|
773
|
+
it "should print the value of the option" do
|
774
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
775
|
+
@settings.stubs(:include?).with("something").returns(true)
|
776
|
+
@settings.stubs(:value).with("something", nil).returns("foo")
|
777
|
+
@settings.expects(:puts).with("foo")
|
778
|
+
@settings.print_configs
|
779
|
+
end
|
780
|
+
|
781
|
+
it "should print the value pairs if there are multiple options" do
|
782
|
+
@settings.stubs(:value).with(:configprint).returns("bar,baz")
|
783
|
+
@settings.stubs(:include?).with("bar").returns(true)
|
784
|
+
@settings.stubs(:include?).with("baz").returns(true)
|
785
|
+
@settings.stubs(:value).with("bar", nil).returns("foo")
|
786
|
+
@settings.stubs(:value).with("baz", nil).returns("fud")
|
787
|
+
@settings.expects(:puts).with("bar = foo")
|
788
|
+
@settings.expects(:puts).with("baz = fud")
|
789
|
+
@settings.print_configs
|
790
|
+
end
|
791
|
+
|
792
|
+
it "should print a whole bunch of stuff if :configprint = all"
|
793
|
+
|
794
|
+
it "should return true after printing" do
|
795
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
796
|
+
@settings.stubs(:include?).with("something").returns(true)
|
797
|
+
@settings.stubs(:value).with("something", nil).returns("foo")
|
798
|
+
@settings.stubs(:puts).with("foo")
|
799
|
+
@settings.print_configs.should be_true
|
800
|
+
end
|
801
|
+
|
802
|
+
it "should return false if a config param is not found" do
|
803
|
+
@settings.stubs :puts
|
804
|
+
@settings.stubs(:value).with(:configprint).returns("something")
|
805
|
+
@settings.stubs(:include?).with("something").returns(false)
|
806
|
+
@settings.print_configs.should be_false
|
807
|
+
end
|
808
|
+
end
|
809
|
+
|
810
|
+
describe "when genconfig is true" do
|
811
|
+
before do
|
812
|
+
@settings.stubs :puts
|
813
|
+
end
|
814
|
+
|
815
|
+
it "should call to_config" do
|
816
|
+
@settings.stubs(:value).with(:genconfig).returns(true)
|
817
|
+
@settings.expects(:to_config)
|
818
|
+
@settings.print_configs
|
819
|
+
end
|
820
|
+
|
821
|
+
it "should return true from print_configs" do
|
822
|
+
@settings.stubs(:value).with(:genconfig).returns(true)
|
823
|
+
@settings.stubs(:to_config)
|
824
|
+
@settings.print_configs.should be_true
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
828
|
+
describe "when genmanifest is true" do
|
829
|
+
before do
|
830
|
+
@settings.stubs :puts
|
831
|
+
end
|
832
|
+
|
833
|
+
it "should call to_config" do
|
834
|
+
@settings.stubs(:value).with(:genmanifest).returns(true)
|
835
|
+
@settings.expects(:to_manifest)
|
836
|
+
@settings.print_configs
|
837
|
+
end
|
838
|
+
|
839
|
+
it "should return true from print_configs" do
|
840
|
+
@settings.stubs(:value).with(:genmanifest).returns(true)
|
841
|
+
@settings.stubs(:to_manifest)
|
842
|
+
@settings.print_configs.should be_true
|
843
|
+
end
|
844
|
+
end
|
845
|
+
end
|
846
|
+
end
|
847
|
+
end
|