summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorballman <ballman@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-09 01:51:20 +0000
committerballman <ballman@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-09 01:51:20 +0000
commitc1643600e1130e2ddd112abcf16bb040fbffe0bf (patch)
tree73db9055495e529b0cac11ba8e81eb910db1e6a5
parent8f187461a357898395ded25fb0c29a0d90a76896 (diff)
downloadpuppet-c1643600e1130e2ddd112abcf16bb040fbffe0bf.tar.gz
puppet-c1643600e1130e2ddd112abcf16bb040fbffe0bf.tar.xz
puppet-c1643600e1130e2ddd112abcf16bb040fbffe0bf.zip
Merging of refactor-transacton to the trunk. This work removes the :is attribute from properties and relies on the provider to cache or return the current value of the property.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2487 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/metatype/attributes.rb38
-rw-r--r--lib/puppet/metatype/evaluation.rb80
-rw-r--r--lib/puppet/metatype/providers.rb5
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb29
-rw-r--r--lib/puppet/propertychange.rb18
-rwxr-xr-xlib/puppet/provider/parsedfile.rb6
-rw-r--r--lib/puppet/provider/zone/solaris.rb2
-rw-r--r--lib/puppet/transaction.rb2
-rwxr-xr-xlib/puppet/type/cron.rb62
-rwxr-xr-xlib/puppet/type/exec.rb6
-rwxr-xr-xlib/puppet/type/group.rb31
-rwxr-xr-xlib/puppet/type/host.rb45
-rwxr-xr-xlib/puppet/type/mount.rb17
-rw-r--r--lib/puppet/type/notify.rb2
-rw-r--r--lib/puppet/type/package.rb50
-rwxr-xr-xlib/puppet/type/parsedtype.rb16
-rw-r--r--lib/puppet/type/pfile.rb31
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb104
-rwxr-xr-xlib/puppet/type/pfile/content.rb32
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb22
-rwxr-xr-xlib/puppet/type/pfile/group.rb35
-rwxr-xr-xlib/puppet/type/pfile/mode.rb47
-rwxr-xr-xlib/puppet/type/pfile/owner.rb40
-rwxr-xr-xlib/puppet/type/pfile/source.rb32
-rw-r--r--lib/puppet/type/pfile/target.rb14
-rwxr-xr-xlib/puppet/type/pfile/type.rb9
-rw-r--r--lib/puppet/type/property.rb63
-rw-r--r--lib/puppet/type/resources.rb4
-rw-r--r--lib/puppet/type/service.rb9
-rwxr-xr-xlib/puppet/type/sshkey.rb7
-rwxr-xr-xlib/puppet/type/tidy.rb40
-rwxr-xr-xlib/puppet/type/user.rb66
-rw-r--r--lib/puppet/type/yumrepo.rb14
-rw-r--r--lib/puppet/type/zone.rb68
-rw-r--r--test/lib/puppettest/support/assertions.rb4
-rwxr-xr-xtest/other/propertychange.rb14
-rwxr-xr-xtest/other/transactions.rb8
-rwxr-xr-xtest/ral/manager/attributes.rb16
-rwxr-xr-xtest/ral/manager/type.rb4
-rwxr-xr-xtest/ral/providers/package/apt.rb4
-rwxr-xr-xtest/ral/providers/package/aptitude.rb27
-rwxr-xr-xtest/ral/providers/package/aptrpm.rb4
-rwxr-xr-xtest/ral/providers/package/dpkg.rb4
-rwxr-xr-xtest/ral/providers/parsedfile.rb27
-rwxr-xr-xtest/ral/providers/user/useradd.rb4
-rwxr-xr-xtest/ral/types/cron.rb79
-rwxr-xr-xtest/ral/types/file.rb70
-rwxr-xr-xtest/ral/types/file/target.rb6
-rwxr-xr-xtest/ral/types/filesources.rb43
-rwxr-xr-xtest/ral/types/group.rb6
-rwxr-xr-xtest/ral/types/host.rb25
-rwxr-xr-xtest/ral/types/mount.rb18
-rwxr-xr-xtest/ral/types/package.rb6
-rwxr-xr-xtest/ral/types/property.rb31
-rwxr-xr-xtest/ral/types/resources.rb2
-rwxr-xr-xtest/ral/types/schedule.rb2
-rwxr-xr-xtest/ral/types/service.rb3
-rwxr-xr-xtest/ral/types/tidy.rb19
-rwxr-xr-xtest/ral/types/user.rb28
-rwxr-xr-xtest/ral/types/yumrepo.rb4
-rwxr-xr-xtest/ral/types/zone.rb39
61 files changed, 780 insertions, 763 deletions
diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb
index 131aafac6..50ee53c2b 100644
--- a/lib/puppet/metatype/attributes.rb
+++ b/lib/puppet/metatype/attributes.rb
@@ -307,9 +307,7 @@ class Puppet::Type
# method on the class.
if options[:retrieve]
define_method(:retrieve) do
- instance_variable_set(
- "@is", provider.send(options[:retrieve])
- )
+ provider.send(options[:retrieve])
end
end
@@ -458,22 +456,16 @@ class Puppet::Type
obj = @parameters[:ensure] and obj.should == :absent
end
- # Allow an outside party to specify the 'is' value for a property. The
- # arguments are an array because you can't use parens with 'is=' calls.
- # Most classes won't use this.
- def is=(ary)
- param, value = ary
- param = attr_alias(param)
- if self.class.validproperty?(param)
- unless prop = @parameters[param]
- prop = self.newattr(param)
- end
- prop.is = value
- else
- self[param] = value
+ # Create a new property if it is valid but doesn't exist
+ # Returns: true if a new parameter was added, false otherwise
+ def add_property_parameter(prop_name)
+ if self.class.validproperty?(prop_name) && !@parameters[prop_name]
+ self.newattr(prop_name)
+ return true
end
+ return false
end
-
+
# abstract accessing parameters and properties, and normalize
# access to always be symbols, not strings
# This returns a value, not an object. It returns the 'is'
@@ -492,7 +484,7 @@ class Puppet::Type
if obj = @parameters[name]
if obj.is_a?(Puppet::Type::Property)
- return obj.is
+ fail "[] called on a property"
else
return obj.value
end
@@ -554,16 +546,6 @@ class Puppet::Type
}
end
- # retrieve the 'is' value for a specified property
- def is(name)
- name = attr_alias(name)
- if prop = @parameters[name] and prop.is_a?(Puppet::Type::Property)
- return prop.is
- else
- return nil
- end
- end
-
# retrieve the 'should' value for a specified property
def should(name)
name = attr_alias(name)
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index 58f316e2c..09495d6d1 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -20,9 +20,9 @@ class Puppet::Type
# it's important that we call retrieve() on the type instance,
# not directly on the property, because it allows the type to override
# the method, like pfile does
- self.retrieve
+ currentvalues = self.retrieve
- changes = propertychanges().flatten
+ changes = propertychanges(currentvalues).flatten
# now record how many changes we've resulted in
if changes.length > 0
@@ -44,19 +44,32 @@ class Puppet::Type
# if all contained objects are in sync, then we're in sync
# FIXME I don't think this is used on the type instances any more,
# it's really only used for testing
- def insync?
+ def insync?(is)
insync = true
-
+
if property = @parameters[:ensure]
- if property.insync? and property.should == :absent
+ unless is.include? property
+ raise Puppet::DevError,
+ "The is value is not in the is array for '%s'" %
+ [property.name]
+ end
+ ensureis = is[property]
+ if property.insync?(ensureis) and property.should == :absent
return true
end
end
properties.each { |property|
- unless property.insync?
+ unless is.include? property
+ raise Puppet::DevError,
+ "The is value is not in the is array for '%s'" %
+ [property.name]
+ end
+
+ propis = is[property]
+ unless property.insync?(propis)
property.debug("Not in sync: %s vs %s" %
- [property.is.inspect, property.should.inspect])
+ [propis.inspect, property.should.inspect])
insync = false
#else
# property.debug("In sync")
@@ -66,28 +79,40 @@ class Puppet::Type
#self.debug("%s sync status is %s" % [self,insync])
return insync
end
-
+
# retrieve the current value of all contained properties
def retrieve
+ return currentpropvalues
+ end
+
+ # get a hash of the current properties.
+ def currentpropvalues(override_value = nil)
# it's important to use the method here, as it follows the order
# in which they're defined in the object
- properties().each { |property|
- property.retrieve
- }
+ return properties().inject({}) { | prophash, property|
+ prophash[property] = override_value.nil? ?
+ property.retrieve :
+ override_value
+ prophash
+ }
end
-
+
# Retrieve the changes associated with all of the properties.
- def propertychanges
+ def propertychanges(currentvalues)
# If we are changing the existence of the object, then none of
# the other properties matter.
changes = []
- if @parameters.include?(:ensure) and ! @parameters[:ensure].insync?
+ ensureparam = @parameters[:ensure]
+ if @parameters.include?(:ensure) && !currentvalues.include?(ensureparam)
+ raise Puppet::DevError, "Parameter ensure defined but missing from current values"
+ end
+ if @parameters.include?(:ensure) and ! ensureparam.insync?(currentvalues[ensureparam])
# self.info "ensuring %s from %s" %
# [@parameters[:ensure].should, @parameters[:ensure].is]
- changes = [Puppet::PropertyChange.new(@parameters[:ensure])]
+ changes << Puppet::PropertyChange.new(ensureparam, currentvalues[ensureparam])
# Else, if the 'ensure' property is correctly absent, then do
# nothing
- elsif @parameters.include?(:ensure) and @parameters[:ensure].is == :absent
+ elsif @parameters.include?(:ensure) and currentvalues[ensureparam] == :absent
# self.info "Object is correctly absent"
return []
else
@@ -98,9 +123,13 @@ class Puppet::Type
# self.info "no ensure property"
# end
changes = properties().find_all { |property|
- ! property.insync?
+ unless currentvalues.include?(property)
+ raise Puppet::DevError, "Property %s does not have a current value",
+ [property.name]
+ end
+ ! property.insync?(currentvalues[property])
}.collect { |property|
- Puppet::PropertyChange.new(property)
+ Puppet::PropertyChange.new(property, currentvalues[property])
}
end
@@ -113,6 +142,21 @@ class Puppet::Type
changes
end
+
+ private
+ # FIXARB: This can go away
+ def checknewinsync(currentvalues)
+ currentvalues.each { |prop, val|
+ if prop.respond_to? :new_insync? and prop.new_insync?(val) != prop.insync?
+ puts "#{prop.name} new_insync? != insync?"
+ self.devfail "#{prop.name} new_insync? != insync?"
+ end
+ }
+
+ properties().each { |prop|
+ puts "#{prop.name} is missing from current values" if (!currentvalues.include?(prop))
+ }
+ end
end
# $Id$
diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb
index ed9c68ab6..a130fc186 100644
--- a/lib/puppet/metatype/providers.rb
+++ b/lib/puppet/metatype/providers.rb
@@ -61,15 +61,12 @@ class Puppet::Type
# we've set up our naming stuff correctly everywhere.
# Mark found objects as present
- obj.is = [:ensure, :present]
hash.each { |param, value|
if property = obj.property(param)
- property.is = value
elsif val = obj[param]
obj[param] = val
else
# There is a value on disk, but it should go away
- obj.is = [param, value]
obj[param] = :absent
end
}
@@ -82,7 +79,7 @@ class Puppet::Type
# because it sets the should value, not the is value.
hash.delete(namevar)
hash.each { |param, value|
- obj.is = [param, value]
+ obj[param] = value unless obj.add_property_parameter(param)
}
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 4331d27fd..5ba507b16 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -42,20 +42,23 @@ class Puppet::Network::Handler
end
obj = nil
- unless obj = mount.check(path, links)
+ unless obj = mount.getfileobject(path, links)
return ""
end
+ currentvalues = mount.check(obj)
+
desc = []
CHECKPARAMS.each { |check|
if property = obj.property(check)
- unless property.is
+ if currentvalues[property]
+ desc << currentvalues[property]
+ else
mount.debug "Manually retrieving info for %s" % check
- property.retrieve
+ desc << property.retrieve
end
- desc << property.is
else
- if check == "checksum" and obj.property(:type).is == "file"
+ if check == "checksum" and currentvalues[obj.property(:type)] == "file"
mount.notice "File %s does not have data for %s" %
[obj.name, check]
end
@@ -424,16 +427,18 @@ class Puppet::Network::Handler
Puppet::Util.logmethods(self, true)
- # Run 'retrieve' on a file. This gets the actual parameters, so
- # we can pass them to the client.
- def check(dir, links)
+ def getfileobject(dir, links)
unless FileTest.exists?(dir)
self.notice "File source %s does not exist" % dir
return nil
end
- obj = fileobj(dir, links)
-
+ return fileobj(dir, links)
+ end
+
+ # Run 'retrieve' on a file. This gets the actual parameters, so
+ # we can pass them to the client.
+ def check(obj)
# FIXME we should really have a timeout here -- we don't
# want to actually check on every connection, maybe no more
# than every 60 seconds or something. It'd be nice if we
@@ -444,9 +449,7 @@ class Puppet::Network::Handler
# any state changes or anything. We don't even need to sync
# the checksum, because we're always going to hit the disk
# directly.
- obj.retrieve
-
- return obj
+ return obj.retrieve
end
# Create a map for a specific client.
diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb
index bbd18a22d..53d8ceec4 100644
--- a/lib/puppet/propertychange.rb
+++ b/lib/puppet/propertychange.rb
@@ -14,19 +14,19 @@ module Puppet
# Switch the goals of the property, thus running the change in reverse.
def backward
@property.should = @is
- @property.retrieve
+ @is = @property.retrieve
unless defined? @transaction
raise Puppet::Error,
"PropertyChange '%s' tried to be executed outside of transaction" %
self
end
- unless @property.insync?
+ unless @property.insync?(@is)
@property.info "Backing %s" % self
return self.go
else
@property.debug "rollback is already in sync: %s vs. %s" %
- [@property.is.inspect, @property.should.inspect]
+ [@is, @property.should.inspect]
return nil
end
end
@@ -52,14 +52,14 @@ module Puppet
)
end
- def initialize(property)
+ def initialize(property, currentvalue)
unless property.is_a?(Puppet::Type::Property)
raise Puppet::DevError, "Got a %s instead of a property" %
property.class
end
@property = property
@path = [property.path,"change"].flatten
- @is = property.is
+ @is = currentvalue
@should = property.should
@@ -92,7 +92,7 @@ module Puppet
end
return events.collect { |name|
- @report = @property.log(@property.change_to_s)
+ @report = @property.log(@property.change_to_s(@is, @should))
event(name)
}
end
@@ -114,14 +114,14 @@ module Puppet
end
def skip?
- if @property.insync?
+ if @property.insync?(@is)
@property.info "Already in sync"
return true
end
if @property.noop
@property.log "is %s, should be %s (noop)" %
- [property.is_to_s, property.should_to_s]
+ [property.is_to_s(@is), property.should_to_s(@should)]
#@property.debug "%s is noop" % @property
return true
end
@@ -134,7 +134,7 @@ module Puppet
def to_s
return "change %s.%s(%s)" %
- [@transaction.object_id, self.object_id, @property.change_to_s]
+ [@transaction.object_id, self.object_id, @property.change_to_s(@is, @should)]
#return "change %s.%s" % [@transaction.object_id, self.object_id]
end
end
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index 8d1936ceb..334768d6b 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -273,9 +273,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
# This is only the case for properties, and targets should always
# be properties.
- if model.respond_to?(:is)
- targets << model.is(:target)
- end
+ #if model.respond_to?(:is)
+ # targets << model.is(:target)
+ #end
end
targets.uniq.reject { |t| t.nil? }
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index 572f137b0..e22192c22 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -114,6 +114,8 @@ set zonepath=%s
return hash
end
+ # FIXARB: Not sure what this one is doing. It is not setting @is for the
+ # if case.
def retrieve
if hash = statushash()
setstatus(hash)
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 75332c145..a276d138c 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -107,7 +107,7 @@ class Transaction
puts detail.backtrace
end
change.property.err "change from %s to %s failed: %s" %
- [change.property.is_to_s, change.property.should_to_s, detail]
+ [change.property.is_to_s(change.is), change.property.should_to_s(change.should), detail]
@failures[resource] += 1
next
# FIXME this should support using onerror to determine
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index ebf0fbe8a..3c72224e0 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -39,9 +39,9 @@ Puppet::Type.newtype(:cron) do
# We have to override the parent method, because we consume the entire
# "should" array
- def insync?
+ def insync?(is)
if defined? @should and @should
- self.is_to_s == self.should_to_s
+ self.is_to_s(is) == self.should_to_s
else
true
end
@@ -93,36 +93,28 @@ Puppet::Type.newtype(:cron) do
return false
end
- def should_to_s
- if @should
- if self.name == :command or @should[0].is_a? Symbol
- @should[0]
+ def should_to_s(newvalue = @should)
+ if newvalue
+ if self.name == :command or newvalue[0].is_a? Symbol
+ newvalue[0]
else
- @should.join(",")
+ newvalue.join(",")
end
else
nil
end
end
- def is=(val)
- if val.is_a?(Array)
- @is = val
- else
- @is = [val]
- end
- end
-
- def is_to_s
- if @is
- unless @is.is_a?(Array)
- return @is
+ def is_to_s(currentvalue = @is)
+ if currentvalue
+ unless currentvalue.is_a?(Array)
+ return currentvalue
end
- if self.name == :command or @is[0].is_a? Symbol
- @is[0]
+ if self.name == :command or currentvalue[0].is_a? Symbol
+ currentvalue[0]
else
- @is.join(",")
+ currentvalue.join(",")
end
else
nil
@@ -206,12 +198,13 @@ Puppet::Type.newtype(:cron) do
All cron parameters support ``absent`` as a value; this will
remove any existing values for that field."
- def is
- if @is
- @is[0]
- else
- nil
- end
+ def retrieve
+ return_value = super
+ if return_value && return_value.is_a?(Array)
+ return_value = return_value[0]
+ end
+
+ return return_value
end
def should
@@ -286,6 +279,7 @@ Puppet::Type.newtype(:cron) do
can be no guarantees that other, earlier settings will not also
affect a given cron job.
+
Also, Puppet cannot automatically determine whether an existing,
unmanaged environment setting is associated with a given cron
job. If you already have cron jobs with environment settings,
@@ -302,11 +296,11 @@ Puppet::Type.newtype(:cron) do
end
end
- def insync?
- if @is.is_a? Array
- return @is.sort == @should.sort
+ def insync?(is)
+ if is.is_a? Array
+ return is.sort == @should.sort
else
- return @is == @should
+ return is == @should
end
end
@@ -370,7 +364,7 @@ Puppet::Type.newtype(:cron) do
ret = obj.should
if ret.nil?
- ret = obj.is
+ ret = obj.retrieve
end
if ret == :absent
@@ -394,4 +388,6 @@ Puppet::Type.newtype(:cron) do
end
end
+
# $Id$
+
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 5a045f630..9097f6179 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -79,7 +79,7 @@ module Puppet
executed command returns something else. Defaults to 0."
# Make output a bit prettier
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
return "executed successfully"
end
@@ -88,9 +88,9 @@ module Puppet
# Default to somethinng
if @parent.check
- self.is = :notrun
+ return :notrun
else
- self.is = self.should
+ return self.should
end
end
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index 27d4b90d6..c0cfd900c 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -47,15 +47,16 @@ module Puppet
end
end
- def change_to_s
+ # FIXARB: Check this... I think it may be the same as in Ensure class.
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -67,22 +68,12 @@ module Puppet
end
def retrieve
- if provider.exists?
- @is = :present
- else
- @is = :absent
- end
+ return provider.exists? ? :present : :absent
end
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
- #else
- #self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
- end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -101,7 +92,7 @@ module Puppet
GID is picked according to local system standards."
def retrieve
- @is = provider.gid
+ return provider.gid
end
def sync
@@ -167,13 +158,9 @@ module Puppet
def retrieve
if self.provider and @provider.exists?
- super
+ return super
else
- properties().each { |property|
- property.is = :absent
- }
-
- return
+ return currentpropvalues(:absent)
end
end
end
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index 8a449da4b..0d3013dbd 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -15,47 +15,28 @@ module Puppet
make those aliases available in your Puppet scripts and also on
disk."
- def insync?
- @is == @should
+ def insync?(is)
+ is == @should
end
- # Make sure our "is" value is always an array.
- def is
- current = super
- current = [current] unless current.is_a? Array
- current
+ def is_to_s(currentvalue = @is)
+ currentvalue = [currentvalue] unless currentvalue.is_a? Array
+ currentvalue.join(" ")
end
- def is_to_s
- self.is.join(" ")
- end
-
- # We have to override the feeding mechanism; it might be nil or
- # white-space separated
- def is=(value)
- # If it's just whitespace, ignore it
- case value
- when /^\s+$/
- @is = nil
- when String
- @is = value.split(/\s+/)
- else
- @is = value
- end
- end
-
def retrieve
- super
- case @is
+ is = super
+ case is
when String
- @is = @is.split(/\s*,\s*/)
+ is = is.split(/\s*,\s*/)
when Symbol:
- @is = [@is]
+ is = [is]
when Array
# nothing
else
- raise Puppet::DevError, "Invalid @is type %s" % @is.class
+ raise Puppet::DevError, "Invalid @is type %s" % is.class
end
+ return is
end
# We actually want to return the whole array here, not just the first
@@ -72,8 +53,8 @@ module Puppet
end
end
- def should_to_s
- @should.join(" ")
+ def should_to_s(newvalue = @should)
+ newvalue.join(" ")
end
validate do |value|
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index 6e882687d..ea25d5b5b 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -43,7 +43,8 @@ module Puppet
newvalue(:mounted, :event => :mount_mounted) do
# Create the mount point if it does not already exist.
- if self.is == :absent or self.is.nil?
+ current_value = self.retrieve
+ if current_value.nil? or current_value == :absent
provider.create
end
@@ -52,20 +53,22 @@ module Puppet
end
def retrieve
- if provider.mounted?
- @is = :mounted
- else
- @is = super()
- end
+ return provider.mounted? ? :mounted : super()
end
def syncothers
# We have to flush any changes to disk.
+ currentvalues = @parent.retrieve
oos = @parent.send(:properties).find_all do |prop|
+ unless currentvalues.include?(prop)
+ raise Puppet::DevError,
+ "Parent has property %s but it doesn't appear in the current vallues",
+ [prop.name]
+ end
if prop.name == :ensure
false
else
- ! prop.insync?
+ ! prop.insync?(currentvalues[prop])
end
end.each { |prop| prop.sync }.length
if oos > 0
diff --git a/lib/puppet/type/notify.rb b/lib/puppet/type/notify.rb
index 8877e3398..599197f76 100644
--- a/lib/puppet/type/notify.rb
+++ b/lib/puppet/type/notify.rb
@@ -22,7 +22,7 @@ module Puppet
return
end
- def insync?
+ def insync?(is)
false
end
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 642d1bc99..244a79072 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -79,7 +79,7 @@ module Puppet
# Because yum always exits with a 0 exit code, there's a retrieve
# in the "install" method. So, check the current state now,
# to compare against later.
- current = self.is
+ current = self.retrieve
begin
provider.update
rescue => detail
@@ -106,7 +106,7 @@ module Puppet
self.fail "Could not update: %s" % detail
end
- if self.is == :absent
+ if self.retrieve == :absent
:package_installed
else
:package_changed
@@ -118,7 +118,7 @@ module Puppet
# Override the parent method, because we've got all kinds of
# funky definitions of 'in sync'.
- def insync?
+ def insync?(is)
@should ||= []
@latest = nil unless defined? @latest
@@ -128,12 +128,12 @@ module Puppet
@should.each { |should|
case should
when :present
- unless @is == :absent
+ unless is == :absent
return true
end
when :latest
# Short-circuit packages that are not present
- if @is == :absent
+ if is == :absent
return false
end
@@ -156,7 +156,7 @@ module Puppet
end
end
- case @is
+ case is
when @latest:
return true
when :present:
@@ -164,14 +164,14 @@ module Puppet
# that can't query versions.
return true
else
- self.debug "@is is %s, latest %s is %s" %
- [@is.inspect, @parent.name, @latest.inspect]
+ self.debug "is is %s, latest %s is %s" %
+ [is.inspect, @parent.name, @latest.inspect]
end
when :absent
- if @is == :absent
+ if is == :absent
return true
end
- when @is
+ when is
return true
end
}
@@ -181,15 +181,15 @@ module Puppet
# This retrieves the current state. LAK: I think this method is unused.
def retrieve
- @is = @parent.retrieve
+ return @parent.retrieve
end
# Provide a bit more information when logging upgrades.
- def should_to_s
+ def should_to_s(newvalue = @should)
if @latest
@latest.to_s
else
- super
+ super(newvalue)
end
end
end
@@ -379,7 +379,7 @@ module Puppet
self.each do |pkg|
next unless packages[:provider] == pkgtype
unless packages.include? pkg
- pkg.is = [:ensure, :absent]
+ pkg.provider.send(:ensure, :absent)
end
end
end
@@ -428,7 +428,7 @@ module Puppet
# about it and set it appropriately.
if hash = @provider.query
if hash == :listed # Mmmm, hackalicious
- return
+ return {}
end
hash.each { |param, value|
unless self.class.validattr?(param)
@@ -437,11 +437,19 @@ module Puppet
}
setparams(hash)
+
+ return properties().inject({}) { |prop_hash, property|
+ prop_hash[property] = hash[property.name] if hash.has_key?(property.name)
+ prop_hash
+ }
else
# Else just mark all of the properties absent.
- self.class.validproperties.each { |name|
- self.is = [name, :absent]
- }
+ # FIXARB: Not sure why this is using validproperties instead of
+ # properties()?
+ return self.class.validproperties.inject({}) { |h, name|
+ h[@parameters[name]] = :absent
+ h
+ }
end
end
@@ -449,9 +457,11 @@ module Puppet
# are properties.
def setparams(hash)
# Everything on packages is a parameter except :ensure
- hash.each { |param, value|
+ hash.each { |param, value|
+ next if param == :ensure
if self.class.attrtype(param) == :property
- self.is = [param, value]
+ add_property_parameter(param)
+ self.provider.send("%s=" % param, value)
else
self[param] = value
end
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index 40a90d5ae..488922efd 100755
--- a/lib/puppet/type/parsedtype.rb
+++ b/lib/puppet/type/parsedtype.rb
@@ -52,7 +52,7 @@ module Puppet
# just collect our current state. Note that this method is not called
# during a transaction, since transactions call the parent object method.
def retrieve
- @parent.retrieve
+ return @parent.retrieve
end
# All this does is return an event; all of the work gets done
@@ -197,20 +197,22 @@ module Puppet
end
end
- properties().each do |property|
+ currentvalues = properties().inject({}) do |prophash, property|
if h.has_key? property.name
property.is = h[property.name]
+ prophash[property] = h[property.name]
else
property.is = :absent
+ prophash[property] = :absent
end
+ prophash
end
- return h
+ # FIXARB: This used to return h, find what broke ;)
+ return currentvalues
else
- properties().each do |property|
- property.is = :absent
- end
- return nil
+ # FIXARB: This used to return nil, find what broke ;)
+ return currentpropvalues(:absent)
end
end
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 39a298ed9..bfa10dda2 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -823,22 +823,21 @@ module Puppet
def retrieve
unless stat = self.stat(true)
self.debug "File does not exist"
- properties().each { |property|
- property.is = :absent
- }
-
# If the file doesn't exist but we have a source, then call
# retrieve on that property
+
+ propertyvalues = properties().inject({}) { |hash, property|
+ hash[property] = :absent
+ hash
+ }
+
if @parameters.include?(:source)
- @parameters[:source].retrieve
+ propertyvalues[:source] = @parameters[:source].retrieve
end
-
- return
+ return propertyvalues
end
- properties().each { |property|
- property.retrieve
- }
+ return currentpropvalues()
end
# This recurses against the remote source and makes sure the local
@@ -929,8 +928,8 @@ module Puppet
else
# If they didn't pass in a sum, then tell checksum to
# figure it out.
- @parameters[:checksum].retrieve
- @parameters[:checksum].checksum = @parameters[:checksum].is
+ currentvalue = @parameters[:checksum].retrieve
+ @parameters[:checksum].checksum = currentvalue
end
end
end
@@ -1118,7 +1117,7 @@ module Puppet
# Override the parent method, because we don't want to generate changes
# when the file is missing and there is no 'ensure' state.
- def propertychanges
+ def propertychanges(currentvalues)
unless self.stat
found = false
([:ensure] + CREATORS).each do |prop|
@@ -1143,8 +1142,8 @@ module Puppet
# Make sure we get a new stat objct
self.stat(true)
- thing.retrieve
- unless thing.insync?
+ currentvalue = thing.retrieve
+ unless thing.insync?(currentvalue)
thing.sync
end
end
@@ -1159,7 +1158,7 @@ module Puppet
# We put all of the properties in separate files, because there are so many
# of them. The order these are loaded is important, because it determines
- # the order they are in the property list.
+ # the order they are in the property lit.
require 'puppet/type/pfile/checksum'
require 'puppet/type/pfile/content' # can create the file
require 'puppet/type/pfile/source' # can create the file
diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb
index 09dc016c1..ec4c8a34f 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -83,9 +83,8 @@ module Puppet
# Because source and content and whomever else need to set the checksum
# and do the updating, we provide a simple mechanism for doing so.
def checksum=(value)
- @is = value
munge(@should)
- self.updatesum
+ self.updatesum(value)
end
def checktype
@@ -93,21 +92,21 @@ module Puppet
end
# Checksums need to invert how changes are printed.
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "defined '%s' as '%s'" %
[self.name, self.currentsum]
- elsif self.should == :absent
+ elsif newvalue == :absent
return "undefined %s from '%s'" %
- [self.name, self.is_to_s]
+ [self.name, self.is_to_s(currentvalue)]
else
if defined? @cached and @cached
return "%s changed '%s' to '%s'" %
- [self.name, @cached, self.is_to_s]
+ [self.name, @cached, self.is_to_s(currentvalue)]
else
return "%s changed '%s' to '%s'" %
- [self.name, self.currentsum, self.is_to_s]
+ [self.name, self.currentsum, self.is_to_s(currentvalue)]
end
end
rescue Puppet::Error, Puppet::DevError
@@ -209,80 +208,78 @@ module Puppet
# the stored state to reflect the current state, and then kick
# off an event to mark any changes.
def handlesum
- if @is.nil?
+ currentvalue = self.retrieve
+ if currentvalue.nil?
raise Puppet::Error, "Checksum state for %s is somehow nil" %
@parent.title
end
- if @is == :absent
- self.retrieve
-
- if self.insync?
- self.debug "Checksum is already in sync"
- return nil
- end
- #@parent.debug "%s(%s): after refresh, is '%s'" %
+ if self.insync?(currentvalue)
+ self.debug "Checksum is already in sync"
+ return nil
+ end
+ # @parent.debug "%s(%s): after refresh, is '%s'" %
# [self.class.name,@parent.name,@is]
# If we still can't retrieve a checksum, it means that
# the file still doesn't exist
- if @is == :absent
- # if they're copying, then we won't worry about the file
- # not existing yet
- unless @parent.property(:source)
- self.warning(
- "File %s does not exist -- cannot checksum" %
- @parent[:path]
- )
- end
- return nil
+ if currentvalue == :absent
+ # if they're copying, then we won't worry about the file
+ # not existing yet
+ unless @parent.property(:source)
+ self.warning("File %s does not exist -- cannot checksum" %
+ @parent[:path]
+ )
end
+ return nil
end
-
+
# If the sums are different, then return an event.
- if self.updatesum
+ if self.updatesum(currentvalue)
return :file_changed
else
return nil
end
end
- def insync?
- @should = [checktype]
+ def insync?(currentvalue)
+ @should = [checktype()]
if cache(checktype())
- return @is == currentsum()
+ return currentvalue == currentsum()
else
# If there's no cached sum, then we don't want to generate
# an event.
return true
end
end
-
+
# Even though they can specify multiple checksums, the insync?
# mechanism can really only test against one, so we'll just retrieve
# the first specified sum type.
+ # FIXARB: THere is a cache but it seems inconsistent when it
+ # uses the cache vs, when it uses @is. This will
+ # need more attention.
def retrieve(usecache = false)
# When the 'source' is retrieving, it passes "true" here so
# that we aren't reading the file twice in quick succession, yo.
- if usecache and @is
- return @is
+ currentvalue = currentsum()
+ if usecache and currentvalue
+ return currentvalue
end
stat = nil
unless stat = @parent.stat
- self.is = :absent
- return
+ return :absent
end
if stat.ftype == "link" and @parent[:links] != :follow
self.debug "Not checksumming symlink"
- #@parent.delete(:checksum)
- self.is = self.currentsum
- return
+ # @parent.delete(:checksum)
+ return currentvalue
end
# Just use the first allowed check type
- @is = getsum(checktype())
+ currentvalue = getsum(checktype())
# If there is no sum defined, then store the current value
# into the cache, so that we're not marked as being
@@ -290,17 +287,18 @@ module Puppet
# time we get a sum.
unless cache(checktype())
# FIXME we should support an updatechecksums-like mechanism
- self.updatesum
+ self.updatesum(currentvalue)
end
-
- #@parent.debug "checksum state is %s" % self.is
+
+ # @parent.debug "checksum state is %s" % self.is
+ return currentvalue
end
# Store the new sum to the state db.
- def updatesum
+ def updatesum(newvalue)
result = false
- if @is.is_a?(Symbol)
+ if newvalue.is_a?(Symbol)
raise Puppet::Error, "%s has invalid checksum" % @parent.title
end
@@ -313,25 +311,23 @@ module Puppet
# )
# end
- if @is == sum
+ if newvalue == sum
return false
end
- #if cache(self.should) == @is
- # raise Puppet::Error, "Got told to update same sum twice"
- #end
self.debug "Replacing %s checksum %s with %s" %
- [@parent.title, sum, @is]
- #@parent.debug "@is: %s; @should: %s" % [@is,@should]
+ [@parent.title, sum, newvalue]
+ # @parent.debug "currentvalue: %s; @should: %s" %
+ # [newvalue,@should]
result = true
else
- @parent.debug "Creating checksum %s" % @is
+ @parent.debug "Creating checksum %s" % newvalue
result = false
end
# Cache the sum so the log message can be right if possible.
@cached = sum
- cache(checktype(), @is)
+ cache(checktype(), newvalue)
return result
end
end
diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb
index e3e390179..9b8be0d68 100755
--- a/lib/puppet/type/pfile/content.rb
+++ b/lib/puppet/type/pfile/content.rb
@@ -20,13 +20,13 @@ module Puppet
This attribute is especially useful when used with
`PuppetTemplating templating`:trac:."
- def change_to_s
- should = "{md5}" + Digest::MD5.hexdigest(self.should)
- if @is == :absent
- return "created file with contents %s" % should
+ def change_to_s(currentvalue, newvalue)
+ newvalue = "{md5}" + Digest::MD5.hexdigest(newvalue)
+ if currentvalue == :absent
+ return "created file with contents %s" % newvalue
else
- is = "{md5}" + Digest::MD5.hexdigest(@is)
- return "changed file contents from %s to %s" % [is, should]
+ currentvalue = "{md5}" + Digest::MD5.hexdigest(currentvalue)
+ return "changed file contents from %s to %s" % [currentvalue, newvalue]
end
end
@@ -35,25 +35,23 @@ module Puppet
def retrieve
stat = nil
unless stat = @parent.stat
- @is = :absent
- return
+ return :absent
end
if stat.ftype == "link" and @parent[:links] == :ignore
- self.is = self.should
- return
+ return self.should
end
# Don't even try to manage the content on directories
if stat.ftype == "directory" and @parent[:links] == :ignore
@parent.delete(:content)
- return
+ return nil
end
begin
- @is = File.read(@parent[:path])
+ currentvalue = File.read(@parent[:path])
+ return currentvalue
rescue => detail
- @is = nil
raise Puppet::Error, "Could not read %s: %s" %
[@parent.title, detail]
end
@@ -62,13 +60,11 @@ module Puppet
# Just write our content out to disk.
def sync
+ return_event = @parent.stat ? :file_changed : :file_created
+
@parent.write { |f| f.print self.should }
- if @is == :absent
- return :file_created
- else
- return :file_changed
- end
+ return return_event
end
end
end
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index 658c3535e..afd2baae3 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -108,11 +108,13 @@ module Puppet
return :link
end
- def change_to_s
- if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync?
- return property.change_to_s
+ def change_to_s(currentvalue, newvalue)
+ if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync?(currentvalue)
+ currentvalue = property.retrieve
+
+ return property.change_to_s(property.retrieve, property.should)
else
- super
+ super(currentvalue, newvalue)
end
end
@@ -133,26 +135,26 @@ module Puppet
# We have to treat :present specially, because it works with any
# type of file.
- def insync?
+ def insync?(currentvalue)
if self.should == :present
- if @is.nil? or @is == :absent
+ if currentvalue.nil? or currentvalue == :absent
return false
else
return true
end
else
- return super
+ return super(currentvalue)
end
end
def retrieve
if stat = @parent.stat(false)
- @is = stat.ftype.intern
+ return stat.ftype.intern
else
if self.should == :false
- @is = :false
+ return :false
else
- @is = :absent
+ return :absent
end
end
end
diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb
index fb032a1ee..6606f3322 100755
--- a/lib/puppet/type/pfile/group.rb
+++ b/lib/puppet/type/pfile/group.rb
@@ -26,20 +26,19 @@ module Puppet
end
# We want to print names, not numbers
- def is_to_s
- if @is.is_a? Integer
- id2name(@is) || @is
+ def is_to_s(currentvalue)
+ if currentvalue.is_a? Integer
+ id2name(currentvalue) || currentvalue
else
- return @is.to_s
+ return currentvalue.to_s
end
end
- def should_to_s
- should = self.should
- if should.is_a? Integer
- id2name(should) || should
+ def should_to_s(newvalue = @should)
+ if newvalue.is_a? Integer
+ id2name(newvalue) || newalue
else
- return should.to_s
+ return newvalue.to_s
end
end
@@ -60,8 +59,7 @@ module Puppet
stat = @parent.stat(false)
unless stat
- self.is = :absent
- return
+ return :absent
end
# Set our method appropriately, depending on links.
@@ -70,7 +68,8 @@ module Puppet
else
@method = :chown
end
- self.is = stat.gid
+
+ return stat.gid
end
# Determine if the group is valid, and if so, return the GID
@@ -90,19 +89,15 @@ module Puppet
# we'll just let it fail, but we should probably set things up so
# that users get warned if they try to change to an unacceptable group.
def sync
- if @is == :absent
- @parent.stat(true)
- self.retrieve
+ unless @parent.stat(false)
+ stat = @parent.stat(true)
+ currentvalue = self.retrieve
- if @is == :absent
+ unless stat
self.debug "File '%s' does not exist; cannot chgrp" %
@parent[:path]
return nil
end
-
- if self.insync?
- return nil
- end
end
gid = nil
diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/pfile/mode.rb
index e29e74235..ceb4c0d56 100755
--- a/lib/puppet/type/pfile/mode.rb
+++ b/lib/puppet/type/pfile/mode.rb
@@ -10,27 +10,27 @@ module Puppet
# Our modes are octal, so make sure they print correctly. Other
# valid values are symbols, basically
- def is_to_s
- case @is
+ def is_to_s(currentvalue)
+ case currentvalue
when Integer
- return "%o" % @is
+ return "%o" % currentvalue
when Symbol
- return @is
+ return currentvalue
else
- raise Puppet::DevError, "Invalid 'is' value for mode: %s" %
- @is.inspect
+ raise Puppet::DevError, "Invalid current value for mode: %s" %
+ currentvalue.inspect
end
end
- def should_to_s
- case self.should
+ def should_to_s(newvalue = @should)
+ case newvalue
when Integer
- return "%o" % self.should
+ return "%o" % newvalue
when Symbol
- return self.should
+ return newvalue
else
raise Puppet::DevError, "Invalid 'should' value for mode: %s" %
- self.should.inspect
+ newvalue.inspect
end
end
@@ -77,12 +77,12 @@ module Puppet
return value
end
- def insync?
+ def insync?(currentvalue)
if stat = @parent.stat and stat.ftype == "link" and @parent[:links] != :follow
self.debug "Not managing symlink mode"
return true
else
- return super
+ return super(currentvalue)
end
end
@@ -91,30 +91,23 @@ module Puppet
# off mode management entirely.
if stat = @parent.stat(false)
- self.is = stat.mode & 007777
unless defined? @fixed
if defined? @should and @should
@should = @should.collect { |s| self.dirmask(s) }
end
end
+ return stat.mode & 007777
else
- self.is = :absent
+ return :absent
end
-
- #self.debug "chmod state is %o" % self.is
end
def sync
- if @is == :absent
- @parent.stat(true)
- self.retrieve
- if @is == :absent
- self.debug "File does not exist; cannot set mode"
- return nil
- end
+ unless @parent.stat(false)
+ stat = @parent.stat(true)
- if self.insync?
- # we're already in sync
+ unless stat
+ self.debug "File does not exist; cannot set mode"
return nil
end
end
@@ -127,7 +120,7 @@ module Puppet
end
begin
- File.chmod(mode,@parent[:path])
+ File.chmod(mode, @parent[:path])
rescue => detail
error = Puppet::Error.new("failed to chmod %s: %s" %
[@parent[:path], detail.message])
diff --git a/lib/puppet/type/pfile/owner.rb b/lib/puppet/type/pfile/owner.rb
index 07a2b880b..d88e9d04c 100755
--- a/lib/puppet/type/pfile/owner.rb
+++ b/lib/puppet/type/pfile/owner.rb
@@ -64,21 +64,21 @@ module Puppet
end
# We want to print names, not numbers
- def is_to_s
- id2name(@is) || @is
+ def is_to_s(currentvalue)
+ id2name(currentvalue) || currentvalue
end
- def should_to_s
- case self.should
+ def should_to_s(newvalue = @should)
+ case newvalue
when Symbol
- self.should.to_s
+ newvalue.to_s
when Integer
- id2name(self.should) || self.should
+ id2name(newvalue) || newvalue
when String
- self.should
+ newvalue
else
raise Puppet::DevError, "Invalid uid type %s(%s)" %
- [self.should.class, self.should]
+ [newvalue.class, newvalue]
end
end
@@ -98,8 +98,7 @@ module Puppet
end
unless stat = @parent.stat(false)
- @is = :absent
- return
+ return :absent
end
# Set our method appropriately, depending on links.
@@ -109,15 +108,17 @@ module Puppet
@method = :chown
end
- self.is = stat.uid
-
+ currentvalue = stat.uid
+
# On OS X, files that are owned by -2 get returned as really
# large UIDs instead of negative ones. This isn't a Ruby bug,
# it's an OS X bug, since it shows up in perl, too.
- if @is > 120000
- self.warning "current state is silly: %s" % @is
- @is = :silly
+ if currentvalue > 120000
+ self.warning "current state is silly: %s" % is
+ currentvalue = :silly
end
+
+ return currentvalue
end
def sync
@@ -146,16 +147,11 @@ module Puppet
return nil
end
- if @is == :absent
- @parent.stat(true)
- self.retrieve
- if @is == :absent
+ unless @parent.stat(false)
+ unless @parent.stat(true)
self.debug "File does not exist; cannot set owner"
return nil
end
- if self.insync?
- return nil
- end
#self.debug "%s: after refresh, is '%s'" % [self.class.name,@is]
end
diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb
index d007ea301..84e3eb032 100755
--- a/lib/puppet/type/pfile/source.rb
+++ b/lib/puppet/type/pfile/source.rb
@@ -60,9 +60,9 @@ module Puppet
source.sub(/\/$/, '')
end
- def change_to_s
- should = "{md5}" + @stats[:checksum]
- if @parent.is(:ensure) == :absent
+ def change_to_s(currentvalue, newvalue)
+ # newvalue = "{md5}" + @stats[:checksum]
+ if @parent.property(:ensure).retrieve == :absent
return "creating from source %s with contents %s" % [@source, @stats[:checksum]]
else
return "replacing from source %s with contents %s" % [@source, @stats[:checksum]]
@@ -116,17 +116,17 @@ module Puppet
# Have we successfully described the remote source?
def described?
- ! @stats.nil? and ! @stats[:type].nil? and @is != :notdescribed
+ ! @stats.nil? and ! @stats[:type].nil? #and @is != :notdescribed
end
# Use the info we get from describe() to check if we're in sync.
- def insync?
+ def insync?(currentvalue)
unless described?
info "No specified sources exist"
return true
end
- if @is == :nocopy
+ if currentvalue == :nocopy
return true
end
@@ -136,11 +136,15 @@ module Puppet
return true
end
- if @parent.is(:ensure) != :absent and ! @parent.replace?
+ #FIXARB: Inefficient? Needed to call retrieve on parent's ensure and checksum
+ parentensure = @parent.property(:ensure).retrieve
+ if parentensure != :absent and ! @parent.replace?
return true
end
# Now, we just check to see if the checksums are the same
- return @parent.is(:checksum) == @stats[:checksum]
+ parentchecksum = @parent.property(:checksum).retrieve
+ a = (!parentchecksum.nil? and (parentchecksum == @stats[:checksum]))
+ return (!parentchecksum.nil? and (parentchecksum == @stats[:checksum]))
end
def pinparams
@@ -169,8 +173,7 @@ module Puppet
end
if @stats.nil? or @stats[:type].nil?
- @is = :notdescribed
- return nil
+ return nil # :notdescribed
end
case @stats[:type]
@@ -182,8 +185,7 @@ module Puppet
self.info @stats.inspect
self.err "Cannot use files of type %s as sources" %
@stats[:type]
- @is = :nocopy
- return
+ return :nocopy
end
# Take each of the stats and set them as states on the local file
@@ -196,11 +198,11 @@ module Puppet
# be inherited from the source?
unless @parent.argument?(stat)
@parent[stat] = value
- @parent.property(stat).retrieve
+ @parent.property(stat).retrieve # FIXARB: This is calling retrieve on all propertis of File. What are we gonna do with the return values?
end
}
- @is = @stats[:checksum]
+ return @stats[:checksum]
end
def should
@@ -223,7 +225,7 @@ module Puppet
def sync
unless @stats[:type] == "file"
#if @stats[:type] == "directory"
- #[@parent.name, @is.inspect, @should.inspect]
+ #[@parent.name, @should.inspect]
#end
raise Puppet::DevError, "Got told to copy non-file %s" %
@parent[:path]
diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/pfile/target.rb
index c3c9031ec..8913eb86f 100644
--- a/lib/puppet/type/pfile/target.rb
+++ b/lib/puppet/type/pfile/target.rb
@@ -15,7 +15,8 @@ module Puppet
end
# Only call mklink if ensure() didn't call us in the first place.
- if @parent.property(:ensure).insync?
+ currentensure = @parent.property(:ensure).retrieve
+ if @parent.property(:ensure).insync?(currentensure)
mklink()
end
end
@@ -48,23 +49,24 @@ module Puppet
end
end
- def insync?
+ def insync?(currentvalue)
if [:nochange, :notlink].include?(self.should) or @parent.recurse?
return true
else
- return super
+ return super(currentvalue)
end
end
+
def retrieve
if stat = @parent.stat
if stat.ftype == "link"
- @is = File.readlink(@parent[:path])
+ return File.readlink(@parent[:path])
else
- @is = :notlink
+ return :notlink
end
else
- @is = :absent
+ return :absent
end
end
end
diff --git a/lib/puppet/type/pfile/type.rb b/lib/puppet/type/pfile/type.rb
index 5f720ac9c..4c2783c71 100755
--- a/lib/puppet/type/pfile/type.rb
+++ b/lib/puppet/type/pfile/type.rb
@@ -8,14 +8,13 @@ module Puppet
#end
def retrieve
+ currentvalue = :absent
if stat = @parent.stat(false)
- @is = stat.ftype
- else
- @is = :absent
+ currentvalue = stat.ftype
end
-
# so this state is never marked out of sync
- @should = [@is]
+ @should = [currentvalue]
+ return currentvalue
end
diff --git a/lib/puppet/type/property.rb b/lib/puppet/type/property.rb
index 5c4babf38..065da6452 100644
--- a/lib/puppet/type/property.rb
+++ b/lib/puppet/type/property.rb
@@ -1,4 +1,4 @@
-# The virtual base class for properties, which are the self-contained building
+ # The virtual base class for properties, which are the self-contained building
# blocks for actually doing work on the system.
require 'puppet'
@@ -8,7 +8,6 @@ require 'puppet/parameter'
module Puppet
class Property < Puppet::Parameter
- attr_accessor :is
# Because 'should' uses an array, we have a special method for handling
# it. We also want to keep copies of the original values, so that
@@ -143,7 +142,7 @@ class Property < Puppet::Parameter
def call_valuemethod(name, value)
event = nil
if method = self.class.value_option(name, :method) and self.respond_to?(method)
- self.debug "setting %s (currently %s)" % [value, self.is]
+ self.debug "setting %s (currently %s)" % [value, self.retrieve]
begin
event = self.send(method)
@@ -169,17 +168,17 @@ class Property < Puppet::Parameter
end
# How should a property change be printed as a string?
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "defined '%s' as '%s'" %
- [self.name, self.should_to_s]
- elsif self.should == :absent or self.should == [:absent]
+ [self.name, self.should_to_s(newvalue)]
+ elsif newvalue == :absent or newvalue == [:absent]
return "undefined %s from '%s'" %
- [self.name, self.is_to_s]
+ [self.name, self.is_to_s(currentvalue)]
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -219,17 +218,11 @@ class Property < Puppet::Parameter
# initialize our property
def initialize(hash = {})
- @is = nil
super
end
def inspect
str = "Property('%s', " % self.name
- if self.is
- str += "@is = '%s', " % [self.is]
- else
- str += "@is = nil, "
- end
if defined? @should and @should
str += "@should = '%s')" % @should.join(", ")
@@ -244,7 +237,7 @@ class Property < Puppet::Parameter
# since we cannot fix it. Otherwise, we expect our should value
# to be an array, and if @is matches any of those values, then
# we consider it to be in-sync.
- def insync?
+ def insync?(is)
#debug "%s value is '%s', should be '%s'" %
# [self,self.is.inspect,self.should.inspect]
unless defined? @should and @should
@@ -262,7 +255,7 @@ class Property < Puppet::Parameter
# Look for a matching value
@should.each { |val|
- if @is == val or @is == val.to_s
+ if is == val or is == val.to_s
return true
end
}
@@ -275,8 +268,8 @@ class Property < Puppet::Parameter
# we need to set up a mechanism for pretty printing of the values
# default to just the values, but this way individual properties can
# override these methods
- def is_to_s
- @is
+ def is_to_s(currentvalue)
+ currentvalue
end
# Send a log message.
@@ -317,7 +310,10 @@ class Property < Puppet::Parameter
# provider. In other words, if the property name is 'gid', we'll call
# 'provider.gid' to retrieve the current value.
def retrieve
- @is = provider.send(self.class.name)
+ is = provider.send(self.class.name)
+# puts "IS is: " + is.to_s
+# puts "and its an array!!!" if is.is_a? Array
+ return is
end
# Set our value, using the provider, an associated block, or both.
@@ -383,9 +379,10 @@ class Property < Puppet::Parameter
end
end
- def should_to_s
- if defined? @should
- @should.join(" ")
+ def should_to_s(newvalue)
+ newvalue = [newvalue] unless newvalue.is_a? Array
+ if defined? newvalue
+ newvalue.join(" ")
else
return nil
end
@@ -394,10 +391,10 @@ class Property < Puppet::Parameter
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
- end
+# if self.insync?
+# self.info "already in sync"
+# return nil
+# end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -474,15 +471,15 @@ class Property < Puppet::Parameter
end
end
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent or @is.nil?
+ if currentvalue == :absent or currentvalue.nil?
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -507,9 +504,9 @@ class Property < Puppet::Parameter
@parent.class.name
end
if result
- @is = :present
+ return :present
else
- @is = :absent
+ return :absent
end
end
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index a3f6574d8..5778460a5 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -129,13 +129,13 @@ Puppet::Type.newtype(:resources) do
return true unless self[:unless_system_user]
resource[:check] = :uid
- resource.retrieve
+ current_values = resource.retrieve
if system_users().include?(resource[:name])
return false
end
- if resource.is(:uid) <= self[:unless_system_user]
+ if current_values[resource.property(:uid)] <= self[:unless_system_user]
return false
else
return true
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index 0fdd04928..1f04c0246 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -55,7 +55,7 @@ module Puppet
raise Puppet::Error, "Service %s does not support enabling" %
@parent.name
end
- @is = provider.enabled?
+ return provider.enabled?
end
validate do |value|
@@ -116,7 +116,7 @@ module Puppet
aliasvalue(:true, :running)
def retrieve
- self.is = provider.status
+ return provider.status
end
def sync
@@ -313,8 +313,9 @@ module Puppet
# to events.
def refresh
# Only restart if we're supposed to be running
- if ens = @parameters[:ensure] and ens.should == :running and ens.is == :running
- provider.restart
+
+ if ens = @parameters[:ensure] and ens.should == :running and ens.retrieve == :running
+ provider.restart
end
end
end
diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb
index f6622c510..6abbf2de8 100755
--- a/lib/puppet/type/sshkey.rb
+++ b/lib/puppet/type/sshkey.rb
@@ -28,11 +28,10 @@ module Puppet
make those aliases available in your Puppet scripts."
attr_accessor :meta
-
- def insync?
- @is == @should
- end
+ def insync?(is)
+ is == @should
+ end
# We actually want to return the whole array here, not just the first
# value.
def should
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index 2827c1be3..2750f3113 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -27,7 +27,7 @@ module Puppet
defaultto :anything # just so we always get this property
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
start = "Tidying"
if @out.include?(:age)
start += ", older than %s seconds" % @parent.should(:age)
@@ -39,9 +39,9 @@ module Puppet
start
end
- def insync?
- if @is.is_a?(Symbol)
- if [:absent, :notidy].include?(@is)
+ def insync?(is)
+ if is.is_a?(Symbol)
+ if [:absent, :notidy].include?(is)
return true
else
return false
@@ -50,11 +50,13 @@ module Puppet
@out = []
TATTRS.each do |param|
if property = @parent.property(param)
- unless property.insync?
+ self.debug "No is value for %s", [param] if is[property].nil?
+ unless property.insync?(is[property])
@out << param
end
end
end
+
if @out.length > 0
return false
else
@@ -62,24 +64,24 @@ module Puppet
end
end
end
-
+
def retrieve
stat = nil
unless stat = @parent.stat
- @is = :absent
- return
+ return { self => :absent}
end
if stat.ftype == "directory" and ! @parent[:rmdirs]
- @is = :notidy
- return
+ return {self => :notidy}
end
- TATTRS.each { |param|
+ allprops = TATTRS.inject({}) { |prophash, param|
if property = @parent.property(param)
- property.is = property.assess(stat)
+ prophash[property] = property.assess(stat)
end
+ prophash
}
+ return { self => allprops }
end
def sync
@@ -150,8 +152,8 @@ module Puppet
end
end
- def insync?
- if (Time.now.to_i - @is) > self.should
+ def insync?(is)
+ if (Time.now.to_i - is) > self.should
return false
end
@@ -204,8 +206,8 @@ module Puppet
end
end
- def insync?
- if @is > self.should
+ def insync?(is)
+ if is > self.should
return false
end
@@ -277,7 +279,11 @@ module Puppet
def retrieve
# Our ensure property knows how to retrieve everything for us.
- obj = @parameters[:ensure] and obj.retrieve
+ if obj = @parameters[:ensure]
+ return obj.retrieve
+ else
+ return {}
+ end
end
# Hack things a bit so we only ever check the ensure property.
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index c85c0368e..4bbb5b233 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -43,15 +43,16 @@ module Puppet
end
end
- def change_to_s
+ # FIXARB: Check this... I think it is exactly the same as the Ensure classes.
+ def change_to_s(currentvalue, newvalue)
begin
- if @is == :absent
+ if currentvalue == :absent
return "created"
- elsif self.should == :absent
+ elsif newvalue == :absent
return "removed"
else
return "%s changed '%s' to '%s'" %
- [self.name, self.is_to_s, self.should_to_s]
+ [self.name, self.is_to_s(currentvalue), self.should_to_s(newvalue)]
end
rescue Puppet::Error, Puppet::DevError
raise
@@ -64,21 +65,21 @@ module Puppet
def retrieve
if provider.exists?
- @is = :present
+ return :present
else
- @is = :absent
+ return :absent
end
end
# The default 'sync' method only selects among a list of registered
# values.
def sync
- if self.insync?
- self.info "already in sync"
- return nil
+# if self.insync?
+# self.info "already in sync"
+# return nil
#else
#self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
- end
+# end
unless self.class.values
self.devfail "No values defined for %s" %
self.class.name
@@ -185,20 +186,19 @@ module Puppet
group should not be listed. Multiple groups should be
specified as an array."
- def should_to_s
+ # FIXARB: Whoa... That should method requires is?
+ def should_to_s(newvalue = @should)
self.should
end
- def is_to_s
- @is.join(",")
+ def is_to_s(currentvalue)
+ currentvalue.join(",")
end
# We need to override this because the groups need to
# be joined with commas
def should
- unless defined? @is
- retrieve
- end
+ current_value = retrieve
unless defined? @should and @should
return nil
@@ -208,31 +208,31 @@ module Puppet
return @should.sort.join(",")
else
members = @should
- if @is.is_a?(Array)
- members += @is
+ if current_value.is_a?(Array)
+ members += current_value
end
return members.uniq.sort.join(",")
end
end
def retrieve
- if tmp = provider.groups
- @is = tmp.split(",")
+ if tmp = provider.groups and tmp != :absent
+ return tmp.split(",")
else
- @is = :absent
+ return :absent
end
end
- def insync?
+ def insync?(is)
unless defined? @should and @should
return true
end
- unless defined? @is and @is
+ unless defined? is and is
return true
end
- tmp = @is
- if @is.is_a? Array
- tmp = @is.sort.join(",")
+ tmp = is
+ if is.is_a? Array
+ tmp = is.sort.join(",")
end
return tmp == self.should
@@ -361,17 +361,21 @@ module Puppet
def retrieve
absent = false
- properties().each { |property|
+ properties().inject({}) { |prophash, property|
+ current_value = :absent
+
if absent
- property.is = :absent
+ prophash[property] = :absent
else
- property.retrieve
+ current_value = property.retrieve
+ prophash[property] = current_value
end
- if property.name == :ensure and property.is == :absent
+ if property.name == :ensure and current_value == :absent
absent = true
- next
+# next
end
+ prophash
}
end
end
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index 94ba3ef6c..cad411544 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -7,16 +7,16 @@ require 'puppet/type/parsedtype'
module Puppet
# A property for one entry in a .ini-style file
class IniProperty < Puppet::Property
- def insync?
+ def insync?(is)
# A should property of :absent is the same as nil
if is.nil? && (should.nil? || should == :absent)
return true
end
- return super
+ return super(is)
end
def sync
- if insync?
+ if insync?(retrieve)
result = nil
else
result = set(self.should)
@@ -30,7 +30,7 @@ module Puppet
end
def retrieve
- @is = parent.section[inikey]
+ return parent.section[inikey]
end
def inikey
@@ -88,12 +88,12 @@ module Puppet
inifile.each_section do |s|
next if s.name == "main"
obj = create(:name => s.name, :check => check)
- obj.retrieve
+ current_values = obj.retrieve
obj.eachproperty do |property|
- if property.is.nil?
+ if current_values[property].nil?
obj.delete(property.name)
else
- property.should = property.is
+ property.should = current_values[property]
end
end
obj.delete(:check)
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index 35d2a3d87..48f4a90bb 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -15,23 +15,25 @@ Puppet::Type.newtype(:zone) do
class ZoneMultiConfigProperty < ZoneConfigProperty
def configtext
list = @should
+
+ current_value = self.retrieve
- unless @is.is_a? Symbol
- if @is.is_a? Array
- list += @is
+ unless current_value.is_a? Symbol
+ if current_value.is_a? Array
+ list += current_vlue
else
- if @is
- list << @is
+ if current_value
+ list << current_value
end
end
end
- # Some hackery so we can test whether @is is an array or a symbol
- if @is.is_a? Array
- tmpis = @is
+ # Some hackery so we can test whether current_value is an array or a symbol
+ if current_value.is_a? Array
+ tmpis = current_value
else
- if @is
- tmpis = [@is]
+ if current_value
+ tmpis = [current_value]
else
tmpis = []
end
@@ -56,11 +58,11 @@ Puppet::Type.newtype(:zone) do
end
# We want all specified directories to be included.
- def insync?
- if @is.is_a? Array and @should.is_a? Array
- @is.sort == @should.sort
+ def insync?(current_value)
+ if current_value.is_a? Array and @should.is_a? Array
+ current_value.sort == @should.sort
else
- @is == @should
+ current_value == @should
end
end
end
@@ -124,11 +126,6 @@ Puppet::Type.newtype(:zone) do
list[1..-1]
end
- def is=(value)
- value = value.intern if value.is_a? String
- @is = value
- end
-
def sync
method = nil
if up?
@@ -139,8 +136,6 @@ Puppet::Type.newtype(:zone) do
# We need to get the state we're currently in and just call
# everything between it and us.
- states = self.class.valueslice(self.is, self.should)
-
properties.each do |prop|
if method = prop[dir]
warned = false
@@ -163,7 +158,8 @@ Puppet::Type.newtype(:zone) do
# Are we moving up the property tree?
def up?
- self.class.valueindex(self.is) < self.class.valueindex(self.should)
+ current_value = self.retrieve
+ self.class.valueindex(current_value) < self.class.valueindex(self.should)
end
end
@@ -386,56 +382,58 @@ set zonepath=%s
def retrieve
if hash = provider.statushash()
- setstatus(hash)
+ prophash = setstatus(hash)
# Now retrieve the configuration itself and set appropriately.
- config2status(provider.getconfig())
+ return config2status(provider.getconfig(), prophash)
else
- properties().each do |pr|
- pr.is = :absent
- end
+ return currentpropvalues(:absent)
end
end
# Take the results of a listing and set everything appropriately.
def setstatus(hash)
+ prophash = {}
hash.each do |param, value|
next if param == :name
case self.class.attrtype(param)
- when :pr:
- self.is = [param, value]
+ when :property:
+ prophash[self.property(param)] = value
else
self[param] = value
end
end
+ return prophash
end
private
# Turn the results of getconfig into status information.
- def config2status(config)
+ def config2status(config, prophash)
config.each do |name, value|
case name
when :autoboot:
- self.is = [:autoboot, value.intern]
+ prophash[self.property(:autoboot)] = value.intern
when :zonepath:
# Nothing; this is set in the zoneadm list command
when :pool:
- self.is = [:pool, value]
+ prophash[self.property(:pool)] = value
when :shares:
- self.is = [:shares, value]
+ prophash[self.property(:shares)] = value
when "inherit-pkg-dir":
dirs = value.collect do |hash|
hash[:dir]
end
- self.is = [:inherit, dirs]
+ prophash[self.property(:inherit)] = dirs
when "net":
vals = value.collect do |hash|
"%s:%s" % [hash[:physical], hash[:address]]
end
- self.is = [:ip, vals]
+ prophash[self.proeprty(:ip)] = vals
end
end
+
+ return prophash
end
end
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 979f3fbd9..9369f17e7 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -34,8 +34,8 @@ module PuppetTest
FileUtils.rm(filename)
end
- def assert_rollback_events(events, trans, msg = nil)
- run_events(:rollback, events, trans, msg)
+ def assert_rollback_events(trans, events, msg = nil)
+ run_events(:rollback, trans, events, msg)
end
def assert_events(events, *items)
diff --git a/test/other/propertychange.rb b/test/other/propertychange.rb
index d60a2ba2c..97ee3268c 100755
--- a/test/other/propertychange.rb
+++ b/test/other/propertychange.rb
@@ -12,11 +12,11 @@ class TestPropertyChange < Test::Unit::TestCase
class FakeProperty < Puppet::Type::Property
attr_accessor :is, :should, :parent
attr_reader :noop
- def change_to_s
+ def change_to_s(currentvalue, newvalue)
"fake change"
end
- def insync?
- @is == @should
+ def insync?(is)
+ is == @should
end
def log(msg)
Puppet::Util::Log.create(
@@ -35,11 +35,11 @@ class TestPropertyChange < Test::Unit::TestCase
def path
"fakechange"
end
- def should_to_s
- @should.to_s
+ def should_to_s(newvalue)
+ newvalue.to_s
end
def sync
- if insync?
+ if insync?(@is)
return nil
else
@is = @should
@@ -58,7 +58,7 @@ class TestPropertyChange < Test::Unit::TestCase
property.parent = :parent
change = nil
assert_nothing_raised do
- change = Puppet::PropertyChange.new(property)
+ change = Puppet::PropertyChange.new(property, :start)
end
change.transaction = :trans
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 00241c93e..3a9ba3d79 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -17,7 +17,7 @@ class TestTransactions < Test::Unit::TestCase
def should_to_s
@should.to_s
end
- def insync?
+ def insync?(foo)
true
end
def info(*args)
@@ -466,7 +466,7 @@ class TestTransactions < Test::Unit::TestCase
file[:content] = "totally different content"
- assert(! file.insync?, "Uh, file is in sync?")
+ assert(! file.insync?(file.retrieve), "Uh, file is in sync?")
assert_events([:file_changed, :triggered], comp)
assert(FileTest.exists?(fname), "File did not get recreated")
@@ -766,7 +766,7 @@ class TestTransactions < Test::Unit::TestCase
type = mkreducer do
def evaluate
return Puppet::PropertyChange.new(Fakeprop.new(
- :path => :path, :is => :is, :should => :should, :name => self.name, :parent => "a parent"))
+ :path => :path, :is => :is, :should => :should, :name => self.name, :parent => "a parent"), :is)
end
end
@@ -1015,7 +1015,7 @@ class TestTransactions < Test::Unit::TestCase
obj = type.create(:name => "yay", :testing => "cool")
- assert(! obj.insync?, "fake object is already in sync")
+ assert(! obj.insync?(obj.retrieve), "fake object is already in sync")
# Now make sure it gets refreshed when the change happens
assert_apply(obj)
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb
index 43f716ec2..9826638ee 100755
--- a/test/ral/manager/attributes.rb
+++ b/test/ral/manager/attributes.rb
@@ -42,19 +42,14 @@ class TestTypeAttributes < Test::Unit::TestCase
if param == :property
assert(inst.property(param), "did not get obj for %s" % param)
- end
-
- if param == :property
assert_equal(true, inst.should(param),
"should value did not get set")
- inst.is = [:property, true]
+ else
+ assert_equal(true, inst[param],
+ "did not get correct value for %s from symbol" % param)
+ assert_equal(true, inst[param.to_s],
+ "did not get correct value for %s from string" % param)
end
-
- # Now make sure we can get it back
- assert_equal(true, inst[param],
- "did not get correct value for %s from symbol" % param)
- assert_equal(true, inst[param.to_s],
- "did not get correct value for %s from string" % param)
end
end
@@ -232,7 +227,6 @@ class TestTypeAttributes < Test::Unit::TestCase
type.provide(:testing) {}
provider = type.attrclass(:provider)
should = [[name, :param], [provider, :param], [two, :property], [one, :param]]
-
assert_nothing_raised do
result = nil
type.eachattr do |obj, name|
diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb
index 6c1d6156c..3872ef637 100755
--- a/test/ral/manager/type.rb
+++ b/test/ral/manager/type.rb
@@ -452,7 +452,7 @@ end
ret = inst.retrieve
}
- assert_equal(:noopts, inst.is)
+ assert_equal(:noopts, inst.retrieve)
# Now create a property with a different way of doing it
property = nil
@@ -468,7 +468,7 @@ end
ret = inst.retrieve
}
- assert_equal(:yayness, inst.is)
+ assert_equal(:yayness, ret)
end
def test_name_vs_title
diff --git a/test/ral/providers/package/apt.rb b/test/ral/providers/package/apt.rb
index d289bdd3c..97998e4bb 100755
--- a/test/ral/providers/package/apt.rb
+++ b/test/ral/providers/package/apt.rb
@@ -28,7 +28,7 @@ class AptPackageProviderTest < PuppetTest::TestCase
'faff'
).returns(
"deinstall ok config-files faff 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:aptget
@@ -56,7 +56,7 @@ class AptPackageProviderTest < PuppetTest::TestCase
'faff'
).returns(
"install ok installed faff 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:aptget
).with(
diff --git a/test/ral/providers/package/aptitude.rb b/test/ral/providers/package/aptitude.rb
index a8ab6f7b7..891603f64 100755
--- a/test/ral/providers/package/aptitude.rb
+++ b/test/ral/providers/package/aptitude.rb
@@ -19,16 +19,16 @@ class AptitudePackageProviderTest < PuppetTest::TestCase
:ensure => :present,
:source => "/tmp/faff.deb"
- pkg.provider.expects(
- :dpkgquery
- ).with(
- '-W',
- '--showformat',
- '${Status} ${Package} ${Version}\n',
- 'faff'
- ).returns(
- "deinstall ok config-files faff 1.2.3-1\n"
- )
+ pkg.provider.expects(
+ :dpkgquery
+ ).with(
+ '-W',
+ '--showformat',
+ '${Status} ${Package} ${Version}\n',
+ 'faff'
+ ).returns(
+ "deinstall ok config-files faff 1.2.3-1\n"
+ ).times(2)
pkg.provider.expects(
:aptitude
@@ -40,7 +40,10 @@ class AptitudePackageProviderTest < PuppetTest::TestCase
'faff'
).returns(0)
- pkg.evaluate.each { |state| state.transaction = self; state.forward }
+ pkg.evaluate.each { |state|
+ state.transaction = self
+ state.forward
+ }
end
def test_purge
@@ -55,7 +58,7 @@ class AptitudePackageProviderTest < PuppetTest::TestCase
'faff'
).returns(
"install ok installed faff 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:aptitude
).with(
diff --git a/test/ral/providers/package/aptrpm.rb b/test/ral/providers/package/aptrpm.rb
index 488862683..0388135df 100755
--- a/test/ral/providers/package/aptrpm.rb
+++ b/test/ral/providers/package/aptrpm.rb
@@ -28,7 +28,7 @@ class AptrpmPackageProviderTest < PuppetTest::TestCase
'--nodigest',
'--qf',
"%{NAME}-%{VERSION}-%{RELEASE} %{VERSION}-%{RELEASE}\n"
- ).raises(Puppet::ExecutionFailure, "couldn't find rpm")
+ ).raises(Puppet::ExecutionFailure, "couldn't find rpm").times(2)
pkg.provider.expects(
:aptget
@@ -56,7 +56,7 @@ class AptrpmPackageProviderTest < PuppetTest::TestCase
"%{NAME}-%{VERSION}-%{RELEASE} %{VERSION}-%{RELEASE}\n"
).returns(
"faff-1.2.3-1 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:aptget
).with(
diff --git a/test/ral/providers/package/dpkg.rb b/test/ral/providers/package/dpkg.rb
index 3d26150d8..69b6a3c10 100755
--- a/test/ral/providers/package/dpkg.rb
+++ b/test/ral/providers/package/dpkg.rb
@@ -27,7 +27,7 @@ class DpkgPackageProviderTest < PuppetTest::TestCase
'faff'
).returns(
"deinstall ok config-files faff 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:dpkg
@@ -51,7 +51,7 @@ class DpkgPackageProviderTest < PuppetTest::TestCase
'faff'
).returns(
"install ok installed faff 1.2.3-1\n"
- )
+ ).times(2)
pkg.provider.expects(
:dpkg
).with(
diff --git a/test/ral/providers/parsedfile.rb b/test/ral/providers/parsedfile.rb
index cfc966a6c..015d0a8b7 100755
--- a/test/ral/providers/parsedfile.rb
+++ b/test/ral/providers/parsedfile.rb
@@ -301,14 +301,14 @@ class TestParsedFile < Test::Unit::TestCase
# Lastly, create a model with separate is and should values
mtarget = tempfile()
- istarget = tempfile()
+ # istarget = tempfile()
files[:models] = mtarget
- files[:ismodels] = istarget
+ # files[:ismodels] = istarget
model = mkmodel "yay", :target => mtarget
- model.is = [:target, istarget]
+ # model.is = [:target, istarget]
assert(model.should(:target), "Did not get a value for target")
- assert(model.is(:target), "Did not get a value for target")
+ # assert(model.is(:target), "Did not get a value for target")
list = nil
assert_nothing_raised do
@@ -559,12 +559,20 @@ class TestParsedFile < Test::Unit::TestCase
# First make sure we can retrieve values multiple times from the
# provider
- assert(bill.is(:one), "Bill does not have a value for 'one'")
- assert(bill.is(:one), "Bill does not have a value for 'one' on second try")
+ bills_values = nil
+ assert_nothing_raised do
+ bills_values = bill.retrieve
+ end
+
+ assert(bills_values[bill.property(:one)],
+ "Bill does not have a value for 'one'")
+ assert(bills_values[bill.property(:one)],
+ "Bill does not have a value for 'one' on second try")
assert_nothing_raised do
bill.retrieve
end
- assert(bill.is(:one), "bill's value for 'one' disappeared")
+ assert(bills_values[bill.property(:one)],
+ "bill's value for 'one' disappeared")
end
# Make sure that creating a new model finds existing records in memory
@@ -603,11 +611,12 @@ class TestParsedFile < Test::Unit::TestCase
assert_apply(bill)
prov.prefetch
+ current_value = nil
assert_nothing_raised do
- bill.retrieve
+ current_value = bill.retrieve
end
- assert(bill.insync?,
+ assert(bill.insync?(current_value),
"An invalid field marked the record out of sync")
end
diff --git a/test/ral/providers/user/useradd.rb b/test/ral/providers/user/useradd.rb
index ca917f6c4..55bb96f2a 100755
--- a/test/ral/providers/user/useradd.rb
+++ b/test/ral/providers/user/useradd.rb
@@ -29,7 +29,6 @@ class UserAddProviderTest < PuppetTest::TestCase
@vals.each do |name, val|
next unless @user.class.validproperty?(name)
- @user.is = [name, :absent]
end
@user
end
@@ -46,7 +45,6 @@ class UserAddProviderTest < PuppetTest::TestCase
@vals.each do |name, val|
next unless user.class.validproperty?(name)
- user.is = [name, :absent]
end
user.expects(:allowdupe?).returns(false)
@@ -204,8 +202,6 @@ class UserAddProviderTest < PuppetTest::TestCase
# Now mark the user made, and make sure the right command is called
setup_user
- @user.is = [:ensure, :present]
- @user.is = [:password, :present]
@vals[:password] = "somethingelse"
@user.provider.expects(:execute).with do |params|
diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb
index 2b09fd66d..ead815071 100755
--- a/test/ral/types/cron.rb
+++ b/test/ral/types/cron.rb
@@ -97,9 +97,9 @@ class TestCron < Test::Unit::TestCase
assert_events([:cron_created], comp)
cron.provider.class.prefetch
- cron.retrieve
+ currentvalue = cron.retrieve
- assert(cron.insync?, "Cron is not in sync")
+ assert(cron.insync?(currentvalue), "Cron is not in sync")
assert_events([], comp)
@@ -114,9 +114,9 @@ class TestCron < Test::Unit::TestCase
assert_events([:cron_removed], comp)
cron.provider.class.prefetch
- cron.retrieve
+ currentvalue = cron.retrieve
- assert(cron.insync?, "Cron is not in sync")
+ assert(cron.insync?(currentvalue), "Cron is not in sync")
assert_events([], comp)
end
@@ -137,10 +137,12 @@ class TestCron < Test::Unit::TestCase
}
property = cron.send(:property, :command)
cron.provider.command = command
+ cron.provider.ensure = :present
+ cron.provider.month = ["4"]
cron.provider.class.prefetch
- cron.retrieve
+ currentvalue = cron.retrieve
- assert(property.insync?, "command parsing removes trailing whitespace")
+ assert(cron.insync?(currentvalue), "command parsing removes trailing whitespace")
@crontype.clear
end
end
@@ -230,12 +232,14 @@ class TestCron < Test::Unit::TestCase
)
}
- minute = cron.send(:property, :minute)
+ #minute = cron.send(:property, :minute)
+ cron.provider.ensure = :present
+ cron.provider.command = '/bin/date > /dev/null'
cron.provider.minute = %w{0 30}
cron.provider.class.prefetch
- cron.retrieve
+ currentvalue = cron.retrieve
- assert(minute.insync?, "minute is out of sync with %s" % provider.name)
+ assert(cron.insync?(currentvalue), "minute is out of sync with %s" % provider.name)
@crontype.clear
end
end
@@ -256,11 +260,13 @@ class TestCron < Test::Unit::TestCase
cron[:minute] = :absent
assert_events([:cron_changed], cron)
+
+ current_values = nil
assert_nothing_raised {
cron.provider.class.prefetch
- cron.retrieve
+ current_values = cron.retrieve
}
- assert_equal(:absent, cron.is(:minute))
+ assert_equal(:absent, current_values[cron.property(:minute)])
end
def test_listing
@@ -325,9 +331,9 @@ class TestCron < Test::Unit::TestCase
assert_apply(cron)
cron.provider.class.prefetch
- cron.retrieve
+ currentvalue = cron.retrieve
- assert_equal(["*/5"], cron.is(:minute))
+ assert_equal(["*/5"], currentvalue[cron.property(:minute)])
end
def test_ranges
@@ -336,10 +342,22 @@ class TestCron < Test::Unit::TestCase
assert_apply(cron)
- cron.provider.class.prefetch
- cron.retrieve
+ current_values = nil
+ assert_nothing_raised {
+ cron.provider.class.prefetch
+ current_values = cron.retrieve
+ }
+
+ assert_equal(["2-4"], current_values[cron.property(:minute)])
+ end
+
- assert_equal(["2-4"], cron.is(:minute))
+ def provider_set(cron, param, value)
+ unless param =~ /=$/
+ param = "%s=" % param
+ end
+
+ cron.provider.send(param, value)
end
def test_value
@@ -353,22 +371,19 @@ class TestCron < Test::Unit::TestCase
assert(property, "Did not get %s property" % param)
assert_nothing_raised {
- property.is = :absent
+# property.is = :absent
+ provider_set(cron, param, :absent)
}
- val = [:absent]
+ val = "*"
assert_equal(val, cron.value(param))
- # Make sure we correctly get the "is" value if that's all there is
- cron.is = [param, "1"]
- assert_equal(%w{1}, cron.value(param))
-
# Make sure arrays work, too
- cron.is = [param, ["1"]]
+ provider_set(cron, param, ["1"])
assert_equal(%w{1}, cron.value(param))
# Make sure values get comma-joined
- cron.is = [param, %w{2 3}]
+ provider_set(cron, param, %w{2 3})
assert_equal(%w{2 3}, cron.value(param))
# Make sure "should" values work, too
@@ -381,7 +396,7 @@ class TestCron < Test::Unit::TestCase
cron[param] = ["4", "5"]
assert_equal(%w{4 5}, cron.value(param))
- cron.is = [param, :absent]
+ provider_set(cron, param, :absent)
assert_equal(%w{4 5}, cron.value(param))
end
@@ -393,20 +408,16 @@ class TestCron < Test::Unit::TestCase
property = cron.property(:command)
assert_nothing_raised {
- property.is = :absent
+ provider_set(cron, :command, :absent)
}
param = :command
- # Make sure we correctly get the "is" value if that's all there is
- cron.is = [param, "/bin/echo"]
- assert_equal("/bin/echo", cron.value(param))
-
# Make sure arrays work, too
- cron.is = [param, ["/bin/echo"]]
+ provider_set(cron, param, ["/bin/echo"])
assert_equal("/bin/echo", cron.value(param))
# Make sure values are not comma-joined
- cron.is = [param, %w{/bin/echo /bin/test}]
+ provider_set(cron, param, %w{/bin/echo /bin/test})
assert_equal("/bin/echo", cron.value(param))
# Make sure "should" values work, too
@@ -419,7 +430,7 @@ class TestCron < Test::Unit::TestCase
cron[param] = %w{/bin/echo /bin/test}
assert_equal("/bin/echo", cron.value(param))
- cron.is = [param, :absent]
+ provider_set(cron, param, :absent)
assert_equal("/bin/echo", cron.value(param))
end
@@ -455,7 +466,7 @@ class TestCron < Test::Unit::TestCase
end
# Make sure the user stuff defaults correctly.
- def test_default_user
+ def test_default_user
crontab = @crontype.provider(:crontab)
if crontab.suitable?
inst = @crontype.create(
diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb
index e58095764..2dcfb17ec 100755
--- a/test/ral/types/file.rb
+++ b/test/ral/types/file.rb
@@ -237,15 +237,15 @@ class TestFile < Test::Unit::TestCase
}
assert(changes.length > 0)
assert_apply(file)
- file.retrieve
- assert(file.insync?())
+ currentvalue = file.retrieve
+ assert(file.insync?(currentvalue))
assert_nothing_raised() {
file[:owner] = uid
}
assert_apply(file)
- file.retrieve
+ currentvalue = file.retrieve
# make sure changing to number doesn't cause a sync
- assert(file.insync?())
+ assert(file.insync?(currentvalue))
}
# We no longer raise an error here, because we check at run time
@@ -269,8 +269,8 @@ class TestFile < Test::Unit::TestCase
assert(file.property(:group))
assert(file.property(:group).should)
assert_apply(file)
- file.retrieve
- assert(file.insync?())
+ currentvalue = file.retrieve
+ assert(file.insync?(currentvalue))
assert_nothing_raised() {
file.delete(:group)
}
@@ -311,7 +311,7 @@ class TestFile < Test::Unit::TestCase
assert_events([:file_created], file)
assert_events([], file)
assert(FileTest.file?(path), "File does not exist")
- assert(file.insync?())
+ assert(file.insync?(file.retrieve))
@@tmpfiles.push path
}
end
@@ -331,7 +331,7 @@ class TestFile < Test::Unit::TestCase
[path])
assert_events([:directory_created], file)
assert_events([], file)
- assert(file.insync?())
+ assert(file.insync?(file.retrieve))
assert(FileTest.directory?(path))
@@tmpfiles.push path
}
@@ -348,7 +348,7 @@ class TestFile < Test::Unit::TestCase
assert_events([:file_changed], file)
assert_events([], file)
- assert(file.insync?())
+ assert(file.insync?(file.retrieve))
assert_nothing_raised() {
file.delete(:mode)
@@ -387,11 +387,11 @@ class TestFile < Test::Unit::TestCase
}
trans = nil
- file.retrieve
+ currentvalues = file.retrieve
if file.title !~ /nonexists/
sum = file.property(:checksum)
- assert(sum.insync?, "file is not in sync")
+ assert(sum.insync?(currentvalues[sum]), "file is not in sync")
end
events = assert_apply(file)
@@ -424,10 +424,11 @@ class TestFile < Test::Unit::TestCase
# Run it a few times to make sure we aren't getting
# spurious changes.
+ sum = nil
assert_nothing_raised do
- file.property(:checksum).retrieve
+ sum = file.property(:checksum).retrieve
end
- assert(file.property(:checksum).insync?,
+ assert(file.property(:checksum).insync?(sum),
"checksum is not in sync")
sleep 1.1 if type =~ /time/
@@ -713,7 +714,7 @@ class TestFile < Test::Unit::TestCase
file.evaluate
}
- assert_equal("directory", file.property(:type).is)
+ assert_equal("directory", file.property(:type).retrieve)
# And then check files
assert_nothing_raised {
@@ -727,15 +728,16 @@ class TestFile < Test::Unit::TestCase
file[:check] = "type"
assert_apply(file)
- assert_equal("file", file.property(:type).is)
+ assert_equal("file", file.property(:type).retrieve)
file[:type] = "directory"
- assert_nothing_raised { file.retrieve }
+ currentvalues = {}
+ assert_nothing_raised { currentvalues = file.retrieve }
# The 'retrieve' method sets @should to @is, so they're never
# out of sync. It's a read-only class.
- assert(file.insync?)
+ assert(file.insync?(currentvalues))
end
def test_remove
@@ -840,13 +842,13 @@ class TestFile < Test::Unit::TestCase
)
}
- assert(!obj.insync?, "Object is incorrectly in sync")
+ assert(!obj.insync?(obj.retrieve), "Object is incorrectly in sync")
assert_events([:file_created], obj)
- obj.retrieve
+ currentvalues = obj.retrieve
- assert(obj.insync?, "Object is not in sync")
+ assert(obj.insync?(currentvalues), "Object is not in sync")
text = File.read(file)
@@ -856,7 +858,7 @@ class TestFile < Test::Unit::TestCase
obj[:content] = newstr
- assert(!obj.insync?, "Object is incorrectly in sync")
+ assert(!obj.insync?(obj.retrieve), "Object is incorrectly in sync")
assert_events([:file_changed], obj)
@@ -864,8 +866,8 @@ class TestFile < Test::Unit::TestCase
assert_equal(newstr, text, "Content did not copy correctly")
- obj.retrieve
- assert(obj.insync?, "Object is not in sync")
+ currentvalues = obj.retrieve
+ assert(obj.insync?(currentvalues), "Object is not in sync")
end
# Unfortunately, I know this fails
@@ -943,7 +945,7 @@ class TestFile < Test::Unit::TestCase
)
}
- file.retrieve
+ currentvalues = file.retrieve
assert_events([:file_created], file)
file.retrieve
@@ -1218,21 +1220,21 @@ class TestFile < Test::Unit::TestCase
file = Puppet::Type.newfile(:path => path, :ensure => :present)
- file.retrieve
- assert(! file.insync?, "File incorrectly in sync")
+ currentvalues = file.retrieve
+ assert(! file.insync?(currentvalues), "File incorrectly in sync")
# Now make a file
File.open(path, "w") { |f| f.puts "yay" }
- file.retrieve
- assert(file.insync?, "File not in sync")
+ currentvalues = file.retrieve
+ assert(file.insync?(currentvalues), "File not in sync")
# Now make a directory
File.unlink(path)
Dir.mkdir(path)
- file.retrieve
- assert(file.insync?, "Directory not considered 'present'")
+ currentvalues = file.retrieve
+ assert(file.insync?(currentvalues), "Directory not considered 'present'")
Dir.rmdir(path)
@@ -1242,8 +1244,8 @@ class TestFile < Test::Unit::TestCase
otherfile = tempfile()
File.symlink(otherfile, path)
- file.retrieve
- assert(file.insync?, "Symlink not considered 'present'")
+ currentvalues = file.retrieve
+ assert(file.insync?(currentvalues), "Symlink not considered 'present'")
File.unlink(path)
# Now set some content, and make sure it works
@@ -1459,8 +1461,8 @@ class TestFile < Test::Unit::TestCase
property = obj.property(:ensure)
- property.retrieve
- unless property.insync?
+ currentvalue = property.retrieve
+ unless property.insync?(currentvalue)
assert_nothing_raised do
property.sync
end
diff --git a/test/ral/types/file/target.rb b/test/ral/types/file/target.rb
index f016b148a..1e62f07ac 100755
--- a/test/ral/types/file/target.rb
+++ b/test/ral/types/file/target.rb
@@ -222,19 +222,19 @@ class TestFileTarget < Test::Unit::TestCase
prop = obj.send(:property, :target)
prop.send(:instance_variable_set, "@should", [:nochange])
- assert(prop.insync?,
+ assert(prop.insync?(prop.retrieve),
"Property not in sync with should == :nochange")
prop = obj.send(:property, :target)
prop.send(:instance_variable_set, "@should", [:notlink])
- assert(prop.insync?,
+ assert(prop.insync?(prop.retrieve),
"Property not in sync with should == :nochange")
# Lastly, make sure that we don't try to do anything when we're
# recursing, since 'ensure' does the work.
obj[:recurse] = true
prop.should = dest
- assert(prop.insync?,
+ assert(prop.insync?(prop.retrieve),
"Still out of sync during recursion")
end
diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb
index 60d3214b6..fed5e3f2a 100755
--- a/test/ral/types/filesources.rb
+++ b/test/ral/types/filesources.rb
@@ -143,26 +143,27 @@ class TestFileSources < Test::Unit::TestCase
assert_equal([source], property.should, "munging changed the source")
# First try it with a missing source
+ currentvalue = nil
assert_nothing_raised do
- property.retrieve
+ currentvalue = property.retrieve
end
# And make sure the property considers itself in sync, since there's nothing
# to do
- assert(property.insync?, "source thinks there's work to do with no file or dest")
+ assert(property.insync?(currentvalue), "source thinks there's work to do with no file or dest")
# Now make the dest a directory, and make sure the object sets :ensure
# up to create a directory
Dir.mkdir(source)
assert_nothing_raised do
- property.retrieve
+ currentvalue = property.retrieve
end
assert_equal(:directory, file.should(:ensure),
"Did not set to create directory")
# And make sure the source property won't try to do anything with a
# remote dir
- assert(property.insync?, "Source was out of sync even tho remote is dir")
+ assert(property.insync?(currentvalue), "Source was out of sync even tho remote is dir")
# Now remove the source, and make sure :ensure was not modified
Dir.rmdir(source)
@@ -205,29 +206,29 @@ class TestFileSources < Test::Unit::TestCase
assert(property, "did not get source property")
# Try it with no source at all
- file.retrieve
- assert(property.insync?, "source property not in sync with missing source")
+ currentvalues = file.retrieve
+ assert(property.insync?(currentvalues[property]), "source property not in sync with missing source")
# with a directory
Dir.mkdir(source)
- file.retrieve
- assert(property.insync?, "source property not in sync with directory as source")
+ currentvalues = file.retrieve
+ assert(property.insync?(currentvalues[property]), "source property not in sync with directory as source")
Dir.rmdir(source)
# with a file
File.open(source, "w") { |f| f.puts "yay" }
- file.retrieve
- assert(!property.insync?, "source property was in sync when file was missing")
+ currentvalues = file.retrieve
+ assert(!property.insync?(currentvalues[property]), "source property was in sync when file was missing")
# With a different file
File.open(dest, "w") { |f| f.puts "foo" }
- file.retrieve
- assert(!property.insync?, "source property was in sync with different file")
+ currentvalues = file.retrieve
+ assert(!property.insync?(currentvalues[property]), "source property was in sync with different file")
# with matching files
File.open(dest, "w") { |f| f.puts "yay" }
- file.retrieve
- assert(property.insync?, "source property was not in sync with matching file")
+ currentvalues = file.retrieve
+ assert(property.insync?(currentvalues[property]), "source property was not in sync with matching file")
end
def test_source_sync
@@ -240,8 +241,8 @@ class TestFileSources < Test::Unit::TestCase
File.open(source, "w") { |f| f.puts "yay" }
- file.retrieve
- assert(! property.insync?, "source thinks it's in sync")
+ currentvalues = file.retrieve
+ assert(! property.insync?(currentvalues[property]), "source thinks it's in sync")
event = nil
assert_nothing_raised do
@@ -253,8 +254,8 @@ class TestFileSources < Test::Unit::TestCase
# Now write something different
File.open(source, "w") { |f| f.puts "rah" }
- file.retrieve
- assert(! property.insync?, "source should be out of sync")
+ currentvalues = file.retrieve
+ assert(! property.insync?(currentvalues[property]), "source should be out of sync")
assert_nothing_raised do
event = property.sync
end
@@ -692,12 +693,12 @@ class TestFileSources < Test::Unit::TestCase
)
}
- file.retrieve
+ currentvalue = file.retrieve
- assert(file.is(:checksum), "File does not have a checksum property")
+ assert(currentvalue[file.property(:checksum)],
+ "File does not have a checksum property")
assert_equal(0, file.evaluate.length, "File produced changes")
-
end
def test_sourcepaths
diff --git a/test/ral/types/group.rb b/test/ral/types/group.rb
index 9f091f699..9870d533a 100755
--- a/test/ral/types/group.rb
+++ b/test/ral/types/group.rb
@@ -125,11 +125,13 @@ class TestGroup < Test::Unit::TestCase
# Set a fake gid
gobj.provider.gid = rand(100)
+ current_values = nil
assert_nothing_raised {
- gobj.retrieve
+ current_values = gobj.retrieve
}
- assert(gobj.is(:gid), "Failed to retrieve gid")
+ assert(current_values[gobj.property(:gid)],
+ "Failed to retrieve gid")
}
end
diff --git a/test/ral/types/host.rb b/test/ral/types/host.rb
index f315cbd1f..57d425e7c 100755
--- a/test/ral/types/host.rb
+++ b/test/ral/types/host.rb
@@ -79,20 +79,21 @@ class TestHost < Test::Unit::TestCase
)
}
- host.retrieve
+ current_values = nil
+ assert_nothing_raised { current_values = host.retrieve }
assert_events([:host_created], host)
- assert_nothing_raised { host.retrieve }
+ assert_nothing_raised { current_values = host.retrieve }
- assert_equal(:present, host.is(:ensure))
+ assert_equal(:present, current_values[host.property(:ensure)])
host[:ensure] = :absent
assert_events([:host_removed], host)
- assert_nothing_raised { host.retrieve }
+ assert_nothing_raised { current_values = host.retrieve }
- assert_equal(:absent, host.is(:ensure))
+ assert_equal(:absent, current_values[host.property(:ensure)])
end
def test_moddinghost
@@ -111,18 +112,24 @@ class TestHost < Test::Unit::TestCase
assert_events([:host_created], host)
- host.retrieve
+ current_values = nil
+ assert_nothing_raised {
+ current_values = host.retrieve
+ }
# This was a hard bug to track down.
- assert_instance_of(String, host.is(:ip))
+ assert_instance_of(String, current_values[host.property(:ip)])
host[:alias] = %w{madstop kirby yayness}
assert_events([:host_changed], host)
- host.retrieve
+ assert_nothing_raised {
+ current_values = host.retrieve
+ }
- assert_equal(%w{madstop kirby yayness}, host.is(:alias))
+ assert_equal(%w{madstop kirby yayness},
+ current_values[host.property(:alias)])
host[:ensure] = :absent
assert_events([:host_removed], host)
diff --git a/test/ral/types/mount.rb b/test/ral/types/mount.rb
index 23fee5ac7..4b76b3ec2 100755
--- a/test/ral/types/mount.rb
+++ b/test/ral/types/mount.rb
@@ -178,10 +178,11 @@ class TestMounts < Test::Unit::TestCase
assert_events([:mount_mounted, :triggered], obj)
assert_events([], obj)
- obj.retrieve
- assert_equal(:mounted, obj.is(:ensure))
+ current_values = nil
+ assert_nothing_raised { current_values = obj.retrieve }
+ assert_equal(:mounted, current_values[obj.property(:ensure)])
- obj.retrieve
+ assert_nothing_raised { current_values = obj.retrieve }
assert(obj.provider.mounted?, "Object is not mounted")
end
@@ -200,16 +201,13 @@ class TestMounts < Test::Unit::TestCase
root = list.find { |o| o[:name] == "/" }
assert(root, "Could not find root root filesystem in list results")
-
- assert(root.is(:device), "Device was not set")
- assert(root.property(:device).value, "Device was not returned by value method")
-
+
+ current_values = nil
assert_nothing_raised do
- root.retrieve
+ current_values = root.retrieve
end
- assert(root.is(:device), "Device was not set")
- assert(root.property(:device).value, "Device was not returned by value method")
+ assert(current_values[root.property(:device)], "Device was not set")
end
end
diff --git a/test/ral/types/package.rb b/test/ral/types/package.rb
index f49a36bb6..e45f68d34 100755
--- a/test/ral/types/package.rb
+++ b/test/ral/types/package.rb
@@ -43,11 +43,13 @@ class TestPackages < Test::Unit::TestCase
end
assert(pkg, "did not create package")
+ current_values = nil
assert_nothing_raised do
- pkg.retrieve
+ current_values = pkg.retrieve
end
- assert_equal(:absent, pkg.is(:ensure), "package not considered missing")
+ assert_equal(:absent, current_values[pkg.property(:ensure)],
+ "package not considered missing")
assert_equal(:present, pkg.should(:ensure),
"package did not default to installed")
diff --git a/test/ral/types/property.rb b/test/ral/types/property.rb
index 38a4b2e81..11c31179f 100755
--- a/test/ral/types/property.rb
+++ b/test/ral/types/property.rb
@@ -12,9 +12,13 @@ class TestProperty < Test::Unit::TestCase
unless parent
parent = "fakeparent"
parent.meta_def(:pathbuilder) do [self.to_s] end
+ parent.meta_def(:provider) do nil end
+ parent.meta_def(:fakeproperty) do '' end
end
assert_nothing_raised {
- return property.new(:parent => parent)
+ newinst = property.new(:parent => parent)
+ def newinst.retrieve(); return @fakeprovidervalue; end;
+ return newinst
}
end
@@ -104,13 +108,13 @@ class TestProperty < Test::Unit::TestCase
# These are bogus because they don't define events. :/
assert_nothing_raised {
property.newvalue(:one) do
- @is = 1
+ @fakeprovidervalue = 1
end
}
assert_nothing_raised {
property.newvalue("two") do
- @is = 2
+ @fakeprovidervalue = 2
end
}
@@ -127,7 +131,7 @@ class TestProperty < Test::Unit::TestCase
assert_equal(:one, inst.should)
ret = nil
assert_nothing_raised { inst.set_one }
- assert_equal(1, inst.is)
+ assert_equal(1, inst.retrieve)
assert_nothing_raised {
inst.should = :two
@@ -135,7 +139,7 @@ class TestProperty < Test::Unit::TestCase
assert_equal(:two, inst.should)
assert_nothing_raised { inst.set_two }
- assert_equal(2, inst.is)
+ assert_equal(2, inst.retrieve)
end
def test_newpropertyvaluewithregexes
@@ -143,7 +147,6 @@ class TestProperty < Test::Unit::TestCase
assert_nothing_raised {
property.newvalue(/^\w+$/) do
- @is = self.should.upcase
return :regex_matched
end
}
@@ -160,7 +163,7 @@ class TestProperty < Test::Unit::TestCase
inst.sync
}
- assert_equal("yayness".upcase, inst.is)
+ assert_equal("yayness".upcase, inst.retrieve)
end
def test_newvalue_event_option
@@ -168,10 +171,8 @@ class TestProperty < Test::Unit::TestCase
assert_nothing_raised do
property.newvalue(:myvalue, :event => :fake_valued) do
- @is = :valued
end
property.newvalue(:other, :event => "fake_other") do
- @is = :valued
end
end
inst = newinst(property)
@@ -263,9 +264,15 @@ class TestProperty < Test::Unit::TestCase
end
def test_failure
- s = Struct.new(:line, :file, :path, :pathbuilder)
- p = s.new(1, "yay", "rah", "struct")
- myproperty = Class.new(Puppet::Property)
+ s = Struct.new(:line, :file, :path, :pathbuilder, :name)
+ p = s.new(1, "yay", "rah", "struct", "name")
+
+ myprovider = Class.new(Puppet::Provider)
+
+ def p.provider; nil; end;
+ myproperty = Class.new(Puppet::Property) do
+ @name = 'name'
+ end
myproperty.initvars
myproperty.newvalue :mkfailure do
diff --git a/test/ral/types/resources.rb b/test/ral/types/resources.rb
index bc6c9f6a9..56603c611 100755
--- a/test/ral/types/resources.rb
+++ b/test/ral/types/resources.rb
@@ -212,7 +212,7 @@ class TestResources < Test::Unit::TestCase
assert(! list.empty?, "did not get any users")
bad = list.find_all { |u|
- %w{root bin nobody}.include?(u[:name]) or (u.retrieve and u.is(:uid) < 500)
+ %w{root bin nobody}.include?(u[:name]) or (cv = u.retrieve and cv[u.property(:uid)] < 500)
}
assert(bad.empty?, "incorrectly passed users %s" % bad.collect { |u| u[:name]}.join(", "))
end
diff --git a/test/ral/types/schedule.rb b/test/ral/types/schedule.rb
index e9b3ef8b3..cc565bbfc 100755
--- a/test/ral/types/schedule.rb
+++ b/test/ral/types/schedule.rb
@@ -94,7 +94,7 @@ class TestSchedule < Test::Unit::TestCase
#end
end
- Puppet.err @@times.inspect
+ Puppet.err @@times.inspect
@@times.each { |time|
@now = time
diff --git a/test/ral/types/service.rb b/test/ral/types/service.rb
index 0e2e1e962..e682709ac 100755
--- a/test/ral/types/service.rb
+++ b/test/ral/types/service.rb
@@ -23,9 +23,8 @@ class TestServiceType < Test::Unit::TestCase
def test_refresh_normally
service = Puppet::Type.type(:service).create :name => "testing",
- :ensure => :running, :provider => :base
+ :ensure => :running, :provider => :base, :status => "cat /dev/null"
- service.is = [:ensure, :running]
service.provider.expects(:restart)
assert_nothing_raised do
diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb
index 5e6720bb3..b8d576b9a 100755
--- a/test/ral/types/tidy.rb
+++ b/test/ral/types/tidy.rb
@@ -151,14 +151,10 @@ class TestTidy < Test::Unit::TestCase
age = tidy.property(:age)
# Set it to something that should be fine
- age.is = Time.now.to_i - 5
-
- assert(age.insync?, "Tried to tidy a low age")
+ assert(age.insync?(Time.now.to_i - 5), "Tried to tidy a low age")
# Now to something that should fail
- age.is = Time.now.to_i - 120
-
- assert(! age.insync?, "Incorrectly skipped tidy")
+ assert(! age.insync?(Time.now.to_i - 120), "Incorrectly skipped tidy")
end
def test_sizetest
@@ -167,14 +163,10 @@ class TestTidy < Test::Unit::TestCase
size = tidy.property(:size)
# Set it to something that should be fine
- size.is = 50
-
- assert(size.insync?, "Tried to tidy a low size")
+ assert(size.insync?(50), "Tried to tidy a low size")
# Now to something that should fail
- size.is = 2048
-
- assert(! size.insync?, "Incorrectly skipped tidy")
+ assert(! size.insync?(2048), "Incorrectly skipped tidy")
end
# Make sure we can remove different types of files
@@ -197,7 +189,6 @@ class TestTidy < Test::Unit::TestCase
# And a directory
Dir.mkdir(path)
- tidy.is = [:ensure, [Time.now - 1024, 1]]
tidy[:rmdirs] = true
assert_events([:file_tidied], tidy)
assert(! FileTest.exists?(path), "File was not removed")
@@ -218,7 +209,7 @@ class TestTidy < Test::Unit::TestCase
File.open(path, "w") { |f| 10.times { f.puts "yayness " } }
tidy = Puppet::Type.type(:tidy).create :path => path, :age => "5s"
- tidy.property(:age).is = "0s"
+
assert_apply(tidy)
assert(! FileTest.exists?(path), "file did not get tidied")
end
diff --git a/test/ral/types/user.rb b/test/ral/types/user.rb
index be1dd6f78..ef113ee84 100755
--- a/test/ral/types/user.rb
+++ b/test/ral/types/user.rb
@@ -305,11 +305,11 @@ class TestUser < Test::Unit::TestCase
assert(user.provider.groups.is_a?(String),
"Incorrectly passed an array to groups")
- user.retrieve
+ currentvalue = user.retrieve
- assert(user.property(:groups).is, "Did not retrieve group list")
+ assert(currentvalue[user.property(:groups)], "Did not retrieve group list")
- list = user.property(:groups).is
+ list = currentvalue[user.property(:groups)]
assert_equal(extra.sort, list.sort, "Group list is not equal")
# Now set to our main list of groups
@@ -319,45 +319,45 @@ class TestUser < Test::Unit::TestCase
assert_equal((main + extra).sort, user.property(:groups).should.split(",").sort)
+ currentvalue = nil
assert_nothing_raised {
- user.retrieve
+ currentvalue = user.retrieve
}
- assert(!user.insync?, "User is incorrectly in sync")
+ assert(!user.insync?(currentvalue), "User is incorrectly in sync")
assert_apply(user)
assert_nothing_raised {
- user.retrieve
+ currentvalue = user.retrieve
}
# We're not managing inclusively, so it should keep the old group
# memberships and add the new ones
- list = user.property(:groups).is
+ list = currentvalue[user.property(:groups)]
assert_equal((main + extra).sort, list.sort, "Group list is not equal")
assert_nothing_raised {
user[:membership] = :inclusive
}
assert_nothing_raised {
- user.retrieve
+ currentvalue = user.retrieve
}
- assert(!user.insync?, "User is incorrectly in sync")
+ assert(!user.insync?(currentvalue), "User is incorrectly in sync")
assert_events([:user_changed], user)
assert_nothing_raised {
- user.retrieve
+ currentvalue = user.retrieve
}
- list = user.property(:groups).is
+ list = currentvalue[user.property(:groups)]
assert_equal(main.sort, list.sort, "Group list is not equal")
# Set the values a bit differently.
user.property(:groups).should = list.sort { |a,b| b <=> a }
- user.property(:groups).is = list.sort
- assert(user.property(:groups).insync?, "Groups property did not sort groups")
+ assert(user.property(:groups).insync?(list.sort), "Groups property did not sort groups")
user.delete(:groups)
end
@@ -460,7 +460,7 @@ class TestUser < Test::Unit::TestCase
user.evaluate
end
- assert(user.send(:property, :groups).insync?,
+ assert(user.send(:property, :groups).insync?(nil),
"Groups state considered out of sync with no :should value")
end
diff --git a/test/ral/types/yumrepo.rb b/test/ral/types/yumrepo.rb
index 2f8be32c6..e1c948e33 100755
--- a/test/ral/types/yumrepo.rb
+++ b/test/ral/types/yumrepo.rb
@@ -23,10 +23,10 @@ class TestYumRepo < Test::Unit::TestCase
def test_modify
copy_datafiles
devel = make_repo("development", { :descr => "New description" })
- devel.retrieve
+ current_values = devel.retrieve
assert_equal("development", devel[:name])
assert_equal('Fedora Core $releasever - Development Tree',
- devel.property(:descr).is)
+ current_values[devel.property(:descr)])
assert_equal('New description',
devel.property(:descr).should)
assert_apply(devel)
diff --git a/test/ral/types/zone.rb b/test/ral/types/zone.rb
index c1724b93a..abb042a04 100755
--- a/test/ral/types/zone.rb
+++ b/test/ral/types/zone.rb
@@ -1,3 +1,4 @@
+
#!/usr/bin/env ruby
$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
@@ -114,7 +115,6 @@ class TestZone < Test::Unit::TestCase
assert(property.up?, "Property incorrectly thinks it is not moving up")
- zone.is = [:ensure, :configured]
zone[:ensure] = :installed
assert(property.up?, "Property incorrectly thinks it is not moving up")
zone[:ensure] = :absent
@@ -161,10 +161,10 @@ class TestZone < Test::Unit::TestCase
assert_equal("add inherit-pkg-dir\nset dir=/usr\nend", property.configtext,
"Got incorrect config text")
- property.is = "/usr"
-
- assert_equal("", property.configtext,
- "Got incorrect config text")
+# property.is = "/usr"
+#
+# assert_equal("", property.configtext,
+# "Got incorrect config text")
# Now we want multiple directories
property.should = %w{/usr /sbin /lib}
@@ -180,13 +180,13 @@ end"
assert_equal(text, property.configtext,
"Got incorrect config text")
- property.is = %w{/usr /sbin /lib}
- property.should = %w{/usr /sbin}
+ # property.is = %w{/usr /sbin /lib}
+ # property.should = %w{/usr /sbin}
- text = "remove inherit-pkg-dir dir=/lib"
+# text = "remove inherit-pkg-dir dir=/lib"
- assert_equal(text, property.configtext,
- "Got incorrect config text")
+# assert_equal(text, property.configtext,
+# "Got incorrect config text")
end
if Puppet::Util::SUIDManager.uid == 0
@@ -254,13 +254,13 @@ end
# And make sure it gets set correctly.
assert_equal(%w{/sbin /usr /opt/csw /lib /platform}.sort,
- zone.is(:inherit).sort, "Inherited dirs did not get collected correctly."
+ zone.property(:inherit).retrieve.sort, "Inherited dirs did not get collected correctly."
)
assert_equal(["#{interface}:#{ip}"], zone.is(:ip),
"IP addresses did not get collected correctly.")
- assert_equal(:true, zone.is(:autoboot),
+ assert_equal(:true, zone.property(:autoboot).retrieve,
"Autoboot did not get collected correctly.")
end
@@ -361,9 +361,10 @@ end
assert_apply(zone)
- zone.retrieve
+ currentvalues = zone.retrieve
- assert_equal(:absent, zone.is(:ensure), "Zone is not absent")
+ assert_equal(:absent, currentvalues[zone.property(:ensure)],
+ "Zone is not absent")
end
# Just go through each method linearly and make sure it works.
@@ -390,10 +391,11 @@ end
assert_nothing_raised {
zone.provider.send(method)
}
+ current_values = nil
assert_nothing_raised {
- zone.retrieve
+ current_values = zone.retrieve
}
- assert_equal(property, zone.is(:ensure),
+ assert_equal(property, current_values[zone.property(:ensure)],
"Method %s did not correctly set property %s" %
[method, property])
end
@@ -426,9 +428,10 @@ end
assert(zone.insync?, "Zone is incorrectly out of sync")
end
- zone.retrieve
+ currentvalues = zone.retrieve
- assert_equal(:absent, zone.is(:ensure), "Zone is not absent")
+ assert_equal(:absent, currentvalues[zone.property(:ensure)],
+ "Zone is not absent")
end
end
end