summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-07 06:47:10 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-07 06:47:10 +0000
commitd4031312ecddc6fab15b5bc9693b8af0a23a57b8 (patch)
treeba48576ea294a4a72201a18e093bca4d6ce1537d
parentf6f72f2288e3e3427abf0883a7ec507becc90f08 (diff)
downloadpuppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.tar.gz
puppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.tar.xz
puppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.zip
Merging the state-rename branch. This includes the diff from version 2156 to 2168. All states should now be properties, with backward compatibility for the types that restricted themselves to the methods.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2169 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/config.rb2
-rw-r--r--lib/puppet/element.rb6
-rw-r--r--lib/puppet/metatype/attributes.rb404
-rw-r--r--lib/puppet/metatype/closure.rb14
-rw-r--r--lib/puppet/metatype/container.rb9
-rw-r--r--lib/puppet/metatype/evaluation.rb81
-rw-r--r--lib/puppet/metatype/manager.rb6
-rw-r--r--lib/puppet/metatype/metaparams.rb26
-rw-r--r--lib/puppet/metatype/providers.rb4
-rw-r--r--lib/puppet/metatype/relationships.rb2
-rw-r--r--lib/puppet/parameter.rb717
-rw-r--r--lib/puppet/propertychange.rb (renamed from lib/puppet/statechange.rb)68
-rw-r--r--lib/puppet/provider/nameservice.rb16
-rw-r--r--lib/puppet/provider/nameservice/netinfo.rb18
-rw-r--r--lib/puppet/provider/package/up2date.rb2
-rwxr-xr-xlib/puppet/provider/parsedfile.rb50
-rw-r--r--lib/puppet/provider/user/pw.rb8
-rw-r--r--lib/puppet/provider/user/useradd.rb8
-rw-r--r--lib/puppet/provider/zone/solaris.rb14
-rwxr-xr-xlib/puppet/server/fileserver.rb10
-rwxr-xr-xlib/puppet/server/resource.rb2
-rw-r--r--lib/puppet/transaction.rb20
-rw-r--r--lib/puppet/type.rb52
-rwxr-xr-xlib/puppet/type/cron.rb81
-rwxr-xr-xlib/puppet/type/exec.rb12
-rwxr-xr-xlib/puppet/type/group.rb15
-rwxr-xr-xlib/puppet/type/host.rb16
-rwxr-xr-xlib/puppet/type/mount.rb34
-rw-r--r--lib/puppet/type/notify.rb4
-rw-r--r--lib/puppet/type/package.rb20
-rwxr-xr-xlib/puppet/type/parsedtype.rb40
-rw-r--r--lib/puppet/type/pfile.rb78
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb4
-rwxr-xr-xlib/puppet/type/pfile/content.rb2
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb14
-rwxr-xr-xlib/puppet/type/pfile/group.rb2
-rwxr-xr-xlib/puppet/type/pfile/mode.rb3
-rwxr-xr-xlib/puppet/type/pfile/owner.rb2
-rwxr-xr-xlib/puppet/type/pfile/source.rb10
-rw-r--r--lib/puppet/type/pfile/target.rb17
-rwxr-xr-xlib/puppet/type/pfile/type.rb2
-rwxr-xr-xlib/puppet/type/pfilebucket.rb4
-rwxr-xr-xlib/puppet/type/port.rb16
-rw-r--r--lib/puppet/type/property.rb (renamed from lib/puppet/type/state.rb)66
-rw-r--r--lib/puppet/type/resources.rb5
-rwxr-xr-xlib/puppet/type/schedule.rb4
-rw-r--r--lib/puppet/type/service.rb14
-rwxr-xr-xlib/puppet/type/sshkey.rb23
-rwxr-xr-xlib/puppet/type/tidy.rb30
-rwxr-xr-xlib/puppet/type/user.rb69
-rw-r--r--lib/puppet/type/yumrepo.rb62
-rw-r--r--lib/puppet/type/zone.rb46
-rwxr-xr-xtest/certmgr/certmgr.rb2
-rwxr-xr-xtest/language/snippets.rb8
-rw-r--r--test/lib/puppettest/fakes.rb16
-rwxr-xr-xtest/other/log.rb10
-rwxr-xr-xtest/other/propertychange.rb (renamed from test/other/statechange.rb)20
-rwxr-xr-xtest/other/transactions.rb30
-rwxr-xr-xtest/providers/group.rb2
-rwxr-xr-xtest/providers/host/parsed.rb2
-rwxr-xr-xtest/providers/mount/netinfo.rb4
-rwxr-xr-xtest/providers/mount/parsed.rb6
-rwxr-xr-xtest/providers/parsedfile.rb12
-rwxr-xr-xtest/providers/parsedsshkey.rb2
-rwxr-xr-xtest/providers/user.rb36
-rwxr-xr-xtest/ral/manager/attributes.rb187
-rwxr-xr-xtest/ral/manager/manager.rb (renamed from test/types/manager.rb)5
-rwxr-xr-xtest/ral/manager/type.rb (renamed from test/types/type.rb)47
-rwxr-xr-xtest/server/resource.rb16
-rwxr-xr-xtest/types/basic.rb8
-rwxr-xr-xtest/types/cron.rb20
-rwxr-xr-xtest/types/exec.rb16
-rwxr-xr-xtest/types/file.rb35
-rwxr-xr-xtest/types/filesources.rb75
-rwxr-xr-xtest/types/group.rb2
-rwxr-xr-xtest/types/host.rb4
-rwxr-xr-xtest/types/mount.rb20
-rwxr-xr-xtest/types/parameter.rb59
-rwxr-xr-xtest/types/port.rb6
-rwxr-xr-xtest/types/property.rb (renamed from test/types/state.rb)132
-rwxr-xr-xtest/types/resources.rb6
-rwxr-xr-xtest/types/service.rb20
-rwxr-xr-xtest/types/sshkey.rb13
-rwxr-xr-xtest/types/tidy.rb6
-rwxr-xr-xtest/types/user.rb32
-rwxr-xr-xtest/types/yumrepo.rb5
-rwxr-xr-xtest/types/zone.rb56
87 files changed, 1658 insertions, 1496 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 77c167ae8..77838fec0 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -422,7 +422,7 @@ class Config
done[type][name].tags = tags << section
end
elsif newobj = Puppet::Type.type(type)[name]
- unless newobj.state(:ensure)
+ unless newobj.property(:ensure)
newobj[:ensure] = "present"
end
newobj.tag(section)
diff --git a/lib/puppet/element.rb b/lib/puppet/element.rb
index 56c88c5f1..1cda5e83b 100644
--- a/lib/puppet/element.rb
+++ b/lib/puppet/element.rb
@@ -1,7 +1,7 @@
# included so we can test object types
require 'puppet'
-# the base class for both types and states
+# the base class for both types and parameters.
# very little functionality; basically just defines the interface
# and provides a few simple across-the-board functions like 'noop'
class Puppet::Element
@@ -23,8 +23,8 @@ class Puppet::Element
# so raise an error if a method that isn't overridden gets called
@@interface_methods.each { |method|
self.send(:define_method,method) {
- raise Puppet::DevError, "%s has not overridden %s" %
- [self.class.name,method]
+ raise Puppet::DevError, "%s(%s) has not overridden %s" %
+ [self.class, self.class.name,method]
}
}
diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb
index 8956b754b..ad964b7ed 100644
--- a/lib/puppet/metatype/attributes.rb
+++ b/lib/puppet/metatype/attributes.rb
@@ -4,11 +4,17 @@ require 'puppet/type'
class Puppet::Type
class << self
include Puppet::Util::ClassGen
- attr_reader :states
+ include Puppet::Util::Warnings
+ attr_reader :properties
+ end
+
+ def self.states
+ warnonce "The states method is deprecated; use properties"
+ properties()
end
# All parameters, in the appropriate order. The namevar comes first,
- # then the states, then the params and metaparams in the order they
+ # then the properties, then the params and metaparams in the order they
# were specified in the files.
def self.allattrs
# now get all of the arguments, in a specific order
@@ -16,7 +22,7 @@ class Puppet::Type
namevar = self.namevar
order = [namevar]
- order << [self.states.collect { |state| state.name },
+ order << [self.properties.collect { |property| property.name },
self.parameters,
self.metaparams].flatten.reject { |param|
# we don't want our namevar in there multiple times
@@ -36,7 +42,7 @@ class Puppet::Type
# of times (as in, hundreds of thousands in a given run).
unless @attrclasses.include?(name)
@attrclasses[name] = case self.attrtype(name)
- when :state: @validstates[name]
+ when :property: @validproperties[name]
when :meta: @@metaparamhash[name]
when :param: @paramhash[name]
end
@@ -50,9 +56,9 @@ class Puppet::Type
@attrtypes ||= {}
unless @attrtypes.include?(attr)
@attrtypes[attr] = case
- when @validstates.include?(attr): :state
- when @@metaparamhash.include?(attr): :meta
+ when @validproperties.include?(attr): :property
when @paramhash.include?(attr): :param
+ when @@metaparamhash.include?(attr): :meta
else
raise Puppet::DevError,
"Invalid attribute '%s' for class '%s'" %
@@ -89,8 +95,8 @@ class Puppet::Type
if ary.empty?
ary = nil
end
- self.states.each { |state|
- yield(state, :state) if ary.nil? or ary.include?(state.name)
+ self.properties.each { |property|
+ yield(property, :property) if ary.nil? or ary.include?(property.name)
}
@parameters.each { |param|
@@ -110,25 +116,22 @@ class Puppet::Type
# can easily call it and create their own 'ensure' values.
def self.ensurable(&block)
if block_given?
- self.newstate(:ensure, :parent => Puppet::State::Ensure, &block)
+ self.newproperty(:ensure, :parent => Puppet::Property::Ensure, &block)
else
- self.newstate(:ensure, :parent => Puppet::State::Ensure) do
+ self.newproperty(:ensure, :parent => Puppet::Property::Ensure) do
self.defaultvalues
end
end
end
- # Should we add the 'ensure' state to this class?
+ # Should we add the 'ensure' property to this class?
def self.ensurable?
# If the class has all three of these methods defined, then it's
# ensurable.
- #ens = [:create, :destroy].inject { |set, method|
ens = [:exists?, :create, :destroy].inject { |set, method|
set &&= self.public_method_defined?(method)
}
- #puts "%s ensurability: %s" % [self.name, ens]
-
return ens
end
@@ -149,8 +152,7 @@ class Puppet::Type
# Is the parameter in question a meta-parameter?
def self.metaparam?(param)
- param = symbolize(param)
- @@metaparamhash.include?(param)
+ @@metaparamhash.include?(symbolize(param))
end
# Find the metaparameter class associated with a given metaparameter name.
@@ -184,7 +186,7 @@ class Puppet::Type
handle_param_options(name, options)
- param.ismetaparameter
+ param.metaparam = true
return param
end
@@ -239,13 +241,19 @@ class Puppet::Type
return param
end
- # Create a new state. The first parameter must be the name of the state;
- # this is how users will refer to the state when creating new instances.
+ def self.newstate(name, options = {}, &block)
+ Puppet.warning "newstate() has been deprecrated; use newproperty(%s)" %
+ name
+ newproperty(name, options, &block)
+ end
+
+ # Create a new property. The first parameter must be the name of the property;
+ # this is how users will refer to the property when creating new instances.
# The second parameter is a hash of options; the options are:
- # * <tt>:parent</tt>: The parent class for the state. Defaults to Puppet::State.
+ # * <tt>:parent</tt>: The parent class for the property. Defaults to Puppet::Property.
# * <tt>:retrieve</tt>: The method to call on the provider or @parent object (if
# the provider is not set) to retrieve the current value.
- def self.newstate(name, options = {}, &block)
+ def self.newproperty(name, options = {}, &block)
name = symbolize(name)
# This is here for types that might still have the old method of defining
@@ -255,8 +263,8 @@ class Puppet::Type
"Options must be a hash, not %s" % options.inspect
end
- if @validstates.include?(name)
- raise Puppet::DevError, "Class %s already has a state named %s" %
+ if @validproperties.include?(name)
+ raise Puppet::DevError, "Class %s already has a property named %s" %
[self.name, name]
end
@@ -264,8 +272,8 @@ class Puppet::Type
# an initial :retrieve method, if told to, and then eval the passed
# block if available.
s = genclass(name,
- :parent => options[:parent] || Puppet::State,
- :hash => @validstates
+ :parent => options[:parent] || Puppet::Property,
+ :hash => @validproperties
) do
# If they've passed a retrieve method, then override the retrieve
# method on the class.
@@ -282,11 +290,11 @@ class Puppet::Type
end
end
- # If it's the 'ensure' state, always put it first.
+ # If it's the 'ensure' property, always put it first.
if name == :ensure
- @states.unshift s
+ @properties.unshift s
else
- @states << s
+ @properties << s
end
if options[:event]
@@ -294,11 +302,11 @@ class Puppet::Type
end
# define_method(name) do
-# @states[name].should
+# @parameters[name].should
# end
#
# define_method(name.to_s + "=") do |value|
-# newstate(name, :should => value)
+# newproperty(name, :should => value)
# end
return s
@@ -319,9 +327,9 @@ class Puppet::Type
@paramhash[name]
end
- # Return the state class associated with a name
- def self.statebyname(name)
- @validstates[name]
+ # Return the property class associated with a name
+ def self.propertybyname(name)
+ @validproperties[name]
end
def self.validattr?(name)
@@ -330,7 +338,7 @@ class Puppet::Type
@validattrs ||= {}
unless @validattrs.include?(name)
- if self.validstate?(name) or self.validparameter?(name) or self.metaparam?(name)
+ if self.validproperty?(name) or self.validparameter?(name) or self.metaparam?(name)
@validattrs[name] = true
else
@validattrs[name] = false
@@ -340,21 +348,21 @@ class Puppet::Type
@validattrs[name]
end
- # does the name reflect a valid state?
- def self.validstate?(name)
+ # does the name reflect a valid property?
+ def self.validproperty?(name)
name = symbolize(name)
- if @validstates.include?(name)
- return @validstates[name]
+ if @validproperties.include?(name)
+ return @validproperties[name]
else
return false
end
end
- # Return the list of validstates
- def self.validstates
- return {} unless defined? @states
+ # Return the list of validproperties
+ def self.validproperties
+ return {} unless defined? @parameters
- return @validstates.keys
+ return @validproperties.keys
end
# does the name reflect a valid parameter?
@@ -401,24 +409,13 @@ class Puppet::Type
return hash
end
-
- # Is the specified parameter set?
- def attrset?(type, attr)
- case type
- when :state: return @states.include?(attr)
- when :param: return @parameters.include?(attr)
- when :meta: return @metaparams.include?(attr)
- else
- self.devfail "Invalid set type %s" % [type]
- end
- end
# Are we deleting this resource?
def deleting?
- obj = @states[:ensure] and obj.should == :absent
+ obj = @parameters[:ensure] and obj.should == :absent
end
- # Allow an outside party to specify the 'is' value for a state. The
+ # 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)
@@ -426,21 +423,21 @@ class Puppet::Type
if param.is_a?(String)
param = param.intern
end
- if self.class.validstate?(param)
- unless @states.include?(param)
- self.newstate(param)
+ if self.class.validproperty?(param)
+ unless prop = @parameters[param]
+ prop = self.newattr(param)
end
- @states[param].is = value
+ prop.is = value
else
self[param] = value
end
end
- # abstract accessing parameters and states, and normalize
+ # 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'
# value, but you can also specifically return 'is' and 'should'
- # values using 'object.is(:state)' or 'object.should(:state)'.
+ # values using 'object.is(:property)' or 'object.should(:property)'.
def [](name)
if name.is_a?(String)
name = name.intern
@@ -449,45 +446,30 @@ class Puppet::Type
if name == :name
name = self.class.namevar
end
- case self.class.attrtype(name)
- when :state
- if @states.include?(name)
- return @states[name].is
- else
- return nil
- end
- when :meta
- if @metaparams.include?(name)
- return @metaparams[name].value
- else
- if default = self.class.metaparamclass(name).default
- return default
- else
- return nil
- end
- end
- when :param
- if @parameters.include?(name)
- return @parameters[name].value
+
+ unless self.class.validattr?(name)
+ raise TypeError.new("Invalid parameter %s(%s)" % [name, name.inspect])
+ end
+
+ if obj = @parameters[name]
+ if obj.is_a?(Puppet::Type::Property)
+ return obj.is
else
- if default = self.class.paramclass(name).default
- return default
- else
- return nil
- end
+ return obj.value
end
else
- raise TypeError.new("Invalid parameter %s(%s)" % [name, name.inspect])
+ return nil
end
end
- # Abstract setting parameters and states, and normalize
+ # Abstract setting parameters and properties, and normalize
# access to always be symbols, not strings. This sets the 'should'
- # value on states, and otherwise just sets the appropriate parameter.
+ # value on properties, and otherwise just sets the appropriate parameter.
def []=(name,value)
- if name.is_a?(String)
- name = name.intern
+ unless self.class.validattr?(name)
+ raise TypeError.new("Invalid parameter %s" % [name])
end
+ name = symbolize(name)
if name == :name
name = self.class.namevar
@@ -496,158 +478,89 @@ class Puppet::Type
raise Puppet::Error.new("Got nil value for %s" % name)
end
- case self.class.attrtype(name)
- when :state
- if value.is_a?(Puppet::State)
- self.debug "'%s' got handed a state for '%s'" % [self,name]
- @states[name] = value
- else
- if @states.include?(name)
- @states[name].should = value
- else
- # newstate returns true if it successfully created the state,
- # false otherwise; I just don't know what to do with that
- # fact.
- unless newstate(name, :should => value)
- #self.info "%s failed" % name
- end
- end
- end
- when :meta
- self.newmetaparam(self.class.metaparamclass(name), value)
- when :param
- klass = self.class.attrclass(name)
- # if they've got a method to handle the parameter, then do it that way
- self.newparam(klass, value)
+ if obj = @parameters[name]
+ obj.value = value
+ return nil
else
- raise Puppet::Error, "Invalid parameter %s" % [name]
+ self.newattr(name, :value => value)
end
+
+ nil
end
- # remove a state from the object; useful in testing or in cleanup
+ # remove a property from the object; useful in testing or in cleanup
# when an error has been encountered
def delete(attr)
+ attr = symbolize(attr)
case attr
when Puppet::Type
if @children.include?(attr)
@children.delete(attr)
end
else
- if @states.has_key?(attr)
- @states.delete(attr)
- elsif @parameters.has_key?(attr)
+ if @parameters.has_key?(attr)
@parameters.delete(attr)
- elsif @metaparams.has_key?(attr)
- @metaparams.delete(attr)
else
raise Puppet::DevError.new("Undefined attribute '#{attr}' in #{self}")
end
end
end
- # iterate across the existing states
- def eachstate
- # states() is a private method
- states().each { |state|
- yield state
+ # iterate across the existing properties
+ def eachproperty
+ # properties() is a private method
+ properties().each { |property|
+ yield property
}
end
- # retrieve the 'is' value for a specified state
- def is(state)
- if @states.include?(state)
- return @states[state].is
+ # retrieve the 'is' value for a specified property
+ def is(name)
+ if prop = @parameters[symbolize(name)] and prop.is_a?(Puppet::Type::Property)
+ return prop.is
else
return nil
end
end
- # retrieve the 'should' value for a specified state
- def should(state)
- if @states.include?(state)
- return @states[state].should
+ # retrieve the 'should' value for a specified property
+ def should(name)
+ if prop = @parameters[symbolize(name)] and prop.is_a?(Puppet::Type::Property)
+ return prop.should
else
return nil
end
end
- # Create a new parameter.
- def newparam(klass, value = nil)
- newattr(:param, klass, value)
- end
-
- # Create a new parameter or metaparameter. We'll leave the calling
- # method to store it appropriately.
- def newmetaparam(klass, value = nil)
- newattr(:meta, klass, value)
- end
-
- # The base function that the others wrap.
- def newattr(type, klass, value = nil)
- # This should probably be a bit, um, different, but...
- if type == :state
- return newstate(klass)
+ # Create the actual attribute instance. Requires either the attribute
+ # name or class as the first argument, then an optional hash of
+ # attributes to set during initialization.
+ def newattr(name, options = {})
+ if name.is_a?(Class)
+ klass = name
+ name = klass.name
end
- param = klass.new
- param.parent = self
- unless value.nil?
- param.value = value
+ unless klass = self.class.attrclass(name)
+ raise Puppet::Error, "Invalid parameter %s" % name
end
- case type
- when :meta
- @metaparams[klass.name] = param
- when :param
- @parameters[klass.name] = param
- else
- self.devfail("Invalid param type %s" % type)
+ if @parameters.include?(name)
+ raise Puppet::Error, "Parameter '%s' is already defined in %s" %
+ [name, self.ref]
end
- return param
- end
-
- # create a new state
- def newstate(name, hash = {})
- stateklass = nil
- if name.is_a?(Class)
- stateklass = name
- name = stateklass.name
- else
- stateklass = self.class.validstate?(name)
- unless stateklass
- self.fail("Invalid state %s" % name)
- end
- end
- if @states.include?(name)
- hash.each { |var,value|
- @states[name].send(var.to_s + "=", value)
- }
- else
- #Puppet.warning "Creating state %s for %s" %
- # [stateklass.name,self.name]
- begin
- hash[:parent] = self
- # make sure the state doesn't have any errors
- newstate = stateklass.new(hash)
- @states[name] = newstate
- return newstate
- rescue Puppet::Error => detail
- # the state failed, so just ignore it
- self.warning "State %s failed: %s" %
- [name, detail]
- return false
- rescue Puppet::DevError => detail
- # the state failed, so just ignore it
- self.err "State %s failed: %s" %
- [name, detail]
- return false
- rescue => detail
- # the state failed, so just ignore it
- self.err "State %s failed: %s (%s)" %
- [name, detail, detail.class]
- return false
- end
+ # Add parent information at creation time, so it's available
+ # during validation.
+ options[:parent] = self
+ begin
+ # make sure the parameter doesn't have any errors
+ return @parameters[name] = klass.new(options)
+ rescue => detail
+ error = Puppet::Error.new("Parameter %s failed: %s" %
+ [name, detail])
+ error.set_backtrace(detail.backtrace)
+ raise error
end
end
@@ -659,21 +572,22 @@ class Puppet::Type
return @parameters[name].value
end
- # Is the named state defined?
- def statedefined?(name)
+ # Is the named property defined?
+ def propertydefined?(name)
unless name.is_a? Symbol
name = name.intern
end
- return @states.include?(name)
+ return @parameters.include?(name)
end
# return an actual type by name; to return the value, use 'inst[name]'
# FIXME this method should go away
- def state(name)
- unless name.is_a? Symbol
- name = name.intern
+ def property(name)
+ if obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Type::Property)
+ return obj
+ else
+ return nil
end
- return @states[name]
end
# def set(name, value)
@@ -684,61 +598,71 @@ class Puppet::Type
# send(name)
# end
- # For any parameters or states that have defaults and have not yet been
- # set, set them now.
+ # For any parameters or properties that have defaults and have not yet been
+ # set, set them now. This method can be handed a list of attributes,
+ # and if so it will only set defaults for those attributes.
def setdefaults(*ary)
self.class.eachattr(*ary) { |klass, type|
# not many attributes will have defaults defined, so we short-circuit
# those away
next unless klass.method_defined?(:default)
- next if self.attrset?(type, klass.name)
+ next if @parameters[klass.name]
+
+ next unless obj = self.newattr(klass)
- obj = self.newattr(type, klass)
- value = obj.default
- unless value.nil?
- #self.debug "defaulting %s to %s" % [obj.name, obj.default]
+ # We have to check for nil values, not "truth", so we allow defaults
+ # to false.
+ value = obj.default and ! value.nil?
+ if ! value.nil?
obj.value = value
else
- #self.debug "No default for %s" % obj.name
- # "obj" is a Parameter.
- self.delete(obj.name)
+ @parameters.delete(obj.name)
end
}
-
end
- # Convert our object to a hash. This just includes states.
+ # Convert our object to a hash. This just includes properties.
def to_hash
rethash = {}
- [@parameters, @metaparams, @states].each do |hash|
- hash.each do |name, obj|
- rethash[name] = obj.value
- end
+ @parameters.each do |name, obj|
+ rethash[name] = obj.value
end
rethash
end
+ # Return a specific value for an attribute.
+ def value(name)
+ name = symbolize(name)
+ if obj = @parameters[name] and obj.respond_to?(:value)
+ return obj.value
+ else
+ return nil
+ end
+ end
+
# Meta-parameter methods: These methods deal with the results
# of specifying metaparameters
private
- def states
- #debug "%s has %s states" % [self,@states.length]
- tmpstates = []
- self.class.states.each { |state|
- if @states.include?(state.name)
- tmpstates.push(@states[state.name])
+ # Return all of the property objects, in the order specified in the
+ # class.
+ def properties
+ #debug "%s has %s properties" % [self,@parameters.length]
+ props = self.class.properties.collect { |prop|
+ @parameters[prop.name]
+ }.find_all { |p|
+ ! p.nil?
+ }.each do |prop|
+ unless prop.is_a?(Puppet::Type::Property)
+ raise Puppet::DevError, "got a non-property %s(%s)" %
+ [prop.class, prop.class.name]
end
- }
- unless tmpstates.length == @states.length
- self.devfail(
- "Something went very wrong with tmpstates creation"
- )
end
- return tmpstates
+
+ props
end
end
diff --git a/lib/puppet/metatype/closure.rb b/lib/puppet/metatype/closure.rb
index ebff33eeb..efb4712c6 100644
--- a/lib/puppet/metatype/closure.rb
+++ b/lib/puppet/metatype/closure.rb
@@ -45,9 +45,9 @@ class Puppet::Type
return @managed
else
@managed = false
- states.each { |state|
- s = state.should
- if s and ! state.class.unmanaged
+ properties.each { |property|
+ s = property.should
+ if s and ! property.class.unmanaged
@managed = true
break
end
@@ -59,8 +59,8 @@ class Puppet::Type
# Merge new information with an existing object, checking for conflicts
# and such. This allows for two specifications of the same object and
# the same values, but it's pretty limited right now. The result of merging
- # states is very different from the result of merging parameters or metaparams.
- # This is currently unused.
+ # properties is very different from the result of merging parameters or
+ # metaparams. This is currently unused.
def merge(hash)
hash.each { |param, value|
if param.is_a?(String)
@@ -74,7 +74,7 @@ class Puppet::Type
value = [value]
end
- if @states.include?(param) and oldvals = @states[param].shouldorig
+ if @parameters.include?(param) and oldvals = @parameters[param].shouldorig
unless oldvals.is_a?(Array)
oldvals = [oldvals]
end
@@ -94,7 +94,7 @@ class Puppet::Type
else
self.debug "Reduced old values %s and new values %s to %s" %
[oldvals.inspect, value.inspect, newvals.inspect]
- @states[param].should = newvals
+ @parameters[param].should = newvals
#self.should = newvals
return true
end
diff --git a/lib/puppet/metatype/container.rb b/lib/puppet/metatype/container.rb
index 364639fd5..b48f8018e 100644
--- a/lib/puppet/metatype/container.rb
+++ b/lib/puppet/metatype/container.rb
@@ -75,13 +75,10 @@ class Puppet::Type
# This is hackish (mmm, cut and paste), but it works for now, and it's
# better than warnings.
- [@states, @parameters, @metaparams].each do |hash|
- hash.each do |name, obj|
- obj.remove
- end
-
- hash.clear
+ @parameters.each do |name, obj|
+ obj.remove
end
+ @parameters.clear
self.class.delete(self)
@parent = nil
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index 30a3e7a80..746375d49 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -1,9 +1,8 @@
class Puppet::Type
- # this method is responsible for collecting state changes
- # we always descend into the children before we evaluate our current
- # states
- # this returns any changes resulting from testing, thus 'collect'
- # rather than 'each'
+ # This method is responsible for collecting property changes we always
+ # descend into the children before we evaluate our current properties.
+ # This returns any changes resulting from testing, thus 'collect' rather
+ # than 'each'.
def evaluate
#Puppet.err "Evaluating %s" % self.path.join(":")
unless defined? @evalcount
@@ -15,15 +14,15 @@ class Puppet::Type
changes = []
- # this only operates on states, not states + children
+ # this only operates on properties, not properties + children
# it's important that we call retrieve() on the type instance,
- # not directly on the state, because it allows the type to override
+ # not directly on the property, because it allows the type to override
# the method, like pfile does
self.retrieve
- # states() is a private method, returning an ordered list
+ # properties() is a private method, returning an ordered list
unless self.class.depthfirst?
- changes += statechanges()
+ changes += propertychanges()
end
changes << @children.collect { |child|
@@ -33,7 +32,7 @@ class Puppet::Type
}
if self.class.depthfirst?
- changes += statechanges()
+ changes += propertychanges()
end
changes.flatten!
@@ -60,19 +59,19 @@ class Puppet::Type
def insync?
insync = true
- if state = @states[:ensure]
- if state.insync? and state.should == :absent
+ if property = @parameters[:ensure]
+ if property.insync? and property.should == :absent
return true
end
end
- states.each { |state|
- unless state.insync?
- state.debug("Not in sync: %s vs %s" %
- [state.is.inspect, state.should.inspect])
+ properties.each { |property|
+ unless property.insync?
+ property.debug("Not in sync: %s vs %s" %
+ [property.is.inspect, property.should.inspect])
insync = false
#else
- # state.debug("In sync")
+ # property.debug("In sync")
end
}
@@ -80,46 +79,46 @@ class Puppet::Type
return insync
end
- # retrieve the current value of all contained states
+ # retrieve the current value of all contained properties
def retrieve
# it's important to use the method here, as it follows the order
# in which they're defined in the object
- states().each { |state|
- state.retrieve
+ properties().each { |property|
+ property.retrieve
}
end
- # Retrieve the changes associated with all of the states.
- def statechanges
+ # Retrieve the changes associated with all of the properties.
+ def propertychanges
# If we are changing the existence of the object, then none of
- # the other states matter.
+ # the other properties matter.
changes = []
- if @states.include?(:ensure) and ! @states[:ensure].insync?
- #self.info "ensuring %s from %s" %
- # [@states[:ensure].should, @states[:ensure].is]
- changes = [Puppet::StateChange.new(@states[:ensure])]
- # Else, if the 'ensure' state is correctly absent, then do
+ if @parameters.include?(:ensure) and ! @parameters[:ensure].insync?
+# self.info "ensuring %s from %s" %
+# [@parameters[:ensure].should, @parameters[:ensure].is]
+ changes = [Puppet::PropertyChange.new(@parameters[:ensure])]
+ # Else, if the 'ensure' property is correctly absent, then do
# nothing
- elsif @states.include?(:ensure) and @states[:ensure].is == :absent
- #self.info "Object is correctly absent"
+ elsif @parameters.include?(:ensure) and @parameters[:ensure].is == :absent
+ # self.info "Object is correctly absent"
return []
else
- #if @states.include?(:ensure)
- # self.info "ensure: Is: %s, Should: %s" %
- # [@states[:ensure].is, @states[:ensure].should]
- #else
- # self.info "no ensure state"
- #end
- changes = states().find_all { |state|
- ! state.insync?
- }.collect { |state|
- Puppet::StateChange.new(state)
+# if @parameters.include?(:ensure)
+# self.info "ensure: Is: %s, Should: %s" %
+# [@parameters[:ensure].is, @parameters[:ensure].should]
+# else
+# self.info "no ensure property"
+# end
+ changes = properties().find_all { |property|
+ ! property.insync?
+ }.collect { |property|
+ Puppet::PropertyChange.new(property)
}
end
if Puppet[:debug] and changes.length > 0
self.debug("Changing " + changes.collect { |ch|
- ch.state.name
+ ch.property.name
}.join(",")
)
end
diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb
index 172d3f6d4..1e2d6db97 100644
--- a/lib/puppet/metatype/manager.rb
+++ b/lib/puppet/metatype/manager.rb
@@ -18,7 +18,7 @@ module Manager
def eachtype
@types.each do |name, type|
# Only consider types that have names
- #if ! type.parameters.empty? or ! type.validstates.empty?
+ #if ! type.parameters.empty? or ! type.validproperties.empty?
yield type
#end
end
@@ -103,8 +103,8 @@ module Manager
end
# If they've got all the necessary methods defined and they haven't
- # already added the state, then do so now.
- if klass.ensurable? and ! klass.validstate?(:ensure)
+ # already added the property, then do so now.
+ if klass.ensurable? and ! klass.validproperty?(:ensure)
klass.ensurable
end
diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb
index b5f6a0e3b..ee667bfb3 100644
--- a/lib/puppet/metatype/metaparams.rb
+++ b/lib/puppet/metatype/metaparams.rb
@@ -49,7 +49,7 @@ class Puppet::Type
end
newmetaparam(:check) do
- desc "States which should have their values retrieved
+ desc "Propertys which should have their values retrieved
but which should not actually be modified. This is currently used
internally, but will eventually be used for querying, so that you
could specify that you wanted to check the install state of all
@@ -57,10 +57,10 @@ class Puppet::Type
on all packages."
munge do |args|
- # If they've specified all, collect all known states
+ # If they've specified all, collect all known properties
if args == :all
- args = @parent.class.states.collect do |state|
- state.name
+ args = @parent.class.properties.collect do |property|
+ property.name
end
end
@@ -73,20 +73,18 @@ class Puppet::Type
[self.class, self.name]
end
- args.each { |state|
- unless state.is_a?(Symbol)
- state = state.intern
+ args.each { |property|
+ unless property.is_a?(Symbol)
+ property = property.intern
end
- next if @parent.statedefined?(state)
+ next if @parent.propertydefined?(property)
- stateklass = @parent.class.validstate?(state)
-
- unless stateklass
+ unless propertyklass = @parent.class.validproperty?(property)
raise Puppet::Error, "%s is not a valid attribute for %s" %
- [state, self.class.name]
+ [property, self.class.name]
end
- next unless stateklass.checkable?
- @parent.newstate(state)
+ next unless propertyklass.checkable?
+ @parent.newattr(property)
}
end
end
diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb
index 62f36b807..ef7f73c6c 100644
--- a/lib/puppet/metatype/providers.rb
+++ b/lib/puppet/metatype/providers.rb
@@ -59,8 +59,8 @@ class Puppet::Type
# Mark found objects as present
obj.is = [:ensure, :present]
hash.each { |param, value|
- if state = obj.state(param)
- state.is = value
+ if property = obj.property(param)
+ property.is = value
elsif val = obj[param]
obj[param] = val
else
diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb
index cd6b87bed..494407e68 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -51,7 +51,7 @@ class Puppet::Type
def builddepends
# Handle the requires
self.class.relationship_params.collect do |klass|
- if param = @metaparams[klass.name]
+ if param = @parameters[klass.name]
param.to_edges
end
end.flatten.reject { |r| r.nil? }
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index e480a06bd..35db58815 100644
--- a/lib/puppet/parameter.rb
+++ b/lib/puppet/parameter.rb
@@ -1,424 +1,461 @@
-module Puppet
- class Parameter < Puppet::Element
- class << self
- attr_reader :validater, :munger, :name, :default
- attr_accessor :ismetaparameter, :element
-
- # Define the default value for a given parameter or parameter. This
- # means that 'nil' is an invalid default value. This defines
- # the 'default' instance method.
- def defaultto(value = nil, &block)
- if block
- define_method(:default, &block)
- else
- if value.nil?
- raise Puppet::DevError,
- "Either a default value or block must be provided"
- end
- define_method(:default) do value end
+require 'puppet/util/methodhelper'
+
+class Puppet::Parameter < Puppet::Element
+ include Puppet::Util::MethodHelper
+ class << self
+ attr_reader :validater, :munger, :name, :default
+ attr_accessor :metaparam, :element
+
+ # Define the default value for a given parameter or parameter. This
+ # means that 'nil' is an invalid default value. This defines
+ # the 'default' instance method.
+ def defaultto(value = nil, &block)
+ if block
+ define_method(:default, &block)
+ else
+ if value.nil?
+ raise Puppet::DevError,
+ "Either a default value or block must be provided"
end
+ define_method(:default) do value end
end
+ end
- # Return a documentation string. If there are valid values,
- # then tack them onto the string.
- def doc
- @doc ||= ""
-
- unless defined? @addeddocvals
- unless values.empty?
- if @aliasvalues.empty?
- @doc += " Valid values are ``" +
- values.join("``, ``") + "``."
- else
- @doc += " Valid values are "
-
- @doc += values.collect do |value|
- ary = @aliasvalues.find do |name, val|
- val == value
- end
- if ary
- "``%s`` (also called ``%s``)" % [value, ary[0]]
- else
- "``#{value}``"
- end
- end.join(", ") + "."
- end
- end
+ # Return a documentation string. If there are valid values,
+ # then tack them onto the string.
+ def doc
+ @doc ||= ""
- if defined? @parameterregexes and ! @parameterregexes.empty?
- regs = @parameterregexes
- if @parameterregexes.is_a? Hash
- regs = @parameterregexes.keys
- end
- unless regs.empty?
- @doc += " Values can also match ``" +
- regs.join("``, ``") + "``."
- end
+ unless defined? @addeddocvals
+ unless values.empty?
+ if @aliasvalues.empty?
+ @doc += " Valid values are ``" +
+ values.join("``, ``") + "``."
+ else
+ @doc += " Valid values are "
+
+ @doc += values.collect do |value|
+ ary = @aliasvalues.find do |name, val|
+ val == value
+ end
+ if ary
+ "``%s`` (also called ``%s``)" % [value, ary[0]]
+ else
+ "``#{value}``"
+ end
+ end.join(", ") + "."
end
- @addeddocvals = true
end
- @doc
- end
-
- def nodefault
- if public_method_defined? :default
- undef_method :default
+ if defined? @parameterregexes and ! @parameterregexes.empty?
+ regs = @parameterregexes
+ if @parameterregexes.is_a? Hash
+ regs = @parameterregexes.keys
+ end
+ unless regs.empty?
+ @doc += " Values can also match ``" +
+ regs.join("``, ``") + "``."
+ end
end
+ @addeddocvals = true
end
- # Store documentation for this parameter.
- def desc(str)
- @doc = str
- end
+ @doc
+ end
- def initvars
- @parametervalues = []
- @aliasvalues = {}
- @parameterregexes = []
+ def nodefault
+ if public_method_defined? :default
+ undef_method :default
end
+ end
- # This is how we munge the value. Basically, this is our
- # opportunity to convert the value from one form into another.
- def munge(&block)
- # I need to wrap the unsafe version in begin/rescue parameterments,
- # but if I directly call the block then it gets bound to the
- # class's context, not the instance's, thus the two methods,
- # instead of just one.
- define_method(:unsafe_munge, &block)
-
- define_method(:munge) do |*args|
- begin
- unsafe_munge(*args)
- rescue Puppet::Error => detail
- Puppet.debug "Reraising %s" % detail
- raise
- rescue => detail
- raise Puppet::DevError, "Munging failed for value %s in class %s: %s" %
- [args.inspect, self.name, detail], detail.backtrace
- end
- end
- #@munger = block
- end
+ # Store documentation for this parameter.
+ def desc(str)
+ @doc = str
+ end
- # Mark whether we're the namevar.
- def isnamevar
- @isnamevar = true
- @required = true
- end
+ def initvars
+ @parametervalues = []
+ @aliasvalues = {}
+ @parameterregexes = []
+ end
- # Is this parameter the namevar? Defaults to false.
- def isnamevar?
- if defined? @isnamevar
- return @isnamevar
- else
- return false
+ # This is how we munge the value. Basically, this is our
+ # opportunity to convert the value from one form into another.
+ def munge(&block)
+ # I need to wrap the unsafe version in begin/rescue parameterments,
+ # but if I directly call the block then it gets bound to the
+ # class's context, not the instance's, thus the two methods,
+ # instead of just one.
+ define_method(:unsafe_munge, &block)
+
+ define_method(:munge) do |*args|
+ begin
+ ret = unsafe_munge(*args)
+ rescue Puppet::Error => detail
+ Puppet.debug "Reraising %s" % detail
+ raise
+ rescue => detail
+ raise Puppet::DevError, "Munging failed for value %s in class %s: %s" %
+ [args.inspect, self.name, detail], detail.backtrace
end
- end
- # This parameter is required.
- def isrequired
- @required = true
- end
-
- # Is this parameter required? Defaults to false.
- def required?
- if defined? @required
- return @required
- else
- return false
+ if self.shadow
+ self.shadow.munge(*args)
end
+ ret
end
+ end
- # Verify that we got a good value
- def validate(&block)
- #@validater = block
- define_method(:unsafe_validate, &block)
-
- define_method(:validate) do |*args|
- begin
- unsafe_validate(*args)
- rescue ArgumentError, Puppet::Error, TypeError
- raise
- rescue => detail
- raise Puppet::DevError,
- "Validate method failed for class %s: %s" %
- [self.name, detail], detail.backtrace
- end
- end
- end
+ # Mark whether we're the namevar.
+ def isnamevar
+ @isnamevar = true
+ @required = true
+ end
- # Does the value match any of our regexes?
- def match?(value)
- value = value.to_s unless value.is_a? String
- @parameterregexes.find { |r|
- r = r[0] if r.is_a? Array # States use a hash here
- r =~ value
- }
+ # Is this parameter the namevar? Defaults to false.
+ def isnamevar?
+ if defined? @isnamevar
+ return @isnamevar
+ else
+ return false
end
+ end
- # Define a new value for our parameter.
- def newvalues(*names)
- names.each { |name|
- name = name.intern if name.is_a? String
-
- case name
- when Symbol
- if @parametervalues.include?(name)
- Puppet.warning "%s already has a value for %s" %
- [name, name]
- end
- @parametervalues << name
- when Regexp
- if @parameterregexes.include?(name)
- Puppet.warning "%s already has a value for %s" %
- [name, name]
- end
- @parameterregexes << name
- else
- raise ArgumentError, "Invalid value %s of type %s" %
- [name, name.class]
- end
- }
+ # This parameter is required.
+ def isrequired
+ @required = true
+ end
+
+ # Is this parameter required? Defaults to false.
+ def required?
+ if defined? @required
+ return @required
+ else
+ return false
end
+ end
- def aliasvalue(name, other)
- other = symbolize(other)
- unless @parametervalues.include?(other)
+ # Verify that we got a good value
+ def validate(&block)
+ #@validater = block
+ define_method(:unsafe_validate, &block)
+
+ define_method(:validate) do |*args|
+ begin
+ unsafe_validate(*args)
+ rescue ArgumentError, Puppet::Error, TypeError
+ raise
+ rescue => detail
raise Puppet::DevError,
- "Cannot alias nonexistent value %s" % other
+ "Validate method failed for class %s: %s" %
+ [self.name, detail], detail.backtrace
end
-
- @aliasvalues[name] = other
end
+ end
- def alias(name)
- @aliasvalues[name]
- end
+ # Does the value match any of our regexes?
+ def match?(value)
+ value = value.to_s unless value.is_a? String
+ @parameterregexes.find { |r|
+ r = r[0] if r.is_a? Array # Properties use a hash here
+ r =~ value
+ }
+ end
- def regexes
- return @parameterregexes.dup
- end
+ # Define a new value for our parameter.
+ def newvalues(*names)
+ names.each { |name|
+ name = name.intern if name.is_a? String
- # Return the list of valid values.
- def values
- #[@aliasvalues.keys, @parametervalues.keys].flatten
- if @parametervalues.is_a? Array
- return @parametervalues.dup
- elsif @parametervalues.is_a? Hash
- return @parametervalues.keys
+ case name
+ when Symbol
+ if @parametervalues.include?(name)
+ Puppet.warning "%s already has a value for %s" %
+ [name, name]
+ end
+ @parametervalues << name
+ when Regexp
+ if @parameterregexes.include?(name)
+ Puppet.warning "%s already has a value for %s" %
+ [name, name]
+ end
+ @parameterregexes << name
else
- return []
- end
- end
- end
-
- # Just a simple method to proxy instance methods to class methods
- def self.proxymethods(*values)
- values.each { |val|
- define_method(val) do
- self.class.send(val)
+ raise ArgumentError, "Invalid value %s of type %s" %
+ [name, name.class]
end
}
end
- # And then define one of these proxies for each method in our
- # ParamHandler class.
- proxymethods("required?", "isnamevar?")
+ def aliasvalue(name, other)
+ other = symbolize(other)
+ unless @parametervalues.include?(other)
+ raise Puppet::DevError,
+ "Cannot alias nonexistent value %s" % other
+ end
+
+ @aliasvalues[name] = other
+ end
- attr_accessor :parent
+ def alias(name)
+ @aliasvalues[name]
+ end
- def devfail(msg)
- self.fail(Puppet::DevError, msg)
+ def regexes
+ return @parameterregexes.dup
end
- def fail(*args)
- type = nil
- if args[0].is_a?(Class)
- type = args.shift
+ # Return the list of valid values.
+ def values
+ #[@aliasvalues.keys, @parametervalues.keys].flatten
+ if @parametervalues.is_a? Array
+ return @parametervalues.dup
+ elsif @parametervalues.is_a? Hash
+ return @parametervalues.keys
else
- type = Puppet::Error
+ return []
end
+ end
+ end
- error = type.new(args.join(" "))
-
- if defined? @parent and @parent and @parent.line
- error.line = @parent.line
+ # Just a simple method to proxy instance methods to class methods
+ def self.proxymethods(*values)
+ values.each { |val|
+ define_method(val) do
+ self.class.send(val)
end
+ }
+ end
- if defined? @parent and @parent and @parent.file
- error.file = @parent.file
- end
+ # And then define one of these proxies for each method in our
+ # ParamHandler class.
+ proxymethods("required?", "isnamevar?")
- raise error
- end
+ attr_accessor :parent
+ attr_reader :shadow
- # Log a message using the parent's log level.
- def log(msg)
- unless @parent[:loglevel]
- p @parent
- self.devfail "Parent %s has no loglevel" %
- @parent.name
- end
- Puppet::Log.create(
- :level => @parent[:loglevel],
- :message => msg,
- :source => self
- )
+ def devfail(msg)
+ self.fail(Puppet::DevError, msg)
+ end
+
+ def fail(*args)
+ type = nil
+ if args[0].is_a?(Class)
+ type = args.shift
+ else
+ type = Puppet::Error
end
- # each parameter class must define the name() method, and parameter
- # instances do not change that name this implicitly means that a given
- # object can only have one parameter instance of a given parameter
- # class
- def name
- return self.class.name
+ error = type.new(args.join(" "))
+
+ if defined? @parent and @parent and @parent.line
+ error.line = @parent.line
end
- # for testing whether we should actually do anything
- def noop
- unless defined? @noop
- @noop = false
- end
- tmp = @noop || self.parent.noop || Puppet[:noop] || false
- #debug "noop is %s" % tmp
- return tmp
+ if defined? @parent and @parent and @parent.file
+ error.file = @parent.file
end
- # return the full path to us, for logging and rollback; not currently
- # used
- def pathbuilder
- if defined? @parent and @parent
- return [@parent.pathbuilder, self.name]
- else
- return [self.name]
- end
+ raise error
+ end
+
+ # Basic parameter initialization.
+ def initialize(options = {})
+ options = symbolize_options(options)
+ if parent = options[:parent]
+ self.parent = parent
+ options.delete(:parent)
+ else
+ raise Puppet::DevError, "No parent set for %s" % self.class.name
end
- # If the specified value is allowed, then munge appropriately.
- munge do |value|
- if self.class.values.empty? and self.class.regexes.empty?
- # This parameter isn't using defined values to do its work.
- return value
- end
+ if ! self.metaparam? and klass = Puppet::Type.metaparamclass(self.class.name)
+ setup_shadow(klass)
+ end
- # We convert to a string and then a symbol so that things like
- # booleans work as we expect.
- intern = value.to_s.intern
-
- # If it's a valid value, always return it as a symbol.
- if self.class.values.include?(intern)
- retval = intern
- elsif other = self.class.alias(intern)
- retval = other
- elsif ary = self.class.match?(value)
- retval = value
- else
- # If it passed the validation but is not a registered value,
- # we just return it as is.
- retval = value
- end
+ set_options(options)
+ end
- retval
+ # Log a message using the parent's log level.
+ def log(msg)
+ unless @parent[:loglevel]
+ p @parent
+ self.devfail "Parent %s has no loglevel" %
+ @parent.name
end
+ Puppet::Log.create(
+ :level => @parent[:loglevel],
+ :message => msg,
+ :source => self
+ )
+ end
- # Verify that the passed value is valid.
- validate do |value|
- vals = self.class.values
- regs = self.class.regexes
+ # Is this parameter a metaparam?
+ def metaparam?
+ self.class.metaparam
+ end
- if regs.is_a? Hash # this is true on states
- regs = regs.keys
- end
- if vals.empty? and regs.empty?
- # This parameter isn't using defined values to do its work.
- return
- end
- newval = value
- unless value.is_a?(Symbol)
- newval = value.to_s.intern
- end
+ # each parameter class must define the name() method, and parameter
+ # instances do not change that name this implicitly means that a given
+ # object can only have one parameter instance of a given parameter
+ # class
+ def name
+ return self.class.name
+ end
- unless vals.include?(newval) or
- self.class.alias(newval) or
- self.class.match?(value) # We match the string, not the symbol
- str = "Invalid '%s' value %s. " %
- [self.class.name, value.inspect]
+ # for testing whether we should actually do anything
+ def noop
+ unless defined? @noop
+ @noop = false
+ end
+ tmp = @noop || self.parent.noop || Puppet[:noop] || false
+ #debug "noop is %s" % tmp
+ return tmp
+ end
- unless vals.empty?
- str += "Valid values are %s. " % vals.join(", ")
- end
+ # return the full path to us, for logging and rollback; not currently
+ # used
+ def pathbuilder
+ if defined? @parent and @parent
+ return [@parent.pathbuilder, self.name]
+ else
+ return [self.name]
+ end
+ end
- unless regs.empty?
- str += "Valid values match %s." % regs.collect { |r|
- r.to_s
- }.join(", ")
- end
+ # If the specified value is allowed, then munge appropriately.
+ munge do |value|
+ if self.class.values.empty? and self.class.regexes.empty?
+ # This parameter isn't using defined values to do its work.
+ return value
+ end
- raise ArgumentError, str
- end
+ # We convert to a string and then a symbol so that things like
+ # booleans work as we expect.
+ intern = value.to_s.intern
+
+ # If it's a valid value, always return it as a symbol.
+ if self.class.values.include?(intern)
+ retval = intern
+ elsif other = self.class.alias(intern)
+ retval = other
+ elsif ary = self.class.match?(value)
+ retval = value
+ else
+ # If it passed the validation but is not a registered value,
+ # we just return it as is.
+ retval = value
end
- def remove
- @parent = nil
+ retval
+ end
+
+ # Verify that the passed value is valid.
+ validate do |value|
+ vals = self.class.values
+ regs = self.class.regexes
+
+ if regs.is_a? Hash # this is true on properties
+ regs = regs.keys
+ end
+ if vals.empty? and regs.empty?
+ # This parameter isn't using defined values to do its work.
+ return
+ end
+ newval = value
+ unless value.is_a?(Symbol)
+ newval = value.to_s.intern
end
- # This should only be called for parameters, but go ahead and make
- # it possible to call for states, too.
- def value
- if self.is_a?(Puppet::State)
- # We should return the 'is' value if there's not 'should'
- # value. This might be bad, though, because the 'should'
- # method knows whether to return an array or not and that info
- # is not exposed, and the 'is' value could be a symbol. I
- # can't seem to create a test in which this is a problem, but
- # that doesn't mean it's not one.
- if self.should
- return self.should
- else
- return self.is
+ unless vals.include?(newval) or
+ self.class.alias(newval) or
+ self.class.match?(value) # We match the string, not the symbol
+ str = "Invalid '%s' value %s. " %
+ [self.class.name, value.inspect]
+
+ unless vals.empty?
+ str += "Valid values are %s. " % vals.join(", ")
end
- else
- if defined? @value
- return @value
- else
- return nil
+
+ unless regs.empty?
+ str += "Valid values match %s." % regs.collect { |r|
+ r.to_s
+ }.join(", ")
end
- end
+
+ raise ArgumentError, str
end
+ end
- # Store the value provided. All of the checking should possibly be
- # late-binding (e.g., users might not exist when the value is assigned
- # but might when it is asked for).
- def value=(value)
- # If we're a parameter, just hand the processing off to the should
- # method.
- if self.is_a?(Puppet::State)
- return self.should = value
+ def remove
+ @parent = nil
+ @shadow = nil
+ end
+
+ # This should only be called for parameters, but go ahead and make
+ # it possible to call for properties, too.
+ def value
+ if self.is_a?(Puppet::Property)
+ # We should return the 'is' value if there's not 'should'
+ # value. This might be bad, though, because the 'should'
+ # method knows whether to return an array or not and that info
+ # is not exposed, and the 'is' value could be a symbol. I
+ # can't seem to create a test in which this is a problem, but
+ # that doesn't mean it's not one.
+ if self.should
+ return self.should
+ else
+ return self.is
end
- if respond_to?(:validate)
- validate(value)
+ else
+ if defined? @value
+ return @value
+ else
+ return nil
end
+ end
+ end
- if respond_to?(:munge)
- value = munge(value)
- end
- @value = value
+ # Store the value provided. All of the checking should possibly be
+ # late-binding (e.g., users might not exist when the value is assigned
+ # but might when it is asked for).
+ def value=(value)
+ # If we're a parameter, just hand the processing off to the should
+ # method.
+ if self.is_a?(Puppet::Property)
+ return self.should = value
+ end
+ if respond_to?(:validate)
+ validate(value)
end
- def inspect
- s = "Parameter(%s = %s" % [self.name, self.value || "nil"]
- if defined? @parent
- s += ", @parent = %s)" % @parent
- else
- s += ")"
- end
+ if respond_to?(:munge)
+ value = munge(value)
end
+ @value = value
+ end
- def to_s
- s = "Parameter(%s)" % self.name
+ def inspect
+ s = "Parameter(%s = %s" % [self.name, self.value || "nil"]
+ if defined? @parent
+ s += ", @parent = %s)" % @parent
+ else
+ s += ")"
end
end
+
+ # If there's a shadowing metaparam, instantiate it now.
+ # This allows us to create a property or parameter with the
+ # same name as a metaparameter, and the metaparam will only be
+ # stored as a shadow.
+ def setup_shadow(klass)
+ @shadow = klass.new(:parent => self.parent)
+ end
+
+ def to_s
+ s = "Parameter(%s)" % self.name
+ end
end
# $Id$
diff --git a/lib/puppet/statechange.rb b/lib/puppet/propertychange.rb
index de160d584..0ae9b93d8 100644
--- a/lib/puppet/statechange.rb
+++ b/lib/puppet/propertychange.rb
@@ -4,29 +4,29 @@
module Puppet
# Handle all of the work around performing an actual change,
- # including calling 'sync' on the states and producing events.
- class StateChange
- attr_accessor :is, :should, :type, :path, :state, :transaction, :changed, :proxy
+ # including calling 'sync' on the properties and producing events.
+ class PropertyChange
+ attr_accessor :is, :should, :type, :path, :property, :transaction, :changed, :proxy
# The log file generated when this object was changed.
attr_reader :report
- # Switch the goals of the state, thus running the change in reverse.
+ # Switch the goals of the property, thus running the change in reverse.
def backward
- @state.should = @is
- @state.retrieve
+ @property.should = @is
+ @property.retrieve
unless defined? @transaction
raise Puppet::Error,
- "StateChange '%s' tried to be executed outside of transaction" %
+ "PropertyChange '%s' tried to be executed outside of transaction" %
self
end
- unless @state.insync?
- @state.info "Backing %s" % self
+ unless @property.insync?
+ @property.info "Backing %s" % self
return self.go
else
- @state.debug "rollback is already in sync: %s vs. %s" %
- [@state.is.inspect, @state.should.inspect]
+ @property.debug "rollback is already in sync: %s vs. %s" %
+ [@property.is.inspect, @property.should.inspect]
return nil
end
end
@@ -35,12 +35,16 @@ module Puppet
self.changed
end
- def initialize(state)
- @state = state
- @path = [state.path,"change"].flatten
- @is = state.is
+ def initialize(property)
+ 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
- @should = state.should
+ @should = property.should
@changed = false
end
@@ -51,7 +55,7 @@ module Puppet
return nil if skip?
# The transaction catches any exceptions here.
- events = @state.sync
+ events = @property.sync
if events.nil?
return nil
end
@@ -67,13 +71,13 @@ module Puppet
return events.collect { |event|
# default to a simple event type
unless event.is_a?(Symbol)
- @state.warning("State '%s' returned invalid event '%s'; resetting to default" %
- [@state.class,event])
+ @property.warning("Property '%s' returned invalid event '%s'; resetting to default" %
+ [@property.class,event])
- event = @state.parent.class.name.id2name + "_changed"
+ event = @property.parent.class.name.id2name + "_changed"
end
- @report = @state.log(@state.change_to_s)
+ @report = @property.log(@property.change_to_s)
Puppet::Event.new(
:event => event,
:transaction => @transaction,
@@ -83,11 +87,11 @@ module Puppet
end
def forward
- #@state.debug "moving change forward"
+ #@property.debug "moving change forward"
unless defined? @transaction
raise Puppet::Error,
- "StateChange '%s' tried to be executed outside of transaction" %
+ "PropertyChange '%s' tried to be executed outside of transaction" %
self
end
@@ -95,31 +99,31 @@ module Puppet
end
def noop
- return @state.noop
+ return @property.noop
end
def skip?
- if @state.insync?
- @state.info "Already in sync"
+ if @property.insync?
+ @property.info "Already in sync"
return true
end
- if @state.noop
- @state.log "is %s, should be %s (noop)" %
- [state.is_to_s, state.should_to_s]
- #@state.debug "%s is noop" % @state
+ if @property.noop
+ @property.log "is %s, should be %s (noop)" %
+ [property.is_to_s, property.should_to_s]
+ #@property.debug "%s is noop" % @property
return true
end
return false
end
def source
- self.proxy || @state.parent
+ self.proxy || @property.parent
end
def to_s
return "change %s.%s(%s)" %
- [@transaction.object_id, self.object_id, @state.change_to_s]
+ [@transaction.object_id, self.object_id, @property.change_to_s]
#return "change %s.%s" % [@transaction.object_id, self.object_id]
end
end
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb
index dc4aadcc9..377393973 100644
--- a/lib/puppet/provider/nameservice.rb
+++ b/lib/puppet/provider/nameservice.rb
@@ -24,7 +24,7 @@ class Puppet::Provider::NameService < Puppet::Provider
objects = []
listbyname do |name|
obj = nil
- check = model.validstates
+ check = model.validproperties
if obj = model[name]
obj[:check] = check
else
@@ -119,8 +119,8 @@ class Puppet::Provider::NameService < Puppet::Provider
private
- def op(state)
- @ops[state.name] || ("-" + state.name)
+ def op(property)
+ @ops[property.name] || ("-" + property.name)
end
end
@@ -202,7 +202,7 @@ class Puppet::Provider::NameService < Puppet::Provider
return nil
end
- # again, needs to be set by the ind. state or its
+ # again, needs to be set by the ind. property or its
# parent
cmd = self.deletecmd
type = "delete"
@@ -293,7 +293,7 @@ class Puppet::Provider::NameService < Puppet::Provider
# Convert the Etc struct into a hash.
def info2hash(info)
hash = {}
- self.class.model.validstates.each do |param|
+ self.class.model.validproperties.each do |param|
method = posixmethod(param)
if info.respond_to? method
hash[param] = info.send(posixmethod(param))
@@ -313,10 +313,10 @@ class Puppet::Provider::NameService < Puppet::Provider
def method_missing(name, *args)
name = name.to_s
- # Make sure it's a valid state. We go up our class structure instead of
+ # Make sure it's a valid property. We go up our class structure instead of
# our model's because the model is fake during testing.
- unless self.class.model.validstate?(name.sub("=",''))
- raise Puppet::DevError, "%s is not a valid %s state" %
+ unless self.class.model.validproperty?(name.sub("=",''))
+ raise Puppet::DevError, "%s is not a valid %s property" %
[name, @model.class.name]
end
diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb
index b5e3d0536..134ef37e9 100644
--- a/lib/puppet/provider/nameservice/netinfo.rb
+++ b/lib/puppet/provider/nameservice/netinfo.rb
@@ -62,7 +62,7 @@ class NetInfo < Puppet::Provider::NameService
end
def self.list
- report(@model.validstates).collect do |hash|
+ report(@model.validproperties).collect do |hash|
@model.hash2obj(hash)
end
end
@@ -92,7 +92,7 @@ class NetInfo < Puppet::Provider::NameService
cmd << key.to_s
else
raise Puppet::DevError,
- "Could not find netinfokey for state %s" %
+ "Could not find netinfokey for property %s" %
self.class.name
end
end
@@ -136,7 +136,7 @@ class NetInfo < Puppet::Provider::NameService
# Because our stupid type can't create the whole thing at once,
# we have to do this hackishness. Yay.
if arg == :present
- @model.class.validstates.each do |name|
+ @model.class.validproperties.each do |name|
next if name == :ensure
next unless val = @model.should(name) || autogen(name)
self.send(name.to_s + "=", val)
@@ -157,9 +157,9 @@ class NetInfo < Puppet::Provider::NameService
# Retrieve everything about this object at once, instead of separately.
def getinfo(refresh = false)
if refresh or (! defined? @infohash or ! @infohash)
- states = [:name] + self.class.model.validstates
- states.delete(:ensure) if states.include? :ensure
- @infohash = single_report(*states)
+ properties = [:name] + self.class.model.validproperties
+ properties.delete(:ensure) if properties.include? :ensure
+ @infohash = single_report(*properties)
end
return @infohash
@@ -179,7 +179,7 @@ class NetInfo < Puppet::Provider::NameService
cmd += value
else
raise Puppet::DevError,
- "Could not find netinfokey for state %s" %
+ "Could not find netinfokey for property %s" %
self.class.name
end
cmd
@@ -191,8 +191,8 @@ class NetInfo < Puppet::Provider::NameService
end
# Get a report for a single resource, not the whole table
- def single_report(*states)
- self.class.report(*states).find do |hash| hash[:name] == @model[:name] end
+ def single_report(*properties)
+ self.class.report(*properties).find do |hash| hash[:name] == @model[:name] end
end
def setuserlist(group, list)
diff --git a/lib/puppet/provider/package/up2date.rb b/lib/puppet/provider/package/up2date.rb
index 85a0ddde6..c11be0947 100644
--- a/lib/puppet/provider/package/up2date.rb
+++ b/lib/puppet/provider/package/up2date.rb
@@ -9,8 +9,6 @@ Puppet.type(:package).provide :up2date, :parent => :rpm do
def install
up2date "-u", @model[:name]
- #@states[:ensure].retrieve
- #if @states[:ensure].is == :absent
unless self.query
raise Puppet::ExecutionFailure.new(
"Could not find package %s" % self.name
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index ddb18ff17..a685c7250 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -17,7 +17,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
attr_accessor :default_target, :target
end
- attr_accessor :state_hash
+ attr_accessor :property_hash
def self.clean(hash)
newhash = hash.dup
@@ -119,14 +119,14 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
# Create attribute methods for each of the model's non-metaparam attributes.
def self.model=(model)
- [model.validstates, model.parameters].flatten.each do |attr|
+ [model.validproperties, model.parameters].flatten.each do |attr|
attr = symbolize(attr)
define_method(attr) do
# If it's not a valid field for this record type (which can happen
# when different platforms support different fields), then just
# return the should value, so the model shuts up.
- if @state_hash[attr] or self.class.valid_attr?(self.class.name, attr)
- @state_hash[attr] || :absent
+ if @property_hash[attr] or self.class.valid_attr?(self.class.name, attr)
+ @property_hash[attr] || :absent
else
@model.should(attr)
end
@@ -137,19 +137,19 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
modeltarget = @model[:target] || self.class.default_target
# If they're the same, then just mark that one as modified
- if @state_hash[:target] and @state_hash[:target] == modeltarget
+ if @property_hash[:target] and @property_hash[:target] == modeltarget
self.class.modified(modeltarget)
else
# Always mark the modeltarget as modified, and if there's
- # and old state_hash target, mark it as modified and replace
+ # and old property_hash target, mark it as modified and replace
# it.
self.class.modified(modeltarget)
- if @state_hash[:target]
- self.class.modified(@state_hash[:target])
+ if @property_hash[:target]
+ self.class.modified(@property_hash[:target])
end
- @state_hash[:target] = modeltarget
+ @property_hash[:target] = modeltarget
end
- @state_hash[attr] = val
+ @property_hash[attr] = val
end
end
@model = model
@@ -185,16 +185,16 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
r[:ensure] = :present
end
- # Set current state on any existing resource instances.
+ # Set current property on any existing resource instances.
target_records(target).find_all { |i| i.is_a?(Hash) }.each do |record|
# Find any model instances whose names match our instances.
if instance = self.model[record[:name]]
next unless instance.provider.is_a?(self)
- instance.provider.state_hash = record
+ instance.provider.property_hash = record
elsif self.respond_to?(:match)
if instance = self.match(record)
record[:name] = instance[:name]
- instance.provider.state_hash = record
+ instance.provider.property_hash = record
end
end
end
@@ -260,12 +260,12 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
end
def create
- @model.class.validstates.each do |state|
- if value = @model.should(state)
- @state_hash[state] = value
+ @model.class.validproperties.each do |property|
+ if value = @model.should(property)
+ @property_hash[property] = value
end
end
- self.class.modified(@state_hash[:target] || self.class.default_target)
+ self.class.modified(@property_hash[:target] || self.class.default_target)
return (@model.class.name.to_s + "_created").intern
end
@@ -276,7 +276,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
end
def exists?
- if @state_hash[:ensure] == :absent or @state_hash[:ensure].nil?
+ if @property_hash[:ensure] == :absent or @property_hash[:ensure].nil?
return false
else
return true
@@ -289,24 +289,24 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
# If the target isn't set, then this is our first modification, so
# mark it for flushing.
- unless @state_hash[:target]
- @state_hash[:target] = @model[:target] || self.class.default_target
- self.class.modified(@state_hash[:target])
+ unless @property_hash[:target]
+ @property_hash[:target] = @model[:target] || self.class.default_target
+ self.class.modified(@property_hash[:target])
end
- @state_hash[:name] ||= @model.name
+ @property_hash[:name] ||= @model.name
- self.class.flush(@state_hash)
+ self.class.flush(@property_hash)
end
def initialize(model)
super
- # See if there's already a matching state_hash in the records list;
+ # See if there's already a matching property_hash in the records list;
# else, use a default value.
# We provide a default for 'ensure' here, because the provider will
# override it if the thing exists, but it won't touch it if it doesn't
# exist.
- @state_hash = self.class.record?(model[:name]) ||
+ @property_hash = self.class.record?(model[:name]) ||
{:record_type => self.class.name, :ensure => :absent}
end
end
diff --git a/lib/puppet/provider/user/pw.rb b/lib/puppet/provider/user/pw.rb
index bc81e5ce5..9b85a22f9 100644
--- a/lib/puppet/provider/user/pw.rb
+++ b/lib/puppet/provider/user/pw.rb
@@ -21,12 +21,12 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::
def addcmd
cmd = [command(:pw), "useradd", @model[:name]]
- @model.class.validstates.each do |state|
- next if state == :ensure
+ @model.class.validproperties.each do |property|
+ next if property == :ensure
# the value needs to be quoted, mostly because -c might
# have spaces in it
- if value = @model.should(state) and value != ""
- cmd << flag(state) << value
+ if value = @model.should(property) and value != ""
+ cmd << flag(property) << value
end
end
diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb
index d8adb8c69..55cc2d5dd 100644
--- a/lib/puppet/provider/user/useradd.rb
+++ b/lib/puppet/provider/user/useradd.rb
@@ -19,12 +19,12 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ
def addcmd
cmd = [command(:add)]
- @model.class.validstates.each do |state|
- next if state == :ensure
+ @model.class.validproperties.each do |property|
+ next if property == :ensure
# the value needs to be quoted, mostly because -c might
# have spaces in it
- if value = @model.should(state) and value != ""
- cmd << flag(state) << value
+ if value = @model.should(property) and value != ""
+ cmd << flag(property) << value
end
end
# stupid fedora
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index e4871f812..572f137b0 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -45,9 +45,9 @@ set zonepath=%s
# Then perform all of our configuration steps. It's annoying
# that we need this much internal info on the model.
- @model.send(:states).each do |state|
- if state.is_a? ZoneConfigState and ! state.insync?
- str += state.configtext + "\n"
+ @model.send(:properties).each do |property|
+ if property.is_a? ZoneConfigProperty and ! property.insync?
+ str += property.configtext + "\n"
end
end
@@ -64,7 +64,7 @@ set zonepath=%s
end
# We need a way to test whether a zone is in process. Our 'ensure'
- # state models the static states, but we need to handle the temporary ones.
+ # property models the static states, but we need to handle the temporary ones.
def processing?
if hash = statushash()
case hash[:ensure]
@@ -121,14 +121,14 @@ set zonepath=%s
# Now retrieve the configuration itself and set appropriately.
getconfig()
else
- @states.each do |name, state|
- state.is = :absent
+ @properties.each do |name, property|
+ property.is = :absent
end
end
end
# Execute a configuration string. Can't be private because it's called
- # by the states.
+ # by the properties.
def setconfig(str)
command = "#{command(:cfg)} -z %s -f -" % @model[:name]
debug "Executing '%s' in zone %s with '%s'" % [command, @model[:name], str]
diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb
index 2b91c8811..b541f2474 100755
--- a/lib/puppet/server/fileserver.rb
+++ b/lib/puppet/server/fileserver.rb
@@ -43,14 +43,14 @@ class Server
desc = []
CHECKPARAMS.each { |check|
- if state = obj.state(check)
- unless state.is
+ if property = obj.property(check)
+ unless property.is
mount.debug "Manually retrieving info for %s" % check
- state.retrieve
+ property.retrieve
end
- desc << state.is
+ desc << property.is
else
- if check == "checksum" and obj.state(:type).is == "file"
+ if check == "checksum" and obj.property(:type).is == "file"
mount.notice "File %s does not have data for %s" %
[obj.name, check]
end
diff --git a/lib/puppet/server/resource.rb b/lib/puppet/server/resource.rb
index 12a188a18..d2bad52f3 100755
--- a/lib/puppet/server/resource.rb
+++ b/lib/puppet/server/resource.rb
@@ -49,7 +49,7 @@ class Server::Resource < Server::Handler
return "success"
end
- # Describe a given object. This returns the 'is' values for every state
+ # Describe a given object. This returns the 'is' values for every property
# available on the object type.
def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
Puppet.info "Describing %s[%s]" % [type.to_s.capitalize, name]
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 347d94432..3c8a3a2e8 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -1,8 +1,8 @@
-# the class that actually walks our resource/state tree, collects the changes,
+# the class that actually walks our resource/property tree, collects the changes,
# and performs them
require 'puppet'
-require 'puppet/statechange'
+require 'puppet/propertychange'
module Puppet
class Transaction
@@ -113,9 +113,8 @@ class Transaction
if Puppet[:trace]
puts detail.backtrace
end
- puts detail
- change.state.err "change from %s to %s failed: %s" %
- [change.state.is_to_s, change.state.should_to_s, detail]
+ change.property.err "change from %s to %s failed: %s" %
+ [change.property.is_to_s, change.property.should_to_s, detail]
@failures[resource] += 1
next
# FIXME this should support using onerror to determine
@@ -137,7 +136,7 @@ class Transaction
# Find all of the changed resources.
def changed?
@changes.find_all { |change| change.changed }.collect { |change|
- change.state.parent
+ change.property.parent
}.uniq
end
@@ -178,7 +177,7 @@ class Transaction
# Are we deleting this resource?
def deleting?(changes)
changes.detect { |change|
- change.state.name == :ensure and change.should == :absent
+ change.property.name == :ensure and change.should == :absent
}
end
@@ -188,6 +187,9 @@ class Transaction
begin
children = resource.eval_generate
rescue => detail
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
resource.err "Failed to generate additional resources during transaction: %s" %
detail
return nil
@@ -571,7 +573,7 @@ class Transaction
# at this point, we would normally do error handling
# but i haven't decided what to do for that yet
# so just record that a sync failed for a given resource
- #@@failures[change.state.parent] += 1
+ #@@failures[change.property.parent] += 1
# this still could get hairy; what if file contents changed,
# but a chmod failed? how would i handle that error? dern
end
@@ -584,7 +586,7 @@ class Transaction
# Now check to see if there are any events for this child.
# Kind of hackish, since going backwards goes a change at a
# time, not a child at a time.
- trigger(change.state.parent)
+ trigger(change.property.parent)
# And return the events for collection
events
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 26d2df24a..fd4704ae5 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -3,7 +3,7 @@ require 'puppet/log'
require 'puppet/element'
require 'puppet/event'
require 'puppet/metric'
-require 'puppet/type/state'
+require 'puppet/type/property'
require 'puppet/parameter'
require 'puppet/util'
require 'puppet/autoload'
@@ -31,7 +31,7 @@ class Type < Puppet::Element
# Types (which map to elements in the languages) are entirely composed of
# attribute value pairs. Generally, Puppet calls any of these things an
# 'attribute', but these attributes always take one of three specific
- # forms: parameters, metaparams, or states.
+ # forms: parameters, metaparams, or properties.
# In naming methods, I have tried to consistently name the method so
# that it is clear whether it operates on all attributes (thus has 'attr' in
@@ -68,8 +68,8 @@ class Type < Puppet::Element
@parameters = []
end
- @validstates = {}
- @states = []
+ @validproperties = {}
+ @properties = []
@parameters = []
@paramhash = {}
@@ -88,10 +88,6 @@ class Type < Puppet::Element
@doc = ""
end
- unless defined? @states
- @states = []
- end
-
end
def self.to_s
@@ -109,13 +105,13 @@ class Type < Puppet::Element
#@validate = block
end
- # iterate across all children, and then iterate across states
+ # iterate across all children, and then iterate across properties
# we do children first so we're sure that all dependent objects
# are checked first
# we ignore parameters here, because they only modify how work gets
# done, they don't ever actually result in work specifically
def each
- # we want to return the states in the order that each type
+ # we want to return the properties in the order that each type
# specifies it, because it may (as in the case of File#create)
# be important
if self.class.depthfirst?
@@ -123,8 +119,8 @@ class Type < Puppet::Element
yield child
}
end
- self.eachstate { |state|
- yield state
+ self.eachproperty { |property|
+ yield property
}
unless self.class.depthfirst?
@children.each { |child|
@@ -133,7 +129,7 @@ class Type < Puppet::Element
end
end
- # Recurse deeply through the tree, but only yield types, not states.
+ # Recurse deeply through the tree, but only yield types, not properties.
def delve(&block)
self.each do |obj|
if obj.is_a? Puppet::Type
@@ -146,7 +142,7 @@ class Type < Puppet::Element
# create a log at specified level
def log(msg)
Puppet::Log.create(
- :level => @metaparams[:loglevel].value,
+ :level => @parameters[:loglevel].value,
:message => msg,
:source => self
)
@@ -168,20 +164,14 @@ class Type < Puppet::Element
chash[key] = {}
}
- # states and parameters are treated equivalently from the outside:
+ # properties and parameters are treated equivalently from the outside:
# as name-value pairs (using [] and []=)
- # internally, however, parameters are merely a hash, while states
- # point to State objects
- # further, the lists of valid states and parameters are defined
+ # internally, however, parameters are merely a hash, while properties
+ # point to Property objects
+ # further, the lists of valid properties and parameters are defined
# at the class level
- unless defined? @states
- @states = Hash.new(false)
- end
unless defined? @parameters
- @parameters = Hash.new(false)
- end
- unless defined? @metaparams
- @metaparams = Hash.new(false)
+ @parameters = {}
end
# set defalts
@@ -349,7 +339,7 @@ class Type < Puppet::Element
namevar = self.class.namevar
if self.class.validparameter?(namevar)
@title = self[:name]
- elsif self.class.validstate?(namevar)
+ elsif self.class.validproperty?(namevar)
@title = self.should(namevar)
else
self.devfail "Could not find namevar %s for %s" %
@@ -374,8 +364,8 @@ class Type < Puppet::Element
trans = TransObject.new(self.title, self.class.name)
- states().each do |state|
- trans[state.name] = state.is
+ properties().each do |property|
+ trans[property.name] = property.is
end
@parameters.each do |name, param|
@@ -384,10 +374,6 @@ class Type < Puppet::Element
trans[name] = param.value
end
- @metaparams.each do |name, param|
- trans[name] = param.value
- end
-
trans.tags = self.tags
# FIXME I'm currently ignoring 'parent' and 'path'
@@ -398,7 +384,7 @@ class Type < Puppet::Element
end # Puppet::Type
end
-require 'puppet/statechange'
+require 'puppet/propertychange'
require 'puppet/provider'
require 'puppet/type/component'
require 'puppet/type/pfile'
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 69c337249..9c991886e 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -1,12 +1,12 @@
require 'etc'
require 'facter'
-require 'puppet/type/state'
+require 'puppet/type/property'
require 'puppet/filetype'
require 'puppet/type/parsedtype'
module Puppet
# Model the actual cron jobs. Supports all of the normal cron job fields
- # as parameters, with the 'command' as the single state. Also requires a
+ # as parameters, with the 'command' as the single property. Also requires a
# completely symbolic 'name' paremeter, which gets written to the file
# and is used to manage the job.
newtype(:cron) do
@@ -14,12 +14,12 @@ module Puppet
# A stupid hack because Cron is the only parsed type that I haven't
# converted to using providers. This whole stupid type needs to
# be rewritten.
- class CronHackParam < Puppet::State::ParsedParam
- # Normally this would retrieve the current value, but our state is not
+ class CronHackParam < Puppet::Property::ParsedParam
+ # Normally this would retrieve the current value, but our property is not
# actually capable of doing so.
def retrieve
# If we've synced, then just copy the values over and return.
- # This allows this state to behave like any other state.
+ # This allows this property to behave like any other property.
if defined? @synced and @synced
# by default, we only copy over the first value.
@is = @synced
@@ -32,7 +32,7 @@ module Puppet
end
end
- # If the ensure state is out of sync, it will always be called
+ # If the ensure property is out of sync, it will always be called
# first, so I don't need to worry about that.
def sync(nostore = false)
ebase = @parent.class.name.to_s
@@ -44,13 +44,13 @@ module Puppet
#@is = self.should
tail = "created"
- # If we're creating it, then sync all of the other states
+ # If we're creating it, then sync all of the other properties
# but tell them not to store (we'll store just once,
# at the end).
unless nostore
- @parent.eachstate { |state|
- next if state == self or state.name == :ensure
- state.sync(true)
+ @parent.eachproperty { |property|
+ next if property == self or property.name == :ensure
+ property.sync(true)
}
end
elsif self.should == :absent
@@ -216,21 +216,21 @@ module Puppet
end
- # Override 'newstate' so that all states default to having the
+ # Override 'newproperty' so that all properties default to having the
# correct parent type
- def self.newstate(name, options = {}, &block)
- options[:parent] ||= Puppet::State::CronParam
+ def self.newproperty(name, options = {}, &block)
+ options[:parent] ||= Puppet::Property::CronParam
super(name, options, &block)
end
- # Somewhat uniquely, this state does not actually change anything -- it
+ # Somewhat uniquely, this property does not actually change anything -- it
# just calls +@parent.sync+, which writes out the whole cron tab for
# the user in question. There is no real way to change individual cron
# jobs without rewriting the entire cron file.
#
# Note that this means that managing many cron jobs for a given user
# could currently result in multiple write sessions for that user.
- newstate(:command, :parent => CronParam) do
+ newproperty(:command, :parent => CronParam) do
desc "The command to execute in the cron job. The environment
provided to the command varies by local system rules, and it is
best to always provide a fully qualified command. The user's
@@ -253,7 +253,7 @@ module Puppet
end
end
- newstate(:special, :parent => CronHackParam) do
+ newproperty(:special, :parent => CronHackParam) do
desc "Special schedules only supported on FreeBSD."
def specials
@@ -268,19 +268,19 @@ module Puppet
end
end
- newstate(:minute) do
+ newproperty(:minute) do
self.boundaries = [0, 59]
desc "The minute at which to run the cron job.
Optional; if specified, must be between 0 and 59, inclusive."
end
- newstate(:hour) do
+ newproperty(:hour) do
self.boundaries = [0, 23]
desc "The hour at which to run the cron job. Optional;
if specified, must be between 0 and 23, inclusive."
end
- newstate(:weekday) do
+ newproperty(:weekday) do
def alpha
%w{sunday monday tuesday wednesday thursday friday saturday}
end
@@ -290,7 +290,7 @@ module Puppet
0 being Sunday, or must be the name of the day (e.g., Tuesday)."
end
- newstate(:month) do
+ newproperty(:month) do
def alpha
%w{january february march april may june july
august september october november december}
@@ -300,13 +300,13 @@ module Puppet
must be between 1 and 12 or the month name (e.g., December)."
end
- newstate(:monthday) do
+ newproperty(:monthday) do
self.boundaries = [1, 31]
desc "The day of the month on which to run the
command. Optional; if specified, must be between 1 and 31."
end
- newstate(:environment, :parent => CronHackParam) do
+ newproperty(:environment, :parent => CronHackParam) do
desc "Any environment settings associated with this cron job. They
will be stored between the header and the job in the crontab. There
can be no guarantees that other, earlier settings will not also
@@ -476,8 +476,8 @@ module Puppet
# Mark all of the values appropriately
hash.each { |param, value|
- if state = obj.state(param)
- state.is = value
+ if property = obj.property(param)
+ property.is = value
elsif val = obj[param]
obj[param] = val
else
@@ -785,7 +785,7 @@ module Puppet
end
def exists?
- @states.include?(:ensure) and @states[:ensure].is == :present
+ obj = @parameters[:ensure] and obj.is == :present
end
# Override the default Puppet::Type method because we need to call
@@ -796,15 +796,9 @@ module Puppet
end
self.class.retrieve(self[:user])
- if withtab = self.class["testwithtab"]
- Puppet.info withtab.is(:ensure).inspect
- end
- self.eachstate { |st|
+ self.eachproperty { |st|
st.retrieve
}
- if withtab = self.class["testwithtab"]
- Puppet.info withtab.is(:ensure).inspect
- end
end
# Write the entire user's cron tab out.
@@ -830,14 +824,13 @@ module Puppet
str = "# Puppet Name: %s\n" % self.name
- if @states.include?(:environment) and
- @states[:environment].should != :absent
- envs = @states[:environment].should
- unless envs.is_a? Array
- envs = [envs]
- end
+ if env = @parameters[:environment] and env.should != :absent
+ envs = env.should
+ unless envs.is_a? Array
+ envs = [envs]
+ end
- envs.each do |line| str += (line + "\n") end
+ envs.each do |line| str += (line + "\n") end
end
line = nil
@@ -858,13 +851,13 @@ module Puppet
end
def value(name)
- name = name.intern if name.is_a? String
+ name = symbolize(name)
ret = nil
- if @states.include?(name)
- ret = @states[name].should_to_s
+ if obj = @parameters[name]
+ ret = obj.should_to_s
if ret.nil?
- ret = @states[name].is_to_s
+ ret = obj.is_to_s
end
if ret == :absent
@@ -879,7 +872,7 @@ module Puppet
when :special
# nothing
else
- #ret = (self.class.validstate?(name).default || "*").to_s
+ #ret = (self.class.validproperty?(name).default || "*").to_s
ret = "*"
end
end
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 01870770c..55b3eb271 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -48,7 +48,7 @@ module Puppet
it is a Puppet bug if you need ``exec`` to do your work."
require 'open3'
- require 'puppet/type/state'
+ require 'puppet/type/property'
# Create a new check mechanism. It's basically just a parameter that
# provides one extra 'check' method.
@@ -63,7 +63,7 @@ module Puppet
@checks.keys
end
- newstate(:returns) do |state|
+ newproperty(:returns) do |property|
include Puppet::Util::Execution
munge do |value|
value.to_s
@@ -477,16 +477,16 @@ module Puppet
end
def output
- if self.state(:returns).nil?
+ if self.property(:returns).nil?
return nil
else
- return self.state(:returns).output
+ return self.property(:returns).output
end
end
# this might be a very, very bad idea...
def refresh
- self.state(:returns).sync
+ self.property(:returns).sync
end
# Run a command.
@@ -564,7 +564,7 @@ module Puppet
# if we're not fully qualified, require a path
if cmd !~ /^\//
if self[:path].nil?
- self.fail "both unqualifed and specified no search path"
+ self.fail "'%s' is both unqualifed and specified no search path" % cmd
end
end
end
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index f4eb03cac..91c17580b 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -8,7 +8,7 @@
require 'etc'
require 'facter'
-require 'puppet/type/state'
+require 'puppet/type/property'
module Puppet
newtype(:group) do
@@ -22,7 +22,7 @@ module Puppet
for Mac OS X, NetInfo is used. This is currently unconfigurable,
but if you desperately need it to be so, please contact us."
- newstate(:ensure) do
+ newproperty(:ensure) do
desc "The basic state that the object should be in."
newvalue(:present) do
@@ -94,7 +94,7 @@ module Puppet
end
- newstate(:gid) do
+ newproperty(:gid) do
desc "The group ID. Must be specified numerically. If not
specified, a number will be picked, which can result in ID
differences across systems and thus is not recommended. The
@@ -169,13 +169,8 @@ module Puppet
if self.provider and @provider.exists?
super
else
- # the group does not exist
- #unless @states.include?(:gid)
- # self[:gid] = :auto
- #end
-
- @states.each { |name, state|
- state.is = :absent
+ properties().each { |property|
+ property.is = :absent
}
return
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index d11d1894c..ef56bc7c8 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -4,11 +4,11 @@ module Puppet
newtype(:host) do
ensurable
- newstate(:ip) do
+ newproperty(:ip) do
desc "The host's IP address, IPv4 or IPv6."
end
- newstate(:alias) do
+ newproperty(:alias) do
desc "Any alias the host might have. Multiple values must be
specified as an array. Note that this state has the same name
as one of the metaparams; using this state to set aliases will
@@ -81,19 +81,9 @@ module Puppet
raise Puppet::Error, "Aliases cannot include whitespace"
end
end
-
- munge do |value|
- if value == :absent or value == "absent"
- :absent
- else
- # Add the :alias metaparam in addition to the state
- @parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
- value
- end
- end
end
- newstate(:target) do
+ newproperty(:target) do
desc "The file in which to store service information. Only used by
those providers that write to disk (i.e., not NetInfo)."
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index 1f8147b77..c7f122e36 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -5,7 +5,7 @@ module Puppet
newtype(:mount, :self_refresh => true) do
# Use the normal parent class, because we actually want to
# call code when sync() is called.
- newstate(:ensure) do
+ newproperty(:ensure) do
desc "Control what to do with this mount. If the value is
``present``, the mount is entered into the mount table,
but not mounted, if it is ``absent``, the entry is removed
@@ -53,20 +53,20 @@ module Puppet
def syncothers
# We have to flush any changes to disk.
- oos = @parent.send(:states).find_all do |st|
- if st.name == :ensure
+ oos = @parent.send(:properties).find_all do |prop|
+ if prop.name == :ensure
false
else
- ! st.insync?
+ ! prop.insync?
end
- end.each { |st| st.sync }.length
+ end.each { |prop| prop.sync }.length
if oos > 0
@parent.flush
end
end
end
- newstate(:device) do
+ newproperty(:device) do
desc "The device providing the mount. This can be whatever
device is supporting by the mount, including network
devices or devices specified by UUID rather than device
@@ -74,8 +74,8 @@ module Puppet
end
# Solaris specifies two devices, not just one.
- newstate(:blockdevice) do
- desc "The the device to fsck. This is state is only valid
+ newproperty(:blockdevice) do
+ desc "The the device to fsck. This is property is only valid
on Solaris, and in most cases will default to the correct
value."
@@ -94,31 +94,31 @@ module Puppet
end
end
- newstate(:fstype) do
+ newproperty(:fstype) do
desc "The mount type. Valid values depend on the
operating system."
end
- newstate(:options) do
+ newproperty(:options) do
desc "Mount options for the mounts, as they would
appear in the fstab."
end
- newstate(:pass) do
+ newproperty(:pass) do
desc "The pass in which the mount is checked."
end
- newstate(:atboot) do
+ newproperty(:atboot) do
desc "Whether to mount the mount at boot. Not all platforms
support this."
end
- newstate(:dump) do
+ newproperty(:dump) do
desc "Whether to dump the mount. Not all platforms
support this."
end
- newstate(:target) do
+ newproperty(:target) do
desc "The file in which to store the mount table. Only used by
those providers that write to disk (i.e., not NetInfo)."
@@ -167,7 +167,7 @@ module Puppet
def refresh
# Only remount if we're supposed to be mounted.
- if ens = @states[:ensure] and ens.should == :mounted
+ if ens = @parameters[:ensure] and ens.should == :mounted
provider.remount
end
end
@@ -175,8 +175,8 @@ module Puppet
def value(name)
name = symbolize(name)
ret = nil
- if state = @states[name]
- return state.value
+ if property = @parameters[name]
+ return property.value
end
end
end
diff --git a/lib/puppet/type/notify.rb b/lib/puppet/type/notify.rb
index 925cb6b1f..a51397d48 100644
--- a/lib/puppet/type/notify.rb
+++ b/lib/puppet/type/notify.rb
@@ -6,7 +6,7 @@ module Puppet
newtype(:notify) do
@doc = "Sends an arbitrary message to the puppetd run-time log."
- newstate(:message) do
+ newproperty(:message) do
desc "The message to be sent to the log."
def sync
case @parent["withpath"]
@@ -42,4 +42,4 @@ module Puppet
end
end
-# $Id:$
+# $Id$
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 0f5ec26c0..da4ec5db2 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -3,7 +3,7 @@
# This allows packages to exist on the same machine using different packaging
# systems.
-require 'puppet/type/state'
+require 'puppet/type/property'
module Puppet
class PackageError < Puppet::Error; end
@@ -349,7 +349,9 @@ module Puppet
# This only exists for testing.
def clear
- @states[:ensure].latest = nil
+ if obj = @parameters[:ensure]
+ obj.latest = nil
+ end
end
# The 'query' method returns a hash of info if the package
@@ -379,11 +381,6 @@ module Puppet
super
- #unless @states.include?(:ensure)
- # self.debug "Defaulting to installing a package"
- # self[:ensure] = true
- #end
-
unless @parameters.include?(:provider)
raise Puppet::DevError, "No package type set"
end
@@ -392,7 +389,6 @@ module Puppet
def retrieve
# If the package is installed, then retrieve all of the information
# about it and set it appropriately.
- #@states[:ensure].retrieve
if hash = @provider.query
if hash == :listed # Mmmm, hackalicious
return
@@ -405,19 +401,19 @@ module Puppet
setparams(hash)
else
- # Else just mark all of the states absent.
- self.class.validstates.each { |name|
+ # Else just mark all of the properties absent.
+ self.class.validproperties.each { |name|
self.is = [name, :absent]
}
end
end
# Set all of the params' "is" value. Most are parameters, but some
- # are states.
+ # are properties.
def setparams(hash)
# Everything on packages is a parameter except :ensure
hash.each { |param, value|
- if self.class.attrtype(param) == :state
+ if self.class.attrtype(param) == :property
self.is = [param, value]
else
self[param] = value
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index 607134c46..1232c979e 100755
--- a/lib/puppet/type/parsedtype.rb
+++ b/lib/puppet/type/parsedtype.rb
@@ -1,13 +1,13 @@
require 'etc'
require 'facter'
require 'puppet/filetype'
-require 'puppet/type/state'
+require 'puppet/type/property'
module Puppet
# The base parameter for all of these types. Its only job is to copy
# the 'should' value to the 'is' value and to do support the right logging
# and such.
- class State::ParsedParam < Puppet::State
+ class Property::ParsedParam < Puppet::Property
# This is the info retrieved from disk.
attr_accessor :found
@@ -47,7 +47,7 @@ module Puppet
self.is == self.should
end
- # Normally this would retrieve the current value, but our state is not
+ # Normally this would retrieve the current value, but our property is not
# actually capable of doing so. So, we retrieve the whole object and
# just collect our current state. Note that this method is not called
# during a transaction, since transactions call the parent object method.
@@ -96,10 +96,10 @@ module Puppet
# Mark found objects as present
obj.is = [:ensure, :present]
- obj.state(:ensure).found = :present
+ obj.property(:ensure).found = :present
hash.each { |param, value|
- if state = obj.state(param)
- state.is = value
+ if property = obj.property(param)
+ property.is = value
elsif val = obj[param]
obj[param] = val
else
@@ -124,10 +124,10 @@ module Puppet
return obj
end
- # Override 'newstate' so that all states default to having the
+ # Override 'newproperty' so that all properties default to having the
# correct parent type
- def self.newstate(name, options = {}, &block)
- options[:parent] ||= Puppet::State::ParsedParam
+ def self.newproperty(name, options = {}, &block)
+ options[:parent] ||= Puppet::Property::ParsedParam
super(name, options, &block)
end
@@ -145,8 +145,8 @@ module Puppet
# Make sure they've got an explicit :ensure class.
def self.postinit
- unless validstate? :ensure
- newstate(:ensure) do
+ unless validproperty? :ensure
+ newproperty(:ensure) do
newvalue(:present) do
# The value will get flushed appropriately
return nil
@@ -191,24 +191,24 @@ module Puppet
# If they passed back info we don't have, then mark it to
# be deleted.
h.each do |name, value|
- next unless self.class.validstate?(name)
- unless @states.has_key? name
- self.newstate(name, :should => :absent)
+ next unless self.class.validproperty?(name)
+ unless @parameters[name]
+ self.newproperty(name, :should => :absent)
end
end
- @states.each do |name, state|
- if h.has_key? name
- state.is = h[name]
+ properties().each do |property|
+ if h.has_key? property.name
+ property.is = h[property.name]
else
- state.is = :absent
+ property.is = :absent
end
end
return h
else
- @states.each do |name, state|
- state.is = :absent
+ properties().each do |property|
+ property.is = :absent
end
return nil
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 93d715f01..478978623 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -3,7 +3,7 @@ require 'cgi'
require 'etc'
require 'uri'
require 'fileutils'
-require 'puppet/type/state'
+require 'puppet/type/property'
require 'puppet/server/fileserver'
module Puppet
@@ -205,11 +205,11 @@ module Puppet
end
# Autorequire the owner and group of the file.
- {:user => :owner, :group => :group}.each do |type, state|
+ {:user => :owner, :group => :group}.each do |type, property|
autorequire(type) do
- if @states.include?(state)
- # The user/group states automatically converts to IDs
- next unless should = @states[state].shouldorig
+ if @parameters.include?(property)
+ # The user/group property automatically converts to IDs
+ next unless should = @parameters[property].shouldorig
val = should[0]
if val.is_a?(Integer) or val =~ /^\d+$/
nil
@@ -276,7 +276,7 @@ module Puppet
# If the parent directory is writeable, then we execute
# as the user in question. Otherwise we'll rely on
- # the 'owner' state to do things.
+ # the 'owner' property to do things.
if writeable
asuser = self.should(:owner)
end
@@ -462,7 +462,7 @@ module Puppet
# Build a recursive map of a link source
def linkrecurse(recurse)
- target = @states[:target].should
+ target = @parameters[:target].should
method = :lstat
if self[:links] == :follow
@@ -481,7 +481,6 @@ module Puppet
# Now that we know our corresponding target is a directory,
# change our type
- info "setting ensure to target"
self[:ensure] = :directory
unless FileTest.readable? target
@@ -544,17 +543,6 @@ module Puppet
options = {:recurse => recurse}
if child = self.newchild(file, true, options)
- # Mark any unmanaged files for removal if purge is set.
- # Use the array rather than [] because tidy uses this method, too.
-# if @parameters.include?(:purge) and self.purge?
-# child.info "source: %s" % child.should(:source)
-# unless child.managed?
-# info "purging %s" % child.ref
-# child[:ensure] = :absent
-# end
-# #else
-# #child[:require] = self
-# end
added << child
end
}
@@ -701,13 +689,13 @@ module Puppet
# We want to do link-recursing before normal recursion so that all
# of the target stuff gets copied over correctly.
- if @states.include? :target and ret = self.linkrecurse(recurse)
+ if @parameters.include? :target and ret = self.linkrecurse(recurse)
children += ret
end
if ret = self.localrecurse(recurse)
children += ret
end
- if @states.include?(:source) and ret = self.sourcerecurse(recurse)
+ if @parameters.include?(:source) and ret = self.sourcerecurse(recurse)
children += ret
end
@@ -799,21 +787,21 @@ module Puppet
def retrieve
unless stat = self.stat(true)
self.debug "File does not exist"
- @states.each { |name,state|
- state.is = :absent
+ properties().each { |property|
+ property.is = :absent
}
# If the file doesn't exist but we have a source, then call
- # retrieve on that state
- if @states.include?(:source)
- @states[:source].retrieve
+ # retrieve on that property
+ if @parameters.include?(:source)
+ @parameters[:source].retrieve
end
return
end
- states().each { |state|
- state.retrieve
+ properties().each { |property|
+ property.retrieve
}
end
@@ -840,7 +828,7 @@ module Puppet
result = []
found = []
- @states[:source].should.each do |source|
+ @parameters[:source].should.each do |source|
sourceobj, path = uri2obj(source)
# okay, we've got our source object; now we need to
@@ -864,9 +852,10 @@ module Puppet
# for conflicting files.
next if found.include?(name)
- # For directories, keep all of the sources, so that sourceselect still works as planned.
+ # For directories, keep all of the sources, so that
+ # sourceselect still works as planned.
if type == "directory"
- newsource = @states[:source].should.collect do |source|
+ newsource = @parameters[:source].should.collect do |source|
source + file
end
else
@@ -889,25 +878,26 @@ module Puppet
return result
end
- # Set the checksum, from another state. There are multiple states that
- # modify the contents of a file, and they need the ability to make sure
- # that the checksum value is in sync.
+ # Set the checksum, from another property. There are multiple
+ # properties that modify the contents of a file, and they need the
+ # ability to make sure that the checksum value is in sync.
def setchecksum(sum = nil)
- if @states.include? :checksum
+ if @parameters.include? :checksum
if sum
- @states[:checksum].checksum = sum
+ @parameters[:checksum].checksum = sum
else
# If they didn't pass in a sum, then tell checksum to
# figure it out.
- @states[:checksum].retrieve
- @states[:checksum].checksum = @states[:checksum].is
+ @parameters[:checksum].retrieve
+ @parameters[:checksum].checksum = @parameters[:checksum].is
end
end
end
- # Stat our file. Depending on the value of the 'links' attribute, we use
- # either 'stat' or 'lstat', and we expect the states to use the resulting
- # stat object accordingly (mostly by testing the 'ftype' value).
+ # Stat our file. Depending on the value of the 'links' attribute, we
+ # use either 'stat' or 'lstat', and we expect the properties to use the
+ # resulting stat object accordingly (mostly by testing the 'ftype'
+ # value).
def stat(refresh = false)
method = :stat
@@ -936,7 +926,7 @@ module Puppet
end
# We have to hack this just a little bit, because otherwise we'll get
- # an error when the target and the contents are created as states on
+ # an error when the target and the contents are created as properties on
# the far side.
def to_trans
obj = super
@@ -1087,9 +1077,9 @@ module Puppet
attr_accessor :mount, :root, :server, :local
end
- # We put all of the states in separate files, because there are so many
+ # 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 state list.
+ # the order they are in the property list.
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 af3161b9f..09dc016c1 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -3,7 +3,7 @@
# This state never actually modifies the system, it only notices when the system
# changes on its own.
module Puppet
- Puppet.type(:file).newstate(:checksum) do
+ Puppet.type(:file).newproperty(:checksum) do
desc "How to check whether a file has changed. This state is used internally
for file copying, but it can also be used to monitor files somewhat
like Tripwire without managing the file contents in any way. You can
@@ -229,7 +229,7 @@ module Puppet
if @is == :absent
# if they're copying, then we won't worry about the file
# not existing yet
- unless @parent.state(:source)
+ unless @parent.property(:source)
self.warning(
"File %s does not exist -- cannot checksum" %
@parent[:path]
diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb
index e05e639c1..48bf95537 100755
--- a/lib/puppet/type/pfile/content.rb
+++ b/lib/puppet/type/pfile/content.rb
@@ -1,5 +1,5 @@
module Puppet
- Puppet.type(:file).newstate(:content) do
+ Puppet.type(:file).newproperty(:content) do
desc "Specify the contents of a file as a string. Newlines, tabs, and
spaces can be specified using the escaped syntax (e.g., \\n for a
newline). The primary purpose of this parameter is to provide a
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index 2f1113a13..908c07df1 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -32,7 +32,7 @@ module Puppet
with directories corresponding to each directory
and links corresponding to each file."
- # Most 'ensure' states have a default, but with files we, um, don't.
+ # Most 'ensure' properties have a default, but with files we, um, don't.
nodefault
newvalue(:absent) do
@@ -43,8 +43,8 @@ module Puppet
newvalue(:file) do
# Make sure we're not managing the content some other way
- if state = @parent.state(:content) or state = @parent.state(:source)
- state.sync
+ if property = (@parent.property(:content) || @parent.property(:source))
+ property.sync
else
@parent.write(false) { |f| f.flush }
mode = @parent.should(:mode)
@@ -82,10 +82,10 @@ module Puppet
newvalue(:link) do
- if state = @parent.state(:target)
- state.retrieve
+ if property = @parent.property(:target)
+ property.retrieve
- return state.mklink
+ return property.mklink
else
self.fail "Cannot create a symlink without a target"
end
@@ -159,7 +159,7 @@ module Puppet
# There are some cases where all of the work does not get done on
# file creation, so we have to do some extra checking.
@parent.each do |thing|
- next unless thing.is_a? Puppet::State
+ next unless thing.is_a? Puppet::Property
next if thing == self
thing.retrieve
diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb
index fbde811c3..fb032a1ee 100755
--- a/lib/puppet/type/pfile/group.rb
+++ b/lib/puppet/type/pfile/group.rb
@@ -1,6 +1,6 @@
# Manage file group ownership.
module Puppet
- Puppet.type(:file).newstate(:group) do
+ Puppet.type(:file).newproperty(:group) do
require 'etc'
desc "Which group should own the file. Argument can be either group
name or group ID."
diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/pfile/mode.rb
index ee6fb37d8..0a796239e 100755
--- a/lib/puppet/type/pfile/mode.rb
+++ b/lib/puppet/type/pfile/mode.rb
@@ -2,7 +2,7 @@
# for specification (e.g., u+rwx, or -0011), but for now only supports
# specifying the full mode.
module Puppet
- Puppet.type(:file).newstate(:mode) do
+ Puppet.type(:file).newproperty(:mode) do
require 'etc'
desc "Mode the file should be. Currently relatively limited:
you must specify the exact mode the file should be."
@@ -129,6 +129,7 @@ module Puppet
rescue => detail
error = Puppet::Error.new("failed to chmod %s: %s" %
[@parent[:path], detail.message])
+ error.set_backtrace detail.backtrace
raise error
end
return :file_changed
diff --git a/lib/puppet/type/pfile/owner.rb b/lib/puppet/type/pfile/owner.rb
index cca888494..908f25d0f 100755
--- a/lib/puppet/type/pfile/owner.rb
+++ b/lib/puppet/type/pfile/owner.rb
@@ -1,5 +1,5 @@
module Puppet
- Puppet.type(:file).newstate(:owner) do
+ Puppet.type(:file).newproperty(:owner) do
require 'etc'
desc "To whom the file should belong. Argument can be user name or
user ID."
diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb
index 7cbd54fe0..12bb7003e 100755
--- a/lib/puppet/type/pfile/source.rb
+++ b/lib/puppet/type/pfile/source.rb
@@ -6,7 +6,7 @@ module Puppet
# the file down. If the remote file is a dir or a link or whatever, then
# this state, during retrieval, modifies the appropriate other states
# so that things get taken care of appropriately.
- Puppet.type(:file).newstate(:source) do
+ Puppet.type(:file).newproperty(:source) do
PINPARAMS = Puppet::Server::FileServer::CHECKPARAMS
attr_accessor :source, :local
@@ -173,9 +173,7 @@ module Puppet
case @stats[:type]
when "directory", "file":
- if @parent.deleting?
- p @parent.should(:ensure)
- else
+ unless @parent.deleting?
@parent[:ensure] = @stats[:type]
end
else
@@ -196,7 +194,7 @@ module Puppet
# be inherited from the source?
unless @parent.argument?(stat)
@parent[stat] = value
- @parent.state(stat).retrieve
+ @parent.property(stat).retrieve
end
}
@@ -215,7 +213,7 @@ module Puppet
checks.delete(:checksum)
@parent[:check] = checks
- unless @parent.state(:checksum)
+ unless @parent.property(:checksum)
@parent[:checksum] = :md5
end
end
diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/pfile/target.rb
index 8b3a25b49..f6ae0f9c8 100644
--- a/lib/puppet/type/pfile/target.rb
+++ b/lib/puppet/type/pfile/target.rb
@@ -1,5 +1,5 @@
module Puppet
- Puppet.type(:file).newstate(:target) do
+ Puppet.type(:file).newproperty(:target) do
desc "The target for creating a link. Currently, symlinks are the
only type supported."
@@ -12,11 +12,10 @@ module Puppet
newvalue(/./) do
if ! @parent.should(:ensure)
@parent[:ensure] = :link
- elsif @parent.should(:ensure) != :link
- raise Puppet::Error,
- "You cannot specify a target unless 'ensure' is set to 'link'"
end
- if @parent.state(:ensure).insync?
+
+ # Only call mklink if ensure() didn't call us in the first place.
+ if @parent.property(:ensure).insync?
mklink()
end
end
@@ -44,6 +43,14 @@ module Puppet
end
end
+ def insync?
+ if [:nochange, :notlink].include?(self.should) or @parent.should(:ensure) != :link
+ return true
+ else
+ return super
+ end
+ end
+
def retrieve
if stat = @parent.stat
if stat.ftype == "link"
diff --git a/lib/puppet/type/pfile/type.rb b/lib/puppet/type/pfile/type.rb
index e5db7d694..5f720ac9c 100755
--- a/lib/puppet/type/pfile/type.rb
+++ b/lib/puppet/type/pfile/type.rb
@@ -1,5 +1,5 @@
module Puppet
- Puppet.type(:file).newstate(:type) do
+ Puppet.type(:file).newproperty(:type) do
require 'etc'
desc "A read-only state to check the file type."
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 078aff9dd..6f9da3112 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -101,7 +101,9 @@ module Puppet
:Path => self[:path]
)
rescue => detail
- puts detail.backtrace
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
self.fail(
"Could not create local filebucket: %s" % detail
)
diff --git a/lib/puppet/type/port.rb b/lib/puppet/type/port.rb
index 0460c0972..7a0177c12 100755
--- a/lib/puppet/type/port.rb
+++ b/lib/puppet/type/port.rb
@@ -8,7 +8,7 @@ require 'puppet/type/parsedtype'
#
# ensurable
#
-# newstate(:protocols) do
+# newproperty(:protocols) do
# desc "The protocols the port uses. Valid values are *udp* and *tcp*.
# Most services have both protocols, but not all. If you want
# both protocols, you must specify that; Puppet replaces the
@@ -51,18 +51,18 @@ require 'puppet/type/parsedtype'
# end
# end
#
-# newstate(:number) do
+# newproperty(:number) do
# desc "The port number."
# end
#
-# newstate(:description) do
+# newproperty(:description) do
# desc "The port description."
# end
#
-# newstate(:alias) do
+# newproperty(:alias) do
# desc "Any aliases the port might have. Multiple values must be
-# specified as an array. Note that this state has the same name as
-# one of the metaparams; using this state to set aliases will make
+# specified as an array. Note that this property has the same name as
+# one of the metaparams; using this property to set aliases will make
# those aliases available in your Puppet scripts and also on disk."
#
# # We actually want to return the whole array here, not just the first
@@ -89,7 +89,7 @@ require 'puppet/type/parsedtype'
#
# munge do |value|
# unless value == "absent" or value == :absent
-# # Add the :alias metaparam in addition to the state
+# # Add the :alias metaparam in addition to the property
# @parent.newmetaparam(
# @parent.class.metaparamclass(:alias), value
# )
@@ -98,7 +98,7 @@ require 'puppet/type/parsedtype'
# end
# end
#
-# newstate(:target) do
+# newproperty(:target) do
# desc "The file in which to store service information. Only used by
# those providers that write to disk (i.e., not NetInfo)."
#
diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/property.rb
index fab0e5c17..7279ffee7 100644
--- a/lib/puppet/type/state.rb
+++ b/lib/puppet/type/property.rb
@@ -1,13 +1,13 @@
-# The virtual base class for states, 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'
require 'puppet/element'
-require 'puppet/statechange'
+require 'puppet/propertychange'
require 'puppet/parameter'
module Puppet
-class State < Puppet::Parameter
+class Property < Puppet::Parameter
attr_accessor :is
# Because 'should' uses an array, we have a special method for handling
@@ -68,7 +68,7 @@ class State < Puppet::Parameter
@parameteroptions = {}
end
- # Define a new valid value for a state. You must provide the value itself,
+ # Define a new valid value for a property. You must provide the value itself,
# usually as a symbol, or a regex to match the value.
#
# The first argument to the method is either the value itself or a regex.
@@ -168,7 +168,7 @@ class State < Puppet::Parameter
return event, name
end
- # How should a state change be printed as a string?
+ # How should a property change be printed as a string?
def change_to_s
begin
if @is == :absent
@@ -213,27 +213,14 @@ class State < Puppet::Parameter
return event
end
- # initialize our state
- def initialize(hash)
- super()
+ # initialize our property
+ def initialize(hash = {})
@is = nil
-
- unless hash.include?(:parent)
- self.devfail "State %s was not passed a parent" % self
- end
- @parent = hash[:parent]
-
- if hash.include?(:should)
- self.should = hash[:should]
- end
-
- if hash.include?(:is)
- self.is = hash[:is]
- end
+ super
end
def inspect
- str = "State('%s', " % self.name
+ str = "Property('%s', " % self.name
if self.is
str += "@is = '%s', " % [self.is]
else
@@ -247,9 +234,9 @@ class State < Puppet::Parameter
end
end
- # Determine whether the state is in-sync or not. If @should is
+ # Determine whether the property is in-sync or not. If @should is
# not defined or is set to a non-true value, then we do not have
- # a valid value for it and thus consider the state to be in-sync
+ # a valid value for it and thus consider the property to be in-sync
# 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.
@@ -282,7 +269,7 @@ class State < Puppet::Parameter
# because the @should and @is vars might be in weird formats,
# we need to set up a mechanism for pretty printing of the values
- # default to just the values, but this way individual states can
+ # default to just the values, but this way individual properties can
# override these methods
def is_to_s
@is
@@ -301,10 +288,10 @@ class State < Puppet::Parameter
)
end
- # each state class must define the name() method, and state instances
+ # each property class must define the name() method, and property instances
# do not change that name
- # this implicitly means that a given object can only have one state
- # instance of a given state class
+ # this implicitly means that a given object can only have one property
+ # instance of a given property class
def name
return self.class.name
end
@@ -325,8 +312,8 @@ class State < Puppet::Parameter
@parent.provider || @parent
end
- # By default, call the method associated with the state name on our
- # provider. In other words, if the state name is 'gid', we'll call
+ # By default, call the method associated with the property name on our
+ # 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)
@@ -422,7 +409,7 @@ class State < Puppet::Parameter
end
end
- # The states need to return tags so that logs correctly collect them.
+ # The properties need to return tags so that logs correctly collect them.
def tags
unless defined? @tags
@tags = []
@@ -439,9 +426,14 @@ class State < Puppet::Parameter
return "%s(%s)" % [@parent.name,self.name]
end
- # This state will get automatically added to any type that responds
+ # Provide a common hook for setting @should, just like params.
+ def value=(value)
+ self.should = value
+ end
+
+ # This property will get automatically added to any type that responds
# to the methods 'exists?', 'create', and 'destroy'.
- class Ensure < Puppet::State
+ class Ensure < Puppet::Property
@name = :ensure
def self.defaultvalues
@@ -472,11 +464,11 @@ class State < Puppet::Parameter
end
# This doc will probably get overridden
- @doc ||= "The basic state that the object should be in."
+ @doc ||= "The basic property that the object should be in."
end
def self.inherited(sub)
- # Add in the two states that everyone will have.
+ # Add in the two properties that everyone will have.
sub.class_eval do
end
end
@@ -501,8 +493,8 @@ class State < Puppet::Parameter
def retrieve
# XXX This is a problem -- whether the object exists or not often
- # depends on the results of other states, yet we're the first state
- # to get checked, which means that those other states do not have
+ # depends on the results of other properties, yet we're the first property
+ # to get checked, which means that those other properties do not have
# @is values set. This seems to be the source of quite a few bugs,
# although they're mostly logging bugs, not functional ones.
if prov = @parent.provider and prov.respond_to?(:exists?)
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index 3f9681826..ea944d6b7 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -34,7 +34,7 @@ Puppet::Type.newtype(:resources) do
unless @parent.resource_type.respond_to?(:list)
raise ArgumentError, "Purging resources of type %s is not supported, since they cannot be listed" % @parent[:name]
end
- unless @parent.resource_type.validstate?(:ensure)
+ unless @parent.resource_type.validproperty?(:ensure)
raise ArgumentError, "Purging is only supported on types that accept 'ensure'"
end
end
@@ -103,7 +103,8 @@ Puppet::Type.newtype(:resources) do
[self[:name]]
return []
end
- @metaparams.each do |name, param|
+ @parameters.each do |name, param|
+ next unless param.metaparam?
resource[name] = param.value
end
end
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index a329686ef..e664a6e0c 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -43,8 +43,6 @@ module Puppet
This will cause elements to be applied every 30 minutes by default.
"
- @states = []
-
newparam(:name) do
desc "The name of the schedule. This name is used to retrieve the
schedule when assigning it to an object:
@@ -76,7 +74,7 @@ module Puppet
This is mostly useful for restricting certain elements to being
applied in maintenance windows or during off-peak hours."
- # This is lame; states all use arrays as values, but parameters don't.
+ # This is lame; properties all use arrays as values, but parameters don't.
# That's going to hurt eventually.
validate do |values|
values = [values] unless values.is_a?(Array)
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index c8726e4da..182831392 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -19,10 +19,10 @@ module Puppet
attr_reader :stat
- newstate(:enable) do
+ newproperty(:enable) do
attr_reader :runlevel
desc "Whether a service should be enabled to start at boot.
- This state behaves quite differently depending on the platform;
+ This property behaves quite differently depending on the platform;
wherever possible, it relies on local tools to enable or disable
a given service. *true*/*false*/*runlevels*"
@@ -93,7 +93,7 @@ module Puppet
end
# Handle whether the service should actually be running right now.
- newstate(:ensure) do
+ newproperty(:ensure) do
desc "Whether a service should be running. **true**/*false*"
newvalue(:stopped, :event => :service_stopped) do
@@ -125,10 +125,10 @@ module Puppet
# self
# end
- if state = @parent.state(:enable)
- state.retrieve
- unless state.insync?
- state.sync
+ if property = @parent.property(:enable)
+ property.retrieve
+ unless property.insync?
+ property.sync
end
end
diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb
index a9236d057..f6622c510 100755
--- a/lib/puppet/type/sshkey.rb
+++ b/lib/puppet/type/sshkey.rb
@@ -6,7 +6,7 @@ module Puppet
ensurable
- newstate(:type) do
+ newproperty(:type) do
desc "The encryption type used. Probably ssh-dss or ssh-rsa."
newvalue("ssh-dss")
@@ -15,17 +15,19 @@ module Puppet
aliasvalue(:rsa, "ssh-rsa")
end
- newstate(:key) do
+ newproperty(:key) do
desc "The key itself; generally a long string of hex digits."
end
# FIXME This should automagically check for aliases to the hosts, just
# to see if we can automatically glean any aliases.
- newstate(:alias) do
+ newproperty(:alias) do
desc "Any alias the host might have. Multiple values must be
- specified as an array. Note that this state has the same name
- as one of the metaparams; using this state to set aliases will
+ specified as an array. Note that this parameter has the same name
+ as one of the metaparams; using this parameter to set aliases will
make those aliases available in your Puppet scripts."
+
+ attr_accessor :meta
def insync?
@is == @should
@@ -49,15 +51,6 @@ module Puppet
raise Puppet::Error, "Aliases cannot include whitespace"
end
end
-
- # Make a puppet alias in addition.
- munge do |value|
- unless value == :absent
- # Add the :alias metaparam in addition to the state
- @parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
- end
- value
- end
end
newparam(:name) do
@@ -66,7 +59,7 @@ module Puppet
isnamevar
end
- newstate(:target) do
+ newproperty(:target) do
desc "The file in which to store the mount table. Only used by
those providers that write to disk (i.e., not NetInfo)."
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index cc3258766..bc622f682 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -1,6 +1,6 @@
require 'etc'
-require 'puppet/type/state'
+require 'puppet/type/property'
require 'puppet/type/pfile'
module Puppet
@@ -17,7 +17,7 @@ module Puppet
copyparam(Puppet.type(:file), :backup)
- newstate(:ensure) do
+ newproperty(:ensure) do
desc "An internal attribute used to determine which files should be removed."
require 'etc'
@@ -25,7 +25,7 @@ module Puppet
TATTRS = [:age, :size]
- defaultto :anything # just so we always get this state
+ defaultto :anything # just so we always get this property
def change_to_s
start = "Tidying"
@@ -49,8 +49,8 @@ module Puppet
else
@out = []
TATTRS.each do |param|
- if state = @parent.state(param)
- unless state.insync?
+ if property = @parent.property(param)
+ unless property.insync?
@out << param
end
end
@@ -76,8 +76,8 @@ module Puppet
end
TATTRS.each { |param|
- if state = @parent.state(param)
- state.is = state.assess(stat)
+ if property = @parent.property(param)
+ property.is = property.assess(stat)
end
}
end
@@ -115,7 +115,7 @@ module Puppet
end
end
- newstate(:age) do
+ newproperty(:age) do
desc "Tidy files whose age is equal to or greater than
the specified time. You can choose seconds, minutes,
hours, days, or weeks by specifying the first letter of any
@@ -175,7 +175,7 @@ module Puppet
end
end
- newstate(:size) do
+ newproperty(:size) do
desc "Tidy files whose size is equal to or greater than
the specified size. Unqualified values are in kilobytes, but
*b*, *k*, and *m* can be appended to specify *bytes*, *kilobytes*,
@@ -261,8 +261,8 @@ module Puppet
def initialize(hash)
super
- unless @states.include?(:age) or
- @states.include?(:size)
+ unless @parameters.include?(:age) or
+ @parameters.include?(:size)
unless FileTest.directory?(self[:path])
# don't do size comparisons for directories
self.fail "Tidy must specify size, age, or both"
@@ -276,12 +276,12 @@ module Puppet
end
def retrieve
- # Our ensure state knows how to retrieve everything for us.
- @states[:ensure].retrieve
+ # Our ensure property knows how to retrieve everything for us.
+ obj = @parameters[:ensure] and obj.retrieve
end
- # Hack things a bit so we only ever check the ensure state.
- def states
+ # Hack things a bit so we only ever check the ensure property.
+ def properties
[]
end
end
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index e27436c68..fa0344931 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -1,29 +1,29 @@
require 'etc'
require 'facter'
-require 'puppet/type/state'
+require 'puppet/type/property'
module Puppet
newtype(:user) do
- newstate(:ensure) do
+ newproperty(:ensure) do
newvalue(:present, :event => :user_created) do
# Verify that they have provided everything necessary, if we
# are trying to manage the user
# if @parent.managed?
-# @parent.class.states.each { |state|
-# next if stateobj = @parent.state(state.name)
-# next if state.name == :ensure
+# @parent.class.properties.each { |property|
+# next if propertyobj = @parent.property(property.name)
+# next if property.name == :ensure
#
-# unless state.autogen? or state.isoptional?
-# if state.method_defined?(:autogen)
-# @parent[state.name] = :auto
+# unless property.autogen? or property.isoptional?
+# if property.method_defined?(:autogen)
+# @parent[property.name] = :auto
# else
# @parent.fail "Users require a value for %s" %
-# state.name
+# property.name
# end
# end
# }
#
-# #if @states.empty?
+# #if @properties.empty?
# # @parent[:comment] = @parent[:name]
# #end
# end
@@ -93,7 +93,7 @@ module Puppet
end
- newstate(:uid) do
+ newproperty(:uid) do
desc "The user ID. Must be specified numerically. For new users
being created, if no user ID is specified then one will be
chosen automatically, which will likely result in the same user
@@ -114,7 +114,7 @@ module Puppet
end
end
- newstate(:gid) do
+ newproperty(:gid) do
desc "The user's primary group. Can be specified numerically or
by name."
@@ -164,21 +164,21 @@ module Puppet
end
end
- newstate(:comment) do
+ newproperty(:comment) do
desc "A description of the user. Generally is a user's full name."
end
- newstate(:home) do
+ newproperty(:home) do
desc "The home directory of the user. The directory must be created
separately and is not currently checked for existence."
end
- newstate(:shell) do
+ newproperty(:shell) do
desc "The user's login shell. The shell must exist and be
executable."
end
- newstate(:groups) do
+ newproperty(:groups) do
desc "The groups of which the user is a member. The primary
group should not be listed. Multiple groups should be
specified as an array."
@@ -243,24 +243,24 @@ module Puppet
end
end
- # these three states are all implemented differently on each platform,
+ # these three properties are all implemented differently on each platform,
# so i'm disabling them for now
- # FIXME Puppet::State::UserLocked is currently non-functional
- #newstate(:locked) do
+ # FIXME Puppet::Property::UserLocked is currently non-functional
+ #newproperty(:locked) do
# desc "The expected return code. An error will be returned if the
# executed command returns something else."
#end
- # FIXME Puppet::State::UserExpire is currently non-functional
- #newstate(:expire) do
+ # FIXME Puppet::Property::UserExpire is currently non-functional
+ #newproperty(:expire) do
# desc "The expected return code. An error will be returned if the
# executed command returns something else."
# @objectaddflag = "-e"
#end
- # FIXME Puppet::State::UserInactive is currently non-functional
- #newstate(:inactive) do
+ # FIXME Puppet::Property::UserInactive is currently non-functional
+ #newproperty(:inactive) do
# desc "The expected return code. An error will be returned if the
# executed command returns something else."
# @objectaddflag = "-f"
@@ -307,11 +307,9 @@ module Puppet
# Autorequire the group, if it's around
autorequire(:group) do
- #return nil unless @states.include?(:gid)
- #return nil unless groups = @states[:gid].shouldorig
autos = []
- if @states.include?(:gid) and groups = @states[:gid].shouldorig
+ if obj = @parameters[:gid] and groups = obj.shouldorig
groups = groups.collect { |group|
if group =~ /^\d+$/
Integer(group)
@@ -334,7 +332,7 @@ module Puppet
}
end
- if @states.include?(:groups) and groups = @states[:groups].should
+ if obj = @parameters[:groups] and groups = obj.should
autos += groups.split(",")
end
@@ -359,27 +357,18 @@ module Puppet
def retrieve
absent = false
- states().each { |state|
+ properties().each { |property|
if absent
- state.is = :absent
+ property.is = :absent
else
- state.retrieve
+ property.retrieve
end
- if state.name == :ensure and state.is == :absent
+ if property.name == :ensure and property.is == :absent
absent = true
next
end
}
- #if provider.exists?
- # super
- #else
- # # the user does not exist
- # @states.each { |name, state|
- # state.is = :absent
- # }
- # return
- #end
end
end
end
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index de2c13f2f..b7a1ff5e7 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -1,16 +1,14 @@
# Description of yum repositories
-require 'puppet/statechange'
+require 'puppet/propertychange'
require 'puppet/inifile'
require 'puppet/type/parsedtype'
module Puppet
-
- # A state for one entry in a .ini-style file
- class IniState < Puppet::State
-
+ # A property for one entry in a .ini-style file
+ class IniProperty < Puppet::Property
def insync?
- # A should state of :absent is the same as nil
+ # A should property of :absent is the same as nil
if is.nil? && (should.nil? || should == :absent)
return true
end
@@ -39,8 +37,8 @@ module Puppet
name.to_s
end
- # Set the key associated with this state to KEY, instead
- # of using the state's NAME
+ # Set the key associated with this property to KEY, instead
+ # of using the property's NAME
def self.inikey(key)
# Override the inikey instance method
# Is there a way to do this without resorting to strings ?
@@ -51,7 +49,7 @@ module Puppet
end
- # Doc string for states that can be made 'absent'
+ # Doc string for properties that can be made 'absent'
ABSENT_DOC="Set this to 'absent' to remove it from the file completely"
newtype(:yumrepo) do
@@ -85,17 +83,17 @@ module Puppet
def self.list
l = []
- check = validstates
+ check = validproperties
clear
inifile.each_section do |s|
next if s.name == "main"
obj = create(:name => s.name, :check => check)
obj.retrieve
- obj.eachstate do |state|
- if state.is.nil?
- obj.delete(state.name)
+ obj.eachproperty do |property|
+ if property.is.nil?
+ obj.delete(property.name)
else
- state.should = state.is
+ property.should = property.is
end
end
obj.delete(:check)
@@ -203,16 +201,16 @@ module Puppet
# writing the whole file
# A cleaner solution would be to either use the composite
# pattern and encapsulate all changes into a change that does
- # not depend on a state and triggers storing, or insert another
+ # not depend on a property and triggers storing, or insert another
# change at the end of changes to trigger storing Both
- # solutions require that the StateChange interface be
+ # solutions require that the PropertyChange interface be
# abstracted so that it can work with a change that is not
- # directly backed by a State
+ # directly backed by a Property
unless changes.empty?
class << changes[-1]
def go
result = super
- self.state.parent.store
+ self.property.parent.store
return result
end
end
@@ -230,7 +228,7 @@ module Puppet
isnamevar
end
- newstate(:descr, :parent => Puppet::IniState) do
+ newproperty(:descr, :parent => Puppet::IniProperty) do
desc "A human readable description of the repository.
#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
@@ -238,7 +236,7 @@ module Puppet
inikey "name"
end
- newstate(:mirrorlist, :parent => Puppet::IniState) do
+ newproperty(:mirrorlist, :parent => Puppet::IniProperty) do
desc "The URL that holds the list of mirrors for this repository.
#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
@@ -246,21 +244,21 @@ module Puppet
newvalue(/.*/) { }
end
- newstate(:baseurl, :parent => Puppet::IniState) do
+ newproperty(:baseurl, :parent => Puppet::IniProperty) do
desc "The URL for this repository.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
# Should really check that it's a valid URL
newvalue(/.*/) { }
end
- newstate(:enabled, :parent => Puppet::IniState) do
+ newproperty(:enabled, :parent => Puppet::IniProperty) do
desc "Whether this repository is enabled or disabled. Possible
values are '0', and '1'.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
newvalue(%r{(0|1)}) { }
end
- newstate(:gpgcheck, :parent => Puppet::IniState) do
+ newproperty(:gpgcheck, :parent => Puppet::IniProperty) do
desc "Whether to check the GPG signature on packages installed
from this repository. Possible values are '0', and '1'.
\n#{ABSENT_DOC}"
@@ -268,7 +266,7 @@ module Puppet
newvalue(%r{(0|1)}) { }
end
- newstate(:gpgkey, :parent => Puppet::IniState) do
+ newproperty(:gpgkey, :parent => Puppet::IniProperty) do
desc "The URL for the GPG key with which packages from this
repository are signed.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
@@ -276,14 +274,14 @@ module Puppet
newvalue(/.*/) { }
end
- newstate(:include, :parent => Puppet::IniState) do
+ newproperty(:include, :parent => Puppet::IniProperty) do
desc "A URL from which to include the config.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
# Should really check that it's a valid URL
newvalue(/.*/) { }
end
- newstate(:exclude, :parent => Puppet::IniState) do
+ newproperty(:exclude, :parent => Puppet::IniProperty) do
desc "List of shell globs. Matching packages will never be
considered in updates or installs for this repo.
#{ABSENT_DOC}"
@@ -291,7 +289,7 @@ module Puppet
newvalue(/.*/) { }
end
- newstate(:includepkgs, :parent => Puppet::IniState) do
+ newproperty(:includepkgs, :parent => Puppet::IniProperty) do
desc "List of shell globs. If this is set, only packages
matching one of the globs will be considered for
update or install.\n#{ABSENT_DOC}"
@@ -299,7 +297,7 @@ module Puppet
newvalue(/.*/) { }
end
- newstate(:enablegroups, :parent => Puppet::IniState) do
+ newproperty(:enablegroups, :parent => Puppet::IniProperty) do
desc "Determines whether yum will allow the use of
package groups for this repository. Possible
values are '0', and '1'.\n#{ABSENT_DOC}"
@@ -307,27 +305,27 @@ module Puppet
newvalue(%r{(0|1)}) { }
end
- newstate(:failovermethod, :parent => Puppet::IniState) do
+ newproperty(:failovermethod, :parent => Puppet::IniProperty) do
desc "Either 'roundrobin' or 'priority'.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
newvalue(%r(roundrobin|priority)) { }
end
- newstate(:keepalive, :parent => Puppet::IniState) do
+ newproperty(:keepalive, :parent => Puppet::IniProperty) do
desc "Either '1' or '0'. This tells yum whether or not HTTP/1.1
keepalive should be used with this repository.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
newvalue(%r{(0|1)}) { }
end
- newstate(:timeout, :parent => Puppet::IniState) do
+ newproperty(:timeout, :parent => Puppet::IniProperty) do
desc "Number of seconds to wait for a connection before timing
out.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
newvalue(%r{[0-9]+}) { }
end
- newstate(:metadata_expire, :parent => Puppet::IniState) do
+ newproperty(:metadata_expire, :parent => Puppet::IniProperty) do
desc "Number of seconds after which the metadata will expire.
#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index 30051d52e..acae0d8b5 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -1,18 +1,18 @@
Puppet::Type.newtype(:zone) do
@doc = "Solaris zones."
- # These states modify the zone configuration, and they need to provide
+ # These properties modify the zone configuration, and they need to provide
# the text separately from syncing it, so all config statements can be rolled
# into a single creation statement.
- class ZoneConfigState < Puppet::State
+ class ZoneConfigProperty < Puppet::Property
# Perform the config operation.
def sync
provider.setconfig self.configtext
end
end
- # Those states that can have multiple instances.
- class ZoneMultiConfigState < ZoneConfigState
+ # Those properties that can have multiple instances.
+ class ZoneMultiConfigProperty < ZoneConfigProperty
def configtext
list = @should
@@ -72,7 +72,7 @@ Puppet::Type.newtype(:zone) do
only then can be ``running``. Note also that ``halt`` is currently
used to stop zones."
- @states = {}
+ @properties = {}
def self.newvalue(name, hash)
if @parametervalues.is_a? Hash
@@ -81,7 +81,7 @@ Puppet::Type.newtype(:zone) do
@parametervalues << name
- @states[name] = hash
+ @properties[name] = hash
hash[:name] = name
end
@@ -112,11 +112,11 @@ Puppet::Type.newtype(:zone) do
# the range op twice.
if findex > sindex
list = @parametervalues[sindex..findex].collect do |name|
- @states[name]
+ @properties[name]
end.reverse
else
list = @parametervalues[findex..sindex].collect do |name|
- @states[name]
+ @properties[name]
end
end
@@ -141,8 +141,8 @@ Puppet::Type.newtype(:zone) do
# everything between it and us.
states = self.class.valueslice(self.is, self.should)
- states.each do |st|
- if method = st[dir]
+ properties.each do |prop|
+ if method = prop[dir]
warned = false
while @parent.processing?
unless warned
@@ -161,7 +161,7 @@ Puppet::Type.newtype(:zone) do
return ("zone_" + self.should.to_s).intern
end
- # Are we moving up the state tree?
+ # Are we moving up the property tree?
def up?
self.class.valueindex(self.is) < self.class.valueindex(self.should)
end
@@ -178,7 +178,7 @@ Puppet::Type.newtype(:zone) do
and cannot be changed."
end
- newstate(:ip, :parent => ZoneMultiConfigState) do
+ newproperty(:ip, :parent => ZoneMultiConfigProperty) do
require 'ipaddr'
desc "The IP address of the zone. IP addresses must be specified
@@ -225,7 +225,7 @@ end
end
end
- newstate(:autoboot, :parent => ZoneConfigState) do
+ newproperty(:autoboot, :parent => ZoneConfigProperty) do
desc "Whether the zone should automatically boot."
defaultto true
@@ -238,7 +238,7 @@ end
end
end
- newstate(:pool, :parent => ZoneConfigState) do
+ newproperty(:pool, :parent => ZoneConfigProperty) do
desc "The resource pool for this zone."
def configtext
@@ -246,7 +246,7 @@ end
end
end
- newstate(:shares, :parent => ZoneConfigState) do
+ newproperty(:shares, :parent => ZoneConfigProperty) do
desc "Number of FSS CPU shares allocated to the zone."
def configtext
@@ -254,7 +254,7 @@ end
end
end
- newstate(:inherit, :parent => ZoneMultiConfigState) do
+ newproperty(:inherit, :parent => ZoneMultiConfigProperty) do
desc "The list of directories that the zone inherits from the global
zone. All directories must be fully qualified."
@@ -362,9 +362,9 @@ set zonepath=%s
} % self[:path]
# Then perform all of our configuration steps.
- @states.each do |name, state|
- if state.is_a? ZoneConfigState and ! state.insync?
- str += state.configtext + "\n"
+ properties().each do |property|
+ if property.is_a? ZoneConfigProperty and ! property.insync?
+ str += property.configtext + "\n"
end
end
@@ -373,7 +373,7 @@ set zonepath=%s
end
# We need a way to test whether a zone is in process. Our 'ensure'
- # state models the static states, but we need to handle the temporary ones.
+ # property models the static states, but we need to handle the temporary ones.
def processing?
if hash = provider.statushash()
case hash[:ensure]
@@ -394,8 +394,8 @@ set zonepath=%s
# Now retrieve the configuration itself and set appropriately.
config2status(provider.getconfig())
else
- @states.each do |name, state|
- state.is = :absent
+ properties().each do |pr|
+ pr.is = :absent
end
end
end
@@ -405,7 +405,7 @@ set zonepath=%s
hash.each do |param, value|
next if param == :name
case self.class.attrtype(param)
- when :state:
+ when :pr:
self.is = [param, value]
else
self[param] = value
diff --git a/test/certmgr/certmgr.rb b/test/certmgr/certmgr.rb
index 561012c12..ea4ce19bd 100755
--- a/test/certmgr/certmgr.rb
+++ b/test/certmgr/certmgr.rb
@@ -119,7 +119,7 @@ class TestCertMgr < Test::Unit::TestCase
assert_nothing_raised {
cert = Puppet::SSLCertificates::Certificate.new(
:name => "signedcertest",
- :state => "TN",
+ :property => "TN",
:city => "Nashville",
:country => "US",
:email => "luke@madstop.com",
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index c82a124bd..2438083b0 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -70,8 +70,8 @@ class TestSnippets < Test::Unit::TestCase
objs = scope2objs(scope)
end
- def states(type)
- states = type.validstates
+ def properties(type)
+ properties = type.validproperties
end
def metaparams(type)
@@ -85,7 +85,7 @@ class TestSnippets < Test::Unit::TestCase
def params(type)
params = []
- type.parameters.each { |name,state|
+ type.parameters.each { |name,property|
params.push name
}
@@ -98,7 +98,7 @@ class TestSnippets < Test::Unit::TestCase
end
def randeach(type)
- [:states, :metaparams, :params].collect { |thing|
+ [:properties, :metaparams, :params].collect { |thing|
randthing(thing,type)
}
end
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index 137042d7f..ca47268c8 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -13,12 +13,12 @@ module PuppetTest
@realmodel.namevar
end
- def self.validstates
- Puppet::Type.type(@name).validstates
+ def self.validproperties
+ Puppet::Type.type(@name).validproperties
end
- def self.validstate?(name)
- Puppet::Type.type(@name).validstate?(name)
+ def self.validproperty?(name)
+ Puppet::Type.type(@name).validproperty?(name)
end
def self.to_s
@@ -26,7 +26,7 @@ module PuppetTest
end
def [](param)
- if @realmodel.attrtype(param) == :state
+ if @realmodel.attrtype(param) == :property
@is[param]
else
@params[param]
@@ -39,7 +39,7 @@ module PuppetTest
raise Puppet::DevError, "Invalid attribute %s for %s" %
[param, @realmodel.name]
end
- if @realmodel.attrtype(param) == :state
+ if @realmodel.attrtype(param) == :property
@should[param] = value
else
@params[param] = value
@@ -96,8 +96,8 @@ module PuppetTest
# Set up methods to fake things
def self.apimethods(*ary)
- @model.validstates.each do |state|
- ary << state unless ary.include? state
+ @model.validproperties.each do |property|
+ ary << property unless ary.include? property
end
attr_accessor(*ary)
diff --git a/test/other/log.rb b/test/other/log.rb
index 6cf6da2d9..3c720ca15 100755
--- a/test/other/log.rb
+++ b/test/other/log.rb
@@ -136,13 +136,13 @@ class TestLog < Test::Unit::TestCase
)
file.tags = %w{this is a test}
- state = file.state(:ensure)
- assert(state, "Did not get state")
+ property = file.property(:ensure)
+ assert(property, "Did not get property")
log = nil
assert_nothing_raised {
log = Puppet::Log.new(
:level => :info,
- :source => state,
+ :source => property,
:message => "A test message"
)
}
@@ -157,8 +157,8 @@ class TestLog < Test::Unit::TestCase
assert(msg.tagged?(tag), "Was not tagged with %s" % tag)
end
- assert_equal(msg.tags, state.tags, "Tags were not equal")
- assert_equal(msg.source, state.path, "Source was not set correctly")
+ assert_equal(msg.tags, property.tags, "Tags were not equal")
+ assert_equal(msg.source, property.path, "Source was not set correctly")
end
end
diff --git a/test/other/statechange.rb b/test/other/propertychange.rb
index 5f6438c57..75c6056de 100755
--- a/test/other/statechange.rb
+++ b/test/other/propertychange.rb
@@ -7,9 +7,9 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppettest'
-class TestStateChange < Test::Unit::TestCase
+class TestPropertyChange < Test::Unit::TestCase
include PuppetTest
- class FakeState
+ class FakeProperty
attr_accessor :is, :should, :parent
def change_to_s
"fake change"
@@ -44,13 +44,13 @@ class TestStateChange < Test::Unit::TestCase
end
def mkchange
- state = FakeState.new
- state.is = :start
- state.should = :finish
- state.parent = :parent
+ property = FakeProperty.new
+ property.is = :start
+ property.should = :finish
+ property.parent = :parent
change = nil
assert_nothing_raised do
- change = Puppet::StateChange.new(state)
+ change = Puppet::PropertyChange.new(property)
end
change.transaction = :trans
@@ -83,14 +83,14 @@ class TestStateChange < Test::Unit::TestCase
# Disabled, because it fails when running the whole suite at once.
#assert(coll.detect { |l| l.message == "fake change" }, "Did not log change")
- assert_equal(change.state.is, change.state.should, "did not call sync method")
+ assert_equal(change.property.is, change.property.should, "did not call sync method")
# Now make sure that proxy sources can be set.
assert_nothing_raised do
change.proxy = :other
end
# Reset, so we change again
- change.state.is = :start
+ change.property.is = :start
change.is = :start
assert_nothing_raised do
events = change.go
@@ -105,7 +105,7 @@ class TestStateChange < Test::Unit::TestCase
end
#assert(coll.detect { |l| l.message == "fake change" }, "Did not log change")
- assert_equal(change.state.is, change.state.should, "did not call sync method")
+ assert_equal(change.property.is, change.property.should, "did not call sync method")
end
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 6901abe73..3b6333306 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -224,7 +224,7 @@ class TestTransactions < Test::Unit::TestCase
transaction = nil
file = newfile()
- states = {}
+ properties = {}
check = [:group,:mode]
file[:check] = check
@@ -233,9 +233,9 @@ class TestTransactions < Test::Unit::TestCase
}
assert_nothing_raised() {
- check.each { |state|
- assert(file[state])
- states[state] = file[state]
+ check.each { |property|
+ assert(file[property])
+ properties[property] = file[property]
}
}
@@ -261,9 +261,9 @@ class TestTransactions < Test::Unit::TestCase
assert_nothing_raised() {
file.retrieve
}
- states.each { |state,value|
+ properties.each { |property,value|
assert_equal(
- value,file.is(state), "File %s remained %s" % [state, file.is(state)]
+ value,file.is(property), "File %s remained %s" % [property, file.is(property)]
)
}
end
@@ -275,7 +275,7 @@ class TestTransactions < Test::Unit::TestCase
file = newfile()
execfile = File.join(tmpdir(), "exectestingness")
exec = newexec(execfile)
- states = {}
+ properties = {}
check = [:group,:mode]
file[:check] = check
file[:group] = @groups[0]
@@ -295,8 +295,8 @@ class TestTransactions < Test::Unit::TestCase
exec.retrieve
}
- check.each { |state|
- states[state] = file[state]
+ check.each { |property|
+ properties[property] = file[property]
}
assert_nothing_raised() {
file[:mode] = "755"
@@ -322,7 +322,7 @@ class TestTransactions < Test::Unit::TestCase
execfile = File.join(tmpdir(), "exectestingness2")
@@tmpfiles << execfile
exec = newexec(execfile)
- states = {}
+ properties = {}
check = [:group,:mode]
file[:check] = check
file[:group] = @groups[0]
@@ -773,14 +773,14 @@ class TestTransactions < Test::Unit::TestCase
# Make sure changes generated by eval_generated resources have proxies
# set to the top-level resource.
def test_proxy_resources
- Struct.new("FakeEvalState", :path, :is, :should, :name)
- Struct::FakeEvalState.send(:define_method, :insync?) { true }
- Struct::FakeEvalState.send(:define_method, :info) { |*args| false }
+ Struct.new("FakeEvalProperty", :path, :is, :should, :name)
+ Struct::FakeEvalProperty.send(:define_method, :insync?) { true }
+ Struct::FakeEvalProperty.send(:define_method, :info) { |*args| false }
type = mkreducer do
def evaluate
- return Puppet::StateChange.new(Struct::FakeEvalState.new(:path, :is, :should, self.name))
+ return Puppet::PropertyChange.new(Struct::FakeEvalProperty.new(:path, :is, :should, self.name))
end
end
@@ -1015,7 +1015,7 @@ class TestTransactions < Test::Unit::TestCase
type = Puppet::Type.newtype(:refresher, :self_refresh => true) do
attr_accessor :refreshed, :testing
newparam(:name) {}
- newstate(:testing) do
+ newproperty(:testing) do
def sync
self.is = self.should
:ran_testing
diff --git a/test/providers/group.rb b/test/providers/group.rb
index 8779073bb..1333f28b7 100755
--- a/test/providers/group.rb
+++ b/test/providers/group.rb
@@ -193,7 +193,7 @@ class TestGroupProvider < Test::Unit::TestCase
}
assert(!missing?(name), "Group %s is missing" % name)
- tests = Puppet.type(:group).validstates
+ tests = Puppet.type(:group).validproperties
tests.each { |test|
if self.respond_to?("attrtest_%s" % test)
diff --git a/test/providers/host/parsed.rb b/test/providers/host/parsed.rb
index 6f7d36b8c..d0b072e7d 100755
--- a/test/providers/host/parsed.rb
+++ b/test/providers/host/parsed.rb
@@ -217,7 +217,7 @@ class TestParsedHostProvider < Test::Unit::TestCase
hosts.each { |host|
name = host.model[:name]
assert(text.include?(name), "Host %s is not in file" % name)
- hash = host.state_hash
+ hash = host.property_hash
assert(! hash.empty?, "Could not find host %s" % name)
assert(hash[:ip], "Could not find ip for host %s" % name)
}
diff --git a/test/providers/mount/netinfo.rb b/test/providers/mount/netinfo.rb
index fcd814264..1ee09e7da 100755
--- a/test/providers/mount/netinfo.rb
+++ b/test/providers/mount/netinfo.rb
@@ -44,7 +44,7 @@ require 'puppettest'
# def test_simple
# root = nil
# assert_nothing_raised do
-# root = @mount.create :name => "/", :check => @mount.validstates
+# root = @mount.create :name => "/", :check => @mount.validproperties
# end
#
# assert_nothing_raised do
@@ -77,4 +77,4 @@ require 'puppettest'
# end
# end
-# $Id$ \ No newline at end of file
+# $Id$
diff --git a/test/providers/mount/parsed.rb b/test/providers/mount/parsed.rb
index c062960f3..9e9aec72e 100755
--- a/test/providers/mount/parsed.rb
+++ b/test/providers/mount/parsed.rb
@@ -58,7 +58,7 @@ class TestParsedMounts < Test::Unit::TestCase
assert(mount, "Could not create provider mount")
hash[:record_type] = :parsed
hash[:ensure] = :present
- mount.state_hash = hash
+ mount.property_hash = hash
return mount
end
@@ -104,7 +104,7 @@ class TestParsedMounts < Test::Unit::TestCase
# Make sure it's now in the file. The file format is validated in
# the isomorphic methods.
assert(@provider.target_object(target).read.include?("\t%s\t" %
- mount.state_hash[:name]), "Mount was not written to disk")
+ mount.property_hash[:name]), "Mount was not written to disk")
# now make a change
assert_nothing_raised { mount.dump = 5 }
@@ -138,7 +138,7 @@ class TestParsedMounts < Test::Unit::TestCase
@provider.prefetch
end
- assert_equal(:present, provider.state_hash[:ensure],
+ assert_equal(:present, provider.property_hash[:ensure],
"Could not find root fs with provider %s" % provider.name)
assert_nothing_raised {
diff --git a/test/providers/parsedfile.rb b/test/providers/parsedfile.rb
index 252bf26b2..952626001 100755
--- a/test/providers/parsedfile.rb
+++ b/test/providers/parsedfile.rb
@@ -15,11 +15,11 @@ class TestParsedFile < Test::Unit::TestCase
Puppet::Type.newtype(:testparsedfiletype) do
ensurable
- newstate(:one) do
+ newproperty(:one) do
newvalue(:a)
newvalue(:b)
end
- newstate(:two) do
+ newproperty(:two) do
newvalue(:c)
newvalue(:d)
end
@@ -455,7 +455,7 @@ class TestParsedFile < Test::Unit::TestCase
"Mover was not removed from first file")
end
- # Make sure that 'ensure' correctly calls 'sync' on all states.
+ # Make sure that 'ensure' correctly calls 'sync' on all properties.
def test_ensure
prov = mkprovider
@@ -476,9 +476,9 @@ class TestParsedFile < Test::Unit::TestCase
assert_nothing_raised { notdisk.provider.create() }
# Now make sure all of the data is copied over correctly.
- notdisk.class.validstates.each do |state|
- assert_equal(notdisk.should(state), notdisk.provider.state_hash[state],
- "%s was not copied over during creation" % state)
+ notdisk.class.validproperties.each do |property|
+ assert_equal(notdisk.should(property), notdisk.provider.property_hash[property],
+ "%s was not copied over during creation" % property)
end
# Flush it to disk and make sure it got copied down
diff --git a/test/providers/parsedsshkey.rb b/test/providers/parsedsshkey.rb
index edda8317f..898c449ce 100755
--- a/test/providers/parsedsshkey.rb
+++ b/test/providers/parsedsshkey.rb
@@ -72,7 +72,7 @@ class TestParsedSSHKey < Test::Unit::TestCase
assert(key.alias, "No alias set for key")
- hash = key.state_hash.dup
+ hash = key.property_hash.dup
text = @provider.target_object(file).read
names = [key.name, key.alias].flatten.join(",")
diff --git a/test/providers/user.rb b/test/providers/user.rb
index 67a5796c1..341049ea3 100755
--- a/test/providers/user.rb
+++ b/test/providers/user.rb
@@ -46,7 +46,7 @@ class TestUserProvider < Test::Unit::TestCase
end
def current?(param, user)
- state = Puppet.type(:user).states.find { |st|
+ property = Puppet.type(:user).properties.find { |st|
st.name == param
}
@@ -81,7 +81,7 @@ class TestUserProvider < Test::Unit::TestCase
end
def current?(param, user)
- state = Puppet.type(:user).states.find { |st|
+ property = Puppet.type(:user).properties.find { |st|
st.name == param
}
@@ -99,9 +99,9 @@ class TestUserProvider < Test::Unit::TestCase
end
- def eachstate
- Puppet::Type.type(:user).validstates.each do |state|
- yield state
+ def eachproperty
+ Puppet::Type.type(:user).validproperties.each do |property|
+ yield property
end
end
@@ -170,17 +170,17 @@ class TestUserProvider < Test::Unit::TestCase
}
assert(user, "Could not create user provider")
- Puppet::Type.type(:user).validstates.each do |state|
- next if state == :ensure
+ Puppet::Type.type(:user).validproperties.each do |property|
+ next if property == :ensure
val = nil
assert_nothing_raised {
- val = user.send(state)
+ val = user.send(property)
}
assert(val != :absent,
- "State %s is missing" % state)
+ "Property %s is missing" % property)
- assert(val, "Did not get value for %s" % state)
+ assert(val, "Did not get value for %s" % property)
end
end
@@ -411,9 +411,9 @@ class TestUserProvider < Test::Unit::TestCase
user = mkuser(name)
- eachstate do |state|
- if val = fakedata(user.name, state)
- user.model[state] = val
+ eachproperty do |property|
+ if val = fakedata(user.name, property)
+ user.model[property] = val
end
end
@@ -434,7 +434,7 @@ class TestUserProvider < Test::Unit::TestCase
assert(missing?(user.name), "User was not deleted")
end
- def test_alluserstates
+ def test_alluserproperties
user = nil
name = "pptest"
@@ -442,9 +442,9 @@ class TestUserProvider < Test::Unit::TestCase
user = mkuser(name)
- eachstate do |state|
- if val = fakedata(user.name, state)
- user.model[state] = val
+ eachproperty do |property|
+ if val = fakedata(user.name, property)
+ user.model[property] = val
end
end
@@ -456,7 +456,7 @@ class TestUserProvider < Test::Unit::TestCase
assert_equal("Puppet's Testing User pptest", user.comment,
"Comment was not set")
- tests = Puppet::Type.type(:user).validstates
+ tests = Puppet::Type.type(:user).validproperties
just = nil
tests.each { |test|
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb
new file mode 100755
index 000000000..6fd132aef
--- /dev/null
+++ b/test/ral/manager/attributes.rb
@@ -0,0 +1,187 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke A. Kanies on 2007-02-05.
+# Copyright (c) 2007. All rights reserved.
+
+$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+
+class TestTypeAttributes < Test::Unit::TestCase
+ include PuppetTest
+
+ def mktype
+ Puppet::Type.newtype(:faketype) {}
+ end
+
+ def teardown
+ super
+ if Puppet::Type.type(:faketype)
+ Puppet::Type.rmtype(:faketype)
+ end
+ end
+
+ def test_bracket_methods
+ type = mktype
+
+ # make a namevar
+ type.newparam(:name) {}
+
+ # make a property
+ type.newproperty(:property) {}
+
+ # and a param
+ type.newparam(:param)
+
+ inst = type.create(:name => "yay")
+
+ # Make sure we can set each of them, including a metaparam
+ [:param, :property, :noop].each do |param|
+ assert_nothing_raised("Failed to set symbol") do
+ inst[param] = true
+ end
+
+ assert_nothing_raised("Failed to set string") do
+ inst[param.to_s] = true
+ end
+
+ 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]
+ 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
+
+ def test_properties
+ type = mktype
+
+ # make a namevar
+ type.newparam(:name) {}
+
+ # make a couple of properties
+ props = [:one, :two, :three]
+ props.each do |prop|
+ type.newproperty(prop) {}
+ end
+
+ inst = type.create(:name => "yay")
+
+ inst[:one] = "boo"
+ one = inst.property(:one)
+ assert(one, "did not get obj for one")
+ assert_equal([one], inst.send(:properties), "got wrong properties")
+
+ inst[:three] = "rah"
+ three = inst.property(:three)
+ assert(three, "did not get obj for three")
+ assert_equal([one, three], inst.send(:properties), "got wrong properties")
+
+ inst[:two] = "whee"
+ two = inst.property(:two)
+ assert(two, "did not get obj for two")
+ assert_equal([one, two, three], inst.send(:properties), "got wrong properties")
+ end
+
+ def attr_check(type)
+ @num ||= 0
+ @num += 1
+ name = "name%s" % @num
+ inst = type.create(:name => name)
+ [:meta, :param, :prop].each do |name|
+ klass = type.attrclass(name)
+ assert(klass, "did not get class for %s" % name)
+ obj = yield inst, klass
+ assert_instance_of(klass, obj, "did not get object back")
+ assert_equal("value", inst.value(klass.name),
+ "value was not correct from value method")
+ assert_equal("value", obj.value, "value was not correct")
+ end
+ end
+
+ def test_newattr
+ type = mktype
+ type.newparam(:name) {}
+
+ # Make one of each param type
+ {
+ :meta => :newmetaparam, :param => :newparam, :prop => :newproperty
+ }.each do |name, method|
+ assert_nothing_raised("Could not make %s of type %s" % [name, method]) do
+ type.send(method, name) {}
+ end
+ end
+
+ # Now set each of them
+ attr_check(type) do |inst, klass|
+ inst.newattr(klass.name, :value => "value")
+ end
+
+ # Now try it passing the class in
+ attr_check(type) do |inst, klass|
+ inst.newattr(klass, :value => "value")
+ end
+
+ # Lastly, make sure we can create and then set, separately
+ attr_check(type) do |inst, klass|
+ obj = inst.newattr(klass.name)
+ assert_nothing_raised("Could not set value after creation") do
+ obj.value = "value"
+ end
+
+ # Make sure we can't create a new param object
+ assert_raise(Puppet::Error,
+ "Did not throw an error when replacing attr") do
+ inst.newattr(klass.name, :value => "yay")
+ end
+ obj
+ end
+ end
+
+ def test_setdefaults
+ type = mktype
+ type.newparam(:name) {}
+
+ # Make one of each param type
+ {
+ :meta2 => :newmetaparam, :param2 => :newparam, :prop2 => :newproperty
+ }.each do |name, method|
+ assert_nothing_raised("Could not make %s of type %s" % [name, method]) do
+ type.send(method, name) do
+ defaultto "testing"
+ end
+ end
+ end
+
+ inst = type.create(:name => 'yay')
+ assert_nothing_raised do
+ inst.setdefaults
+ end
+
+ [:meta2, :param2, :prop2].each do |name|
+ assert(inst.value(name), "did not get a value for %s" % name)
+ end
+
+ # Try a default of "false"
+ type.newparam(:falsetest) do
+ defaultto false
+ end
+
+ assert_nothing_raised do
+ inst.setdefaults
+ end
+ assert_equal(false, inst[:falsetest], "false default was not set")
+ end
+end
+
+# $Id$
diff --git a/test/types/manager.rb b/test/ral/manager/manager.rb
index 480e5a02e..8a273ecfd 100755
--- a/test/types/manager.rb
+++ b/test/ral/manager/manager.rb
@@ -3,9 +3,8 @@
# Created by Luke A. Kanies on 2006-11-29.
# Copyright (c) 2006. All rights reserved.
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
-require 'puppet'
require 'puppettest'
class TestTypeManager < Test::Unit::TestCase
@@ -53,4 +52,4 @@ class TestTypeManager < Test::Unit::TestCase
end
end
-# $Id$ \ No newline at end of file
+# $Id$
diff --git a/test/types/type.rb b/test/ral/manager/type.rb
index 98ff8101d..c8d4104a8 100755
--- a/test/types/type.rb
+++ b/test/ral/manager/type.rb
@@ -1,8 +1,7 @@
#!/usr/bin/env ruby
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
-require 'puppet/type'
require 'puppettest'
class TestType < Test::Unit::TestCase
@@ -23,8 +22,8 @@ class TestType < Test::Unit::TestCase
"Failed to retrieve %s by name" % name
)
- # Skip types with no parameters or valid states
- #unless ! type.parameters.empty? or ! type.validstates.empty?
+ # Skip types with no parameters or valid properties
+ #unless ! type.parameters.empty? or ! type.validproperties.empty?
# next
#end
@@ -35,13 +34,13 @@ class TestType < Test::Unit::TestCase
)
assert_not_nil(
- type.states,
- "States for %s are nil" % name
+ type.properties,
+ "Properties for %s are nil" % name
)
assert_not_nil(
- type.validstates,
- "Valid states for %s are nil" % name
+ type.validproperties,
+ "Valid properties for %s are nil" % name
)
}
}
@@ -95,11 +94,11 @@ class TestType < Test::Unit::TestCase
}
end
- # This was supposed to test objects whose name was a state, but that
+ # This was supposed to test objects whose name was a property, but that
# fundamentally doesn't make much sense, and we now don't have any such
# types.
- def disabled_test_nameasstate
- # currently groups are the only objects with the namevar as a state
+ def disabled_test_nameasproperty
+ # currently groups are the only objects with the namevar as a property
group = nil
assert_nothing_raised {
group = Puppet.type(:group).create(
@@ -111,7 +110,7 @@ class TestType < Test::Unit::TestCase
end
# Verify that values get merged correctly
- def test_mergestatevalues
+ def test_mergepropertyvalues
file = tempfile()
# Create the first version
@@ -225,7 +224,7 @@ class TestType < Test::Unit::TestCase
}
# make sure we don't get :ensure for unmanaged files
- assert(! user.state(:ensure), "User got an ensure state")
+ assert(! user.property(:ensure), "User got an ensure property")
assert_nothing_raised {
user = Puppet.type(:user).create(
@@ -234,7 +233,7 @@ class TestType < Test::Unit::TestCase
)
}
# but make sure it gets added once we manage them
- assert(user.state(:ensure), "User did not add ensure state")
+ assert(user.property(:ensure), "User did not add ensure property")
assert_nothing_raised {
user = Puppet.type(:user).create(
@@ -244,7 +243,7 @@ class TestType < Test::Unit::TestCase
}
# and make sure managed objects start with them
- assert(user.state(:ensure), "User did not get an ensure state")
+ assert(user.property(:ensure), "User did not get an ensure property")
end
# Make sure removal works
@@ -411,7 +410,7 @@ end
"newparam method got replaced by newtype")
end
- def test_newstate_options
+ def test_newproperty_options
# Create a type with a fake provider
providerclass = Class.new do
def method_missing(method, *args)
@@ -431,17 +430,17 @@ end
end
end
- # Now make a state with no options.
- state = nil
+ # Now make a property with no options.
+ property = nil
assert_nothing_raised do
- state = type.newstate(:noopts) do
+ property = type.newproperty(:noopts) do
end
end
# Now create an instance
obj = type.create(:name => :myobj)
- inst = state.new(:parent => obj)
+ inst = property.new(:parent => obj)
# And make sure it's correctly setting @is
ret = nil
@@ -451,13 +450,13 @@ end
assert_equal(:noopts, inst.is)
- # Now create a state with a different way of doing it
- state = nil
+ # Now create a property with a different way of doing it
+ property = nil
assert_nothing_raised do
- state = type.newstate(:setretrieve, :retrieve => :yayness)
+ property = type.newproperty(:setretrieve, :retrieve => :yayness)
end
- inst = state.new(:parent => obj)
+ inst = property.new(:parent => obj)
# And make sure it's correctly setting @is
ret = nil
diff --git a/test/server/resource.rb b/test/server/resource.rb
index 218b65f74..5a2f602ba 100755
--- a/test/server/resource.rb
+++ b/test/server/resource.rb
@@ -79,12 +79,12 @@ class TestResourceServer < Test::Unit::TestCase
assert(object, "Could not create type")
- retrieve.each do |state|
- assert(object.should(state), "Did not retrieve %s" % state)
+ retrieve.each do |property|
+ assert(object.should(property), "Did not retrieve %s" % property)
end
- ignore.each do |state|
- assert(! object.should(state), "Incorrectly retrieved %s" % state)
+ ignore.each do |property|
+ assert(! object.should(property), "Incorrectly retrieved %s" % property)
end
if i == 0
@@ -154,12 +154,12 @@ class TestResourceServer < Test::Unit::TestCase
assert(object, "Could not create type")
- retrieve.each do |state|
- assert(object.should(state), "Did not retrieve %s" % state)
+ retrieve.each do |property|
+ assert(object.should(property), "Did not retrieve %s" % property)
end
- ignore.each do |state|
- assert(! object.should(state), "Incorrectly retrieved %s" % state)
+ ignore.each do |property|
+ assert(! object.should(property), "Incorrectly retrieved %s" % property)
end
assert_events([:directory_created], object)
diff --git a/test/types/basic.rb b/test/types/basic.rb
index e54f22ccb..64e08d1cb 100755
--- a/test/types/basic.rb
+++ b/test/types/basic.rb
@@ -49,6 +49,14 @@ class TestBasic < Test::Unit::TestCase
stopservices
end
+ def test_values
+ [:ensure, :checksum].each do |param|
+ prop = @configfile.property(param)
+ assert(prop, "got no property for %s" % param)
+ assert(prop.value, "got no value for %s" % param)
+ end
+ end
+
def test_name_calls
[@command, @configfile].each { |obj|
Puppet.debug "obj is %s" % obj
diff --git a/test/types/cron.rb b/test/types/cron.rb
index b91afe045..c4d818a33 100755
--- a/test/types/cron.rb
+++ b/test/types/cron.rb
@@ -325,7 +325,7 @@ class TestCron < Test::Unit::TestCase
cron = mkcron("valtesting")
values.each { |param, hash|
# We have to test the valid ones first, because otherwise the
- # state will fail to create at all.
+ # property will fail to create at all.
[:valid, :invalid].each { |type|
hash[type].each { |value|
case type
@@ -564,15 +564,15 @@ class TestCron < Test::Unit::TestCase
def test_value
cron = mkcron("valuetesting", false)
- # First, test the normal states
+ # First, test the normal properties
[:minute, :hour, :month].each do |param|
- cron.newstate(param)
- state = cron.state(param)
+ cron.newattr(param)
+ property = cron.property(param)
- assert(state, "Did not get %s state" % param)
+ assert(property, "Did not get %s property" % param)
assert_nothing_raised {
- state.is = :absent
+ property.is = :absent
}
# Make sure our minute default is 0, not *
@@ -611,14 +611,14 @@ class TestCron < Test::Unit::TestCase
# Now make sure that :command works correctly
cron.delete(:command)
- cron.newstate(:command)
- state = cron.state(:command)
+ cron.newattr(:command)
+ property = cron.property(:command)
assert_nothing_raised {
- state.is = :absent
+ property.is = :absent
}
- assert(state, "Did not get command state")
+ assert(property, "Did not get command property")
assert_raise(Puppet::DevError) do
cron.value(:command)
end
diff --git a/test/types/exec.rb b/test/types/exec.rb
index 7718825ee..71b98cf3f 100755
--- a/test/types/exec.rb
+++ b/test/types/exec.rb
@@ -127,7 +127,7 @@ class TestExec < Test::Unit::TestCase
cmd = Puppet.type(:exec).create(
:command => "pwd",
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
- :subscribe => [[file.class.name,file.name]],
+ :subscribe => file,
:refreshonly => true
)
}
@@ -143,7 +143,7 @@ class TestExec < Test::Unit::TestCase
trans = comp.evaluate
file.retrieve
- sum = file.state(:checksum)
+ sum = file.property(:checksum)
assert(sum.insync?, "checksum is not in sync")
events = trans.evaluate.collect { |event|
event.event
@@ -158,7 +158,7 @@ class TestExec < Test::Unit::TestCase
}
assert_nothing_raised {
trans = comp.evaluate
- sum = file.state(:checksum)
+ sum = file.property(:checksum)
events = trans.evaluate.collect { |event| event.event }
}
@@ -454,6 +454,7 @@ class TestExec < Test::Unit::TestCase
assert(File.stat(path).mode & 007777 == 0755)
end
+ # Make sure all checks need to be fully qualified.
def test_falsevals
exec = nil
assert_nothing_raised do
@@ -465,7 +466,7 @@ class TestExec < Test::Unit::TestCase
Puppet.type(:exec).checks.each do |check|
klass = Puppet.type(:exec).paramclass(check)
next if klass.values.include? :false
- assert_raise(Puppet::Error, "Check %s did not fail on false" % check) do
+ assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do
exec[check] = false
end
end
@@ -478,6 +479,7 @@ class TestExec < Test::Unit::TestCase
assert_nothing_raised {
exec1 = Puppet.type(:exec).create(
+ :title => "one",
:path => ENV["PATH"],
:command => "mkdir #{dir}"
)
@@ -485,6 +487,7 @@ class TestExec < Test::Unit::TestCase
assert_nothing_raised("Could not create exec w/out existing cwd") {
exec2 = Puppet.type(:exec).create(
+ :title => "two",
:path => ENV["PATH"],
:command => "touch #{file}",
:cwd => dir
@@ -498,12 +501,11 @@ class TestExec < Test::Unit::TestCase
end
assert_raise(Puppet::Error) do
- exec2.state(:returns).sync
+ exec2.property(:returns).sync
end
assert_nothing_raised do
- exec2[:require] = ["exec", exec1.name]
- exec2.finish
+ exec2[:require] = exec1
end
assert_apply(exec1, exec2)
diff --git a/test/types/file.rb b/test/types/file.rb
index 2710c7dc5..e174465e2 100755
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -31,6 +31,7 @@ class TestFile < Test::Unit::TestCase
def setup
super
@file = Puppet::Type.type(:file)
+ $method = @method_name
begin
initstorage
rescue
@@ -103,8 +104,8 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised() {
file[:group] = group
}
- assert(file.state(:group))
- assert(file.state(:group).should)
+ assert(file.property(:group))
+ assert(file.property(:group).should)
}
end
@@ -271,8 +272,8 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised() {
file[:group] = group
}
- assert(file.state(:group))
- assert(file.state(:group).should)
+ assert(file.property(:group))
+ assert(file.property(:group).should)
assert_apply(file)
file.retrieve
assert(file.insync?())
@@ -395,7 +396,7 @@ class TestFile < Test::Unit::TestCase
file.retrieve
if file.title !~ /nonexists/
- sum = file.state(:checksum)
+ sum = file.property(:checksum)
assert(sum.insync?, "file is not in sync")
end
@@ -430,9 +431,9 @@ class TestFile < Test::Unit::TestCase
# Run it a few times to make sure we aren't getting
# spurious changes.
assert_nothing_raised do
- file.state(:checksum).retrieve
+ file.property(:checksum).retrieve
end
- assert(file.state(:checksum).insync?,
+ assert(file.property(:checksum).insync?,
"checksum is not in sync")
sleep 1.1 if type =~ /time/
@@ -708,7 +709,7 @@ class TestFile < Test::Unit::TestCase
file.evaluate
}
- assert_equal("directory", file.state(:type).is)
+ assert_equal("directory", file.property(:type).is)
# And then check files
assert_nothing_raised {
@@ -722,7 +723,7 @@ class TestFile < Test::Unit::TestCase
file[:check] = "type"
assert_apply(file)
- assert_equal("file", file.state(:type).is)
+ assert_equal("file", file.property(:type).is)
file[:type] = "directory"
@@ -999,7 +1000,7 @@ class TestFile < Test::Unit::TestCase
)
}
- assert(file.state(:group), "Group state failed")
+ assert(file.property(:group), "Group property failed")
end
def test_modecreation
@@ -1078,7 +1079,7 @@ class TestFile < Test::Unit::TestCase
end
# If both 'ensure' and 'content' are used, make sure that all of the other
- # states are handled correctly.
+ # properties are handled correctly.
def test_contentwithmode
path = tempfile()
@@ -1746,7 +1747,7 @@ class TestFile < Test::Unit::TestCase
if should == :link
obj[:target] = linkdest
else
- if obj.state(:target)
+ if obj.property(:target)
obj.delete(:target)
end
end
@@ -1767,12 +1768,12 @@ class TestFile < Test::Unit::TestCase
# Now make it again
creators[is].call
- state = obj.state(:ensure)
+ property = obj.property(:ensure)
- state.retrieve
- unless state.insync?
+ property.retrieve
+ unless property.insync?
assert_nothing_raised do
- state.sync
+ property.sync
end
end
FileUtils.rmtree(dir)
@@ -1964,7 +1965,7 @@ class TestFile < Test::Unit::TestCase
end
# Testing #438
- def test_creating_states_conflict
+ def test_creating_properties_conflict
file = tempfile()
first = tempfile()
second = tempfile()
diff --git a/test/types/filesources.rb b/test/types/filesources.rb
index 915f19833..f372fb8e9 100755
--- a/test/types/filesources.rb
+++ b/test/types/filesources.rb
@@ -77,19 +77,19 @@ class TestFileSources < Test::Unit::TestCase
file = Puppet::Type.newfile :path => dest, :source => source,
:title => "copier"
- state = file.state(:source)
+ property = file.property(:source)
# First try describing with a normal source
result = nil
assert_nothing_raised do
- result = state.describe(source)
+ result = property.describe(source)
end
assert_nil(result, "Got a result back when source is missing")
# Now make a remote directory
Dir.mkdir(source)
assert_nothing_raised do
- result = state.describe(source)
+ result = property.describe(source)
end
assert_equal("directory", result[:type])
@@ -97,7 +97,7 @@ class TestFileSources < Test::Unit::TestCase
Dir.rmdir(source)
File.open(source, "w") { |f| f.puts "yay" }
assert_nothing_raised do
- result = state.describe(source)
+ result = property.describe(source)
end
assert_equal("file", result[:type])
assert(result[:checksum], "did not get value for checksum")
@@ -115,18 +115,18 @@ class TestFileSources < Test::Unit::TestCase
File.symlink(target, source)
file[:links] = :ignore
- assert_nil(state.describe(source),
+ assert_nil(property.describe(source),
"Links were not ignored")
file[:links] = :manage
# We can't manage links at this point
assert_raise(Puppet::FileServerError) do
- state.describe(source)
+ property.describe(source)
end
# And then make sure links get followed, otherwise
file[:links] = :follow
- assert_equal("file", state.describe(source)[:type])
+ assert_equal("file", property.describe(source)[:type])
end
def test_source_retrieve
@@ -136,38 +136,39 @@ class TestFileSources < Test::Unit::TestCase
file = Puppet::Type.newfile :path => dest, :source => source,
:title => "copier"
- assert(file.state(:checksum), "source state did not create checksum state")
- state = file.state(:source)
- assert(state, "did not get source state")
+ assert(file.property(:checksum), "source property did not create checksum property")
+ property = file.property(:source)
+ assert(property, "did not get source property")
# Make sure the munge didn't actually change the source
- assert_equal([source], state.should, "munging changed the source")
+ assert_equal([source], property.should, "munging changed the source")
# First try it with a missing source
assert_nothing_raised do
- state.retrieve
+ property.retrieve
end
- # And make sure the state considers itself in sync, since there's nothing
+ # And make sure the property considers itself in sync, since there's nothing
# to do
- assert(state.insync?, "source thinks there's work to do with no file or dest")
+ assert(property.insync?, "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
+ # 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
- state.retrieve
+ property.retrieve
end
assert_equal(:directory, file.should(:ensure),
"Did not set to create directory")
- # And make sure the source state won't try to do anything with a remote dir
- assert(state.insync?, "Source was out of sync even tho remote is dir")
+ # 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")
# Now remove the source, and make sure :ensure was not modified
Dir.rmdir(source)
assert_nothing_raised do
- state.retrieve
+ property.retrieve
end
assert_equal(:directory, file.should(:ensure),
"Did not keep :ensure setting")
@@ -177,7 +178,7 @@ class TestFileSources < Test::Unit::TestCase
File.chmod(0755, source)
assert_nothing_raised do
- state.retrieve
+ property.retrieve
end
assert_equal(:file, file.should(:ensure),
"Did not make correct :ensure setting")
@@ -186,11 +187,11 @@ class TestFileSources < Test::Unit::TestCase
# Now let's make sure that we get the first found source
fake = tempfile()
- state.should = [fake, source]
+ property.should = [fake, source]
assert_nothing_raised do
- state.retrieve
+ property.retrieve
end
- assert_equal(Digest::MD5.hexdigest(File.read(source)), state.checksum.sub(/^\{\w+\}/, ''),
+ assert_equal(Digest::MD5.hexdigest(File.read(source)), property.checksum.sub(/^\{\w+\}/, ''),
"Did not catch later source")
end
@@ -201,33 +202,33 @@ class TestFileSources < Test::Unit::TestCase
file = Puppet::Type.newfile :path => dest, :source => source,
:title => "copier"
- state = file.state(:source)
- assert(state, "did not get source state")
+ property = file.property(:source)
+ assert(property, "did not get source property")
# Try it with no source at all
file.retrieve
- assert(state.insync?, "source state not in sync with missing source")
+ assert(property.insync?, "source property not in sync with missing source")
# with a directory
Dir.mkdir(source)
file.retrieve
- assert(state.insync?, "source state not in sync with directory as source")
+ assert(property.insync?, "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(!state.insync?, "source state was in sync when file was missing")
+ assert(!property.insync?, "source property was in sync when file was missing")
# With a different file
File.open(dest, "w") { |f| f.puts "foo" }
file.retrieve
- assert(!state.insync?, "source state was in sync with different file")
+ assert(!property.insync?, "source property was in sync with different file")
# with matching files
File.open(dest, "w") { |f| f.puts "yay" }
file.retrieve
- assert(state.insync?, "source state was not in sync with matching file")
+ assert(property.insync?, "source property was not in sync with matching file")
end
def test_source_sync
@@ -236,16 +237,16 @@ class TestFileSources < Test::Unit::TestCase
file = Puppet::Type.newfile :path => dest, :source => source,
:title => "copier"
- state = file.state(:source)
+ property = file.property(:source)
File.open(source, "w") { |f| f.puts "yay" }
file.retrieve
- assert(! state.insync?, "source thinks it's in sync")
+ assert(! property.insync?, "source thinks it's in sync")
event = nil
assert_nothing_raised do
- event = state.sync
+ event = property.sync
end
assert_equal(:file_created, event)
assert_equal(File.read(source), File.read(dest),
@@ -254,9 +255,9 @@ class TestFileSources < Test::Unit::TestCase
# Now write something different
File.open(source, "w") { |f| f.puts "rah" }
file.retrieve
- assert(! state.insync?, "source should be out of sync")
+ assert(! property.insync?, "source should be out of sync")
assert_nothing_raised do
- event = state.sync
+ event = property.sync
end
assert_equal(:file_changed, event)
assert_equal(File.read(source), File.read(dest),
@@ -688,7 +689,7 @@ class TestFileSources < Test::Unit::TestCase
file.retrieve
- assert(file.is(:checksum), "File does not have a checksum state")
+ assert(file.is(:checksum), "File does not have a checksum property")
assert_equal(0, file.evaluate.length, "File produced changes")
diff --git a/test/types/group.rb b/test/types/group.rb
index e12089256..2ca3ab5e5 100755
--- a/test/types/group.rb
+++ b/test/types/group.rb
@@ -151,7 +151,7 @@ class TestGroup < Test::Unit::TestCase
assert(gobj.provider.exists?,
"Did not create group")
- tests = Puppet.type(:group).validstates
+ tests = Puppet.type(:group).validproperties
gobj.retrieve
tests.each { |test|
diff --git a/test/types/host.rb b/test/types/host.rb
index 18d87db77..56d12e560 100755
--- a/test/types/host.rb
+++ b/test/types/host.rb
@@ -130,8 +130,8 @@ class TestHost < Test::Unit::TestCase
end
end
- def test_aliasisstate
- assert_equal(:state, @hosttype.attrtype(:alias))
+ def test_aliasisproperty
+ assert_equal(:property, @hosttype.attrtype(:alias))
end
def test_multivalues
diff --git a/test/types/mount.rb b/test/types/mount.rb
index d153d3482..9abf93476 100755
--- a/test/types/mount.rb
+++ b/test/types/mount.rb
@@ -5,6 +5,7 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppettest'
require 'puppet'
+unless Facter.value(:operatingsystem) == "Darwin"
class TestMounts < Test::Unit::TestCase
include PuppetTest
@@ -20,9 +21,9 @@ class TestMounts < Test::Unit::TestCase
def create
@ensure = :present
- @model.class.validstates.each do |state|
- if value = @model.should(state)
- self.send(state.to_s + "=", value)
+ @model.class.validproperties.each do |property|
+ if value = @model.should(property)
+ self.send(property.to_s + "=", value)
end
end
end
@@ -96,7 +97,7 @@ class TestMounts < Test::Unit::TestCase
:device => "/dev/dsk%s" % @pcount,
}
- [@mount.validstates, @mount.parameters].flatten.each do |field|
+ [@mount.validproperties, @mount.parameters].flatten.each do |field|
next if [:path, :provider, :target, :ensure, :remounts].include?(field)
unless args.include? field
args[field] = "fake%s" % @pcount
@@ -111,9 +112,9 @@ class TestMounts < Test::Unit::TestCase
mount[:ensure] = :mounted
assert_apply(mount)
- mount.send(:states).each do |state|
- assert_equal(state.should, mount.provider.send(state.name),
- "%s was not set to %s" % [state.name, state.should])
+ mount.send(:properties).each do |property|
+ assert_equal(property.should, mount.provider.send(property.name),
+ "%s was not set to %s" % [property.name, property.should])
end
assert_events([], mount)
@@ -202,14 +203,14 @@ class TestMounts < Test::Unit::TestCase
assert(root, "Could not find root root filesystem in list results")
assert(root.is(:device), "Device was not set")
- assert(root.state(:device).value, "Device was not returned by value method")
+ assert(root.property(:device).value, "Device was not returned by value method")
assert_nothing_raised do
root.retrieve
end
assert(root.is(:device), "Device was not set")
- assert(root.state(:device).value, "Device was not returned by value method")
+ assert(root.property(:device).value, "Device was not returned by value method")
end
end
@@ -305,5 +306,6 @@ class TestMounts < Test::Unit::TestCase
assert_nil(mount.should(:ensure), "Found default for ensure")
end
end
+end
# $Id$
diff --git a/test/types/parameter.rb b/test/types/parameter.rb
index 603b56590..a47f479d3 100755
--- a/test/types/parameter.rb
+++ b/test/types/parameter.rb
@@ -21,7 +21,7 @@ class TestParameter < Test::Unit::TestCase
def newinst(param)
assert_nothing_raised {
- return param.new
+ return param.new(:parent => "yay")
}
end
@@ -99,6 +99,63 @@ class TestParameter < Test::Unit::TestCase
}
assert_equal("two", inst.value, "Matched value didn't take")
end
+
+ def test_shadowing
+ type = Puppet::Type.newtype(:faketype) { newparam(:name) {} }
+
+ cleanup { Puppet::Type.rmtype(:faketype) }
+
+ param = nil
+ assert_nothing_raised do
+ param = type.newproperty(:alias)
+ end
+
+ assert(param, "did not create param")
+
+ inst = type.create(:name => "test")
+
+ assert_nothing_raised("Could not create shadowed param") {
+ inst[:alias] = "foo"
+ }
+
+ # Get the parameter hash from the instance so we can check the shadow
+ params = inst.instance_variable_get("@parameters")
+ obj = params[:alias]
+ assert(obj, "did not get alias parameter")
+ assert(obj.shadow, "shadow was not created for alias param")
+
+ assert(obj.is_a?(Puppet::Type::Property),
+ "alias instance is not a property")
+ assert_instance_of(param, obj, "alias is an instance of the wrong class")
+
+ # Make sure the alias got created
+ assert(type["foo"], "Did not retrieve object by its alias")
+
+ # Now try it during initialization
+ other = nil
+ assert_nothing_raised("Could not create instance with shadow") do
+ other = type.create(:name => "rah", :alias => "one")
+ end
+ params = other.instance_variable_get("@parameters")
+ obj = params[:alias]
+ assert(obj, "did not get alias parameter")
+ assert(obj.shadow, "shadow was not created for alias param")
+
+ assert_instance_of(param, obj, "alias is an instance of the wrong class")
+ assert(obj.is_a?(Puppet::Type::Property),
+ "alias instance is not a property")
+
+ # Now change the alias and make sure it works out well
+ assert_nothing_raised("Could not modify shadowed alias") do
+ other[:alias] = "two"
+ end
+
+ obj = params[:alias]
+ assert(obj, "did not get alias parameter")
+ assert_instance_of(param, obj, "alias is now an instance of the wrong class")
+ assert(obj.is_a?(Puppet::Type::Property),
+ "alias instance is now not a property")
+ end
end
# $Id$
diff --git a/test/types/port.rb b/test/types/port.rb
index a6bc449ca..c0fa7c1c2 100755
--- a/test/types/port.rb
+++ b/test/types/port.rb
@@ -123,12 +123,12 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
# assert_events([], port)
# end
#
-# def test_addingstates
+# def test_addingproperties
# port = mkport()
# assert_events([:port_created], port)
#
# port.delete(:alias)
-# assert(! port.state(:alias))
+# assert(! port.property(:alias))
# assert_events([:port_changed], port)
#
# assert_nothing_raised {
@@ -142,7 +142,7 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
# port[:alias] = "yaytest"
# assert_events([:port_changed], port)
# port.retrieve
-# assert(port.state(:alias).is == ["yaytest"])
+# assert(port.property(:alias).is == ["yaytest"])
# end
#end
diff --git a/test/types/state.rb b/test/types/property.rb
index a429ecd2c..b63b7237f 100755
--- a/test/types/state.rb
+++ b/test/types/property.rb
@@ -5,37 +5,47 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppet/type'
require 'puppettest'
-class TestState < Test::Unit::TestCase
+class TestProperty < Test::Unit::TestCase
include PuppetTest
- def newinst(state, parent = nil)
+ def newinst(property, parent = nil)
inst = nil
unless parent
parent = "fakeparent"
- parent.meta_def(:path) do self.to_s end
+ parent.meta_def(:pathbuilder) do [self.to_s] end
end
assert_nothing_raised {
- return state.new(:parent => parent)
+ return property.new(:parent => parent)
}
end
- def newstate(name = :fakestate)
- assert_nothing_raised {
- state = Class.new(Puppet::State) do
- @name = name
- end
- state.initvars
+ def newproperty(name = :fakeproperty)
+ property = Class.new(Puppet::Property) do
+ @name = name
+ end
+ Object.const_set("FakeProperty", property)
+ property.initvars
+ cleanup do
+ Object.send(:remove_const, "FakeProperty")
+ end
- return state
- }
+ return property
end
def newmodel(name)
- # Create an object that responds to mystate as an attr
- provklass = Class.new { attr_accessor name }
+ # Create an object that responds to myproperty as an attr
+ provklass = Class.new { attr_accessor name
+ def pathbuilder
+ ["provklass"]
+ end
+ }
prov = provklass.new
- klass = Class.new { attr_accessor :provider, :path }
+ klass = Class.new { attr_accessor :provider, :path
+ def pathbuilder
+ ["instklass"]
+ end
+ }
klassinst = klass.new
klassinst.path = "instpath"
klassinst.provider = prov
@@ -45,27 +55,27 @@ class TestState < Test::Unit::TestCase
# Make sure we correctly look up names.
def test_value_name
- state = newstate()
+ property = newproperty()
- state.newvalue(:one)
- state.newvalue(/\d+/)
+ property.newvalue(:one)
+ property.newvalue(/\d+/)
name = nil
["one", :one].each do |value|
assert_nothing_raised do
- name = state.value_name(value)
+ name = property.value_name(value)
end
assert_equal(:one, name)
end
["42"].each do |value|
assert_nothing_raised do
- name = state.value_name(value)
+ name = property.value_name(value)
end
assert_equal(/\d+/, name)
end
["two", :three].each do |value|
assert_nothing_raised do
- name = state.value_name(value)
+ name = property.value_name(value)
end
assert_nil(name)
end
@@ -73,43 +83,43 @@ class TestState < Test::Unit::TestCase
# Test that we correctly look up options for values.
def test_value_option
- state = newstate()
+ property = newproperty()
options = {
:one => {:event => :yay, :call => :before},
/\d+/ => {:event => :fun, :call => :instead}
}
- state.newvalue(:one, options[:one])
- state.newvalue(/\d+/, options[/\d+/])
+ property.newvalue(:one, options[:one])
+ property.newvalue(/\d+/, options[/\d+/])
options.each do |name, opts|
opts.each do |param, value|
- assert_equal(value, state.value_option(name, param))
+ assert_equal(value, property.value_option(name, param))
end
end
end
def test_newvalue
- state = newstate()
+ property = newproperty()
# These are bogus because they don't define events. :/
assert_nothing_raised {
- state.newvalue(:one) do
+ property.newvalue(:one) do
@is = 1
end
}
assert_nothing_raised {
- state.newvalue("two") do
+ property.newvalue("two") do
@is = 2
end
}
# Make sure we default to using the block instead
- assert_equal(:instead, state.value_option(:one, :call),
+ assert_equal(:instead, property.value_option(:one, :call),
":call was not set to :instead when a block was provided")
- inst = newinst(state)
+ inst = newinst(property)
assert_nothing_raised {
inst.should = "one"
@@ -129,17 +139,17 @@ class TestState < Test::Unit::TestCase
assert_equal(2, inst.is)
end
- def test_newstatevaluewithregexes
- state = newstate()
+ def test_newpropertyvaluewithregexes
+ property = newproperty()
assert_nothing_raised {
- state.newvalue(/^\w+$/) do
+ property.newvalue(/^\w+$/) do
@is = self.should.upcase
return :regex_matched
end
}
- inst = newinst(state)
+ inst = newinst(property)
assert_nothing_raised {
inst.should = "yayness"
@@ -155,17 +165,17 @@ class TestState < Test::Unit::TestCase
end
def test_newvalue_event_option
- state = newstate()
+ property = newproperty()
assert_nothing_raised do
- state.newvalue(:myvalue, :event => :fake_valued) do
+ property.newvalue(:myvalue, :event => :fake_valued) do
@is = :valued
end
- state.newvalue(:other, :event => "fake_other") do
+ property.newvalue(:other, :event => "fake_other") do
@is = :valued
end
end
- inst = newinst(state)
+ inst = newinst(property)
assert_nothing_raised {
inst.should = :myvalue
@@ -195,21 +205,21 @@ class TestState < Test::Unit::TestCase
# If there's no block provided, then we should call the provider mechanism
# like we would normally.
def test_newvalue_with_no_block
- state = newstate(:mystate)
+ property = newproperty(:myproperty)
assert_nothing_raised {
- state.newvalue(:value, :event => :matched_value)
+ property.newvalue(:value, :event => :matched_value)
}
assert_nothing_raised {
- state.newvalue(/^\d+$/, :event => :matched_number)
+ property.newvalue(/^\d+$/, :event => :matched_number)
}
- assert_equal(:none, state.value_option(:value, :call),
+ assert_equal(:none, property.value_option(:value, :call),
":call was not set to none when no block is provided")
- prov, klassinst = newmodel(:mystate)
+ prov, klassinst = newmodel(:myproperty)
- inst = newinst(state, klassinst)
+ inst = newinst(property, klassinst)
# Now make sure we can set the values, they get validated as normal,
# and they set the values on the parent rathe than trying to call
@@ -223,7 +233,7 @@ class TestState < Test::Unit::TestCase
ret = inst.sync
end
assert_equal(event, ret, "Did not return correct event for %s" % value)
- assert_equal(value, prov.mystate, "%s was not set right" % value)
+ assert_equal(value, prov.myproperty, "%s was not set right" % value)
end
# And make sure we still fail validations
@@ -241,11 +251,11 @@ class TestState < Test::Unit::TestCase
tags = [:some, :tags, :for, :testing]
obj.tags = tags
- stateklass = newstate
+ propertyklass = newproperty
inst = nil
assert_nothing_raised do
- inst = stateklass.new(:parent => obj)
+ inst = propertyklass.new(:parent => obj)
end
assert_nothing_raised do
@@ -254,25 +264,25 @@ class TestState < Test::Unit::TestCase
end
def test_failure
- s = Struct.new(:line, :file, :path)
- p = s.new(1, "yay", "rah")
- mystate = Class.new(Puppet::State)
- mystate.initvars
+ s = Struct.new(:line, :file, :path, :pathbuilder)
+ p = s.new(1, "yay", "rah", "struct")
+ myproperty = Class.new(Puppet::Property)
+ myproperty.initvars
- mystate.newvalue :mkfailure do
+ myproperty.newvalue :mkfailure do
raise "It's all broken"
end
- state = mystate.new(:parent => p)
+ property = myproperty.new(:parent => p)
assert_raise(Puppet::Error) do
- state.set(:mkfailure)
+ property.set(:mkfailure)
end
end
# Make sure 'set' behaves correctly WRT to call order. This tests that the
# :call value is handled correctly in all cases.
def test_set
- state = newstate(:mystate)
+ property = newproperty(:myproperty)
$setting = []
@@ -284,9 +294,9 @@ class TestState < Test::Unit::TestCase
end
assert_nothing_raised("Could not create %s value" % name) {
if block
- state.newvalue(name, options, &block)
+ property.newvalue(name, options, &block)
else
- state.newvalue(name, options)
+ property.newvalue(name, options)
end
}
end
@@ -304,17 +314,17 @@ class TestState < Test::Unit::TestCase
# And one with an implicit instead
assert_nothing_raised do
- state.newvalue(:implicit) do
+ property.newvalue(:implicit) do
$setting << :implicit
end
end
# Now create a provider
- prov, model = newmodel(:mystate)
- inst = newinst(state, model)
+ prov, model = newmodel(:myproperty)
+ inst = newinst(property, model)
# Mark when we're called
- prov.meta_def(:mystate=) do |value| $setting << :provider end
+ prov.meta_def(:myproperty=) do |value| $setting << :provider end
# Now run through the list and make sure everything is correct
{:before => [:before, :provider],
diff --git a/test/types/resources.rb b/test/types/resources.rb
index cdf0e68fb..bb2c26080 100755
--- a/test/types/resources.rb
+++ b/test/types/resources.rb
@@ -35,7 +35,7 @@ class TestResources < Test::Unit::TestCase
$purgemembers = {}
@purgetype = Puppet::Type.newtype(:purgetest) do
newparam(:name, :namevar => true) {}
- newstate(:ensure) do
+ newproperty(:ensure) do
newvalue(:absent) do
$purgemembers[@parent[:name]] = @parent
end
@@ -43,7 +43,7 @@ class TestResources < Test::Unit::TestCase
$purgemembers.delete(@parent[:name])
end
end
- newstate(:fake) do
+ newproperty(:fake) do
def sync
:faked
end
@@ -62,7 +62,7 @@ class TestResources < Test::Unit::TestCase
def test_initialize
assert(@type, "Could not retrieve resources type")
# Make sure we can't create them for types that don't exist
- assert_raise(ArgumentError) do
+ assert_raise(Puppet::Error) do
@type.create :name => "thereisnotypewiththisname"
end
diff --git a/test/types/service.rb b/test/types/service.rb
index 0433da9d6..b6f191562 100755
--- a/test/types/service.rb
+++ b/test/types/service.rb
@@ -236,13 +236,13 @@ class TestLocalService < Test::Unit::TestCase
else
def test_servicestartstop
mktestsvcs.each { |svc|
- startstate = nil
+ startproperty = nil
assert_nothing_raised("Could not get status") {
- startstate = svc.provider.status
+ startproperty = svc.provider.status
}
cycleservice(svc)
- svc[:ensure] = startstate
+ svc[:ensure] = startproperty
assert_apply(svc)
Puppet.type(:component).clear
}
@@ -251,14 +251,14 @@ class TestLocalService < Test::Unit::TestCase
def test_serviceenabledisable
mktestsvcs.each { |svc|
assert(svc[:name], "Service has no name")
- startstate = nil
+ startproperty = nil
svc[:check] = :enable
assert_nothing_raised("Could not get status") {
- startstate = svc.provider.enabled?
+ startproperty = svc.provider.enabled?
}
cycleenable(svc)
- svc[:enable] = startstate
+ svc[:enable] = startproperty
assert_apply(svc)
Puppet.type(:component).clear
}
@@ -271,8 +271,8 @@ class TestLocalService < Test::Unit::TestCase
svc[:check] = [:ensure, :enable]
svc.retrieve
assert_nothing_raised("Could not get status") {
- startenable = svc.state(:enable).is
- startensure = svc.state(:ensure).is
+ startenable = svc.property(:enable).is
+ startensure = svc.property(:ensure).is
}
svc[:enable] = false
@@ -281,7 +281,7 @@ class TestLocalService < Test::Unit::TestCase
sleep 1
svc.retrieve
- assert(svc.insync?, "Service did not sync both states")
+ assert(svc.insync?, "Service did not sync both properties")
svc[:enable] = true
svc[:ensure] = :running
@@ -289,7 +289,7 @@ class TestLocalService < Test::Unit::TestCase
sleep 1
svc.retrieve
- assert(svc.insync?, "Service did not sync both states")
+ assert(svc.insync?, "Service did not sync both properties")
svc[:enable] = startenable
svc[:ensure] = startensure
diff --git a/test/types/sshkey.rb b/test/types/sshkey.rb
index 9f86ba955..ac4565e36 100755
--- a/test/types/sshkey.rb
+++ b/test/types/sshkey.rb
@@ -104,13 +104,20 @@ class TestSSHKey < Test::Unit::TestCase
key.retrieve
- key[:alias] = %w{madstop kirby yayness}
+ aliases = %w{madstop kirby yayness}
+ key[:alias] = aliases
+ params = key.instance_variable_get("@parameters")
assert_events([:sshkey_changed], key)
+
+ aliases.each do |name|
+ assert_equal(key, key.class[name],
+ "alias was not set")
+ end
end
- def test_aliasisstate
- assert_equal(:state, @sshkeytype.attrtype(:alias))
+ def test_aliasisproperty
+ assert_equal(:property, @sshkeytype.attrtype(:alias))
end
def test_multivalues
diff --git a/test/types/tidy.rb b/test/types/tidy.rb
index 65ffa7d82..58dd2c263 100755
--- a/test/types/tidy.rb
+++ b/test/types/tidy.rb
@@ -149,7 +149,7 @@ class TestTidy < Test::Unit::TestCase
def test_agetest
tidy = Puppet::Type.newtidy :path => tempfile(), :age => "1m"
- age = tidy.state(:age)
+ age = tidy.property(:age)
# Set it to something that should be fine
age.is = Time.now.to_i - 5
@@ -165,7 +165,7 @@ class TestTidy < Test::Unit::TestCase
def test_sizetest
tidy = Puppet::Type.newtidy :path => tempfile(), :size => "1k"
- size = tidy.state(:size)
+ size = tidy.property(:size)
# Set it to something that should be fine
size.is = 50
@@ -219,7 +219,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.state(:age).is = "0s"
+ tidy.property(:age).is = "0s"
assert_apply(tidy)
assert(! FileTest.exists?(path), "file did not get tidied")
end
diff --git a/test/types/user.rb b/test/types/user.rb
index 485ce1c38..7d7b5a427 100755
--- a/test/types/user.rb
+++ b/test/types/user.rb
@@ -14,16 +14,16 @@ class TestUser < Test::Unit::TestCase
apimethods
def create
@ensure = :present
- @model.eachstate do |state|
- next if state.name == :ensure
- state.sync
+ @model.eachproperty do |property|
+ next if property.name == :ensure
+ property.sync
end
end
def delete
@ensure = :absent
- @model.eachstate do |state|
- send(state.name.to_s + "=", :absent)
+ @model.eachproperty do |property|
+ send(property.name.to_s + "=", :absent)
end
end
@@ -287,7 +287,7 @@ class TestUser < Test::Unit::TestCase
user.retrieve
}
- assert_instance_of(String, user.state(:groups).should)
+ assert_instance_of(String, user.property(:groups).should)
# Some tests to verify that groups work correctly startig from nothing
# Remove our user
@@ -308,9 +308,9 @@ class TestUser < Test::Unit::TestCase
user.retrieve
- assert(user.state(:groups).is, "Did not retrieve group list")
+ assert(user.property(:groups).is, "Did not retrieve group list")
- list = user.state(:groups).is
+ list = user.property(:groups).is
assert_equal(extra.sort, list.sort, "Group list is not equal")
# Now set to our main list of groups
@@ -318,7 +318,7 @@ class TestUser < Test::Unit::TestCase
user[:groups] = main
}
- assert_equal((main + extra).sort, user.state(:groups).should.split(",").sort)
+ assert_equal((main + extra).sort, user.property(:groups).should.split(",").sort)
assert_nothing_raised {
user.retrieve
@@ -334,7 +334,7 @@ class TestUser < Test::Unit::TestCase
# We're not managing inclusively, so it should keep the old group
# memberships and add the new ones
- list = user.state(:groups).is
+ list = user.property(:groups).is
assert_equal((main + extra).sort, list.sort, "Group list is not equal")
assert_nothing_raised {
@@ -351,14 +351,14 @@ class TestUser < Test::Unit::TestCase
user.retrieve
}
- list = user.state(:groups).is
+ list = user.property(:groups).is
assert_equal(main.sort, list.sort, "Group list is not equal")
# Set the values a bit differently.
- user.state(:groups).should = list.sort { |a,b| b <=> a }
- user.state(:groups).is = list.sort
+ user.property(:groups).should = list.sort { |a,b| b <=> a }
+ user.property(:groups).is = list.sort
- assert(user.state(:groups).insync?, "Groups state did not sort groups")
+ assert(user.property(:groups).insync?, "Groups property did not sort groups")
user.delete(:groups)
end
@@ -417,7 +417,7 @@ class TestUser < Test::Unit::TestCase
assert(! user.provider.exists?, "User did not get deleted")
end
- def test_allusermodelstates
+ def test_allusermodelproperties
user = nil
name = "pptest"
@@ -433,7 +433,7 @@ class TestUser < Test::Unit::TestCase
assert_equal("Puppet Testing User", user.provider.comment,
"Comment was not set")
- tests = Puppet.type(:user).validstates
+ tests = Puppet.type(:user).validproperties
tests.each { |test|
if self.respond_to?("attrtest_%s" % test)
diff --git a/test/types/yumrepo.rb b/test/types/yumrepo.rb
index 940fe1738..cd0fb0f42 100755
--- a/test/types/yumrepo.rb
+++ b/test/types/yumrepo.rb
@@ -29,9 +29,9 @@ class TestYumRepo < Test::Unit::TestCase
devel.retrieve
assert_equal("development", devel[:name])
assert_equal('Fedora Core $releasever - Development Tree',
- devel.state(:descr).is)
+ devel.property(:descr).is)
assert_equal('New description',
- devel.state(:descr).should)
+ devel.property(:descr).should)
assert_apply(devel)
inifile = Puppet.type(:yumrepo).read()
assert_equal('New description', inifile['development']['name'])
@@ -53,6 +53,7 @@ class TestYumRepo < Test::Unit::TestCase
:gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"
}
repo = make_repo("base", values)
+
assert_apply(repo)
inifile = Puppet.type(:yumrepo).read()
sections = all_sections(inifile)
diff --git a/test/types/zone.rb b/test/types/zone.rb
index e0df6d28a..75969945e 100755
--- a/test/types/zone.rb
+++ b/test/types/zone.rb
@@ -79,11 +79,11 @@ class TestZone < Test::Unit::TestCase
def test_valueslice
zone = mkzone("slicetest")
- state = zone.state(:ensure)
+ property = zone.property(:ensure)
slice = nil
assert_nothing_raised {
- slice = state.class.valueslice(:absent, :installed).collect do |o|
+ slice = property.class.valueslice(:absent, :installed).collect do |o|
o[:name]
end
}
@@ -92,7 +92,7 @@ class TestZone < Test::Unit::TestCase
assert_equal([:configured, :installed], slice)
assert_nothing_raised {
- slice = state.class.valueslice(:running, :installed).collect do |o|
+ slice = property.class.valueslice(:running, :installed).collect do |o|
o[:name]
end
}
@@ -106,23 +106,23 @@ class TestZone < Test::Unit::TestCase
def test_zoneensure
zone = mkzone("ensurezone")
- state = zone.state(:ensure)
+ property = zone.property(:ensure)
- assert(state, "Did not get ensure state")
+ assert(property, "Did not get ensure property")
assert_nothing_raised {
zone.retrieve
}
- assert(! state.insync?, "State is somehow in sync")
+ assert(! property.insync?, "Property is somehow in sync")
- assert(state.up?, "State incorrectly thinks it is not moving up")
+ assert(property.up?, "Property incorrectly thinks it is not moving up")
zone.is = [:ensure, :configured]
zone[:ensure] = :installed
- assert(state.up?, "State incorrectly thinks it is not moving up")
+ assert(property.up?, "Property incorrectly thinks it is not moving up")
zone[:ensure] = :absent
- assert(! state.up?, "State incorrectly thinks it is moving up")
+ assert(! property.up?, "Property incorrectly thinks it is moving up")
end
# Make sure all mentioned methods actually exist.
@@ -130,9 +130,9 @@ class TestZone < Test::Unit::TestCase
methods = []
zone = mkzone("methodtest")
- state = zone.state(:ensure)
+ property = zone.property(:ensure)
assert_nothing_raised {
- state.class.valueslice(:absent, :running).each do |st|
+ property.class.valueslice(:absent, :running).each do |st|
[:up, :down].each do |m|
if st[m]
methods << st[m]
@@ -151,27 +151,27 @@ class TestZone < Test::Unit::TestCase
end
- # Make sure our state generates the correct text.
- def test_inherit_state
+ # Make sure our property generates the correct text.
+ def test_inherit_property
zone = mkzone("configtesting")
zone[:ensure] = :configured
assert_nothing_raised {
zone[:inherit] = "/usr"
}
- state = zone.state(:inherit)
- assert(zone, "Did not get 'inherit' state")
+ property = zone.property(:inherit)
+ assert(zone, "Did not get 'inherit' property")
- assert_equal("add inherit-pkg-dir\nset dir=/usr\nend", state.configtext,
+ assert_equal("add inherit-pkg-dir\nset dir=/usr\nend", property.configtext,
"Got incorrect config text")
- state.is = "/usr"
+ property.is = "/usr"
- assert_equal("", state.configtext,
+ assert_equal("", property.configtext,
"Got incorrect config text")
# Now we want multiple directories
- state.should = %w{/usr /sbin /lib}
+ property.should = %w{/usr /sbin /lib}
# The statements are sorted
text = "add inherit-pkg-dir
@@ -181,15 +181,15 @@ add inherit-pkg-dir
set dir=/sbin
end"
- assert_equal(text, state.configtext,
+ assert_equal(text, property.configtext,
"Got incorrect config text")
- state.is = %w{/usr /sbin /lib}
- state.should = %w{/usr /sbin}
+ property.is = %w{/usr /sbin /lib}
+ property.should = %w{/usr /sbin}
text = "remove inherit-pkg-dir dir=/lib"
- assert_equal(text, state.configtext,
+ assert_equal(text, property.configtext,
"Got incorrect config text")
end
@@ -336,7 +336,7 @@ end
"ip was not removed")
end
- # Test creating and removing a zone, but only up to the configured state,
+ # Test creating and removing a zone, but only up to the configured property,
# so it's faster.
def test_smallcreate
zone = mkzone("smallcreate")
@@ -386,7 +386,7 @@ end
[:stop, :installed],
[:uninstall, :configured],
[:unconfigure, :absent]
- ].each do |method, state|
+ ].each do |method, property|
Puppet.info "Testing %s" % method
assert_nothing_raised {
zone.retrieve
@@ -397,9 +397,9 @@ end
assert_nothing_raised {
zone.retrieve
}
- assert_equal(state, zone.is(:ensure),
- "Method %s did not correctly set state %s" %
- [method, state])
+ assert_equal(property, zone.is(:ensure),
+ "Method %s did not correctly set property %s" %
+ [method, property])
end
end