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.rb4
-rw-r--r--lib/puppet/indirector/code/configuration.rb10
-rw-r--r--lib/puppet/indirector/indirection.rb24
-rw-r--r--lib/puppet/indirector/terminus.rb39
-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/provider/package/portage.rb4
-rwxr-xr-xlib/puppet/provider/service/debian.rb2
-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.rb162
-rwxr-xr-xspec/unit/indirector/indirector.rb10
-rwxr-xr-xspec/unit/indirector/terminus.rb65
-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
-rwxr-xr-xtest/ral/providers/service/debian.rb71
29 files changed, 717 insertions, 179 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 39802f229..b782969a8 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.rb b/lib/puppet/indirector.rb
index 7ceaa43e2..a2eb41763 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -62,6 +62,10 @@ module Puppet::Indirector
end
module InstanceMethods
+ # Make it easy for the model to set versions,
+ # which are used for caching and such.
+ attr_accessor :version
+
# these become instance methods
def save(*args)
self.class.indirection.save(self, *args)
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 3a6284877..5f7baa3da 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -90,12 +90,21 @@ class Puppet::Indirector::Indirection
end
end
- def find(*args)
- terminus.find(*args)
+ def find(key, *args)
+ 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
+ if cache?
+ Puppet.info "Caching %s %s" % [self.name, key]
+ cache.save(result, *args)
+ end
+ return result
+ end
end
def destroy(*args)
- cache.destroy(*args) if cache?
terminus.destroy(*args)
end
@@ -104,9 +113,12 @@ class Puppet::Indirector::Indirection
end
# these become instance methods
- def save(*args)
- cache.save(*args) if cache?
- terminus.save(*args)
+ def save(instance, *args)
+ instance.version ||= Time.now.utc
+ dest = cache? ? cache : terminus
+ return if dest.has_most_recent?(instance.name, instance.version)
+ cache.save(instance, *args) if cache?
+ terminus.save(instance, *args)
end
private
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index 3e0ea447c..37cfdc499 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -95,25 +95,52 @@ class Puppet::Indirector::Terminus
end
end
+ # 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)
+ #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
+ end
+
+ def indirection
+ self.class.indirection
+ end
+
def initialize
if self.class.abstract_terminus?
raise Puppet::DevError, "Cannot create instances of abstract terminus types"
end
end
- def terminus_type
- self.class.terminus_type
+ def model
+ self.class.model
end
def name
self.class.name
end
- def model
- self.class.model
+ def terminus_type
+ self.class.terminus_type
end
- def indirection
- self.class.indirection
+ # Provide a default method for retrieving an instance's version.
+ # By default, just find the resource and get its version. Individual
+ # terminus types can override this method to provide custom definitions of
+ # 'versions'.
+ def version(name)
+ raise Puppet::DevError.new("Cannot retrieve an instance's version without a :find method") unless respond_to?(:find)
+ if instance = find(name)
+ instance.version
+ else
+ nil
+ end
end
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/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb
index 866ec8730..6a42444ef 100644
--- a/lib/puppet/provider/package/portage.rb
+++ b/lib/puppet/provider/package/portage.rb
@@ -55,7 +55,7 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa
# The common package name format.
def package_name
- "%s/%s" % [@resource[:category], @resource[:name]]
+ @resource[:category] ? "%s/%s" % [@resource[:category], @resource[:name]] : @resource[:name]
end
def uninstall
@@ -71,7 +71,7 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa
result_fields = [:category, :name, :ensure, :version_available, :slot, :vendor, :description]
search_field = @resource[:category] ? "--category-name" : "--name"
- search_value = @resource[:category] ? package_name : @resource[:name]
+ search_value = package_name
search_format = "<category> <name> [<installedversionsshort>] [<best>] <homepage> <description>"
begin
diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb
index d810eac1b..0ba7e1a79 100755
--- a/lib/puppet/provider/service/debian.rb
+++ b/lib/puppet/provider/service/debian.rb
@@ -17,7 +17,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do
# If it's enabled, then it will print output showing removal of
# links.
- if output =~ /etc\/rc[\dS].d|Nothing to do\./
+ if output =~ /etc\/rc[\dS].d|not installed/
return :true
else
return :false
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 4311c88bf..7a1c4531c 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -7,28 +7,62 @@ require 'puppet/indirector'
describe Puppet::Indirector::Indirection do
before do
@indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
- @terminus = mock 'terminus'
+ @terminus = stub 'terminus', :has_most_recent? => false
@indirection.stubs(:terminus).returns(@terminus)
+ @instance = stub 'instance', :version => nil, :version= => nil, :name => "whatever"
+ @name = :mything
+ end
+
+ it "should not attempt to set a timestamp if the terminus cannot find the instance" do
+ @terminus.expects(:find).with(@name).returns(nil)
+ proc { @indirection.find(@name) }.should_not raise_error
end
it "should handle lookups of a model instance by letting the appropriate terminus perform the lookup" do
- @terminus.expects(:find).with(:mything).returns(:whev)
- @indirection.find(:mything).should == :whev
+ @terminus.expects(:find).with(@name).returns(@instance)
+ @indirection.find(@name).should == @instance
end
it "should handle removing model instances from a terminus letting the appropriate terminus remove the instance" do
- @terminus.expects(:destroy).with(:mything).returns(:whev)
- @indirection.destroy(:mything).should == :whev
+ @terminus.expects(:destroy).with(@name).returns(@instance)
+ @indirection.destroy(@name).should == @instance
end
it "should handle searching for model instances by letting the appropriate terminus find the matching instances" do
- @terminus.expects(:search).with(:mything).returns(:whev)
- @indirection.search(:mything).should == :whev
+ @terminus.expects(:search).with(@name).returns(@instance)
+ @indirection.search(@name).should == @instance
end
it "should handle storing a model instance by letting the appropriate terminus store the instance" do
- @terminus.expects(:save).with(:mything).returns(:whev)
- @indirection.save(:mything).should == :whev
+ @terminus.expects(:save).with(@instance).returns(@instance)
+ @indirection.save(@instance).should == @instance
+ end
+
+ it "should add versions to found instances that do not already have them" do
+ @terminus.expects(:find).with(@name).returns(@instance)
+ time = mock 'time'
+ time.expects(:utc).returns(:mystamp)
+ Time.expects(:now).returns(time)
+ @instance.expects(:version=).with(:mystamp)
+ @indirection.find(@name)
+ end
+
+ it "should add versions to saved instances that do not already have them" do
+ time = mock 'time'
+ time.expects(:utc).returns(:mystamp)
+ Time.expects(:now).returns(time)
+ @instance.expects(:version=).with(:mystamp)
+ @terminus.stubs(:save)
+ @indirection.save(@instance)
+ end
+
+ # We've already tested this, basically, but...
+ it "should use the current time in UTC for versions" do
+ @instance.expects(:version=).with do |time|
+ time.utc?
+ end
+ @terminus.stubs(:save)
+ @indirection.save(@instance)
end
after do
@@ -189,33 +223,14 @@ describe Puppet::Indirector::Indirection, " when deciding whether to cache" do
proc { @indirection.cache_class = :foo }.should raise_error(ArgumentError)
end
- it "should not use a cache if there no cache setting" do
- @indirection.expects(:cache).never
- @terminus.stubs(:save)
- @indirection.save(:whev)
- end
-
- it "should use a cache if a cache was configured" do
- cache = mock 'cache'
- cache.expects(:save).with(:whev)
-
- cache_class = mock 'cache class'
- cache_class.expects(:new).returns(cache)
- Puppet::Indirector::Terminus.stubs(:terminus_class).with(:mycache, :test).returns(cache_class)
-
- @indirection.cache_class = :mycache
- @terminus.stubs(:save)
- @indirection.save(:whev)
- end
-
after do
@indirection.delete
Puppet::Indirector::Indirection.clear_cache
end
end
-describe Puppet::Indirector::Indirection, " when using a cache" do
- before do
+module IndirectionCaching
+ def setup
Puppet.settings.stubs(:value).with("test_terminus").returns("test_terminus")
@terminus_class = mock 'terminus_class'
@terminus = mock 'terminus'
@@ -228,13 +243,14 @@ describe Puppet::Indirector::Indirection, " when using a cache" do
@indirection.terminus_class = :test_terminus
end
- it "should copy all writing indirection calls to the cache terminus" do
- @cache_class.expects(:new).returns(@cache)
- @indirection.cache_class = :cache_terminus
- @cache.expects(:save).with(:whev)
- @terminus.stubs(:save)
- @indirection.save(:whev)
+ def teardown
+ @indirection.delete
+ Puppet::Indirector::Indirection.clear_cache
end
+end
+
+describe Puppet::Indirector::Indirection, " when managing the cache terminus" do
+ include IndirectionCaching
it "should not create a cache terminus at initialization" do
# This is weird, because all of the code is in the setup. If we got
@@ -257,9 +273,77 @@ describe Puppet::Indirector::Indirection, " when using a cache" do
@indirection.clear_cache
@indirection.cache.should equal(cache2)
end
+end
- after do
- @indirection.delete
- Puppet::Indirector::Indirection.clear_cache
+describe Puppet::Indirector::Indirection, " when saving and using a cache" do
+ include IndirectionCaching
+
+ before do
+ @indirection.cache_class = :cache_terminus
+ @cache_class.expects(:new).returns(@cache)
+ @name = "testing"
+ @instance = stub 'instance', :version => 5, :name => @name
+ end
+
+ it "should not update the cache or terminus if the new object is not different" do
+ @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(:has_most_recent?).with(@name, 5).returns(false)
+ @terminus.expects(:save).with(@instance)
+ @cache.expects(:save).with(@instance)
+ @indirection.save(@instance)
+ end
+end
+
+describe Puppet::Indirector::Indirection, " when finding and using a cache" do
+ include IndirectionCaching
+
+ before do
+ @indirection.cache_class = :cache_terminus
+ @cache_class.expects(:new).returns(@cache)
+ end
+
+ it "should return the cached object if the cache is up to date" do
+ cached = mock 'cached object'
+
+ name = "myobject"
+
+ @terminus.expects(:version).with(name).returns(1)
+ @cache.expects(:has_most_recent?).with(name, 1).returns(true)
+
+ @cache.expects(:find).with(name).returns(cached)
+
+ @indirection.find(name).should equal(cached)
+ end
+
+ it "should return the original object if the cache is not up to date" do
+ real = stub 'real object', :version => 1
+
+ name = "myobject"
+
+ @cache.stubs(:save)
+ @cache.expects(:has_most_recent?).with(name, 1).returns(false)
+ @terminus.expects(:version).with(name).returns(1)
+
+ @terminus.expects(:find).with(name).returns(real)
+
+ @indirection.find(name).should equal(real)
+ end
+
+ it "should cache any newly returned objects" do
+ real = stub 'real object', :version => 1
+
+ name = "myobject"
+
+ @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)
+
+ @indirection.find(name).should equal(real)
end
end
diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb
index 390907ca2..78c8c614a 100755
--- a/spec/unit/indirector/indirector.rb
+++ b/spec/unit/indirector/indirector.rb
@@ -64,6 +64,16 @@ describe Puppet::Indirector, " when redirecting a model" do
@indirection = @thingie.send(:indirects, :test)
end
+ it "should give the model the ability set a version" do
+ thing = @thingie.new
+ thing.should respond_to(:version=)
+ end
+
+ it "should give the model the ability retrieve a version" do
+ thing = @thingie.new
+ thing.should respond_to(:version)
+ end
+
it "should give the model the ability to lookup a model instance by letting the indirection perform the lookup" do
@indirection.expects(:find)
@thingie.find
diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb
index 44180cf4b..3361bfeeb 100755
--- a/spec/unit/indirector/terminus.rb
+++ b/spec/unit/indirector/terminus.rb
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/defaults'
require 'puppet/indirector'
@@ -200,8 +202,8 @@ describe Puppet::Indirector::Terminus, " when creating terminus classes" do
end
end
-describe Puppet::Indirector::Terminus, " when a terminus instance" do
- before do
+module TerminusInstanceTesting
+ def setup
Puppet::Indirector::Terminus.stubs(:register_terminus_class)
@indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil
Puppet::Indirector::Indirection.stubs(:instance).with(:my_stuff).returns(@indirection)
@@ -218,6 +220,10 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do
@terminus_class.name = :test
@terminus = @terminus_class.new
end
+end
+
+describe Puppet::Indirector::Terminus, " when a terminus instance" do
+ include TerminusInstanceTesting
it "should return the class's name as its name" do
@terminus.name.should == :test
@@ -236,3 +242,58 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do
@terminus.model.should == :yay
end
end
+
+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(:has_most_recent?)
+ end
+
+ it "should fail if the :version method has not been overridden and no :find method is available" do
+ proc { @terminus.version('yay') }.should raise_error(Puppet::DevError)
+ end
+
+ it "should use a found instance's version by default" do
+ name = 'instance'
+ instance = stub name, :version => 2
+ @terminus.expects(:find).with(name).returns(instance)
+ @terminus.version(name).should == 2
+ end
+
+ it "should return nil as the version if no instance can be found" do
+ name = 'instance'
+ @terminus.expects(:find).with(name).returns(nil)
+ @terminus.version(name).should be_nil
+ end
+
+ 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.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.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.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
)
}
diff --git a/test/ral/providers/service/debian.rb b/test/ral/providers/service/debian.rb
new file mode 100755
index 000000000..f74141f9e
--- /dev/null
+++ b/test/ral/providers/service/debian.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/env ruby
+#
+# Created by David Schmitt on 2007-09-13
+# Copyright (c) 2007. All rights reserved.
+
+$:.unshift("../../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+
+class TestDebianServiceProvider < Test::Unit::TestCase
+ include PuppetTest
+ include Puppet::Util
+
+ def prepare_provider(servicename, output)
+ service = Puppet::Type.type(:service).create(
+ :name => servicename, :provider => :debian
+ )
+
+ provider = service.provider
+ assert(provider, "did not get debian provider")
+
+ metaclass = class << provider
+ self
+ end
+
+ metaclass.instance_eval do
+ define_method :update do |*args|
+ return output
+ end
+ end
+
+ provider
+ end
+
+ def assert_enabled( servicename, output)
+ provider = prepare_provider( servicename, output )
+ assert_equal(:true, provider.enabled?,
+ "Service provider=debian thinks service is disabled, when it isn't")
+ end
+
+ def assert_disabled( servicename, output )
+ provider = prepare_provider( servicename, output )
+ assert_equal(:false, provider.enabled?,
+ "Service provider=debian thinks service is enabled, when it isn't")
+ end
+
+ # Testing #822
+ def test_file_rc
+ # These messages are from file-rc's
+ # update-rc.d -n -f $service remove
+ assert_enabled("test1", "/etc/runlevel.tmp not installed as /etc/runlevel.conf\n")
+ assert_disabled("test2", "Nothing to do.\n")
+ end
+
+ def test_sysv_rc
+ # These messages are from file-rc's
+ # update-rc.d -n -f $service remove
+ assert_enabled("test3", """ Removing any system startup links for /etc/init.d/test3 ...
+ /etc/rc0.d/K11test3
+ /etc/rc1.d/K11test3
+ /etc/rc2.d/S89test3
+ /etc/rc3.d/S89test3
+ /etc/rc4.d/S89test3
+ /etc/rc5.d/S89test3
+ /etc/rc6.d/K11test3
+""")
+ assert_disabled("test4", " Removing any system startup links for /etc/init.d/test4 ...\n")
+ end
+end
+
+# $Id$