From 0e336bf62b818aaa31fcc323ab5d31e5eb92eb46 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 5 Oct 2007 00:07:38 -0500 Subject: This commit is focused on getting the 'puppet' executable to work. As a result, it involves a lot of integration-level testing, and a lot of small design changes to make the code actually work. In particular, indirections can now have default termini, so that configurations and facts default to their code terminus Also, I've removed the ability to manually control whether ast nodes are used. I might need to add it back in later, but if so it will be in the form of a global setting, rather than the previous system of passing it through 10 different classes. Instead, the parser detects whether there are AST nodes defined and requires them if so or ignores them if not. About 75 tests are still failing in the main set of tests, but it's going to be a long slog to get them working -- there are significant design issues around them, as most of the failures are a result of tests trying to emulate both the client and server sides of a connection, which normally would have different fact termini but in this case must have the same terminus just because they're in the same process and are global. The next step, then, is to figure that process out, thus finding a way to make this all work. --- lib/puppet/node/configuration.rb | 2 +- lib/puppet/node/facts.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb index 3571eecda..084bdf880 100644 --- a/lib/puppet/node/configuration.rb +++ b/lib/puppet/node/configuration.rb @@ -7,7 +7,7 @@ require 'puppet/external/gratr/digraph' # and the relationships between them. class Puppet::Node::Configuration < Puppet::PGraph extend Puppet::Indirector - indirects :configuration + indirects :configuration, :terminus_class => :code # The host name this is a configuration for. attr_accessor :name diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index a2e6d9c04..2da6c488e 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -9,7 +9,7 @@ class Puppet::Node::Facts extend Puppet::Indirector # Use the node source as the indirection terminus. - indirects :facts + indirects :facts, :terminus_class => :code attr_accessor :name, :values -- cgit From d24c1ccc56b912e0ff69f7572dd36912c8c739c2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 8 Oct 2007 19:12:39 -0500 Subject: All tests should now pass again. This is the first real pass towards using caching. The `puppet` executable actually uses the indirection work, instead of handlers and such (and man! is it cleaner). Most of this work was a result of trying to get the client-side story working, with correct yaml caching of configurations, which means this commit also covers converting configurations to yaml, which was a much bigger PITA than it needed to be. I still need to write integration tests, and I also need to cover the server-side story of a normal configuration retrieval. --- lib/puppet/node/configuration.rb | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'lib/puppet/node') 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 -- cgit