summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/puppet2
-rwxr-xr-xbin/puppetmasterd3
-rwxr-xr-xext/module_puppet43
-rw-r--r--lib/puppet/indirector/code/configuration.rb10
-rw-r--r--lib/puppet/indirector/indirection.rb9
-rw-r--r--lib/puppet/indirector/terminus.rb10
-rw-r--r--lib/puppet/indirector/yaml.rb18
-rw-r--r--lib/puppet/indirector/yaml/configuration.rb18
-rw-r--r--lib/puppet/network/handler/configuration.rb10
-rw-r--r--lib/puppet/node/configuration.rb57
-rw-r--r--lib/puppet/pgraph.rb4
-rw-r--r--lib/puppet/transportable.rb68
-rw-r--r--lib/puppet/type/component.rb10
-rwxr-xr-xspec/unit/indirector/code/configuration.rb4
-rwxr-xr-xspec/unit/indirector/indirection.rb18
-rwxr-xr-xspec/unit/indirector/terminus.rb20
-rwxr-xr-xspec/unit/node/configuration.rb186
-rw-r--r--test/data/snippets/classpathtest4
-rwxr-xr-xtest/language/snippets.rb4
-rwxr-xr-xtest/language/transportable.rb34
-rwxr-xr-xtest/network/client/client.rb2
-rwxr-xr-xtest/network/client/master.rb8
-rwxr-xr-xtest/network/handler/configuration.rb27
-rwxr-xr-xtest/network/handler/master.rb3
24 files changed, 429 insertions, 143 deletions
diff --git a/bin/puppet b/bin/puppet
index b004111c9..e4e3dd309 100755
--- a/bin/puppet
+++ b/bin/puppet
@@ -203,7 +203,7 @@ begin
config = Puppet::Node::Configuration.find(node)
# Translate it to a RAL configuration
- config = config.extract_to_transportable.to_configuration
+ config = config.to_ral
# And apply it
config.apply
diff --git a/bin/puppetmasterd b/bin/puppetmasterd
index f764b1901..643076659 100755
--- a/bin/puppetmasterd
+++ b/bin/puppetmasterd
@@ -186,6 +186,9 @@ end
Puppet.genconfig
Puppet.genmanifest
+# A temporary solution, to at least make the master work for now.
+Puppet::Node::Facts.terminus_class = :yaml
+
require 'etc'
handlers = {
diff --git a/ext/module_puppet b/ext/module_puppet
index 52f65b094..36efb4f0e 100755
--- a/ext/module_puppet
+++ b/ext/module_puppet
@@ -150,14 +150,23 @@ unless setdest
Puppet::Util::Log.newdestination(:syslog)
end
-master[:Manifest] = ARGV.shift
+Puppet[:manifest] = ARGV.shift
unless ENV.include?("CFALLCLASSES")
$stderr.puts "Cfengine classes must be passed to the module"
exit(15)
end
-master[:UseNodes] = false
+# Collect our facts.
+Puppet::Node::Facts.terminus_class = :code
+facts = Puppet::Node::Facts.find("me")
+facts.name = facts.values["hostname"]
+
+# Create our Node
+node = Puppet::Node.new(facts.name)
+
+# Merge in the facts.
+node.merge(facts.values)
classes = ENV["CFALLCLASSES"].split(":")
@@ -166,32 +175,32 @@ if classes.empty?
exit(16)
end
-master[:Classes] = classes
+node.classes = classes
begin
- server = Puppet::Network::Handler.master.new(master)
+ # Compile our configuration
+ config = Puppet::Node::Configuration.find(node)
rescue => detail
- $stderr.puts detail
- exit(1)
-end
-
-begin
- client = Puppet::Network::Client.master.new(
- :Master => server,
- :Cache => false
- )
-rescue => detail
- $stderr.puts detail
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
+ if detail.is_a?(XMLRPC::FaultException)
+ $stderr.puts detail.message
+ else
+ $stderr.puts detail
+ end
exit(1)
end
-
if parseonly
exit(0)
end
begin
- config = client.getconfig
+ # Translate it to a RAL configuration
+ config = config.to_ral
+
+ # And apply it
config.apply
rescue => detail
Puppet.err detail
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb
index 2d8fedcc8..949926a3c 100644
--- a/lib/puppet/indirector/code/configuration.rb
+++ b/lib/puppet/indirector/code/configuration.rb
@@ -21,9 +21,13 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code
node = find_node(key)
end
- configuration = compile(node)
-
- return configuration
+ if configuration = compile(node)
+ return configuration.to_transportable
+ else
+ # This shouldn't actually happen; we should either return
+ # a config or raise an exception.
+ return nil
+ end
end
def initialize
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index cd71c4d66..5f7baa3da 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -91,12 +91,15 @@ class Puppet::Indirector::Indirection
end
def find(key, *args)
- if cache? and terminus.fresh?(key, cache.version(key))
+ if cache? and cache.has_most_recent?(key, terminus.version(key))
return cache.find(key, *args)
end
if result = terminus.find(key, *args)
result.version ||= Time.now.utc
- cache.save(result, *args) if cache?
+ if cache?
+ Puppet.info "Caching %s %s" % [self.name, key]
+ cache.save(result, *args)
+ end
return result
end
end
@@ -113,7 +116,7 @@ class Puppet::Indirector::Indirection
def save(instance, *args)
instance.version ||= Time.now.utc
dest = cache? ? cache : terminus
- return if dest.fresh?(instance.name, instance.version)
+ return if dest.has_most_recent?(instance.name, instance.version)
cache.save(instance, *args) if cache?
terminus.save(instance, *args)
end
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index 5aeb4c6d7..37cfdc499 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -95,13 +95,15 @@ class Puppet::Indirector::Terminus
end
end
- # Is this instance fresh? Meaning, is the version we have equivalent or better
- # than the version being asked about
- def fresh?(key, vers)
+ # Do we have an update for this object? This compares the provided version
+ # to our version, and returns true if our version is at least as high
+ # as the asked-about version.
+ def has_most_recent?(key, vers)
raise Puppet::DevError.new("Cannot check update status when no 'version' method is defined") unless respond_to?(:version)
if existing_version = version(key)
- existing_version >= vers
+ #puts "%s fresh: %s (%s vs %s)" % [self.name, (existing_version.to_f >= vers.to_f).inspect, existing_version.to_f, vers.to_f]
+ existing_version.to_f >= vers.to_f
else
false
end
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index b9ea54f39..e11c88474 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -14,9 +14,9 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
return nil unless FileTest.exist?(file)
begin
- return YAML.load(File.read(file))
+ return from_yaml(File.read(file))
rescue => detail
- raise Puppet::Error, "Could not read YAML data for %s(%s): %s" % [indirection.name, name, detail]
+ raise Puppet::Error, "Could not read YAML data for %s %s: %s" % [indirection.name, name, detail]
end
end
@@ -33,11 +33,23 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
Dir.mkdir(basedir)
end
- File.open(file, "w", 0660) { |f| f.print YAML.dump(object) }
+ begin
+ File.open(file, "w", 0660) { |f| f.print to_yaml(object) }
+ rescue TypeError => detail
+ Puppet.err "Could not save %s %s: %s" % [self.name, object.name, detail]
+ end
end
private
+ def from_yaml(text)
+ YAML.load(text)
+ end
+
+ def to_yaml(object)
+ YAML.dump(object)
+ end
+
# Return the path to a given node's file.
def path(name)
File.join(Puppet[:yamldir], self.name.to_s, name.to_s + ".yaml")
diff --git a/lib/puppet/indirector/yaml/configuration.rb b/lib/puppet/indirector/yaml/configuration.rb
index 691f0e343..8e40ff9bf 100644
--- a/lib/puppet/indirector/yaml/configuration.rb
+++ b/lib/puppet/indirector/yaml/configuration.rb
@@ -2,4 +2,22 @@ require 'puppet/indirector/yaml'
class Puppet::Indirector::Yaml::Configuration < Puppet::Indirector::Yaml
desc "Store configurations as flat files, serialized using YAML."
+
+ private
+
+ # Override these, because yaml doesn't want to convert our self-referential
+ # objects. This is hackish, but eh.
+ def from_yaml(text)
+ if config = YAML.load(text)
+ # We can't yaml-dump classes.
+ #config.edgelist_class = Puppet::Relationship
+ return config
+ end
+ end
+
+ def to_yaml(config)
+ # We can't yaml-dump classes.
+ #config.edgelist_class = nil
+ YAML.dump(config)
+ end
end
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index 09c4b971a..680304e2a 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -13,7 +13,7 @@ class Puppet::Network::Handler
include Puppet::Util
- attr_accessor :local
+ attr_accessor :local, :classes
@interface = XMLRPC::Service::Interface.new("configuration") { |iface|
iface.add_method("string configuration(string)")
@@ -43,16 +43,10 @@ class Puppet::Network::Handler
end
def initialize(options = {})
- if options[:Local]
- @local = options[:Local]
- else
- @local = false
- end
-
options.each do |param, value|
case param
when :Classes: @classes = value
- when :Local: self.local = true
+ when :Local: self.local = value
else
raise ArgumentError, "Configuration handler does not accept %s" % param
end
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 084bdf880..da8dc3a9a 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -22,6 +22,10 @@ class Puppet::Node::Configuration < Puppet::PGraph
# How we should extract the configuration for sending to the client.
attr_reader :extraction_format
+ # We need the ability to set this externally, so we can yaml-dump the
+ # configuration.
+ attr_accessor :edgelist_class
+
# Whether this is a host configuration, which behaves very differently.
# In particular, reports are sent, graphs are made, and state is
# stored in the state database. If this is set incorrectly, then you often
@@ -355,6 +359,16 @@ class Puppet::Node::Configuration < Puppet::PGraph
@tags.dup
end
+ # Convert our configuration into a RAL configuration.
+ def to_ral
+ to_configuration :to_type
+ end
+
+ # Turn our parser configuration into a transportable configuration.
+ def to_transportable
+ to_configuration :to_transobject
+ end
+
# Produce the graph files if requested.
def write_graph(name)
# We only want to graph the main host configuration.
@@ -370,6 +384,14 @@ class Puppet::Node::Configuration < Puppet::PGraph
}
end
+ # LAK:NOTE We cannot yaml-dump the class in the edgelist_class, because classes cannot be
+ # dumped by default, nor does yaml-dumping # the edge-labels work at this point (I don't
+ # know why).
+ # Neither of these matters right now, but I suppose it could at some point.
+ def to_yaml_properties
+ instance_variables.reject { |v| %w{@edgelist_class @edge_labels}.include?(v) }
+ end
+
private
def cleanup
@@ -379,4 +401,39 @@ class Puppet::Node::Configuration < Puppet::PGraph
@relationship_graph = nil
end
end
+
+ # An abstracted method for converting one configuration into another type of configuration.
+ # This pretty much just converts all of the resources from one class to another, using
+ # a conversion method.
+ def to_configuration(convert)
+ result = self.class.new(self.name)
+
+ vertices.each do |resource|
+ next if resource.respond_to?(:virtual?) and resource.virtual?
+
+ result.add_resource resource.send(convert)
+ end
+
+ message = convert.to_s.gsub "_", " "
+ edges.each do |edge|
+ # Skip edges between virtual resources.
+ next if edge.source.respond_to?(:virtual?) and edge.source.virtual?
+ next if edge.target.respond_to?(:virtual?) and edge.target.virtual?
+
+ unless source = result.resource(edge.source.ref)
+ raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.source.ref, message]
+ end
+
+ unless target = result.resource(edge.target.ref)
+ raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.target.ref, message]
+ end
+
+ result.add_edge!(source, target, edge.label)
+ end
+
+ result.add_class *self.classes
+ result.tag(*self.tags)
+
+ return result
+ end
end
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb
index 2399d1651..ca45aa2b3 100644
--- a/lib/puppet/pgraph.rb
+++ b/lib/puppet/pgraph.rb
@@ -190,6 +190,10 @@ class Puppet::PGraph < GRATR::Digraph
return result
end
+ def to_yaml_properties
+ instance_variables
+ end
+
# A different way of walking a tree, and a much faster way than the
# one that comes with GRATR.
def tree_from_vertex2(start, direction = :out)
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index ecd179ed7..2a600b50e 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -8,7 +8,7 @@ module Puppet
# YAML.
class TransObject
include Enumerable
- attr_accessor :type, :name, :file, :line, :collectable, :collected
+ attr_accessor :type, :name, :file, :line, :configuration
attr_writer :tags
@@ -25,7 +25,6 @@ module Puppet
def initialize(name,type)
@type = type
@name = name
- @collectable = false
@params = {}
@tags = []
end
@@ -34,10 +33,44 @@ module Puppet
return [@type,@name].join('--')
end
+ def ref
+ unless defined? @ref
+ if @type == :component
+ @ref = @name
+ else
+ @ref = "%s[%s]" % [type_capitalized, name]
+ end
+ end
+ @ref
+ end
+
def tags
return @tags
end
+ # Convert a defined type into a component.
+ def to_component
+ tmpname = nil
+
+ # Nodes have the same name and type
+ if self.name
+ tmpname = "%s[%s]" % [type_capitalized, self.name]
+ else
+ tmpname = @type
+ end
+ trans = TransObject.new(tmpname, :component)
+ if defined? @parameters
+ @parameters.each { |param,value|
+ Puppet.debug "Defining %s on %s of type %s" %
+ [param,@name,@type]
+ trans[param] = value
+ }
+ else
+ #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
+ end
+ Puppet::Type::Component.create(trans)
+ end
+
def to_hash
@params.dup
end
@@ -57,18 +90,18 @@ module Puppet
end
def to_yaml_properties
- instance_variables
+ instance_variables.reject { |v| %w{@ref}.include?(v) }
end
def to_ref
- unless defined? @ref
+ unless defined? @res_ref
if self.type and self.name
- @ref = "%s[%s]" % [self.type, self.name]
+ @res_ref = "%s[%s]" % [type_capitalized, self.name]
else
- @ref = nil
+ @res_ref = nil
end
end
- @ref
+ @res_ref
end
def to_type
@@ -85,11 +118,16 @@ module Puppet
end
end
else
- raise Puppet::Error.new("Could not find object type %s" % self.type)
+ return to_component
end
return retobj
end
+
+ # Return the type fully capitalized correctly.
+ def type_capitalized
+ type.split("::").collect { |s| s.capitalize }.join("::")
+ end
end
# Just a linear container for objects. Behaves mostly like an array, except
@@ -107,20 +145,6 @@ module Puppet
end
}
- # Remove all collectable objects from our tree, since the client
- # should not see them.
- def collectstrip!
- @children.dup.each do |child|
- if child.is_a? self.class
- child.collectstrip!
- else
- if child.collectable and ! child.collected
- @children.delete(child)
- end
- end
- end
- end
-
# Recursively yield everything.
def delve(&block)
@children.each do |obj|
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index c5842e0e7..4dc542a65 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -109,14 +109,6 @@ Puppet::Type.newtype(:component) do
@children = []
end
- def parent=(parent)
- if self.parentof?(parent)
- devfail "%s[%s] is already the parent of %s[%s]" %
- [self.class.name, self.title, parent.class.name, parent.title]
- end
- @parent = parent
- end
-
# Add a hook for testing for recursion.
def parentof?(child)
if super(child)
@@ -133,7 +125,7 @@ Puppet::Type.newtype(:component) do
def pathbuilder
tmp = []
myname = ""
- if self.title =~ /^class\[(.+)\]$/
+ if self.title =~ /^class\[(.+)\]$/i
# 'main' is the top class, so we want to see '//' instead of
# its name.
unless $1 == "main"
diff --git a/spec/unit/indirector/code/configuration.rb b/spec/unit/indirector/code/configuration.rb
index bc54f4e1c..0038a038e 100755
--- a/spec/unit/indirector/code/configuration.rb
+++ b/spec/unit/indirector/code/configuration.rb
@@ -143,7 +143,9 @@ describe Puppet::Indirector::Code::Configuration, " when creating configurations
it "should return the results of compiling as the configuration" do
config = mock 'config'
- @compiler.interpreter.expects(:compile).with(@node).returns(:configuration)
+ result = mock 'result', :to_transportable => :configuration
+
+ @compiler.interpreter.expects(:compile).with(@node).returns(result)
@compiler.find(@name).should == :configuration
end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 4fcf5fc11..7a1c4531c 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -7,7 +7,7 @@ require 'puppet/indirector'
describe Puppet::Indirector::Indirection do
before do
@indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
- @terminus = stub 'terminus', :fresh? => false
+ @terminus = stub 'terminus', :has_most_recent? => false
@indirection.stubs(:terminus).returns(@terminus)
@instance = stub 'instance', :version => nil, :version= => nil, :name => "whatever"
@name = :mything
@@ -286,12 +286,12 @@ describe Puppet::Indirector::Indirection, " when saving and using a cache" do
end
it "should not update the cache or terminus if the new object is not different" do
- @cache.expects(:fresh?).with(@name, 5).returns(true)
+ @cache.expects(:has_most_recent?).with(@name, 5).returns(true)
@indirection.save(@instance)
end
it "should update the original and the cache if the cached object is different" do
- @cache.expects(:fresh?).with(@name, 5).returns(false)
+ @cache.expects(:has_most_recent?).with(@name, 5).returns(false)
@terminus.expects(:save).with(@instance)
@cache.expects(:save).with(@instance)
@indirection.save(@instance)
@@ -311,8 +311,8 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do
name = "myobject"
- @cache.expects(:version).with(name).returns(1)
- @terminus.expects(:fresh?).with(name, 1).returns(true)
+ @terminus.expects(:version).with(name).returns(1)
+ @cache.expects(:has_most_recent?).with(name, 1).returns(true)
@cache.expects(:find).with(name).returns(cached)
@@ -324,9 +324,9 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do
name = "myobject"
- @cache.expects(:version).with(name).returns(1)
@cache.stubs(:save)
- @terminus.expects(:fresh?).with(name, 1).returns(false)
+ @cache.expects(:has_most_recent?).with(name, 1).returns(false)
+ @terminus.expects(:version).with(name).returns(1)
@terminus.expects(:find).with(name).returns(real)
@@ -338,8 +338,8 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do
name = "myobject"
- @cache.expects(:version).with(name).returns(1)
- @terminus.expects(:fresh?).with(name, 1).returns(false)
+ @terminus.expects(:version).with(name).returns(1)
+ @cache.expects(:has_most_recent?).with(name, 1).returns(false)
@terminus.expects(:find).with(name).returns(real)
@cache.expects(:save).with(real)
diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb
index 2488a1a67..3361bfeeb 100755
--- a/spec/unit/indirector/terminus.rb
+++ b/spec/unit/indirector/terminus.rb
@@ -247,7 +247,7 @@ describe Puppet::Indirector::Terminus, " when managing indirected instances" do
include TerminusInstanceTesting
it "should support comparing an instance's version with the terminus's version using just the instance's key" do
- @terminus.should respond_to(:fresh?)
+ @terminus.should respond_to(:has_most_recent?)
end
it "should fail if the :version method has not been overridden and no :find method is available" do
@@ -270,18 +270,30 @@ describe Puppet::Indirector::Terminus, " when managing indirected instances" do
it "should consider an instance fresh if its version is more recent than the version provided" do
name = "yay"
@terminus.expects(:version).with(name).returns(5)
- @terminus.fresh?(name, 4).should be_true
+ @terminus.has_most_recent?(name, 4).should be_true
end
it "should consider an instance fresh if its version is equal to the version provided" do
name = "yay"
@terminus.expects(:version).with(name).returns(5)
- @terminus.fresh?(name, 5).should be_true
+ @terminus.has_most_recent?(name, 5).should be_true
end
it "should consider an instance not fresh if the provided version is more recent than its version" do
name = "yay"
@terminus.expects(:version).with(name).returns(4)
- @terminus.fresh?(name, 5).should be_false
+ @terminus.has_most_recent?(name, 5).should be_false
+ end
+
+ # Times annoyingly can't be compared directly to numbers, and our
+ # default version is 0.
+ it "should convert versions to floats when checking for freshness" do
+ existing = mock 'existing version'
+ new = mock 'new version'
+ existing.expects(:to_f).returns(1.0)
+ new.expects(:to_f).returns(1.0)
+ name = "yay"
+ @terminus.expects(:version).with(name).returns(existing)
+ @terminus.has_most_recent?(name, new)
end
end
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index 153d0b182..ee3834ef3 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -52,10 +52,6 @@ describe Puppet::Node::Configuration, " when extracting" do
end
end
-describe Puppet::Node::Configuration, " when extracting RAL resources" do
- it "should support an extraction method for converting a parser configuration into a RAL configuration"
-end
-
describe Puppet::Node::Configuration, " when extracting transobjects" do
def mkscope
@@ -155,6 +151,153 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do
end
end
+describe Puppet::Node::Configuration, " when converting to a transobject configuration" do
+ class TestResource
+ attr_accessor :name, :virtual, :builtin
+ def initialize(name, options = {})
+ @name = name
+ options.each { |p,v| send(p.to_s + "=", v) }
+ end
+
+ def ref
+ if builtin?
+ "File[%s]" % name
+ else
+ "Class[%s]" % name
+ end
+ end
+
+ def virtual?
+ virtual
+ end
+
+ def builtin?
+ builtin
+ end
+
+ def to_transobject
+ Puppet::TransObject.new(name, builtin? ? "file" : "class")
+ end
+ end
+
+ before do
+ @original = Puppet::Node::Configuration.new("mynode")
+ @original.tag(*%w{one two three})
+ @original.add_class *%w{four five six}
+
+ @top = TestResource.new 'top'
+ @topobject = TestResource.new 'topobject', :builtin => true
+ @virtual = TestResource.new 'virtual', :virtual => true
+ @virtualobject = TestResource.new 'virtualobject', :builtin => true, :virtual => true
+ @middle = TestResource.new 'middle'
+ @middleobject = TestResource.new 'middleobject', :builtin => true
+ @bottom = TestResource.new 'bottom'
+ @bottomobject = TestResource.new 'bottomobject', :builtin => true
+
+ @resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]
+
+ @original.add_edge!(@top, @topobject)
+ @original.add_edge!(@top, @virtual)
+ @original.add_edge!(@virtual, @virtualobject)
+ @original.add_edge!(@top, @middle)
+ @original.add_edge!(@middle, @middleobject)
+ @original.add_edge!(@middle, @bottom)
+ @original.add_edge!(@bottom, @bottomobject)
+
+ @config = @original.to_transportable
+ end
+
+ it "should add all resources as TransObjects" do
+ @resources.each { |resource| @config.resource(resource.ref).should be_instance_of(Puppet::TransObject) }
+ end
+
+ it "should not extract defined virtual resources" do
+ @config.vertices.find { |v| v.name == "virtual" }.should be_nil
+ end
+
+ it "should not extract builtin virtual resources" do
+ @config.vertices.find { |v| v.name == "virtualobject" }.should be_nil
+ end
+
+ it "should copy the tag list to the new configuration" do
+ @config.tags.sort.should == @original.tags.sort
+ end
+
+ it "should copy the class list to the new configuration" do
+ @config.classes.should == @original.classes
+ end
+
+ it "should duplicate the original edges" do
+ @original.edges.each do |edge|
+ next if edge.source.virtual? or edge.target.virtual?
+ source = @config.resource(edge.source.ref)
+ target = @config.resource(edge.target.ref)
+
+ source.should_not be_nil
+ target.should_not be_nil
+ @config.edge?(source, target).should be_true
+ end
+ end
+
+ it "should set itself as the configuration for each converted resource" do
+ @config.vertices.each { |v| v.configuration.object_id.should equal(@config.object_id) }
+ end
+end
+
+describe Puppet::Node::Configuration, " when converting to a RAL configuration" do
+ before do
+ @original = Puppet::Node::Configuration.new("mynode")
+ @original.tag(*%w{one two three})
+ @original.add_class *%w{four five six}
+
+ @top = Puppet::TransObject.new 'Class[top]', "component"
+ @topobject = Puppet::TransObject.new '/topobject', "file"
+ @middle = Puppet::TransObject.new 'Class[middle]', "component"
+ @middleobject = Puppet::TransObject.new '/middleobject', "file"
+ @bottom = Puppet::TransObject.new 'Class[bottom]', "component"
+ @bottomobject = Puppet::TransObject.new '/bottomobject', "file"
+
+ @resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]
+
+ @original.add_resource(*@resources)
+
+ @original.add_edge!(@top, @topobject)
+ @original.add_edge!(@top, @middle)
+ @original.add_edge!(@middle, @middleobject)
+ @original.add_edge!(@middle, @bottom)
+ @original.add_edge!(@bottom, @bottomobject)
+
+ @config = @original.to_ral
+ end
+
+ it "should add all resources as RAL instances" do
+ @resources.each { |resource| @config.resource(resource.ref).should be_instance_of(Puppet::Type) }
+ end
+
+ it "should copy the tag list to the new configuration" do
+ @config.tags.sort.should == @original.tags.sort
+ end
+
+ it "should copy the class list to the new configuration" do
+ @config.classes.should == @original.classes
+ end
+
+ it "should duplicate the original edges" do
+ @original.edges.each do |edge|
+ @config.edge?(@config.resource(edge.source.ref), @config.resource(edge.target.ref)).should be_true
+ end
+ end
+
+ it "should set itself as the configuration for each converted resource" do
+ @config.vertices.each { |v| v.configuration.object_id.should equal(@config.object_id) }
+ end
+
+ after do
+ # Remove all resource instances.
+ @config.clear(true)
+ end
+end
+
describe Puppet::Node::Configuration, " when functioning as a resource container" do
before do
@config = Puppet::Node::Configuration.new("host")
@@ -500,7 +643,6 @@ describe Puppet::Node::Configuration, " when indirecting" do
@indirection = mock 'indirection'
Puppet::Indirector::Indirection.clear_cache
- @configuration = Puppet::Node::Facts.new("me")
end
it "should redirect to the indirection for retrieval" do
@@ -518,3 +660,37 @@ describe Puppet::Node::Configuration, " when indirecting" do
Puppet::Indirector::Indirection.clear_cache
end
end
+
+describe Puppet::Node::Configuration, " when converting to yaml" do
+ before do
+ @configuration = Puppet::Node::Configuration.new("me")
+ @configuration.add_edge!("one", "two")
+ end
+
+ it "should be able to be dumped to yaml" do
+ YAML.dump(@configuration).should be_instance_of(String)
+ end
+end
+
+describe Puppet::Node::Configuration, " when converting from yaml" do
+ before do
+ @configuration = Puppet::Node::Configuration.new("me")
+ @configuration.add_edge!("one", "two")
+
+ text = YAML.dump(@configuration)
+ @newconfig = YAML.load(text)
+ end
+
+ it "should get converted back to a configuration" do
+ @newconfig.should be_instance_of(Puppet::Node::Configuration)
+ end
+
+ it "should have all vertices" do
+ @newconfig.vertex?("one").should be_true
+ @newconfig.vertex?("two").should be_true
+ end
+
+ it "should have all edges" do
+ @newconfig.edge?("one", "two").should be_true
+ end
+end
diff --git a/test/data/snippets/classpathtest b/test/data/snippets/classpathtest
index 68610958b..580333369 100644
--- a/test/data/snippets/classpathtest
+++ b/test/data/snippets/classpathtest
@@ -1,11 +1,11 @@
# $Id$
-define component {
+define mytype {
file { "/tmp/classtest": ensure => file, mode => 755 }
}
class testing {
- component { "componentname": }
+ mytype { "componentname": }
}
include testing
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index cc3859552..58a6e7f89 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -202,7 +202,7 @@ class TestSnippets < Test::Unit::TestCase
assert_nothing_raised {
assert_equal(
- "//testing/component[componentname]/File[/tmp/classtest]",
+ "//testing/Mytype[componentname]/File[/tmp/classtest]",
file.path)
}
end
@@ -466,7 +466,7 @@ class TestSnippets < Test::Unit::TestCase
}
assert_nothing_raised("Could not convert configuration") {
- config = config.extract_to_transportable.to_configuration
+ config = config.to_ral
}
Puppet::Type.eachtype { |type|
diff --git a/test/language/transportable.rb b/test/language/transportable.rb
index 31931c937..4e4573e0b 100755
--- a/test/language/transportable.rb
+++ b/test/language/transportable.rb
@@ -47,37 +47,17 @@ class TestTransportable < Test::Unit::TestCase
assert(newobj.type, "Bucket has no type")
end
- # Verify that we correctly strip out collectable objects, since they should
- # not be sent to the client.
- def test_collectstrip
- top = mk_transtree do |object, depth, width|
- if width % 2 == 1
- object.collectable = true
- end
- end
-
- assert(top.flatten.find_all { |o| o.collectable }.length > 0,
- "Could not find any collectable objects")
-
- # Now strip out the collectable objects
- top.collectstrip!
-
- # And make sure they're actually gone
- assert_equal(0, top.flatten.find_all { |o| o.collectable }.length,
- "Still found collectable objects")
- end
-
# Make sure our 'delve' command is working
def test_delve
top = mk_transtree do |object, depth, width|
if width % 2 == 1
- object.collectable = true
+ object.file = :funtest
end
end
objects = []
buckets = []
- collectable = []
+ found = []
count = 0
assert_nothing_raised {
@@ -87,8 +67,8 @@ class TestTransportable < Test::Unit::TestCase
buckets << object
else
objects << object
- if object.collectable
- collectable << object
+ if object.file == :funtest
+ found << object
end
end
end
@@ -98,9 +78,9 @@ class TestTransportable < Test::Unit::TestCase
assert(objects.include?(obj), "Missing obj %s[%s]" % [obj.type, obj.name])
end
- assert_equal(collectable.length,
- top.flatten.find_all { |o| o.collectable }.length,
- "Found incorrect number of collectable objects")
+ assert_equal(found.length,
+ top.flatten.find_all { |o| o.file == :funtest }.length,
+ "Found incorrect number of objects")
end
end
diff --git a/test/network/client/client.rb b/test/network/client/client.rb
index e08da357c..a297a87e1 100755
--- a/test/network/client/client.rb
+++ b/test/network/client/client.rb
@@ -143,6 +143,8 @@ class TestClient < Test::Unit::TestCase
def test_classfile
Puppet[:code] = "class yaytest {}\n class bootest {}\n include yaytest, bootest"
+ Puppet::Node::Facts.indirection.stubs(:save)
+
master = client = nil
assert_nothing_raised() {
master = Puppet::Network::Handler.master.new(
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index aaa38b223..4ae77abc2 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -397,6 +397,8 @@ end
manifest = tempfile()
File.open(manifest, "w") { |f| f.puts "file { '#{file}': content => yay }" }
+ Puppet::Node::Facts.indirection.stubs(:save)
+
driver = mkmaster(:Manifest => manifest)
driver.local = false
master = mkclient(driver)
@@ -406,7 +408,7 @@ end
assert(! master.fresh?(master.class.facts),
"Considered fresh with no compile at all")
-
+
assert_nothing_raised { master.run }
assert(master.fresh?(master.class.facts),
"not considered fresh after compile")
@@ -481,7 +483,9 @@ end
master.local = false
driver = master.send(:instance_variable_get, "@driver")
driver.local = false
+ Puppet::Node::Facts.indirection.stubs(:save)
# Retrieve the configuration
+
master.getconfig
# Now the config is up to date, so get rid of the @objects var and
@@ -509,6 +513,8 @@ end
driver = master.send(:instance_variable_get, "@driver")
driver.local = false
+ Puppet::Node::Facts.indirection.stubs(:save)
+
assert_nothing_raised("Could not compile config") do
master.getconfig
end
diff --git a/test/network/handler/configuration.rb b/test/network/handler/configuration.rb
index 29a393769..1c08fd196 100755
--- a/test/network/handler/configuration.rb
+++ b/test/network/handler/configuration.rb
@@ -25,9 +25,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase
config = Config.new
# First test the defaults
- args = {}
- config.instance_variable_set("@options", args)
- config.expects(:create_interpreter).with(args).returns(:interp)
+ config.expects(:create_interpreter).returns(:interp)
assert_equal(:interp, config.send(:interpreter), "Did not return the interpreter")
# Now run it again and make sure we get the same thing
@@ -39,20 +37,8 @@ class TestHandlerConfiguration < Test::Unit::TestCase
args = {}
# Try it first with defaults.
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?).returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
-
- # Now reset it and make sure a specified manifest passes through
- file = tempfile
- args[:Manifest] = file
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?, :Manifest => file).returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
-
- # And make sure the code does, too
- args.delete(:Manifest)
- args[:Code] = "yay"
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?, :Code => "yay").returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
+ Puppet::Parser::Interpreter.expects(:new).returns(:interp)
+ assert_equal(:interp, config.send(:create_interpreter), "Did not return the interpreter")
end
# Make sure node objects get appropriate data added to them.
@@ -67,7 +53,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase
config.send(:add_node_data, fakenode)
# Now try it with classes.
- config.instance_variable_set("@options", {:Classes => %w{a b}})
+ config.classes = %w{a b}
list = []
fakenode = Object.new
fakenode.expects(:merge).with(:facts)
@@ -126,8 +112,9 @@ class TestHandlerConfiguration < Test::Unit::TestCase
# Now a non-local
config = Config.new(:Local => false)
- obj = Object.new
- yamld = Object.new
+ assert(! config.local?, "Config wrongly thinks it's local")
+ obj = mock 'dumpee'
+ yamld = mock 'yaml'
obj.expects(:to_yaml).with(:UseBlock => true).returns(yamld)
CGI.expects(:escape).with(yamld).returns(:translated)
assert_equal(:translated, config.send(:translate, obj), "Did not return translated config")
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index 42c4d22c9..6c4451d06 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -56,11 +56,10 @@ class TestMaster < Test::Unit::TestCase
@@tmpfiles << file2
client = master = nil
+ Puppet[:manifest] = manifest
assert_nothing_raised() {
# this is the default server setup
master = Puppet::Network::Handler.master.new(
- :Manifest => manifest,
- :UseNodes => false,
:Local => true
)
}