summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/metatype/evaluation.rb4
-rw-r--r--lib/puppet/property.rb1
-rw-r--r--lib/puppet/propertychange.rb141
-rw-r--r--lib/puppet/transaction.rb2
-rw-r--r--lib/puppet/transaction/change.rb134
-rw-r--r--lib/puppet/type.rb1
-rw-r--r--lib/puppet/type/yumrepo.rb1
-rwxr-xr-xtest/other/transaction_change.rb (renamed from test/other/propertychange.rb)4
8 files changed, 139 insertions, 149 deletions
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index ff1eddb55..18bbb812f 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -139,7 +139,7 @@ class Puppet::Type
end
if ensureparam and ! ensureparam.insync?(currentvalues[ensureparam])
- changes << Puppet::PropertyChange.new(ensureparam, currentvalues[ensureparam])
+ changes << Puppet::Transaction::Change.new(ensureparam, currentvalues[ensureparam])
# Else, if the 'ensure' property is correctly absent, then do
# nothing
elsif ensureparam and currentvalues[ensureparam] == :absent
@@ -149,7 +149,7 @@ class Puppet::Type
currentvalues[property] ||= :absent
! property.insync?(currentvalues[property])
}.collect { |property|
- Puppet::PropertyChange.new(property, currentvalues[property])
+ Puppet::Transaction::Change.new(property, currentvalues[property])
}
end
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index fcaa19d48..9e8bae7a4 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -2,7 +2,6 @@
# blocks for actually doing work on the system.
require 'puppet'
-require 'puppet/propertychange'
require 'puppet/parameter'
module Puppet
diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb
deleted file mode 100644
index 35bbede1a..000000000
--- a/lib/puppet/propertychange.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-# the class responsible for actually doing any work
-
-# enables no-op and logging/rollback
-
-module Puppet
- # Handle all of the work around performing an actual change,
- # 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 property, thus running the change in reverse.
- def backward
- @property.should = @is
- @is = @property.retrieve
-
- unless defined? @transaction
- raise Puppet::Error,
- "PropertyChange '%s' tried to be executed outside of transaction" %
- self
- end
- unless @property.insync?(@is)
- @property.info "Backing %s" % self
- return self.go
- else
- @property.debug "rollback is already in sync: %s vs. %s" %
- [@is, @property.should.inspect]
- return nil
- end
- end
-
- def changed?
- self.changed
- end
-
- # Create our event object.
- def event(name)
- # default to a simple event type
- unless name.is_a?(Symbol)
- @property.warning("Property '%s' returned invalid event '%s'; resetting to default" %
- [@property.class, name])
-
- event = @property.resource.class.name.id2name + "_changed"
- end
-
- Puppet::Event.new(
- :event => name,
- :transaction => @transaction,
- :source => self.source
- )
- end
-
- def initialize(property, currentvalue)
- unless property.is_a?(Puppet::Property)
- raise Puppet::DevError, "Got a %s instead of a property" %
- property.class
- end
- @property = property
- @path = [property.path,"change"].flatten
- @is = currentvalue
-
- @should = property.should
-
- @changed = false
- end
-
- # Perform the actual change. This method can go either forward or
- # backward, and produces an event.
- def go
- if skip?
- if self.noop
- return [event(:noop)]
- else
- return nil
- end
- end
-
- # The transaction catches any exceptions here.
- events = @property.sync
- if events.nil?
- return nil
- end
-
- if events.is_a?(Array)
- if events.empty?
- return nil
- end
- else
- events = [events]
- end
-
- return events.collect { |name|
- @report = @property.log(@property.change_to_s(@is, @should))
- event(name)
- }
- end
-
- def forward
- #@property.debug "moving change forward"
-
- unless defined? @transaction
- raise Puppet::Error,
- "PropertyChange '%s' tried to be executed outside of transaction" %
- self
- end
-
- return self.go
- end
-
- def noop
- return @property.noop
- end
-
- def skip?
- if @property.insync?(@is)
- @property.info "Already in sync"
- return true
- end
-
- if @property.noop
- @property.log "is %s, should be %s (noop)" %
- [property.is_to_s(@is), property.should_to_s(@should)]
- #@property.debug "%s is noop" % @property
- return true
- end
- return false
- end
-
- def source
- self.proxy || @property.resource
- end
-
- def to_s
- return "change %s.%s(%s)" %
- [@transaction.object_id, self.object_id, @property.change_to_s(@is, @should)]
- #return "change %s.%s" % [@transaction.object_id, self.object_id]
- end
- end
-end
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index b191f8219..84a41d5b8 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -2,10 +2,10 @@
# and performs them
require 'puppet'
-require 'puppet/propertychange'
module Puppet
class Transaction
+ require 'puppet/transaction/change'
attr_accessor :component, :catalog, :ignoreschedules
attr_accessor :sorted_resources, :configurator
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
new file mode 100644
index 000000000..ee92f2249
--- /dev/null
+++ b/lib/puppet/transaction/change.rb
@@ -0,0 +1,134 @@
+require 'puppet/transaction'
+
+# Handle all of the work around performing an actual change,
+# including calling 'sync' on the properties and producing events.
+class Puppet::Transaction::Change
+ 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 property, thus running the change in reverse.
+ def backward
+ @property.should = @is
+ @is = @property.retrieve
+
+ unless defined? @transaction
+ raise Puppet::Error,
+ "PropertyChange '%s' tried to be executed outside of transaction" %
+ self
+ end
+ unless @property.insync?(@is)
+ @property.info "Backing %s" % self
+ return self.go
+ else
+ @property.debug "rollback is already in sync: %s vs. %s" %
+ [@is, @property.should.inspect]
+ return nil
+ end
+ end
+
+ def changed?
+ self.changed
+ end
+
+ # Create our event object.
+ def event(name)
+ # default to a simple event type
+ unless name.is_a?(Symbol)
+ @property.warning("Property '%s' returned invalid event '%s'; resetting to default" %
+ [@property.class, name])
+
+ event = @property.resource.class.name.id2name + "_changed"
+ end
+
+ Puppet::Event.new(
+ :event => name,
+ :transaction => @transaction,
+ :source => self.source
+ )
+ end
+
+ def initialize(property, currentvalue)
+ unless property.is_a?(Puppet::Property)
+ raise Puppet::DevError, "Got a %s instead of a property" %
+ property.class
+ end
+ @property = property
+ @path = [property.path,"change"].flatten
+ @is = currentvalue
+
+ @should = property.should
+
+ @changed = false
+ end
+
+ # Perform the actual change. This method can go either forward or
+ # backward, and produces an event.
+ def go
+ if skip?
+ if self.noop
+ return [event(:noop)]
+ else
+ return nil
+ end
+ end
+
+ # The transaction catches any exceptions here.
+ events = @property.sync
+ if events.nil?
+ return nil
+ end
+
+ if events.is_a?(Array)
+ if events.empty?
+ return nil
+ end
+ else
+ events = [events]
+ end
+
+ return events.collect { |name|
+ @report = @property.log(@property.change_to_s(@is, @should))
+ event(name)
+ }
+ end
+
+ def forward
+ unless defined? @transaction
+ raise Puppet::Error,
+ "PropertyChange '%s' tried to be executed outside of transaction" %
+ self
+ end
+
+ return self.go
+ end
+
+ def noop
+ return @property.noop
+ end
+
+ def skip?
+ if @property.insync?(@is)
+ @property.info "Already in sync"
+ return true
+ end
+
+ if @property.noop
+ @property.log "is %s, should be %s (noop)" %
+ [property.is_to_s(@is), property.should_to_s(@should)]
+ #@property.debug "%s is noop" % @property
+ return true
+ end
+ return false
+ end
+
+ def source
+ self.proxy || @property.resource
+ end
+
+ def to_s
+ return "change %s.%s(%s)" %
+ [@transaction.object_id, self.object_id, @property.change_to_s(@is, @should)]
+ end
+end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index f8949ec90..b7de11de5 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -415,7 +415,6 @@ class Type
end # Puppet::Type
end
-require 'puppet/propertychange'
require 'puppet/provider'
# Always load these types.
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index acb3b9b83..d19b5a470 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -1,6 +1,5 @@
# Description of yum repositories
-require 'puppet/propertychange'
require 'puppet/util/inifile'
module Puppet
diff --git a/test/other/propertychange.rb b/test/other/transaction_change.rb
index eaa4f4082..292f59334 100755
--- a/test/other/propertychange.rb
+++ b/test/other/transaction_change.rb
@@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../lib/puppettest'
require 'puppettest'
-class TestPropertyChange < Test::Unit::TestCase
+class TestTransactionChange < Test::Unit::TestCase
include PuppetTest
class FakeProperty < Puppet::Property
attr_accessor :is, :should, :resource
@@ -58,7 +58,7 @@ class TestPropertyChange < Test::Unit::TestCase
property.resource = :parent
change = nil
assert_nothing_raised do
- change = Puppet::PropertyChange.new(property, :start)
+ change = Puppet::Transaction::Change.new(property, :start)
end
change.transaction = :trans