From aedd59cb2427c8642b817587b0c5ad1319161daa Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Fri, 1 Feb 2008 16:51:48 -0800 Subject: fix bug 974 - filenames with opening bracket characters generate exceptions --- lib/puppet/resource_reference.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/resource_reference.rb b/lib/puppet/resource_reference.rb index 3e92662b2..d5fc90d1f 100644 --- a/lib/puppet/resource_reference.rb +++ b/lib/puppet/resource_reference.rb @@ -37,7 +37,7 @@ class Puppet::ResourceReference # set things appropriately; else, just set it. def title=(value) if value =~ /^(.+)\[(.+)\]$/ - self.type = $1 + @type = $1 @title = $2 else @title = value -- cgit From 139ff33e1f93a0634547fc9a06442a720fe0a58e Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Mon, 21 Jan 2008 17:01:53 -0800 Subject: Fujin's patch for ticket #1007 - consistent use of 'environment' instead of 'env' --- lib/puppet/type/exec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 5bb3158c4..a7a046c43 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -228,7 +228,7 @@ module Puppet end end - newparam(:env) do + newparam(:environment) do desc "Any additional environment variables you want to set for a command. Note that if you use this to set PATH, it will override the ``path`` attribute. Multiple environment variables should be @@ -554,32 +554,32 @@ module Puppet begin # Do our chdir Dir.chdir(dir) do - env = {} + environment = {} if self[:path] - env[:PATH] = self[:path].join(":") + environment[:PATH] = self[:path].join(":") end - if envlist = self[:env] + if envlist = self[:environment] envlist = [envlist] unless envlist.is_a? Array envlist.each do |setting| if setting =~ /^(\w+)=((.|\n)+)$/ name = $1 value = $2 - if env.include? name + if environment.include? name warning( "Overriding environment setting '%s' with '%s'" % [name, value] ) end - env[name] = value + environment[name] = value else - warning "Cannot understand env setting %s" % setting.inspect + warning "Cannot understand environment setting %s" % setting.inspect end end end - withenv env do + withenv environment do Timeout::timeout(self[:timeout]) do output, status = Puppet::Util::SUIDManager.run_and_capture( [command], self[:user], self[:group] -- cgit From 8f0d87d498ca12417a7d20b81ba46465658fa210 Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Tue, 5 Feb 2008 14:05:14 -0800 Subject: Added :env parameter for backwards-compatibility, with warning about deprecation. :env parameter sets new :environment parameter. Changed instances of :env to :environment for consistency with other types. Added tests for new parameters. This cimmit fixes ticket 1007. --- lib/puppet/type/exec.rb | 9 +++++++++ test/ral/types/exec.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index a7a046c43..7d3b1abe1 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -228,6 +228,15 @@ module Puppet end end + newparam(:env) do + desc "This parameter is deprecated. Use 'environment' instead." + + munge do |value| + warning "'env' is deprecated on exec; use 'environment' instead." + resource[:environment] = value + end + end + newparam(:environment) do desc "Any additional environment variables you want to set for a command. Note that if you use this to set PATH, it will override diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb index f718f944e..4133d8519 100755 --- a/test/ral/types/exec.rb +++ b/test/ral/types/exec.rb @@ -587,6 +587,46 @@ and stuff" assert_equal("A B\n", output) end + def test_environmentparam + exec = Puppet::Type.newexec( + :command => "echo $environmenttest", + :path => ENV["PATH"], + :environment => "environmenttest=yayness" + ) + + assert(exec, "Could not make exec") + + output = status = nil + assert_nothing_raised { + output, status = exec.run("echo $environmenttest") + } + + assert_equal("yayness\n", output) + + # Now check whether we can do multiline settings + assert_nothing_raised do + exec[:environment] = "environmenttest=a list of things +and stuff" + end + + output = status = nil + assert_nothing_raised { + output, status = exec.run('echo "$environmenttest"') + } + assert_equal("a list of things\nand stuff\n", output) + + # Now test arrays + assert_nothing_raised do + exec[:environment] = ["funtest=A", "yaytest=B"] + end + + output = status = nil + assert_nothing_raised { + output, status = exec.run('echo "$funtest" "$yaytest"') + } + assert_equal("A B\n", output) + end + def test_timeout exec = Puppet::Type.type(:exec).create(:command => "sleep 1", :path => ENV["PATH"], :timeout => "0.2") time = Time.now -- cgit From b3f67ec4017940a7eb47f3a044fd77c8d32a74cf Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Tue, 5 Feb 2008 15:07:05 -0800 Subject: Fix ticket 974. My original "fix" wasn't. This actually fixes the problem by using a regular expression that matches only up to the first square bracket. --- lib/puppet/resource_reference.rb | 4 ++-- spec/unit/resource_reference.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/puppet/resource_reference.rb b/lib/puppet/resource_reference.rb index d5fc90d1f..771a91be7 100644 --- a/lib/puppet/resource_reference.rb +++ b/lib/puppet/resource_reference.rb @@ -36,8 +36,8 @@ class Puppet::ResourceReference # If the title has square brackets, treat it like a reference and # set things appropriately; else, just set it. def title=(value) - if value =~ /^(.+)\[(.+)\]$/ - @type = $1 + if value =~ /^([^\[\]]+)\[(.+)\]$/ + self.type = $1 @title = $2 else @title = value diff --git a/spec/unit/resource_reference.rb b/spec/unit/resource_reference.rb index ef172d80a..cbbd6ef51 100755 --- a/spec/unit/resource_reference.rb +++ b/spec/unit/resource_reference.rb @@ -40,6 +40,12 @@ describe Puppet::ResourceReference do ref.type.should == "Foo::Bar" ref.title.should == "yay" end + + it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do + ref = Puppet::ResourceReference.new(nil, "foo::bar[baz[yay]]") + ref.type.should == "Foo::Bar" + ref.title.should =="baz[yay]" + end end describe Puppet::ResourceReference, "when resolving resources without a catalog" do -- cgit From 2931723bae9e4226ab8eb7f6f806bf9a2ea5cbb8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Feb 2008 15:31:43 -0600 Subject: Fixing the Settings class so that it correctly handles file values that are false. --- lib/puppet/util/settings.rb | 16 +++++++++------- spec/unit/util/settings.rb | 6 ++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ff019edb8..c84a5bfb1 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -509,12 +509,11 @@ class Puppet::Util::Settings objects += add_user_resources(section, obj, done) end + value = obj.value + # Only files are convertable to transportable resources. - next unless obj.respond_to? :to_transportable - next if value(obj.name) =~ /^\/dev/ - next if Puppet::Type::File[obj.value] # skip files that are in our global resource list. + next unless obj.respond_to? :to_transportable and transobjects = obj.to_transportable - transobjects = obj.to_transportable transobjects = [transobjects] unless transobjects.is_a? Array transobjects.each do |trans| # transportable could return nil @@ -1154,12 +1153,15 @@ Generated on #{Time.now}. def to_transportable type = self.type return nil unless type - path = @parent.value(self.name).split(File::SEPARATOR) - path.shift # remove the leading nil - objects = [] path = self.value + return nil unless path.is_a?(String) + return nil if path =~ /^\/dev/ + return nil if Puppet::Type::File[path] # skip files that are in our global resource list. + + objects = [] + # Skip plain files that don't exist, since we won't be managing them anyway. return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) or self.create obj = Puppet::TransObject.new(path, "file") diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index f00afd1b7..b44a30eb2 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -605,6 +605,12 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d lambda { trans.to_catalog }.should_not raise_error end + it "should ignore file settings whose values are not strings" do + @settings[:maindir] = false + + lambda { trans = @settings.to_transportable }.should_not raise_error + end + it "should be able to turn the current configuration into a parseable manifest" it "should convert octal numbers correctly when producing a manifest" -- cgit From b293763f9ef2e134f18bb2c3fdaaaa502aa2c201 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Feb 2008 15:34:30 -0600 Subject: Applying patch by Jay to fix #989 -- missing crl files are correctly ignored, and you now use 'false' instead of 'none' to explicitly ignore them. --- CHANGELOG | 4 ++++ bin/puppetd | 2 +- lib/puppet/defaults.rb | 2 +- lib/puppet/network/http_server/webrick.rb | 4 ++-- lib/puppet/sslcertificates/ca.rb | 6 +++--- lib/puppet/util/settings.rb | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cfe6657bf..d615ed843 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ + Fixed #989 -- missing CRL files are correctly ignored, and the + value should be set to 'false' to explicitly not look for these + files. + Fixed #1017 -- environment-specific modulepath is no longer ignored. Fixing #794 -- consolidating the gentoo configuration files. diff --git a/bin/puppetd b/bin/puppetd index 297d4876d..e993d3aa8 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -374,7 +374,7 @@ if Puppet[:listen] and ! options[:onetime] # to clients. In the meantime, we just disable CRL checking if # the CRL file doesn't exist unless File::exist?(Puppet[:cacrl]) - Puppet[:cacrl] = 'none' + Puppet[:cacrl] = 'false' end handlers = nil diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 0c8ac3f82..520a18d1a 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -232,7 +232,7 @@ module Puppet :owner => "$user", :group => "$group", :mode => 0664, - :desc => "The certificate revocation list (CRL) for the CA. Set this to 'none' if you do not want to use a CRL." + :desc => "The certificate revocation list (CRL) for the CA. Set this to 'false' if you do not want to use a CRL." }, :caprivatedir => { :default => "$cadir/private", :owner => "$user", diff --git a/lib/puppet/network/http_server/webrick.rb b/lib/puppet/network/http_server/webrick.rb index 3c9f72e17..e4f00dd73 100644 --- a/lib/puppet/network/http_server/webrick.rb +++ b/lib/puppet/network/http_server/webrick.rb @@ -22,12 +22,12 @@ module Puppet # with them, with flags appropriate for checking client # certificates for revocation def x509store - if Puppet[:cacrl] == 'none' + if Puppet[:cacrl] == 'false' # No CRL, no store needed return nil end unless File.exist?(Puppet[:cacrl]) - raise Puppet::Error, "Could not find CRL; set 'cacrl' to 'none' to disable CRL usage" + raise Puppet::Error, "Could not find CRL; set 'cacrl' to 'false' to disable CRL usage" end crl = OpenSSL::X509::CRL.new(File.read(Puppet[:cacrl])) store = OpenSSL::X509::Store.new diff --git a/lib/puppet/sslcertificates/ca.rb b/lib/puppet/sslcertificates/ca.rb index a3edd2cb4..888bcf5b2 100644 --- a/lib/puppet/sslcertificates/ca.rb +++ b/lib/puppet/sslcertificates/ca.rb @@ -194,8 +194,8 @@ class Puppet::SSLCertificates::CA # Revoke the certificate with serial number SERIAL issued by this # CA. The REASON must be one of the OpenSSL::OCSP::REVOKED_* reasons def revoke(serial, reason = OpenSSL::OCSP::REVOKED_STATUS_KEYCOMPROMISE) - if @config[:cacrl] == 'none' - raise Puppet::Error, "Revocation requires a CRL, but ca_crl is set to 'none'" + if @config[:cacrl] == 'false' + raise Puppet::Error, "Revocation requires a CRL, but ca_crl is set to 'false'" end time = Time.now revoked = OpenSSL::X509::Revoked.new @@ -372,7 +372,7 @@ class Puppet::SSLCertificates::CA @crl = OpenSSL::X509::CRL.new( File.read(@config[:cacrl]) ) - elsif @config[:cacrl] == 'none' + elsif @config[:cacrl] == 'false' @crl = nil else # Create new CRL diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index c84a5bfb1..cf15d3194 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -1124,7 +1124,7 @@ Generated on #{Time.now}. # the variable 'dir', or adding a slash at the end. def munge(value) # If it's not a fully qualified path... - if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// + if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// and value != 'false' # Make it one value = File.join(Dir.getwd, value) end -- cgit From 084d0fb6351ed54ff4c052cff20f21e89063620c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Feb 2008 15:52:02 -0600 Subject: Adding more information to dependencies that do not resolve --- lib/puppet/metatype/metaparams.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb index b35adae66..9983c34d2 100644 --- a/lib/puppet/metatype/metaparams.rb +++ b/lib/puppet/metatype/metaparams.rb @@ -258,7 +258,7 @@ class Puppet::Type @value.each do |value| unless @resource.catalog.resource(*value) description = self.class.direction == :in ? "dependency" : "dependent" - raise Puppet::Error, "Could not find #{description} %s[%s]" % [value[0].to_s.capitalize, value[1]] + fail Puppet::Error, "Could not find #{description} %s[%s] for %s" % [value[0].to_s.capitalize, value[1], resource.ref] end end end -- cgit