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,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
|
4
|
+
|
5
|
+
describe Puppet::Network do
|
6
|
+
it "should raise an XMLRPCClientError if a generated class raises a Timeout::Error" do
|
7
|
+
http = mock 'http'
|
8
|
+
Puppet::Network::HttpPool.stubs(:http_instance).returns http
|
9
|
+
file = Puppet::Network::Client.file.new({:Server => "foo.com"})
|
10
|
+
http.stubs(:post2).raises Timeout::Error
|
11
|
+
lambda { file.retrieve }.should raise_error(Puppet::Network::XMLRPCClientError)
|
12
|
+
end
|
13
|
+
end
|
data/spec/unit/node.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Node, "when initializing" do
|
6
|
+
before do
|
7
|
+
@node = Puppet::Node.new("testnode")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set the node name" do
|
11
|
+
@node.name.should == "testnode"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not allow nil node names" do
|
15
|
+
proc { Puppet::Node.new(nil) }.should raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should default to an empty parameter hash" do
|
19
|
+
@node.parameters.should == {}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should default to an empty class array" do
|
23
|
+
@node.classes.should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should note its creation time" do
|
27
|
+
@node.time.should be_instance_of(Time)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should accept parameters passed in during initialization" do
|
31
|
+
params = {"a" => "b"}
|
32
|
+
@node = Puppet::Node.new("testing", :parameters => params)
|
33
|
+
@node.parameters.should == params
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should accept classes passed in during initialization" do
|
37
|
+
classes = %w{one two}
|
38
|
+
@node = Puppet::Node.new("testing", :classes => classes)
|
39
|
+
@node.classes.should == classes
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should always return classes as an array" do
|
43
|
+
@node = Puppet::Node.new("testing", :classes => "myclass")
|
44
|
+
@node.classes.should == ["myclass"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should accept an environment value" do
|
48
|
+
Puppet.settings.stubs(:value).with(:environment).returns("myenv")
|
49
|
+
@node = Puppet::Node.new("testing", :environment => "myenv")
|
50
|
+
@node.environment.should == "myenv"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Puppet::Node, "when returning the environment" do
|
55
|
+
before do
|
56
|
+
Puppet.settings.stubs(:value).with(:environment).returns("one,two")
|
57
|
+
Puppet.settings.stubs(:value).with(:environment).returns("one")
|
58
|
+
@node = Puppet::Node.new("testnode")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return the 'environment' fact if present and there is no explicit environment" do
|
62
|
+
@node.parameters = {"environment" => "two"}
|
63
|
+
@node.environment.should == "two"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use the default environment if there is no environment fact nor explicit environment" do
|
67
|
+
env = mock 'environment', :name => :myenv
|
68
|
+
Puppet::Node::Environment.expects(:new).returns(env)
|
69
|
+
@node.environment.should == "myenv"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe Puppet::Node, "when merging facts" do
|
74
|
+
before do
|
75
|
+
@node = Puppet::Node.new("testnode")
|
76
|
+
Puppet::Node::Facts.stubs(:find).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b"))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should prefer parameters already set on the node over facts from the node" do
|
80
|
+
@node.parameters = {"one" => "a"}
|
81
|
+
@node.fact_merge
|
82
|
+
@node.parameters["one"].should == "a"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should add passed parameters to the parameter list" do
|
86
|
+
@node.parameters = {"one" => "a"}
|
87
|
+
@node.fact_merge
|
88
|
+
@node.parameters["two"].should == "b"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should accept arbitrary parameters to merge into its parameters" do
|
92
|
+
@node.parameters = {"one" => "a"}
|
93
|
+
@node.merge "two" => "three"
|
94
|
+
@node.parameters["two"].should == "three"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe Puppet::Node, "when indirecting" do
|
99
|
+
it "should redirect to the indirection" do
|
100
|
+
@indirection = stub 'indirection', :name => :node
|
101
|
+
Puppet::Node.stubs(:indirection).returns(@indirection)
|
102
|
+
@indirection.expects(:find)
|
103
|
+
Puppet::Node.find(:my_node.to_s)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should default to the 'plain' node terminus" do
|
107
|
+
Puppet::Node.indirection.terminus_class.should == :plain
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not have a cache class defined" do
|
111
|
+
Puppet::Node.indirection.cache_class.should be_nil
|
112
|
+
end
|
113
|
+
|
114
|
+
after do
|
115
|
+
Puppet::Indirector::Indirection.clear_cache
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe Puppet::Node, "when generating the list of names to search through" do
|
120
|
+
before do
|
121
|
+
@node = Puppet::Node.new("foo.domain.com")
|
122
|
+
@node.parameters = {"hostname" => "yay", "domain" => "domain.com"}
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return an array of names" do
|
126
|
+
@node.names.should be_instance_of(Array)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have the node's fqdn as the second name" do
|
130
|
+
@node.names[1].should == "yay.domain.com"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should set the fqdn to the node's 'fqdn' fact if it is available" do
|
134
|
+
@node.parameters["fqdn"] = "boo.domain.com"
|
135
|
+
@node.names[1].should == "boo.domain.com"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should set the fqdn to the node's hostname and domain if no fqdn is available" do
|
139
|
+
@node.names[1].should == "yay.domain.com"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should contain an entry for each name available by stripping a segment of the fqdn" do
|
143
|
+
@node.parameters["fqdn"] = "foo.deep.sub.domain.com"
|
144
|
+
@node.names[2].should == "foo.deep.sub.domain"
|
145
|
+
@node.names[3].should == "foo.deep.sub"
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "and :node_name is set to 'cert'" do
|
149
|
+
before do
|
150
|
+
Puppet.settings.stubs(:value).with(:node_name).returns "cert"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should use the passed-in key as the first value" do
|
154
|
+
@node.names[0].should == "foo.domain.com"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "and :node_name is set to 'facter'" do
|
159
|
+
before do
|
160
|
+
Puppet.settings.stubs(:value).with(:node_name).returns "facter"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should use the node's 'hostname' fact as the first value" do
|
164
|
+
@node.names[0].should == "yay"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,864 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Node::Catalog, " when compiling" do
|
6
|
+
it "should accept tags" do
|
7
|
+
config = Puppet::Node::Catalog.new("mynode")
|
8
|
+
config.tag("one")
|
9
|
+
config.tags.should == %w{one}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should accept multiple tags at once" do
|
13
|
+
config = Puppet::Node::Catalog.new("mynode")
|
14
|
+
config.tag("one", "two")
|
15
|
+
config.tags.should == %w{one two}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should convert all tags to strings" do
|
19
|
+
config = Puppet::Node::Catalog.new("mynode")
|
20
|
+
config.tag("one", :two)
|
21
|
+
config.tags.should == %w{one two}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should tag with both the qualified name and the split name" do
|
25
|
+
config = Puppet::Node::Catalog.new("mynode")
|
26
|
+
config.tag("one::two")
|
27
|
+
config.tags.include?("one").should be_true
|
28
|
+
config.tags.include?("one::two").should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should accept classes" do
|
32
|
+
config = Puppet::Node::Catalog.new("mynode")
|
33
|
+
config.add_class("one")
|
34
|
+
config.classes.should == %w{one}
|
35
|
+
config.add_class("two", "three")
|
36
|
+
config.classes.should == %w{one two three}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should tag itself with passed class names" do
|
40
|
+
config = Puppet::Node::Catalog.new("mynode")
|
41
|
+
config.add_class("one")
|
42
|
+
config.tags.should == %w{one}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Puppet::Node::Catalog, " when extracting" do
|
47
|
+
it "should return extraction result as the method result" do
|
48
|
+
config = Puppet::Node::Catalog.new("mynode")
|
49
|
+
config.expects(:extraction_format).returns(:whatever)
|
50
|
+
config.expects(:extract_to_whatever).returns(:result)
|
51
|
+
config.extract.should == :result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe Puppet::Node::Catalog, " when extracting transobjects" do
|
56
|
+
|
57
|
+
def mkscope
|
58
|
+
@parser = Puppet::Parser::Parser.new :Code => ""
|
59
|
+
@node = Puppet::Node.new("mynode")
|
60
|
+
@compiler = Puppet::Parser::Compiler.new(@node, @parser)
|
61
|
+
|
62
|
+
# XXX This is ridiculous.
|
63
|
+
@compiler.send(:evaluate_main)
|
64
|
+
@scope = @compiler.topscope
|
65
|
+
end
|
66
|
+
|
67
|
+
def mkresource(type, name)
|
68
|
+
Puppet::Parser::Resource.new(:type => type, :title => name, :source => @source, :scope => @scope)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should always create a TransBucket for the 'main' class" do
|
72
|
+
config = Puppet::Node::Catalog.new("mynode")
|
73
|
+
|
74
|
+
@scope = mkscope
|
75
|
+
@source = mock 'source'
|
76
|
+
|
77
|
+
main = mkresource("class", :main)
|
78
|
+
config.add_vertex(main)
|
79
|
+
|
80
|
+
bucket = mock 'bucket'
|
81
|
+
bucket.expects(:classes=).with(config.classes)
|
82
|
+
main.stubs(:builtin?).returns(false)
|
83
|
+
main.expects(:to_transbucket).returns(bucket)
|
84
|
+
|
85
|
+
config.extract_to_transportable.should equal(bucket)
|
86
|
+
end
|
87
|
+
|
88
|
+
# This isn't really a spec-style test, but I don't know how better to do it.
|
89
|
+
it "should transform the resource graph into a tree of TransBuckets and TransObjects" do
|
90
|
+
config = Puppet::Node::Catalog.new("mynode")
|
91
|
+
|
92
|
+
@scope = mkscope
|
93
|
+
@source = mock 'source'
|
94
|
+
|
95
|
+
defined = mkresource("class", :main)
|
96
|
+
builtin = mkresource("file", "/yay")
|
97
|
+
|
98
|
+
config.add_edge(defined, builtin)
|
99
|
+
|
100
|
+
bucket = []
|
101
|
+
bucket.expects(:classes=).with(config.classes)
|
102
|
+
defined.stubs(:builtin?).returns(false)
|
103
|
+
defined.expects(:to_transbucket).returns(bucket)
|
104
|
+
builtin.expects(:to_transobject).returns(:builtin)
|
105
|
+
|
106
|
+
config.extract_to_transportable.should == [:builtin]
|
107
|
+
end
|
108
|
+
|
109
|
+
# Now try it with a more complicated graph -- a three tier graph, each tier
|
110
|
+
it "should transform arbitrarily deep graphs into isomorphic trees" do
|
111
|
+
config = Puppet::Node::Catalog.new("mynode")
|
112
|
+
|
113
|
+
@scope = mkscope
|
114
|
+
@scope.stubs(:tags).returns([])
|
115
|
+
@source = mock 'source'
|
116
|
+
|
117
|
+
# Create our scopes.
|
118
|
+
top = mkresource "class", :main
|
119
|
+
topbucket = []
|
120
|
+
topbucket.expects(:classes=).with([])
|
121
|
+
top.expects(:to_trans).returns(topbucket)
|
122
|
+
topres = mkresource "file", "/top"
|
123
|
+
topres.expects(:to_trans).returns(:topres)
|
124
|
+
config.add_edge top, topres
|
125
|
+
|
126
|
+
middle = mkresource "class", "middle"
|
127
|
+
middle.expects(:to_trans).returns([])
|
128
|
+
config.add_edge top, middle
|
129
|
+
midres = mkresource "file", "/mid"
|
130
|
+
midres.expects(:to_trans).returns(:midres)
|
131
|
+
config.add_edge middle, midres
|
132
|
+
|
133
|
+
bottom = mkresource "class", "bottom"
|
134
|
+
bottom.expects(:to_trans).returns([])
|
135
|
+
config.add_edge middle, bottom
|
136
|
+
botres = mkresource "file", "/bot"
|
137
|
+
botres.expects(:to_trans).returns(:botres)
|
138
|
+
config.add_edge bottom, botres
|
139
|
+
|
140
|
+
toparray = config.extract_to_transportable
|
141
|
+
|
142
|
+
# This is annoying; it should look like:
|
143
|
+
# [[[:botres], :midres], :topres]
|
144
|
+
# but we can't guarantee sort order.
|
145
|
+
toparray.include?(:topres).should be_true
|
146
|
+
|
147
|
+
midarray = toparray.find { |t| t.is_a?(Array) }
|
148
|
+
midarray.include?(:midres).should be_true
|
149
|
+
botarray = midarray.find { |t| t.is_a?(Array) }
|
150
|
+
botarray.include?(:botres).should be_true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe Puppet::Node::Catalog, " when converting to a transobject catalog" do
|
155
|
+
class CatalogTestResource
|
156
|
+
attr_accessor :name, :virtual, :builtin
|
157
|
+
def initialize(name, options = {})
|
158
|
+
@name = name
|
159
|
+
options.each { |p,v| send(p.to_s + "=", v) }
|
160
|
+
end
|
161
|
+
|
162
|
+
def ref
|
163
|
+
if builtin?
|
164
|
+
"File[%s]" % name
|
165
|
+
else
|
166
|
+
"Class[%s]" % name
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def virtual?
|
171
|
+
virtual
|
172
|
+
end
|
173
|
+
|
174
|
+
def builtin?
|
175
|
+
builtin
|
176
|
+
end
|
177
|
+
|
178
|
+
def to_transobject
|
179
|
+
Puppet::TransObject.new(name, builtin? ? "file" : "class")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
before do
|
184
|
+
@original = Puppet::Node::Catalog.new("mynode")
|
185
|
+
@original.tag(*%w{one two three})
|
186
|
+
@original.add_class *%w{four five six}
|
187
|
+
|
188
|
+
@top = CatalogTestResource.new 'top'
|
189
|
+
@topobject = CatalogTestResource.new 'topobject', :builtin => true
|
190
|
+
@virtual = CatalogTestResource.new 'virtual', :virtual => true
|
191
|
+
@virtualobject = CatalogTestResource.new 'virtualobject', :builtin => true, :virtual => true
|
192
|
+
@middle = CatalogTestResource.new 'middle'
|
193
|
+
@middleobject = CatalogTestResource.new 'middleobject', :builtin => true
|
194
|
+
@bottom = CatalogTestResource.new 'bottom'
|
195
|
+
@bottomobject = CatalogTestResource.new 'bottomobject', :builtin => true
|
196
|
+
|
197
|
+
@resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]
|
198
|
+
|
199
|
+
@original.add_edge(@top, @topobject)
|
200
|
+
@original.add_edge(@top, @virtual)
|
201
|
+
@original.add_edge(@virtual, @virtualobject)
|
202
|
+
@original.add_edge(@top, @middle)
|
203
|
+
@original.add_edge(@middle, @middleobject)
|
204
|
+
@original.add_edge(@middle, @bottom)
|
205
|
+
@original.add_edge(@bottom, @bottomobject)
|
206
|
+
|
207
|
+
@catalog = @original.to_transportable
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should add all resources as TransObjects" do
|
211
|
+
@resources.each { |resource| @catalog.resource(resource.ref).should be_instance_of(Puppet::TransObject) }
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should not extract defined virtual resources" do
|
215
|
+
@catalog.vertices.find { |v| v.name == "virtual" }.should be_nil
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should not extract builtin virtual resources" do
|
219
|
+
@catalog.vertices.find { |v| v.name == "virtualobject" }.should be_nil
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should copy the tag list to the new catalog" do
|
223
|
+
@catalog.tags.sort.should == @original.tags.sort
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should copy the class list to the new catalog" do
|
227
|
+
@catalog.classes.should == @original.classes
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should duplicate the original edges" do
|
231
|
+
@original.edges.each do |edge|
|
232
|
+
next if edge.source.virtual? or edge.target.virtual?
|
233
|
+
source = @catalog.resource(edge.source.ref)
|
234
|
+
target = @catalog.resource(edge.target.ref)
|
235
|
+
|
236
|
+
source.should_not be_nil
|
237
|
+
target.should_not be_nil
|
238
|
+
@catalog.edge?(source, target).should be_true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should set itself as the catalog for each converted resource" do
|
243
|
+
@catalog.vertices.each { |v| v.catalog.object_id.should equal(@catalog.object_id) }
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe Puppet::Node::Catalog, " when converting to a RAL catalog" do
|
248
|
+
before do
|
249
|
+
@original = Puppet::Node::Catalog.new("mynode")
|
250
|
+
@original.tag(*%w{one two three})
|
251
|
+
@original.add_class *%w{four five six}
|
252
|
+
|
253
|
+
@top = Puppet::TransObject.new 'top', "class"
|
254
|
+
@topobject = Puppet::TransObject.new '/topobject', "file"
|
255
|
+
@middle = Puppet::TransObject.new 'middle', "class"
|
256
|
+
@middleobject = Puppet::TransObject.new '/middleobject', "file"
|
257
|
+
@bottom = Puppet::TransObject.new 'bottom', "class"
|
258
|
+
@bottomobject = Puppet::TransObject.new '/bottomobject', "file"
|
259
|
+
|
260
|
+
@resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]
|
261
|
+
|
262
|
+
@original.add_resource(*@resources)
|
263
|
+
|
264
|
+
@original.add_edge(@top, @topobject)
|
265
|
+
@original.add_edge(@top, @middle)
|
266
|
+
@original.add_edge(@middle, @middleobject)
|
267
|
+
@original.add_edge(@middle, @bottom)
|
268
|
+
@original.add_edge(@bottom, @bottomobject)
|
269
|
+
|
270
|
+
@catalog = @original.to_ral
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should add all resources as RAL instances" do
|
274
|
+
@resources.each { |resource| @catalog.resource(resource.ref).should be_instance_of(Puppet::Type) }
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should copy the tag list to the new catalog" do
|
278
|
+
@catalog.tags.sort.should == @original.tags.sort
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should copy the class list to the new catalog" do
|
282
|
+
@catalog.classes.should == @original.classes
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should duplicate the original edges" do
|
286
|
+
@original.edges.each do |edge|
|
287
|
+
@catalog.edge?(@catalog.resource(edge.source.ref), @catalog.resource(edge.target.ref)).should be_true
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should set itself as the catalog for each converted resource" do
|
292
|
+
@catalog.vertices.each { |v| v.catalog.object_id.should equal(@catalog.object_id) }
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should convert parser resources to transobjects and set the catalog" do
|
296
|
+
catalog = Puppet::Node::Catalog.new("mynode")
|
297
|
+
|
298
|
+
result = mock 'catalog'
|
299
|
+
result.stub_everything
|
300
|
+
|
301
|
+
Puppet::Node::Catalog.expects(:new).returns result
|
302
|
+
|
303
|
+
trans = mock 'trans'
|
304
|
+
resource = Puppet::Parser::Resource.new(:scope => mock("scope"), :source => mock("source"), :type => :file, :title => "/eh")
|
305
|
+
resource.expects(:to_transobject).returns trans
|
306
|
+
trans.expects(:catalog=).with result
|
307
|
+
|
308
|
+
trans.stub_everything
|
309
|
+
|
310
|
+
catalog.add_resource(resource)
|
311
|
+
|
312
|
+
catalog.to_ral
|
313
|
+
end
|
314
|
+
|
315
|
+
# This tests #931.
|
316
|
+
it "should not lose track of resources whose names vary" do
|
317
|
+
changer = Puppet::TransObject.new 'changer', 'test'
|
318
|
+
|
319
|
+
config = Puppet::Node::Catalog.new('test')
|
320
|
+
config.add_resource(changer)
|
321
|
+
config.add_resource(@top)
|
322
|
+
|
323
|
+
config.add_edge(@top, changer)
|
324
|
+
|
325
|
+
resource = stub 'resource', :name => "changer2", :title => "changer2", :ref => "Test[changer2]", :catalog= => nil, :remove => nil
|
326
|
+
|
327
|
+
#changer is going to get duplicated as part of a fix for aliases 1094
|
328
|
+
changer.expects(:dup).returns(changer)
|
329
|
+
changer.expects(:to_type).returns(resource)
|
330
|
+
|
331
|
+
newconfig = nil
|
332
|
+
|
333
|
+
Puppet::Type.allclear
|
334
|
+
|
335
|
+
proc { @catalog = config.to_ral }.should_not raise_error
|
336
|
+
@catalog.resource("Test[changer2]").should equal(resource)
|
337
|
+
end
|
338
|
+
|
339
|
+
after do
|
340
|
+
# Remove all resource instances.
|
341
|
+
@catalog.clear(true)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe Puppet::Node::Catalog, " when functioning as a resource container" do
|
346
|
+
before do
|
347
|
+
@catalog = Puppet::Node::Catalog.new("host")
|
348
|
+
@one = stub 'resource1', :ref => "Me[one]", :catalog= => nil, :title => "one"
|
349
|
+
@two = stub 'resource2', :ref => "Me[two]", :catalog= => nil, :title => "two"
|
350
|
+
@dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil, :title => "one"
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should provide a method to add one or more resources" do
|
354
|
+
@catalog.add_resource @one, @two
|
355
|
+
@catalog.resource(@one.ref).should equal(@one)
|
356
|
+
@catalog.resource(@two.ref).should equal(@two)
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should set itself as the resource's catalog if it is not a relationship graph" do
|
360
|
+
@one.expects(:catalog=).with(@catalog)
|
361
|
+
@catalog.add_resource @one
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should not set itself as the resource's catalog if it is a relationship graph" do
|
365
|
+
@one.expects(:catalog=).never
|
366
|
+
@catalog.is_relationship_graph = true
|
367
|
+
@catalog.add_resource @one
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should make all vertices available by resource reference" do
|
371
|
+
@catalog.add_resource(@one)
|
372
|
+
@catalog.resource(@one.ref).should equal(@one)
|
373
|
+
@catalog.vertices.find { |r| r.ref == @one.ref }.should equal(@one)
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should canonize how resources are referred to during retrieval when both type and title are provided" do
|
377
|
+
@catalog.add_resource(@one)
|
378
|
+
|
379
|
+
@catalog.resource("me", "one").should equal(@one)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should canonize how resources are referred to during retrieval when just the title is provided" do
|
383
|
+
@catalog.add_resource(@one)
|
384
|
+
|
385
|
+
@catalog.resource("me[one]", nil).should equal(@one)
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should not allow two resources with the same resource reference" do
|
389
|
+
@catalog.add_resource(@one)
|
390
|
+
|
391
|
+
# These are used to build the failure
|
392
|
+
@dupe.stubs(:file)
|
393
|
+
@dupe.stubs(:line)
|
394
|
+
@one.stubs(:file)
|
395
|
+
@one.stubs(:line)
|
396
|
+
proc { @catalog.add_resource(@dupe) }.should raise_error(ArgumentError)
|
397
|
+
end
|
398
|
+
|
399
|
+
it "should not store objects that do not respond to :ref" do
|
400
|
+
proc { @catalog.add_resource("thing") }.should raise_error(ArgumentError)
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should remove all resources when asked" do
|
404
|
+
@catalog.add_resource @one
|
405
|
+
@catalog.add_resource @two
|
406
|
+
@one.expects :remove
|
407
|
+
@two.expects :remove
|
408
|
+
@catalog.clear(true)
|
409
|
+
end
|
410
|
+
|
411
|
+
it "should support a mechanism for finishing resources" do
|
412
|
+
@one.expects :finish
|
413
|
+
@two.expects :finish
|
414
|
+
@catalog.add_resource @one
|
415
|
+
@catalog.add_resource @two
|
416
|
+
|
417
|
+
@catalog.finalize
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should make default resources when finalizing" do
|
421
|
+
@catalog.expects(:make_default_resources)
|
422
|
+
@catalog.finalize
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should add default resources to the catalog upon creation" do
|
426
|
+
@catalog.make_default_resources
|
427
|
+
@catalog.resource(:schedule, "daily").should_not be_nil
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should optionally support an initialization block and should finalize after such blocks" do
|
431
|
+
@one.expects :finish
|
432
|
+
@two.expects :finish
|
433
|
+
config = Puppet::Node::Catalog.new("host") do |conf|
|
434
|
+
conf.add_resource @one
|
435
|
+
conf.add_resource @two
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
it "should inform the resource that it is the resource's catalog" do
|
440
|
+
@one.expects(:catalog=).with(@catalog)
|
441
|
+
@catalog.add_resource @one
|
442
|
+
end
|
443
|
+
|
444
|
+
it "should be able to find resources by reference" do
|
445
|
+
@catalog.add_resource @one
|
446
|
+
@catalog.resource(@one.ref).should equal(@one)
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should be able to find resources by reference or by type/title tuple" do
|
450
|
+
@catalog.add_resource @one
|
451
|
+
@catalog.resource("me", "one").should equal(@one)
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should have a mechanism for removing resources" do
|
455
|
+
@catalog.add_resource @one
|
456
|
+
@one.expects :remove
|
457
|
+
@catalog.remove_resource(@one)
|
458
|
+
@catalog.resource(@one.ref).should be_nil
|
459
|
+
@catalog.vertex?(@one).should be_false
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should have a method for creating aliases for resources" do
|
463
|
+
@catalog.add_resource @one
|
464
|
+
@catalog.alias(@one, "other")
|
465
|
+
@catalog.resource("me", "other").should equal(@one)
|
466
|
+
end
|
467
|
+
|
468
|
+
# This test is the same as the previous, but the behaviour should be explicit.
|
469
|
+
it "should alias using the class name from the resource reference, not the resource class name" do
|
470
|
+
@catalog.add_resource @one
|
471
|
+
@catalog.alias(@one, "other")
|
472
|
+
@catalog.resource("me", "other").should equal(@one)
|
473
|
+
end
|
474
|
+
|
475
|
+
it "should ignore conflicting aliases that point to the aliased resource" do
|
476
|
+
@catalog.alias(@one, "other")
|
477
|
+
lambda { @catalog.alias(@one, "other") }.should_not raise_error
|
478
|
+
end
|
479
|
+
|
480
|
+
it "should fail to add an alias if the aliased name already exists" do
|
481
|
+
@catalog.add_resource @one
|
482
|
+
proc { @catalog.alias @two, "one" }.should raise_error(ArgumentError)
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should not fail when a resource has duplicate aliases created" do
|
486
|
+
@catalog.add_resource @one
|
487
|
+
proc { @catalog.alias @one, "one" }.should_not raise_error
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should not create aliases that point back to the resource" do
|
491
|
+
@catalog.alias(@one, "one")
|
492
|
+
@catalog.resource(:me, "one").should be_nil
|
493
|
+
end
|
494
|
+
|
495
|
+
it "should be able to look resources up by their aliases" do
|
496
|
+
@catalog.add_resource @one
|
497
|
+
@catalog.alias @one, "two"
|
498
|
+
@catalog.resource(:me, "two").should equal(@one)
|
499
|
+
end
|
500
|
+
|
501
|
+
it "should remove resource aliases when the target resource is removed" do
|
502
|
+
@catalog.add_resource @one
|
503
|
+
@catalog.alias(@one, "other")
|
504
|
+
@one.expects :remove
|
505
|
+
@catalog.remove_resource(@one)
|
506
|
+
@catalog.resource("me", "other").should be_nil
|
507
|
+
end
|
508
|
+
|
509
|
+
it "should add an alias for the namevar when the title and name differ on isomorphic resource types" do
|
510
|
+
resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah"
|
511
|
+
resource.expects(:isomorphic?).returns(true)
|
512
|
+
@catalog.add_resource(resource)
|
513
|
+
@catalog.resource(:file, "other").should equal(resource)
|
514
|
+
@catalog.resource(:file, "/something").ref.should == resource.ref
|
515
|
+
end
|
516
|
+
|
517
|
+
it "should not add an alias for the namevar when the title and name differ on non-isomorphic resource types" do
|
518
|
+
resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah"
|
519
|
+
resource.expects(:isomorphic?).returns(false)
|
520
|
+
@catalog.add_resource(resource)
|
521
|
+
@catalog.resource(:file, resource.title).should equal(resource)
|
522
|
+
# We can't use .should here, because the resources respond to that method.
|
523
|
+
if @catalog.resource(:file, resource.name)
|
524
|
+
raise "Aliased non-isomorphic resource"
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
after do
|
529
|
+
Puppet::Type.allclear
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
describe Puppet::Node::Catalog do
|
534
|
+
before :each do
|
535
|
+
@catalog = Puppet::Node::Catalog.new("host")
|
536
|
+
|
537
|
+
@catalog.retrieval_duration = Time.now
|
538
|
+
@transaction = mock 'transaction'
|
539
|
+
Puppet::Transaction.stubs(:new).returns(@transaction)
|
540
|
+
@transaction.stubs(:evaluate)
|
541
|
+
@transaction.stubs(:cleanup)
|
542
|
+
@transaction.stubs(:addtimes)
|
543
|
+
end
|
544
|
+
|
545
|
+
describe Puppet::Node::Catalog, " when applying" do
|
546
|
+
|
547
|
+
it "should create and evaluate a transaction" do
|
548
|
+
@transaction.expects(:evaluate)
|
549
|
+
@catalog.apply
|
550
|
+
end
|
551
|
+
|
552
|
+
it "should provide the catalog time to the transaction" do
|
553
|
+
@transaction.expects(:addtimes).with do |arg|
|
554
|
+
arg[:config_retrieval].should be_instance_of(Time)
|
555
|
+
true
|
556
|
+
end
|
557
|
+
@catalog.apply
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should clean up the transaction" do
|
561
|
+
@transaction.expects :cleanup
|
562
|
+
@catalog.apply
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should return the transaction" do
|
566
|
+
@catalog.apply.should equal(@transaction)
|
567
|
+
end
|
568
|
+
|
569
|
+
it "should yield the transaction if a block is provided" do
|
570
|
+
@catalog.apply do |trans|
|
571
|
+
trans.should equal(@transaction)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should default to not being a host catalog" do
|
576
|
+
@catalog.host_config.should be_nil
|
577
|
+
end
|
578
|
+
|
579
|
+
it "should pass supplied tags on to the transaction" do
|
580
|
+
@transaction.expects(:tags=).with(%w{one two})
|
581
|
+
@catalog.apply(:tags => %w{one two})
|
582
|
+
end
|
583
|
+
|
584
|
+
it "should set ignoreschedules on the transaction if specified in apply()" do
|
585
|
+
@transaction.expects(:ignoreschedules=).with(true)
|
586
|
+
@catalog.apply(:ignoreschedules => true)
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
describe Puppet::Node::Catalog, " when applying host catalogs" do
|
591
|
+
|
592
|
+
# super() doesn't work in the setup method for some reason
|
593
|
+
before do
|
594
|
+
@catalog.host_config = true
|
595
|
+
Puppet::Util::Storage.stubs(:store)
|
596
|
+
end
|
597
|
+
|
598
|
+
it "should send a report if reporting is enabled" do
|
599
|
+
Puppet[:report] = true
|
600
|
+
@transaction.expects :send_report
|
601
|
+
@transaction.stubs :any_failed? => false
|
602
|
+
@catalog.apply
|
603
|
+
end
|
604
|
+
|
605
|
+
it "should send a report if report summaries are enabled" do
|
606
|
+
Puppet[:summarize] = true
|
607
|
+
@transaction.expects :send_report
|
608
|
+
@transaction.stubs :any_failed? => false
|
609
|
+
@catalog.apply
|
610
|
+
end
|
611
|
+
|
612
|
+
it "should initialize the state database before applying a catalog" do
|
613
|
+
Puppet::Util::Storage.expects(:load)
|
614
|
+
|
615
|
+
# Short-circuit the apply, so we know we're loading before the transaction
|
616
|
+
Puppet::Transaction.expects(:new).raises ArgumentError
|
617
|
+
proc { @catalog.apply }.should raise_error(ArgumentError)
|
618
|
+
end
|
619
|
+
|
620
|
+
it "should sync the state database after applying" do
|
621
|
+
Puppet::Util::Storage.expects(:store)
|
622
|
+
@transaction.stubs :any_failed? => false
|
623
|
+
@catalog.apply
|
624
|
+
end
|
625
|
+
|
626
|
+
after { Puppet.settings.clear }
|
627
|
+
end
|
628
|
+
|
629
|
+
describe Puppet::Node::Catalog, " when applying non-host catalogs" do
|
630
|
+
|
631
|
+
before do
|
632
|
+
@catalog.host_config = false
|
633
|
+
end
|
634
|
+
|
635
|
+
it "should never send reports" do
|
636
|
+
Puppet[:report] = true
|
637
|
+
Puppet[:summarize] = true
|
638
|
+
@transaction.expects(:send_report).never
|
639
|
+
@catalog.apply
|
640
|
+
end
|
641
|
+
|
642
|
+
it "should never modify the state database" do
|
643
|
+
Puppet::Util::Storage.expects(:load).never
|
644
|
+
Puppet::Util::Storage.expects(:store).never
|
645
|
+
@catalog.apply
|
646
|
+
end
|
647
|
+
|
648
|
+
after { Puppet.settings.clear }
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
describe Puppet::Node::Catalog, " when creating a relationship graph" do
|
653
|
+
before do
|
654
|
+
Puppet::Type.type(:component)
|
655
|
+
@catalog = Puppet::Node::Catalog.new("host")
|
656
|
+
@compone = Puppet::Type::Component.create :name => "one"
|
657
|
+
@comptwo = Puppet::Type::Component.create :name => "two", :require => ["class", "one"]
|
658
|
+
@file = Puppet::Type.type(:file)
|
659
|
+
@one = @file.create :path => "/one"
|
660
|
+
@two = @file.create :path => "/two"
|
661
|
+
@catalog.add_edge @compone, @one
|
662
|
+
@catalog.add_edge @comptwo, @two
|
663
|
+
|
664
|
+
@three = @file.create :path => "/three"
|
665
|
+
@four = @file.create :path => "/four", :require => ["file", "/three"]
|
666
|
+
@five = @file.create :path => "/five"
|
667
|
+
@catalog.add_resource @compone, @comptwo, @one, @two, @three, @four, @five
|
668
|
+
@relationships = @catalog.relationship_graph
|
669
|
+
end
|
670
|
+
|
671
|
+
it "should fail when trying to create a relationship graph for a relationship graph" do
|
672
|
+
proc { @relationships.relationship_graph }.should raise_error(Puppet::DevError)
|
673
|
+
end
|
674
|
+
|
675
|
+
it "should be able to create a relationship graph" do
|
676
|
+
@relationships.should be_instance_of(Puppet::Node::Catalog)
|
677
|
+
end
|
678
|
+
|
679
|
+
it "should copy its host_config setting to the relationship graph" do
|
680
|
+
config = Puppet::Node::Catalog.new
|
681
|
+
config.host_config = true
|
682
|
+
config.relationship_graph.host_config.should be_true
|
683
|
+
end
|
684
|
+
|
685
|
+
it "should not have any components" do
|
686
|
+
@relationships.vertices.find { |r| r.instance_of?(Puppet::Type::Component) }.should be_nil
|
687
|
+
end
|
688
|
+
|
689
|
+
it "should have all non-component resources from the catalog" do
|
690
|
+
# The failures print out too much info, so i just do a class comparison
|
691
|
+
@relationships.vertex?(@five).should be_true
|
692
|
+
end
|
693
|
+
|
694
|
+
it "should have all resource relationships set as edges" do
|
695
|
+
@relationships.edge?(@three, @four).should be_true
|
696
|
+
end
|
697
|
+
|
698
|
+
it "should copy component relationships to all contained resources" do
|
699
|
+
@relationships.edge?(@one, @two).should be_true
|
700
|
+
end
|
701
|
+
|
702
|
+
it "should get removed when the catalog is cleaned up" do
|
703
|
+
@relationships.expects(:clear).with(false)
|
704
|
+
@catalog.clear
|
705
|
+
@catalog.instance_variable_get("@relationship_graph").should be_nil
|
706
|
+
end
|
707
|
+
|
708
|
+
it "should create a new relationship graph after clearing the old one" do
|
709
|
+
@relationships.expects(:clear).with(false)
|
710
|
+
@catalog.clear
|
711
|
+
@catalog.relationship_graph.should be_instance_of(Puppet::Node::Catalog)
|
712
|
+
end
|
713
|
+
|
714
|
+
it "should look up resources in the relationship graph if not found in the main catalog" do
|
715
|
+
five = stub 'five', :ref => "File[five]", :catalog= => nil
|
716
|
+
@relationships.add_resource five
|
717
|
+
@catalog.resource(five.ref).should equal(five)
|
718
|
+
end
|
719
|
+
|
720
|
+
it "should provide a method to create additional resources that also registers the resource" do
|
721
|
+
args = {:name => "/yay", :ensure => :file}
|
722
|
+
resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
|
723
|
+
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
|
724
|
+
@catalog.create_resource :file, args
|
725
|
+
@catalog.resource("File[/yay]").should equal(resource)
|
726
|
+
end
|
727
|
+
|
728
|
+
it "should provide a mechanism for creating implicit resources" do
|
729
|
+
args = {:name => "/yay", :ensure => :file}
|
730
|
+
resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
|
731
|
+
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
|
732
|
+
resource.expects(:implicit=).with(true)
|
733
|
+
@catalog.create_implicit_resource :file, args
|
734
|
+
@catalog.resource("File[/yay]").should equal(resource)
|
735
|
+
end
|
736
|
+
|
737
|
+
it "should add implicit resources to the relationship graph if there is one" do
|
738
|
+
args = {:name => "/yay", :ensure => :file}
|
739
|
+
resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
|
740
|
+
resource.expects(:implicit=).with(true)
|
741
|
+
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
|
742
|
+
# build the graph
|
743
|
+
relgraph = @catalog.relationship_graph
|
744
|
+
|
745
|
+
@catalog.create_implicit_resource :file, args
|
746
|
+
relgraph.resource("File[/yay]").should equal(resource)
|
747
|
+
end
|
748
|
+
|
749
|
+
it "should remove resources created mid-transaction" do
|
750
|
+
args = {:name => "/yay", :ensure => :file}
|
751
|
+
resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
|
752
|
+
@transaction = mock 'transaction'
|
753
|
+
Puppet::Transaction.stubs(:new).returns(@transaction)
|
754
|
+
@transaction.stubs(:evaluate)
|
755
|
+
@transaction.stubs(:cleanup)
|
756
|
+
@transaction.stubs(:addtimes)
|
757
|
+
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
|
758
|
+
resource.expects :remove
|
759
|
+
@catalog.apply do |trans|
|
760
|
+
@catalog.create_resource :file, args
|
761
|
+
@catalog.resource("File[/yay]").should equal(resource)
|
762
|
+
end
|
763
|
+
@catalog.resource("File[/yay]").should be_nil
|
764
|
+
end
|
765
|
+
|
766
|
+
it "should remove resources from the relationship graph if it exists" do
|
767
|
+
@catalog.remove_resource(@one)
|
768
|
+
@catalog.relationship_graph.vertex?(@one).should be_false
|
769
|
+
end
|
770
|
+
|
771
|
+
after do
|
772
|
+
Puppet::Type.allclear
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
describe Puppet::Node::Catalog, " when writing dot files" do
|
777
|
+
before do
|
778
|
+
@catalog = Puppet::Node::Catalog.new("host")
|
779
|
+
@name = :test
|
780
|
+
@file = File.join(Puppet[:graphdir], @name.to_s + ".dot")
|
781
|
+
end
|
782
|
+
it "should only write when it is a host catalog" do
|
783
|
+
File.expects(:open).with(@file).never
|
784
|
+
@catalog.host_config = false
|
785
|
+
Puppet[:graph] = true
|
786
|
+
@catalog.write_graph(@name)
|
787
|
+
end
|
788
|
+
|
789
|
+
it "should only write when graphing is enabled" do
|
790
|
+
File.expects(:open).with(@file).never
|
791
|
+
@catalog.host_config = true
|
792
|
+
Puppet[:graph] = false
|
793
|
+
@catalog.write_graph(@name)
|
794
|
+
end
|
795
|
+
|
796
|
+
it "should write a dot file based on the passed name" do
|
797
|
+
File.expects(:open).with(@file, "w").yields(stub("file", :puts => nil))
|
798
|
+
@catalog.expects(:to_dot).with("name" => @name.to_s.capitalize)
|
799
|
+
@catalog.host_config = true
|
800
|
+
Puppet[:graph] = true
|
801
|
+
@catalog.write_graph(@name)
|
802
|
+
end
|
803
|
+
|
804
|
+
after do
|
805
|
+
Puppet.settings.clear
|
806
|
+
end
|
807
|
+
end
|
808
|
+
|
809
|
+
describe Puppet::Node::Catalog, " when indirecting" do
|
810
|
+
before do
|
811
|
+
@indirection = stub 'indirection', :name => :catalog
|
812
|
+
|
813
|
+
Puppet::Indirector::Indirection.clear_cache
|
814
|
+
end
|
815
|
+
|
816
|
+
it "should redirect to the indirection for retrieval" do
|
817
|
+
Puppet::Node::Catalog.stubs(:indirection).returns(@indirection)
|
818
|
+
@indirection.expects(:find)
|
819
|
+
Puppet::Node::Catalog.find(:myconfig)
|
820
|
+
end
|
821
|
+
|
822
|
+
it "should default to the 'compiler' terminus" do
|
823
|
+
Puppet::Node::Catalog.indirection.terminus_class.should == :compiler
|
824
|
+
end
|
825
|
+
|
826
|
+
after do
|
827
|
+
mocha_verify
|
828
|
+
Puppet::Indirector::Indirection.clear_cache
|
829
|
+
end
|
830
|
+
end
|
831
|
+
|
832
|
+
describe Puppet::Node::Catalog, " when converting to yaml" do
|
833
|
+
before do
|
834
|
+
@catalog = Puppet::Node::Catalog.new("me")
|
835
|
+
@catalog.add_edge("one", "two")
|
836
|
+
end
|
837
|
+
|
838
|
+
it "should be able to be dumped to yaml" do
|
839
|
+
YAML.dump(@catalog).should be_instance_of(String)
|
840
|
+
end
|
841
|
+
end
|
842
|
+
|
843
|
+
describe Puppet::Node::Catalog, " when converting from yaml" do
|
844
|
+
before do
|
845
|
+
@catalog = Puppet::Node::Catalog.new("me")
|
846
|
+
@catalog.add_edge("one", "two")
|
847
|
+
|
848
|
+
text = YAML.dump(@catalog)
|
849
|
+
@newcatalog = YAML.load(text)
|
850
|
+
end
|
851
|
+
|
852
|
+
it "should get converted back to a catalog" do
|
853
|
+
@newcatalog.should be_instance_of(Puppet::Node::Catalog)
|
854
|
+
end
|
855
|
+
|
856
|
+
it "should have all vertices" do
|
857
|
+
@newcatalog.vertex?("one").should be_true
|
858
|
+
@newcatalog.vertex?("two").should be_true
|
859
|
+
end
|
860
|
+
|
861
|
+
it "should have all edges" do
|
862
|
+
@newcatalog.edge?("one", "two").should be_true
|
863
|
+
end
|
864
|
+
end
|