From 8c5c949b37d3af4439c713e6c6e57e8f4b0415ac Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Fri, 27 Jun 2008 09:32:12 +0200 Subject: ssh_authorized_key: autorequire, default permissions and cleanup Autorequire the target file and its parent directory as well. Default permissions and owner are now set on the file and its parent directory. Moved target attribute setting code from prefetch() in the provider to the type itself. This seems much cleaner to me. --- lib/puppet/provider/ssh_authorized_key/parsed.rb | 16 ----------- lib/puppet/type/ssh_authorized_key.rb | 36 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index 7cb6626de..351ebcd1b 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -29,21 +29,5 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, record[:options] = record[:options].join(',') end } - - def prefetch - if not @resource.should(:target) - # - # Set default target when user is given - if val = @resource.should(:user) - target = File.expand_path("~%s/.ssh/authorized_keys" % val) - Puppet::debug("Setting target to %s" % target) - @resource[:target] = target - else - raise Puppet::Error, "Missing attribute 'user' or 'target'" - end - end - - super - end end diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index e28fb7cda..650ebd879 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -27,6 +27,11 @@ module Puppet newproperty(:user) do desc "The user account in which the ssh key should be installed." + + def value=(value) + @resource[:target] = File.expand_path("~%s/.ssh/authorized_keys" % value) + super + end end newproperty(:target) do @@ -39,6 +44,37 @@ module Puppet defaultto do :absent end end + + autorequire(:file) do + atype = Puppet::Type.type(:file) + target = self.should(:target) + dir = File.dirname(target) + user = should(:user) ? should(:user) : "root" + + rels = [] + + unless atype[dir] + rels << atype.create(:name => dir, :ensure => :directory, :mode => 0700, :owner => user) + end + + unless atype[target] + rels << atype.create(:name => target, :ensure => :present, :mode => 0600, :owner => user) + end + + rels + end + + autorequire(:user) do + if should(:user) + should(:user) + end + end + + validate do + unless should(:target) + raise Puppet::Error, "Attribute 'user' or 'target' is mandatory" + end + end end end -- cgit From 5156230b434adbe6de6606f6bcd8843264b8dab4 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Wed, 2 Jul 2008 16:18:06 +0200 Subject: Use generate instead of autorequire in the ssh_authorized_key type based on Luke's comments --- lib/puppet/type/ssh_authorized_key.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index 650ebd879..a95f316af 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -45,7 +45,7 @@ module Puppet defaultto do :absent end end - autorequire(:file) do + def generate atype = Puppet::Type.type(:file) target = self.should(:target) dir = File.dirname(target) @@ -53,11 +53,11 @@ module Puppet rels = [] - unless atype[dir] + unless catalog.resource(:file, dir) rels << atype.create(:name => dir, :ensure => :directory, :mode => 0700, :owner => user) end - unless atype[target] + unless catalog.resource(:file, target) rels << atype.create(:name => target, :ensure => :present, :mode => 0600, :owner => user) end -- cgit From daf0d9db5dc400a9795a5f741c8c63184f5e8982 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Jul 2008 21:16:45 -0500 Subject: Backporting a test that was failing in master, and fixing it Signed-off-by: Luke Kanies --- lib/puppet/node/catalog.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 720b3752d..17927388a 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -95,6 +95,7 @@ class Puppet::Node::Catalog < Puppet::PGraph # isn't sufficient. return if newref == resource.ref if existing = @resource_table[newref] + return if existing == resource raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref]) end @resource_table[newref] = resource -- cgit From 4b6b22e8d64b6fe8c69d9925eedc703757ce3567 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Jul 2008 22:00:54 -0500 Subject: Adding logging when a node's facts can't be found Signed-off-by: Luke Kanies --- lib/puppet/node.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 14d0f6ac7..afa18f565 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -75,6 +75,8 @@ class Puppet::Node def fact_merge if facts = Puppet::Node::Facts.find(name) merge(facts.values) + else + Puppet.warning "Could not find facts for %s; you probably have a discrepancy between the node and fact names" % name end end -- cgit From c825c991fd68274ae1b172f97059be616d5b057e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Jul 2008 22:03:45 -0500 Subject: Fixing the ldap node terminus to merge facts with the right name. Previously, I was merging early and changing the name later. This commit fixes it so that the node is created with the right name in the first place, so the node.fact_merge actually works. Yay for real-world testing. Signed-off-by: Luke Kanies --- lib/puppet/indirector/node/ldap.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 71d3e3b0e..01010a2af 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -14,7 +14,7 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end # Separate this out so it's relatively atomic. It's tempting to call - # process() instead of entry2hash() here, but it ends up being + # process() instead of name2hash() here, but it ends up being # difficult to test because all exceptions get caught by ldapsearch. # LAK:NOTE Unfortunately, the ldap support is too stupid to throw anything # but LDAP::ResultError, even on bad connections, so we are rough handed @@ -35,21 +35,14 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap node = nil names.each do |name| - break if node = process(name) - end - return nil unless node + next unless info = name2hash(name) - node.name = request.key + break if node = info2node(request.key, info) + end return node end - def process(name) - return nil unless info = name2hash(name) - - info2node(name, info) - end - # Find more than one node. LAK:NOTE This is a bit of a clumsy API, because the 'search' # method currently *requires* a key. It seems appropriate in some cases but not others, # and I don't really know how to get rid of it as a requirement but allow it when desired. -- cgit From 731d0f2291ccf900aab29eabed311607173b70ee Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 3 Jul 2008 13:45:14 +1000 Subject: Minor documentation updates for ssh_authorized_key type --- lib/puppet/type/ssh_authorized_key.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index a95f316af..3a12e95ad 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -5,14 +5,14 @@ module Puppet ensurable newparam(:name) do - desc "The ssh key comment." + desc "The SSH key comment." isnamevar end newproperty(:type) do - desc "The encryption type used. Probably ssh-dss or ssh-rsa for - ssh version 2. Not used for ssh version 1." + desc "The encryption type used. Usually ssh-dss or ssh-rsa for + SSH version 2. Not used for SSH version 1." newvalue("ssh-dss") newvalue("ssh-rsa") @@ -26,7 +26,7 @@ module Puppet end newproperty(:user) do - desc "The user account in which the ssh key should be installed." + desc "The user account in which the SSH key should be installed." def value=(value) @resource[:target] = File.expand_path("~%s/.ssh/authorized_keys" % value) @@ -35,12 +35,12 @@ module Puppet end newproperty(:target) do - desc "The file in which to store the ssh key." + desc "The file in which to store the SSH key." end newproperty(:options, :array_matching => :all) do - desc "Key options, see sshd(8) for possible values. Multiple values - should be specified as an array." + desc "Key options, see sshd(8) for possible values. Multiple values + should be specified as an array." defaultto do :absent end end -- cgit From 04ecb742f46cf8e48337c854a5ff2377caf60db1 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Jul 2008 15:13:09 -0500 Subject: Doing what I can to fix #1128, but just in preparation for removing 'interface'. This type needs to be started again from scratch, and I'm not going to do so for 0.24.5. In particular, the model for red hat and sunos need to match -- they should both use the device name as the actual name. Signed-off-by: Luke Kanies --- lib/puppet/provider/interface/redhat.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/interface/redhat.rb b/lib/puppet/provider/interface/redhat.rb index 4a9fcb491..71f2a6327 100644 --- a/lib/puppet/provider/interface/redhat.rb +++ b/lib/puppet/provider/interface/redhat.rb @@ -57,14 +57,14 @@ LOOPBACKDUMMY def self.instances # parse all of the config files at once Dir.glob("%s/ifcfg-*" % INTERFACE_DIR).collect do |file| - record = parse(file) + instance = parse(file) # store the existing dummy interfaces - @@dummies << record[:ifnum] if (record[:interface_type] == :dummy and ! @@dummies.include?(record[:ifnum])) + @@dummies << instance.ifnum if (instance.interface_type == :dummy and ! @@dummies.include?(instance.ifnum)) - @@aliases[record[:interface]] << record[:ifnum] if record[:interface_type] == :alias + @@aliases[instance.interface] << instance.ifnum if instance.interface_type == :alias - new(record) + instance end end @@ -95,12 +95,18 @@ LOOPBACKDUMMY # Parse the existing file. def self.parse(file) - instance = new() + unless file =~ /-([^-]+)$/ + Puppet.warning "Could not extract interface name from %s; skipping" % file + return nil + end + name = $1 + instance = new(:name => name) return instance unless FileTest.exist?(file) File.readlines(file).each do |line| if line =~ /^(\w+)=(.+)$/ - instance.send($1.downcase + "=", $2) + method = $1.downcase + "=" + instance.send(method, $2) if instance.respond_to?(method) end end @@ -197,11 +203,16 @@ LOOPBACKDUMMY end end + # LAK:NOTE This method is why this resource type has been disabled. + # The model is ridiculous -- the device name should be the interface + # name. We're 90% of the way toward making this possible, but I'm not + # taking the time to fix it. # Set the name to our ip address. def ipaddr=(value) @property_hash[:name] = value end + # whether the device is to be brought up on boot or not. converts # the true / false of the type, into yes / no values respectively # writing out the ifcfg-* files -- cgit From be169da98d34f7305019d9e3be2a7da2bcb3e28c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Jul 2008 15:14:00 -0500 Subject: Removing all of the code related to the interface type. --- lib/puppet/provider/interface/redhat.rb | 261 -------------------------------- lib/puppet/provider/interface/sunos.rb | 133 ---------------- lib/puppet/type/interface.rb | 60 -------- 3 files changed, 454 deletions(-) delete mode 100644 lib/puppet/provider/interface/redhat.rb delete mode 100644 lib/puppet/provider/interface/sunos.rb delete mode 100644 lib/puppet/type/interface.rb (limited to 'lib') diff --git a/lib/puppet/provider/interface/redhat.rb b/lib/puppet/provider/interface/redhat.rb deleted file mode 100644 index 71f2a6327..000000000 --- a/lib/puppet/provider/interface/redhat.rb +++ /dev/null @@ -1,261 +0,0 @@ -require 'puppet/provider/parsedfile' -require 'erb' - -Puppet::Type.type(:interface).provide(:redhat) do - desc "Manage network interfaces on Red Hat operating systems. This provider - parses and generates configuration files in ``/etc/sysconfig/network-scripts``." - - INTERFACE_DIR = "/etc/sysconfig/network-scripts" - confine :exists => INTERFACE_DIR - defaultfor :operatingsystem => [:fedora, :centos, :redhat] - - # Create the setter/gettor methods to match the model. - mk_resource_methods - - @templates = {} - - # Register a template. - def self.register_template(name, string) - @templates[name] = ERB.new(string) - end - - # Retrieve a template by name. - def self.template(name) - @templates[name] - end - - register_template :alias, <<-ALIAS -DEVICE=<%= self.device %> -ONBOOT=<%= self.on_boot %> -BOOTPROTO=none -IPADDR=<%= self.name %> -NETMASK=<%= self.netmask %> -BROADCAST= -ALIAS - - - register_template :normal, <<-LOOPBACKDUMMY -DEVICE=<%= self.device %> -ONBOOT=<%= self.on_boot %> -BOOTPROTO=static -IPADDR=<%= self.name %> -NETMASK=<%= self.netmask %> -BROADCAST= -LOOPBACKDUMMY - - # maximum number of dummy interfaces - @max_dummies = 10 - - # maximum number of aliases per interface - @max_aliases_per_iface = 10 - - @@dummies = [] - @@aliases = Hash.new { |hash, key| hash[key] = [] } - - # calculate which dummy interfaces are currently already in - # use prior to needing to call self.next_dummy later on. - def self.instances - # parse all of the config files at once - Dir.glob("%s/ifcfg-*" % INTERFACE_DIR).collect do |file| - instance = parse(file) - - # store the existing dummy interfaces - @@dummies << instance.ifnum if (instance.interface_type == :dummy and ! @@dummies.include?(instance.ifnum)) - - @@aliases[instance.interface] << instance.ifnum if instance.interface_type == :alias - - instance - end - end - - # return the next avaliable dummy interface number, in the case where - # ifnum is not manually specified - def self.next_dummy - @max_dummies.times do |i| - unless @@dummies.include?(i.to_s) - @@dummies << i.to_s - return i.to_s - end - end - end - - # return the next available alias on a given interface, in the case - # where ifnum if not manually specified - def self.next_alias(interface) - @max_aliases_per_iface.times do |i| - unless @@aliases[interface].include?(i.to_s) - @@aliases[interface] << i.to_s - return i.to_s - end - end - end - - # base the ifnum, for dummy / loopback interface in linux - # on the last octect of the IP address - - # Parse the existing file. - def self.parse(file) - unless file =~ /-([^-]+)$/ - Puppet.warning "Could not extract interface name from %s; skipping" % file - return nil - end - name = $1 - instance = new(:name => name) - return instance unless FileTest.exist?(file) - - File.readlines(file).each do |line| - if line =~ /^(\w+)=(.+)$/ - method = $1.downcase + "=" - instance.send(method, $2) if instance.respond_to?(method) - end - end - - return instance - end - - # Prefetch our interface list, yo. - def self.prefetch(resources) - instances.each do |prov| - if resource = resources[prov.name] - resource.provider = prov - end - end - end - - def create - self.class.resource_type.validproperties.each do |property| - if value = @resource.should(property) - @property_hash[property] = value - end - end - @property_hash[:name] = @resource.name - - return (@resource.class.name.to_s + "_created").intern - end - - def destroy - File.unlink(file_path) - end - - def exists? - FileTest.exist?(file_path) - end - - # generate the content for the interface file, so this is dependent - # on whether we are adding an alias to a real interface, or a loopback - # address (also dummy) on linux. For linux it's quite involved, and we - # will use an ERB template - def generate - itype = self.interface_type == :alias ? :alias : :normal - self.class.template(itype).result(binding) - end - - # Where should the file be written out? - # This defaults to INTERFACE_DIR/ifcfg-, but can have a - # more symbolic name by setting interface_desc in the type. - def file_path - if resource and val = resource[:interface_desc] - desc = val - else - desc = self.name - end - - self.fail("Could not get name for interface") unless desc - - if self.interface_type == :alias - return File.join(INTERFACE_DIR, "ifcfg-" + self.interface + ":" + desc) - else - return File.join(INTERFACE_DIR, "ifcfg-" + desc) - end - end - - # Use the device value to figure out all kinds of nifty things. - def device=(value) - case value - when /:/: - @property_hash[:interface], @property_hash[:ifnum] = value.split(":") - @property_hash[:interface_type] = :alias - when /^dummy/: - @property_hash[:interface_type] = :loopback - @property_hash[:interface] = "dummy" - - # take the number of the dummy interface, as this is used - # when working out whether to call next_dummy when dynamically - # creating these - @property_hash[:ifnum] = value.sub("dummy",'') - - @@dummies << @property_hash[:ifnum].to_s unless @@dummies.include?(@property_hash[:ifnum].to_s) - else - @property_hash[:interface_type] = :normal - @property_hash[:interface] = value - end - end - - # create the device name, so this based on the IP, and interface + type - def device - case @resource.should(:interface_type) - when :loopback - @property_hash[:ifnum] ||= self.class.next_dummy - return "dummy" + @property_hash[:ifnum] - when :alias - @property_hash[:ifnum] ||= self.class.next_alias(@resource[:interface]) - return @resource[:interface] + ":" + @property_hash[:ifnum] - end - end - - # LAK:NOTE This method is why this resource type has been disabled. - # The model is ridiculous -- the device name should be the interface - # name. We're 90% of the way toward making this possible, but I'm not - # taking the time to fix it. - # Set the name to our ip address. - def ipaddr=(value) - @property_hash[:name] = value - end - - - # whether the device is to be brought up on boot or not. converts - # the true / false of the type, into yes / no values respectively - # writing out the ifcfg-* files - def on_boot - case @property_hash[:onboot].to_s - when "true" - return "yes" - when "false" - return "no" - else - return "neither" - end - end - - # Mark whether the interface should be started on boot. - def on_boot=(value) - # translate whether we come up on boot to true/false - case value.downcase - when "yes": - @property_hash[:onboot] = :true - else - @property_hash[:onboot] = :false - end - end - - # Write the new file out. - def flush - # Don't flush to disk if we're removing the config. - return if self.ensure == :absent - - @property_hash.each do |name, val| - if val == :absent - raise ArgumentError, "Propety %s must be provided" % val - end - end - - File.open(file_path, "w") do |f| - f.puts generate() - end - end - - def prefetch - @property_hash = self.class.parse(file_path) - end -end - diff --git a/lib/puppet/provider/interface/sunos.rb b/lib/puppet/provider/interface/sunos.rb deleted file mode 100644 index eda21ca3d..000000000 --- a/lib/puppet/provider/interface/sunos.rb +++ /dev/null @@ -1,133 +0,0 @@ -require 'puppet/provider/parsedfile' -require 'erb' - -Puppet::Type.type(:interface).provide(:sunos) do - confine :kernel => "SunOS" - - # Add accessor/getter methods for each property/parameter; these methods - # modify @property_hash. - mk_resource_methods - - # Get a list of interface instances. - def self.instances - Dir.glob("/etc/hostname.*").collect do |file| - device = File.basename(file).split(".").pop - - instance = new(:interface => device) - instance.parse - instance - end - end - - def self.match(hash) - # see if we can match the has against an existing object - if model.find { |obj| obj.value(:name) == hash[:name] } - return obj - else - return false - end - end - - # Prefetch our interface list, yo. - def self.prefetch(resources) - instances.each do |prov| - if resource = resources[prov.name] - resource.provider = prov - end - end - end - - def initialize(*args) - @property_hash = {} - super - end - - def create - self.class.resource_type.validproperties.each do |property| - if value = resource.should(property) - @property_hash[property] = value - end - end - @property_hash[:name] = resource.name - - return (@resource.class.name.to_s + "_created").intern - end - - def destroy - File.unlink(file_path) - @property_hash[:ensure] = :absent - end - - def exists? - FileTest.exist?(file_path) - end - - # Where should the file be written out? Can be overridden by setting - # :target in the model. - def file_path - self.fail("Could not determine interface") unless interface = @property_hash[:interface] || (resource and resource[:interface]) - return File.join("/etc", "hostname." + interface) - end - - def flush - return if self.ensure == :absent - File.open(file_path, "w") { |f| f.print generate() + "\n" } - end - - # Turn our record into a line. - def generate - ret = [] - if self.interface_type == :alias - ret << "addif" - end - ret << self.name - - if self.ifopts != :absent - if @property_hash[:ifopts].is_a?(Array) - ret << @property_hash[:ifopts].join(" ") - else - ret << @property_hash[:ifopts] - end - end - - if self.onboot and ! [:absent, :false].include?(self.onboot) - ret << "up" - end - - return ret.join(" ") - end - - # Parse our interface file. - def parse - (@property_hash = {:ensure => :absent} and return) unless FileTest.exist?(file_path) - - values = File.read(file_path).chomp.split(/\s+/) - - @property_hash[:ensure] = :present - #@property_hash = {:ensure => :present} - - # Are we the primary interface? - if values[0] == "addif" - @property_hash[:interface_type] = :alias - values.shift - else - @property_hash[:interface_type] = :normal - end - - # Should the interface be up by default? - if values[-1] == "up" - @property_hash[:onboot] = :true - values.pop - else - @property_hash[:onboot] = :false - end - - # Set the interface name. - @property_hash[:name] = values.shift - - # Handle any interface options - unless values.empty? - @property_hash[:ifopts] = values.join(" ") - end - end -end diff --git a/lib/puppet/type/interface.rb b/lib/puppet/type/interface.rb deleted file mode 100644 index 2f6c28ad3..000000000 --- a/lib/puppet/type/interface.rb +++ /dev/null @@ -1,60 +0,0 @@ -Puppet::Type.newtype(:interface) do - require 'erb' - - @doc = "Create configuration for IP address aliases and loopback addresses." - - newparam(:name, :namevar => true) do - desc "The ipaddress to add to alias or loopback/dummy interface" - end - - ensurable - - newparam(:interface) do - desc "The interface the IP should be added to" - end - - newproperty(:interface_type) do - desc "The interface type, loopback (also dummy) or alias" - - newvalue(:loopback) - newvalue(:alias) - newvalue(:normal) - - # Make dummy and loopback equivalent - aliasvalue(:dummy, :loopback) - - defaultto :normal - end - - newparam(:interface_desc) do - desc "On Linux, the description / symbolic name you wish to refer to the - interface by. When absent, Redhat Linux defaults to uses the namevar - which will be either the IP address, or hostname." - end - - newproperty(:onboot) do - desc "Whether the interface should be configured to come up on boot" - newvalue(:true) - newvalue(:false) - end - - newproperty(:ifnum) do - desc "If not automatically configuring the dummy interface or - and alias. This is use to force a given number to be used" - end - - newproperty(:netmask) do - desc "The netmask for the interface." - end - - newproperty(:ifopts) do - desc "Interface options." - end - - newparam(:target) do - include Puppet::Util::Warnings - desc "The path to the file this resource creates." - - munge { |value| warnonce "Interface targets are deprecated and no longer have any function" } - end -end -- cgit From ba12d3000d31dbccb3b60320eae6c1be302e0bd5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Jul 2008 17:27:11 -0500 Subject: Fixed #1232 - the rundir no longer specifies a user/group, and there are now client- and server-specific yaml directories. Signed-off-by: Luke Kanies --- lib/puppet/defaults.rb | 6 +++--- lib/puppet/indirector/yaml.rb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 472d98c4f..5f71bb8b7 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -69,8 +69,6 @@ module Puppet :rundir => { :default => rundir, :mode => 01777, - :owner => "$user", - :group => "$group", :desc => "Where Puppet PID files are kept." }, :genconfig => [false, @@ -358,7 +356,9 @@ module Puppet # To make sure this directory is created before we try to use it on the server, we need # it to be in the server section (#1138). :yamldir => {:default => "$vardir/yaml", :owner => "$user", :group => "$user", :mode => "750", - :desc => "The directory in which YAML data is stored, usually in a subdirectory."} + :desc => "The directory in which YAML data is stored, usually in a subdirectory."}, + :clientyamldir => {:default => "$vardir/client_yaml", :mode => "750", + :desc => "The directory in which client-side YAML data is stored."} ) self.setdefaults(:puppetd, diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 23bca02b8..3573ba560 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -36,7 +36,8 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus # Return the path to a given node's file. def path(name) - File.join(Puppet[:yamldir], self.class.indirection_name.to_s, name.to_s + ".yaml") + base = (Puppet[:name] == "puppetmasterd") ? Puppet[:yamldir] : Puppet[:clientyamldir] + File.join(base, self.class.indirection_name.to_s, name.to_s + ".yaml") end private -- cgit From 6124c693c98217bdb747f455eefd09d303b0b2a5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Jul 2008 17:53:07 -0500 Subject: Renaming the Puppet::PropertyChange class to Puppet::Transaction::Change. Signed-off-by: Luke Kanies --- lib/puppet/metatype/evaluation.rb | 4 +- lib/puppet/property.rb | 1 - lib/puppet/propertychange.rb | 141 -------------------------------------- lib/puppet/transaction.rb | 2 +- lib/puppet/transaction/change.rb | 134 ++++++++++++++++++++++++++++++++++++ lib/puppet/type.rb | 1 - lib/puppet/type/yumrepo.rb | 1 - 7 files changed, 137 insertions(+), 147 deletions(-) delete mode 100644 lib/puppet/propertychange.rb create mode 100644 lib/puppet/transaction/change.rb (limited to 'lib') 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 -- cgit From 5ef89790eb30bc61af4d6f8a429af316aa0a3702 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 4 Jul 2008 09:13:50 +1000 Subject: Removed debugging from lib/puppet/util/ldap/connection.rb --- lib/puppet/util/ldap/connection.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/util/ldap/connection.rb b/lib/puppet/util/ldap/connection.rb index 861539872..f6530f853 100644 --- a/lib/puppet/util/ldap/connection.rb +++ b/lib/puppet/util/ldap/connection.rb @@ -63,7 +63,6 @@ class Puppet::Util::Ldap::Connection @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail - puts detail.class raise Puppet::Error, "Could not connect to LDAP: %s" % detail end end -- cgit From 73c06c05aec8834b6fdebac107fb289575779020 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Jul 2008 18:50:56 -0500 Subject: Renaming Puppet::Event to Puppet::Transaction::Event Signed-off-by: Luke Kanies --- lib/puppet/event.rb | 28 ---------------------------- lib/puppet/transaction.rb | 6 ++++-- lib/puppet/transaction/event.rb | 22 ++++++++++++++++++++++ lib/puppet/type.rb | 1 - 4 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 lib/puppet/event.rb create mode 100644 lib/puppet/transaction/event.rb (limited to 'lib') diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb deleted file mode 100644 index c1928a354..000000000 --- a/lib/puppet/event.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'puppet' -require 'puppet/util/methodhelper' -require 'puppet/util/errors' - -module Puppet - # events are transient packets of information; they result in one or more (or none) - # subscriptions getting triggered, and then they get cleared - # eventually, these will be passed on to some central event system - class Event - include Puppet - include Puppet::Util::MethodHelper - include Puppet::Util::Errors - - attr_accessor :event, :source, :transaction - - @@events = [] - - def initialize(args) - set_options symbolize_options(args) - requiredopts(:event, :source) - end - - def to_s - @source.to_s + " -> " + self.event.to_s - end - end -end - diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 84a41d5b8..78704bb13 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -6,6 +6,8 @@ require 'puppet' module Puppet class Transaction require 'puppet/transaction/change' + require 'puppet/transaction/event' + attr_accessor :component, :catalog, :ignoreschedules attr_accessor :sorted_resources, :configurator @@ -680,7 +682,7 @@ class Transaction [callback, subs.length] # And then add an event for it. - return [Puppet::Event.new( + return [Puppet::Transaction::Event.new( :event => :noop, :transaction => self, :source => resource @@ -712,7 +714,7 @@ class Transaction end # And then add an event for it. - trigged << Puppet::Event.new( + trigged << Puppet::Transaction::Event.new( :event => :triggered, :transaction => self, :source => resource diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb new file mode 100644 index 000000000..418e70516 --- /dev/null +++ b/lib/puppet/transaction/event.rb @@ -0,0 +1,22 @@ +require 'puppet' +require 'puppet/util/methodhelper' +require 'puppet/util/errors' + +# events are transient packets of information; they result in one or more (or none) +# subscriptions getting triggered, and then they get cleared +# eventually, these will be passed on to some central event system +class Puppet::Transaction::Event + include Puppet::Util::MethodHelper + include Puppet::Util::Errors + + attr_accessor :event, :source, :transaction + + def initialize(args) + set_options symbolize_options(args) + requiredopts(:event, :source) + end + + def to_s + @source.to_s + " -> " + self.event.to_s + end +end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index b7de11de5..45dd7f5b5 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1,6 +1,5 @@ require 'puppet' require 'puppet/util/log' -require 'puppet/event' require 'puppet/util/metric' require 'puppet/property' require 'puppet/parameter' -- cgit From 8865bdf112b33660a3e41b03f57d2575809e3cb4 Mon Sep 17 00:00:00 2001 From: Andrew Shafer Date: Fri, 4 Jul 2008 08:24:14 -0600 Subject: file object creation should fail if source is not present removed described? logic from insync? in ensure.rb and source.rb raise in source#retrieve if the source is not found --- lib/puppet/type/file/ensure.rb | 5 ----- lib/puppet/type/file/source.rb | 20 +++++++------------- 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb index 0d2171216..a9ddc2dba 100755 --- a/lib/puppet/type/file/ensure.rb +++ b/lib/puppet/type/file/ensure.rb @@ -138,11 +138,6 @@ module Puppet # We have to treat :present specially, because it works with any # type of file. def insync?(currentvalue) - if property = @resource.property(:source) and ! property.described? - warning "No specified sources exist" - return true - end - if self.should == :present if currentvalue.nil? or currentvalue == :absent return false diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index 1b0dd3141..f2704abb6 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -135,18 +135,8 @@ module Puppet return args end - # Have we successfully described the remote source? - def described? - ! @stats.nil? and ! @stats[:type].nil? #and @is != :notdescribed - end - # Use the info we get from describe() to check if we're in sync. def insync?(currentvalue) - unless described? - warning "No specified sources exist" - return true - end - if currentvalue == :nocopy return true end @@ -180,7 +170,11 @@ module Puppet def pinparams [:mode, :type, :owner, :group] end - + + def found? + ! (@stats.nil? or @stats[:type].nil?) + end + # This basically calls describe() on our file, and then sets all # of the local states appropriately. If the remote file is a normal # file then we set it to copy; if it's a directory, then we just mark @@ -202,8 +196,8 @@ module Puppet } end - if @stats.nil? or @stats[:type].nil? - return nil # :notdescribed + if !found? + raise Puppet::Error, "No specified source was found from" + @should.inject("") { |s, source| s + " #{source},"}.gsub(/,$/,"") end case @stats[:type] -- cgit From 31ffeabad92338d317c3193d50e8dd9a1a78977c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 4 Jul 2008 15:05:29 -0500 Subject: Adding tests to the Transaction::Change class. There's a small amount of refactoring here, mostly removing code that appears to not be used at all. Signed-off-by: Luke Kanies --- lib/puppet/transaction/change.rb | 54 ++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index ee92f2249..e1863ee13 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -1,4 +1,5 @@ require 'puppet/transaction' +require 'puppet/transaction/event' # Handle all of the work around performing an actual change, # including calling 'sync' on the properties and producing events. @@ -13,7 +14,7 @@ class Puppet::Transaction::Change @property.should = @is @is = @property.retrieve - unless defined? @transaction + unless transaction raise Puppet::Error, "PropertyChange '%s' tried to be executed outside of transaction" % self @@ -39,21 +40,17 @@ class Puppet::Transaction::Change @property.warning("Property '%s' returned invalid event '%s'; resetting to default" % [@property.class, name]) - event = @property.resource.class.name.id2name + "_changed" + name = @property.event(should) end - Puppet::Event.new( + Puppet::Transaction::Event.new( :event => name, - :transaction => @transaction, - :source => self.source + :transaction => transaction, + :source => self.resource ) 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 @@ -66,12 +63,9 @@ class Puppet::Transaction::Change # 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 + if self.noop? + @property.log "is %s, should be %s (noop)" % [property.is_to_s(@is), property.should_to_s(@should)] + return [event(:noop)] end # The transaction catches any exceptions here. @@ -95,7 +89,7 @@ class Puppet::Transaction::Change end def forward - unless defined? @transaction + unless transaction raise Puppet::Error, "PropertyChange '%s' tried to be executed outside of transaction" % self @@ -104,31 +98,21 @@ class Puppet::Transaction::Change return self.go end - def noop + # Is our property noop? This is used for generating special events. + 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 + # The resource that generated this change. This is used for handling events, + # and the proxy resource is used for generated resources, since we can't + # send an event to a resource we don't have a direct relationship. If we + # have a proxy resource, then the events will be considered to be from + # that resource, rather than us, so the graph resolution will still work. + def resource 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(%s)" % [transaction.object_id, self.object_id, @property.change_to_s(@is, @should)] end end -- cgit From 2863df288150da87a58ce4d938bbcf9a5d841f43 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 4 Jul 2008 15:35:18 -0500 Subject: Refactoring the Transaction::Event class. The class had a 'transaction' accessor that was assigned but never used, and it is simple enough that it needed direct arguments rather than named arguments. The rest of the code is changing the other classes that use Events. Signed-off-by: Luke Kanies --- lib/puppet/pgraph.rb | 2 +- lib/puppet/transaction.rb | 16 ++++------------ lib/puppet/transaction/change.rb | 6 +----- lib/puppet/transaction/event.rb | 9 ++++----- 4 files changed, 10 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb index 3bcc2ced0..55ad7d2c1 100644 --- a/lib/puppet/pgraph.rb +++ b/lib/puppet/pgraph.rb @@ -58,7 +58,7 @@ class Puppet::PGraph < Puppet::SimpleGraph # to, which is the same thing as saying all edges directly below # This vertex in the graph. adjacent(source, :direction => :out, :type => :edges).find_all do |edge| - edge.match?(event.event) + edge.match?(event.name) end end.compact.flatten end diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 78704bb13..695d0434c 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -98,7 +98,7 @@ class Transaction # Create an edge with this resource as both the source and # target. The triggering method treats these specially for # logging. - events = resourceevents.collect { |e| e.event } + events = resourceevents.collect { |e| e.name } set_trigger(Puppet::Relationship.new(resource, resource, :callback => :refresh, :event => events)) end end @@ -280,7 +280,7 @@ class Transaction # of course, bad. edge = orig_edge.class.new(orig_edge.source, orig_edge.target) label = orig_edge.label.dup - label[:event] = events.collect { |e| e.event } + label[:event] = events.collect { |e| e.name } edge.label = label set_trigger(edge) end @@ -682,11 +682,7 @@ class Transaction [callback, subs.length] # And then add an event for it. - return [Puppet::Transaction::Event.new( - :event => :noop, - :transaction => self, - :source => resource - )] + return [Puppet::Transaction::Event.new(:noop, resource)] end if subs.length == 1 and subs[0].source == resource @@ -714,11 +710,7 @@ class Transaction end # And then add an event for it. - trigged << Puppet::Transaction::Event.new( - :event => :triggered, - :transaction => self, - :source => resource - ) + trigged << Puppet::Transaction::Event.new(:triggered, resource) triggered(resource, callback) end diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index e1863ee13..cc7629376 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -43,11 +43,7 @@ class Puppet::Transaction::Change name = @property.event(should) end - Puppet::Transaction::Event.new( - :event => name, - :transaction => transaction, - :source => self.resource - ) + Puppet::Transaction::Event.new(name, self.resource) end def initialize(property, currentvalue) diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 418e70516..f1a48b382 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -9,14 +9,13 @@ class Puppet::Transaction::Event include Puppet::Util::MethodHelper include Puppet::Util::Errors - attr_accessor :event, :source, :transaction + attr_reader :name, :source - def initialize(args) - set_options symbolize_options(args) - requiredopts(:event, :source) + def initialize(name, source) + @name, @source = name, source end def to_s - @source.to_s + " -> " + self.event.to_s + source.to_s + " -> " + name.to_s end end -- cgit From 61ec332144ad794fae80a16feac543afc014a5f9 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 4 Jul 2008 16:06:02 -0500 Subject: Removing the Transaction::Change#transaction accessor. As with Events, this was never used (beyond being assigned), so I've gotten rid of it. Signed-off-by: Luke Kanies --- lib/puppet/transaction.rb | 1 - lib/puppet/transaction/change.rb | 15 ++------------- 2 files changed, 2 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 695d0434c..f3defb7a2 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -111,7 +111,6 @@ class Transaction changes.collect { |change| @changes << change @count += 1 - change.transaction = self events = nil begin # use an array, so that changes can return more than one diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index cc7629376..396b9233e 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -4,7 +4,7 @@ require 'puppet/transaction/event' # 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 + attr_accessor :is, :should, :type, :path, :property, :changed, :proxy # The log file generated when this object was changed. attr_reader :report @@ -14,11 +14,6 @@ class Puppet::Transaction::Change @property.should = @is @is = @property.retrieve - unless 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 @@ -85,12 +80,6 @@ class Puppet::Transaction::Change end def forward - unless transaction - raise Puppet::Error, - "PropertyChange '%s' tried to be executed outside of transaction" % - self - end - return self.go end @@ -109,6 +98,6 @@ class Puppet::Transaction::Change end def to_s - return "change %s.%s(%s)" % [transaction.object_id, self.object_id, @property.change_to_s(@is, @should)] + return "change %s" % @property.change_to_s(@is, @should) end end -- cgit From 9d69b3fd12f90ddead7b6a3392395fbe4e901d9b Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 4 Jul 2008 16:32:04 -0500 Subject: Testing and simplifying the Transaction::Change#backward method. Signed-off-by: Luke Kanies --- lib/puppet/transaction/change.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index 396b9233e..e05c2592c 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -4,24 +4,15 @@ require 'puppet/transaction/event' # 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, :changed, :proxy - - # The log file generated when this object was changed. - attr_reader :report + attr_accessor :is, :should, :path, :property, :changed, :proxy # Switch the goals of the property, thus running the change in reverse. def backward - @property.should = @is - @is = @property.retrieve + @is, @should = @should, @is + @property.should = @should - 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 + @property.info "Reversing %s" % self + return self.go end def changed? -- cgit From 196494a63eafc495224c1bfea933740fad7d76f0 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 4 Jul 2008 17:33:12 -0500 Subject: Fixed #1231 - Exceptions during startup should now be clear. This will often result in duplicate information, but at least the information will now always be there. Signed-off-by: Luke Kanies --- lib/puppet/util/settings.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index d8197f743..f20dee401 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -731,8 +731,10 @@ Generated on #{Time.now}. begin catalog.host_config = false catalog.apply do |transaction| - if failures = transaction.any_failed? - raise "Could not configure for running; got %s failure(s)" % failures + if transaction.any_failed? + report = transaction.report + failures = report.logs.find_all { |log| log.level == :err } + raise "Got %s failure(s) while initializing: %s" % [failures.length, failures.collect { |l| l.to_s }.join("; ")] end end ensure -- cgit