Best unofficial Apache Server developers community |
| |||||
| Jul 29, 2010 | |||||
|
Nick Lewis |
|
||||
| Tags: | |||||
Similar Threads
PATCH/puppet 1/1] [#4344] Fix for failing templates when module name matches file in local dir.
When the name of a module matches the name of a file in the local
directory, puppet agent would sometimes try to read that file and
interpret it as puppet code. This happened because files.rb was
unintentionally permitting puppet files without an extension. Fixed
by changing the glob pattern to only permit ".pp" and ".rb"
extensions.
Signed-off-by: Paul Berry <pa### @puppetlabs.com>
---
lib/puppet/parser/files.rb | 2 +-
spec/unit/parser/files_spec.rb | 6 +++---
spec/unit/parser/type_loader_spec.rb | 2 +-
test/language/parser.rb | 12 ++++++------
test/lib/puppettest.rb | 4 ++--
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb
index 9ef05e1..f346831 100644
--- a/lib/puppet/parser/files.rb
+++ b/lib/puppet/parser/files.rb
@@ -24,7 +24,7 @@ module Puppet::Parser::Files
# Than that would be a "no."
end
abspat = File::expand_path(start, cwd)
- [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{,.pp,.rb}' :
'' )).uniq.reject { |f| FileTest.directory?(f) }]
+ [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{.pp,.rb}' :
'' )).uniq.reject { |f| FileTest.directory?(f) }]
end
# Find the concrete file denoted by +file+. If +file+ is absolute,
diff --git a/spec/unit/parser/files_spec.rb
b/spec/unit/parser/files_spec.rb
index fcfbfa6..3eb0db0 100644
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -154,7 +154,7 @@ describe Puppet::Parser::Files do
it "should match against provided fully qualified patterns" do
pattern = @basepath + "/fully/qualified/pattern/*"
- Dir.expects(:glob).with(pattern+'{,.pp,.rb}').returns(%w{my file
list})
+ Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns(%w{my file
list})
Puppet::Parser::Files.find_manifests(pattern)[1].should == %w{my
file list}
end
@@ -168,7 +168,7 @@ describe Puppet::Parser::Files do
pattern = @basepath + "/fully/qualified/pattern/*"
file = @basepath + "/my/file"
dir = @basepath + "/my/directory"
- Dir.expects(:glob).with(pattern+'{,.pp,.rb}').returns([file, dir])
+ Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns([file, dir])
FileTest.expects(:directory?).with(file).returns(false)
FileTest.expects(:directory?).with(dir).returns(true)
Puppet::Parser::Files.find_manifests(pattern)[1].should == [file]
@@ -176,7 +176,7 @@ describe Puppet::Parser::Files do
it "should return files once only" do
pattern = @basepath + "/fully/qualified/pattern/*"
- Dir.expects(:glob).with(pattern+'{,.pp,.rb}').returns(%w{one two
one})
+ Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns(%w{one two
one})
Puppet::Parser::Files.find_manifests(pattern)[1].should == %w{one
two}
end
end
diff --git a/spec/unit/parser/type_loader_spec.rb
b/spec/unit/parser/type_loader_spec.rb
index 8f005d5..83006b3 100644
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -192,7 +192,7 @@ describe Puppet::Parser::TypeLoader do
end
it "should be able to add classes to the current resource type
collection" do
- file = tmpfile("simple_file")
+ file = tmpfile("simple_file.pp")
File.open(file, "w") { |f| f.puts "class foo {}" }
@loader.import(file)
diff --git a/test/language/parser.rb b/test/language/parser.rb
index 5a433c7..8cda8ee 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -97,7 +97,7 @@ class TestParser < Test::Unit::TestCase
}
4.times { |i|
- path = File.join(basedir, subdir, "subfile#{i}")
+ path = File.join(basedir, subdir, "subfile#{i}.pp")
mkmanifest(path)
}
@@ -137,8 +137,8 @@ class TestParser < Test::Unit::TestCase
end
def test_importedclasses
- imported = tempfile
- importer = tempfile
+ imported = tempfile '.pp'
+ importer = tempfile '.pp'
made = tempfile
@@ -655,9 +655,9 @@ file { "/tmp/yayness":
end
def test_multiple_imports_on_one_line
- one = tempfile
- two = tempfile
- base = tempfile
+ one = tempfile '.pp'
+ two = tempfile '.pp'
+ base = tempfile '.pp'
File.open(one, "w") { |f| f.puts "$var = value" }
File.open(two, "w") { |f| f.puts "$var = value" }
File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" }
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index e31a319..294d0ef 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -227,14 +227,14 @@ module PuppetTest
#Facter.stubs(:to_hash).returns({})
end
- def tempfile
+ def tempfile(suffix = '')
if defined?(@@tmpfilenum)
@@tmpfilenum += 1
else
@@tmpfilenum = 1
end
- f = File.join(self.tmpdir, "tempfile_" + @@tmpfilenum.to_s)
+ f = File.join(self.tmpdir, "tempfile_" + @@tmpfilenum.to_s + suffix)
@@tmpfiles ||= []
@@tmpfiles << f
f
PATCH/puppet 1/1] [#4208] Missing parameter breaks multithread compilation
import_if_possible calls itself recursively, but it was failing to pass
its block parameter to its younger self. Thus when the inner call
reached the un-blocked case, it raised an exception rather than doing
something useful.
Signed-off-by: Jesse Wolfe <jes### @gmail.com>
---
lib/puppet/parser/type_loader.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/puppet/parser/type_loader.rb
b/lib/puppet/parser/type_loader.rb
index e56ab94..6c32f6a 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -126,16 +126,16 @@ class Puppet::Parser::TypeLoader
# Utility method factored out of load for handling thread-safety.
# This isn't tested in the specs, because that's basically impossible.
- def import_if_possible(file)
+ def import_if_possible(file, &blk)
return if @loaded.include?(file)
begin
case @loading.owner_of(file)
when :this_thread
return
when :another_thread
- return import_if_possible(file)
+ return import_if_possible(file, &blk)
when :nobody
- yield
+ blk.call
end
rescue Puppet::ImportError => detail
# We couldn't load the item
PATCH/puppet] [#4219] Install misses command_line dir, puppet $app --help fails
---
install.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/install.rb b/install.rb
index d35aaa0..b06ec09 100755
--- a/install.rb
+++ b/install.rb
@@ -84,7 +84,7 @@ bins = glob(%w{bin/*})
rdoc = glob(%w{bin/* sbin/* lib/**/*.rb README README-library CHANGELOG
TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ }
ri = glob(%w{bin/*.rb sbin/* lib/**/*.rb}).reject { |e| e=~
/\.(bat|cmd)$/ }
man = glob(%w{man/man[0-9]/*})
-libs = glob(%w{lib/**/*.rb lib/**/*.py})
+libs = glob(%w{lib/**/*.rb lib/**/*.py lib/puppet/util/command_line/*})
tests = glob(%w{test/**/*.rb})
def do_bins(bins, target, strip = 's?bin/')
PATCH/puppet 1/1] [#4247] storeconfigs was calling Puppet::Parser::Resource.new with the wrong argu
When the interface to Puppet::Resource changed, its subclass
Puppet::Parser::Resource was also affected. One case of initializing
those objects did not get updated when the code changed, causing
storeconfigs to break.
Also, this patch adds a error message that would have made it easier to
catch this problem (as puppet could consume all memory and die trying to
print the old error message)
Signed-off-by: Jesse Wolfe <jes5### @gmail.com>
---
lib/puppet/rails/resource.rb | 6 +++---
lib/puppet/resource.rb | 3 +++
spec/unit/rails/resource_spec.rb | 16 ++++++++++++++++
spec/unit/resource_spec.rb | 6 ++++++
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index a5cdd0c..cac9de2 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -212,16 +212,16 @@ class Puppet::Rails::Resource <
ActiveRecord::Base
end
hash[:scope] = scope
hash[:source] = scope.source
- hash[:params] = []
+ hash[:parameters] = []
names = []
self.param_names.each do |pname|
# We can get the same name multiple times because of how the
# db layout works.
next if names.include?(pname.name)
names << pname.name
- hash[:params] << pname.to_resourceparam(self, scope.source)
+ hash[:parameters] << pname.to_resourceparam(self,
scope.source)
end
- obj = Puppet::Parser::Resource.new(hash)
+ obj = Puppet::Parser::Resource.new(hash["type"], hash["title"], hash)
# Store the ID, so we can check if we're re-collecting the same
resource.
obj.rails_id = self.id
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 31237e3..d68e0ee 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -409,6 +409,9 @@ class Puppet::Resource
if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1,
$2 ]
elsif argtitle then [
argtype, argtitle ]
elsif argtype.is_a?(Puppet::Type) then [
argtype.class.name, argtype.title ]
+ elsif argtype.is_a?(Hash) then
+ raise ArgumentError, "Puppet::Resource.new does not take a hash as
the first argument. "+
+ "Did you mean (#{(argtype[:type] || argtype["type"]).inspect},
#{(argtype[:title] || argtype["title"]).inspect }) ?"
else raise ArgumentError, "No title provided and #{argtype.inspect}
is not a valid resource reference"
end
end
diff --git a/spec/unit/rails/resource_spec.rb
b/spec/unit/rails/resource_spec.rb
index ac74693..08deda6 100755
--- a/spec/unit/rails/resource_spec.rb
+++ b/spec/unit/rails/resource_spec.rb
@@ -104,4 +104,20 @@ describe "Puppet::Rails::Resource" do
@resource.merge_parameters(merge_resource)
end
end
+
+ describe "#to_resource" do
+ it "should instantiate a Puppet::Parser::Resource" do
+ scope = stub "scope", :source => nil
+
+ @resource = Puppet::Rails::Resource.new
+ @resource.stubs(:attributes).returns({
+ "restype" => 'notify',
+ "title" => 'hello'
+ })
+ @resource.stubs(:param_names).returns([])
+
+ @resource.to_resource(scope).should be_a(Puppet::Parser::Resource)
+
+ end
+ end
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 95f0dd0..204a2b0 100755
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -98,6 +98,12 @@ describe Puppet::Resource do
lambda { Puppet::Resource.new("foo") }.should
raise_error(ArgumentError)
end
+ it "should fail if the title is a hash and the type is not a valid
resource reference string" do
+ lambda { Puppet::Resource.new({:type => "foo", :title =>
"bar"}) }.should raise_error(ArgumentError,
+ 'Puppet::Resource.new does not take a hash as the first argument.
Did you mean ("foo", "bar") ?'
+ )
+ end
+
it "should be able to produce a backward-compatible reference array" do
Puppet::Resource.new("foobar", "/f").to_trans_ref.should == %w{Foobar
/f}
end
PATCH/puppet 1/1] Fix #4348 - Puppet doc single manifest broken
The refactoring of using environment instances instead of strings
for initializing the parser, rdoc wasn't updated, thus was unable
to initialize the parser.
Signed-off-by: Brice Figureau <brice-pupp### @daysofwonder.com>
---
lib/puppet/util/rdoc.rb | 2 +-
spec/unit/util/rdoc_spec.rb | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/lib/puppet/util/rdoc.rb b/lib/puppet/util/rdoc.rb
index 4a80b06..085d8ec 100644
--- a/lib/puppet/util/rdoc.rb
+++ b/lib/puppet/util/rdoc.rb
@@ -41,7 +41,7 @@ module Puppet::Util::RDoc
def manifestdoc(files)
Puppet[:ignoreimport] = true
files.select { |f| FileTest.file?(f) }.each do |f|
- parser = Puppet::Parser::Parser.new(:environment =>
Puppet[:environment])
+ parser =
Puppet::Parser::Parser.new(Puppet::Node::Environment.new(Puppet[:environment]))
parser.file = f
ast = parser.parse
output(f, ast)
diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb
index 65df261..58c2034 100755
--- a/spec/unit/util/rdoc_spec.rb
+++ b/spec/unit/util/rdoc_spec.rb
@@ -75,6 +75,19 @@ describe Puppet::Util::RDoc do
Puppet::Util::RDoc.manifestdoc([])
end
+ it "should use a parser with the correct environment" do
+ FileTest.stubs(:file?).returns(true)
+ Puppet::Util::RDoc.stubs(:output)
+
+ parser = stub_everything
+ Puppet::Parser::Parser.stubs(:new).with{ |env|
env.is_a?(Puppet::Node::Environment) }.returns(parser)
+
+ parser.expects(:file=).with("file")
+ parser.expects(:parse)
+
+ Puppet::Util::RDoc.manifestdoc(["file"])
+ end
+
it "should puppet parse all given files" do
FileTest.stubs(:file?).returns(true)
Puppet::Util::RDoc.stubs(:output)
PATCH/puppet 0/4] Some random puppet fix for JRuby
Hi, Here is the first stab of JRuby Puppet compatibility. There looks to be more thread issue (the last ones I found are parser functions initializations), which will be addressed in subsequent patches. No patch in this serie have tests, because they most deal with threading issues that can be reproduced only under JRuby. Please review, Brice Brice Figureau (4): JRuby doesn't implement Process.maxgroups Fix #4244 - Cached Attributes is not thread safe Fix race condition in rack autoloading of request/response Fix #4245 - default insertion of ACL is not thread safe lib/puppet/network/http/rack.rb | 3 +++ lib/puppet/network/rest_authconfig.rb | 9 ++++++--- lib/puppet/util/cacher.rb | 31 +++++++++++++++++++++
PATCH/puppet 1/1] [#4347] run_mode was colliding with --mode for "puppet doc"
The run_mode value was incorrectly getting stored to Puppet[:mode], which
was confusing the optparser for applications that declare a --mode
parameter.
Signed-off-by: Jesse Wolfe <jes### @gmail.com>
---
lib/puppet/application.rb | 2 +-
lib/puppet/defaults.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 0a8fbc1..2fec38b 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -285,7 +285,7 @@ class Application
Puppet.settings.set_value(:name, Puppet.application_name.to_s,
:mutable_defaults)
Puppet.settings.set_value(:logdir, Puppet.run_mode.logopts,
:mutable_defaults)
Puppet.settings.set_value(:rundir, Puppet.run_mode.run_dir,
:mutable_defaults)
- Puppet.settings.set_value(:mode, Puppet.run_mode.name.to_s,
:mutable_defaults)
+ Puppet.settings.set_value(:run_mode, Puppet.run_mode.name.to_s,
:mutable_defaults)
end
require 'puppet'
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 84e2d93..0de5f20 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -7,7 +7,7 @@ module Puppet
:vardir => [Puppet.run_mode.var_dir, "Where Puppet stores dynamic
and growing data. The default for this parameter is calculated specially,
like `confdir`_."],
:name => [Puppet.application_name.to_s, "The name of the
application, if we are running as one. The
default is essentially $0 without the path or ``.rb``."],
- :mode => [Puppet.run_mode.name.to_s, "The effective 'run mode' of
the application: master, agent, or user."]
+ :run_mode => [Puppet.run_mode.name.to_s, "The effective 'run mode'
of the application: master, agent, or user."]
)
setdefaults(:main, :logdir => Puppet.run_mode.logopts)
#4224] vardir and confdir when running puppet master as non-root user
Hello, I am currently testing the new 2.6.0 release of puppet and I get a disappointing behavior when running the puppet master as non-root user in our apache/passenger setup: $confdir and $vardir are set to "~/.puppet". In previous versions, these variables were set to their default global values (respectively /etc/puppet and /var/lib/puppet). This new behavior seems related to ticket #4224 which states that $confdir and $vardir should be ~/.puppet if not run as root. Although this new behavior is documented in the man page of puppet.conf, nothing is mentioned in the release notes about it. I think it could be worth to say a few words about it (and update the status of ticket #4224) since it appears to break a majority of passenger setups that migrate to 2.6. I believe it could also be nice to introduce a new configuration variable that enables admins to disable this behavior (making puppet master use the defaults even if not run as root). Regards, Xavier
PATCH/puppet 1/3] conf/redhat: Rebase rundir-perms patch
--- conf/redhat/rundir-perms.patch | 26 +++++++++++++
Puppet Standalone Client + Fileserving, not working.... (+ nice tutorial for puppet stand-alone) :)
Puppet local fileserving not working, as described here: http://docs.reductivelabs.com/guides/modules.html I've made a project to demonstrate this: https://mindre### @github.com/mindr...alone_testing.git There is more in the README...(http://github.com/mindreframer/ puppet_stand_alone_testing/blob/master/Readme.md) Would be nice to get this working, it seems wasteful the rewrite the modules only for stand-alone usage... Thx!
unique behavior on puppet agent running on puppet master node
(reposted from irc) Having just upgraded to 2.6, I am seeing different behavior between the agent running on the master node and the rest of the agents. Most importantly, it complains about "warning: You cannot collect without storeconfigs being set" even though storeconfigs=true in the [master] section of puppet.conf Less important, but still curious: the logging is quite different, including lots of "info: Automatically imported <blah>" lines). my puppet.conf: http://pastebin.com/nLZu9zrf ~jon
Could not retrieve information from source(s) puppet://puppet/plugins error message
Hi. After I upgraded to latest puppet, I started receiving this message both in clients and in master. Following the advice below, i create an empty stub module, with empty "lib" directory: http://projects.puppetlabs.com/issues/2244 Any idea if this is a clean solution, or there is another, better fix? Regards.
PATCH/puppet 1/1] Possible fix for #4297
This fix is based on refactoring Jesse's empirically derived solution
guided by
the assumption that #4297 was introduced / exposed by the fix for #4270; I
do
not have a global understanding of the code here, but am just making an
adjustment that 1) slightly reduces the code complexity, 2) doesn't appear
to
break anything, 3) empirically fixes the observed problem, 4) makes since
in
that resource classes shouldn't have to consult a passed-in scope to find
their
own namespaces.
Basically, I'm fixing what I believe was a thinko in a patch that I don't
fully
understand.
Signed-off-by: Markus Roberts <Mark### @reality.com>
---
lib/puppet/resource/type.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index 85c0979..c27a89a 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -179,7 +179,7 @@ class Puppet::Resource::Type
unless @parent_type
raise "Must pass scope to parent_type when called first time"
unless scope
- unless @parent_type =
scope.environment.known_resource_types.send("find_#{type}",
scope.namespaces, parent)
+ unless @parent_type =
scope.environment.known_resource_types.send("find_#{type}", [names],
parent)
fail Puppet::ParseError, "Could not find parent resource type
'#{parent}' of type #{type} in #{scope.environment}"
end
end
Puppet on Windows (was Re: ANNOUNCE: Puppet 2.6.0 - Final release!)
Rohan McGovern wrote: James Turnbull said: > The journey was long and arduous and many fell along the way but Puppet > Labs is proud to announce the 2.6.0 release! > Is anyone aware of an attempt to package up a complete (puppet + all prereqs) installer for Windows? Either official, or by someone in the community? And, asking from the other direction: would anyone else be interested in such a thing? I would be, because setting up puppet on Windows seems pretty tough right now. I also have no need for Ruby on my Windows boxes except for the usage of puppet. Rohan There isn't such an attempt so far - we've got it on the cards to do - but any progress in that direction would be awesome. We've got some basic notes at: http://projects.puppetlabs.com/projec...ki/Puppet_Windows Regards James Turnbull
Re: [PATCH/puppet 1/1] extlookup() is a builtin
hey, There was some reports from joe-mac on irc that it's behaving inconsistently on 2.6, giving different results between different runs. I hacked at the code a bit to add a 4th option that will enable copious amount of debug messages to be printed to hopefully help sort this out. We should attempt to merge these I gues and ask someone who has 2.6 going to test, maybe Joe has some time? ----- "Jesse A Wolfe" <jes5### @gmail.com> wrote: > Don't we have to move the extlookup code into > lib/puppet/parser/functions or something too? (I don't know the > answer, but it seems likely). I did! > rename from ext/extlookup.rb > rename to lib/puppet/parser/functions/ extlookup.rb On Fri, Jul 23, 2010 at 2:35 PM, Markus Roberts < mar### @puppetlabs.com > wrote: Don't we have to move the extlookup code into lib/puppet/parser/functions or something too? (I don't know the answer, but it seems likely). -- Markus
PATCH/puppet 1/1] extlookup() is a builtin
This patch promotes extlookup() to being a builtin function.
It also adds test and makes some minor tweaks to the code.
The behavior of extlookup has been left unchanged.
Signed-off-by: Jesse Wolfe <jes### @gmail.com>
---
{ext => lib/puppet/parser/functions}/extlookup.rb | 24 ++----
spec/unit/parser/functions/extlookup_spec.rb | 85
+++++++++++++++++++++
2 files changed, 93 insertions(+), 16 deletions(-)
rename {ext => lib/puppet/parser/functions}/extlookup.rb (92%)
create mode 100755 spec/unit/parser/functions/extlookup_spec.rb
diff --git a/ext/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb
similarity index 92%
rename from ext/extlookup.rb
rename to lib/puppet/parser/functions/extlookup.rb
index d87583b..ee230e7 100644
--- a/ext/extlookup.rb
+++ b/lib/puppet/parser/functions/extlookup.rb
@@ -82,11 +82,11 @@ require 'csv'
module Puppet::Parser::Functions
newfunction(:extlookup, :type => :rvalue) do |args|
key = args[0]
- default = "_ExtUNSET_"
- datafile = "_ExtUNSET_"
- default = args[1] if args[1]
- datafile = args[2] if args[2]
+ default = args[1]
+ datafile = args[2]
+
+ raise Puppet::ParseError, ("extlookup(): wrong number of arguments
(#{args.length}; must be <= 3)") if args.length > 3
extlookup_datadir = lookupvar('extlookup_datadir')
extlookup_precedence = Array.new
@@ -123,12 +123,13 @@ module Puppet::Parser::Functions
datafiles << extlookup_datadir + "/#{d}.csv"
end
- desired = "_ExtUNSET_"
+ desired = nil
datafiles.each do |file|
+ parser = Puppet::Parser::Parser.new(environment)
parser.watch_file(file) if File.exists?(file)
- if desired == "_ExtUNSET_"
+ if desired.nil?
if File.exists?(file)
result = CSV.read(file).find_all do |r|
r[0] == key
@@ -167,15 +168,6 @@ module Puppet::Parser::Functions
end
end
- # don't accidently return nil's and such rather throw a parse error
- if desired == "_ExtUNSET_" && default == "_ExtUNSET_"
- raise Puppet::ParseError, "No match found for '#{key}' in any data
file during extlookup()"
- else
- desired = default if desired == "_ExtUNSET_"
- end
-
- desired
+ desired || default or raise Puppet::ParseError, "No match found for
'#{key}' in any data file during extlookup()"
end
end
-
-# vi:tabstop=4:expandtab:ai
diff --git a/spec/unit/parser/functions/extlookup_spec.rb
b/spec/unit/parser/functions/extlookup_spec.rb
new file mode 100755
index 0000000..bf28803
--- /dev/null
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -0,0 +1,85 @@
+#! /usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'tempfile'
+
+describe "the extlookup function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+
+
@scope.stubs(:environment).returns(Puppet::Node::Environment.new('production'))
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("extlookup").should ==
"function_extlookup"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { @scope.function_extlookup([]) }.should(
raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there is more than 3 arguments" do
+ lambda { @scope.function_extlookup(["foo", "bar", "baz", "gazonk"])
}.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return the default" do
+ result = @scope.function_extlookup([ "key", "default"])
+ result.should == "default"
+ end
+
+ it "should lookup the key in a supplied datafile" do
+ t = Tempfile.new('extlookup.csv') do
+ t.puts 'key,value'
+ t.puts 'nonkey,nonvalue'
+ t.close
+
+ result = @scope.function_extlookup([ "key", "default", t.path])
+ result.should == "value"
+ end
+ end
+
+ it "should return an array if the datafile contains more than two
columns" do
+ t = Tempfile.new('extlookup.csv') do
+ t.puts 'key,value1,value2'
+ t.puts 'nonkey,nonvalue,nonvalue'
+ t.close
+
+ result = @scope.function_extlookup([ "key", "default", t.path])
+ result.should == ["value1", "value2"]
+ end
+ end
+
+ it "should raise an error if there's no matching key and no default" do
+ t = Tempfile.new('extlookup.csv') do
+ t.puts 'key,value'
+ t.puts 'nonkey,nonvalue'
+ t.close
+
+ result = @scope.function_extlookup([ "key", nil, t.path])
+ result.should == "value"
+ end
+ end
+
+ describe "should look in $extlookup_datadir for data files listed by
$extlookup_precedence" do
+ before do
+ @scope.stubs(:lookupvar).with('extlookup_datadir').returns("/tmp")
+
@scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"])
+ File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" }
+ File.open("/tmp/two.csv","w") do |two|
+ two.puts "key,value2"
+ two.puts "key2,value_two"
+ end
+ end
+
+ it "when the key is in the first file" do
+ result = @scope.function_extlookup([ "key" ])
+ result.should == "value1"
+ end
+
+ it "when the key is in the second file" do
+ result = @scope.function_extlookup([ "key2" ])
+ result.should == "value_two"
+ end
+ end
+end
PATCH/puppet 1/3] vim: added elsif
Signed-off-by: Marc Fournier <marc.fo### @camptocamp.com>
---
ext/vim/syntax/puppet.vim | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/ext/vim/syntax/puppet.vim b/ext/vim/syntax/puppet.vim
index 80cd91c..81efa92 100644
--- a/ext/vim/syntax/puppet.vim
+++ b/ext/vim/syntax/puppet.vim
@@ -68,7 +68,7 @@ syn match puppetNotVariable "\\$\w\+" contained
syn match puppetNotVariable "\\${\w\+}" contained
syn keyword puppetKeyword import inherits include
-syn keyword puppetControl case default if else
+syn keyword puppetControl case default if else elsif
syn keyword puppetSpecial true false undef
" comments last overriding everything else
PATCH/puppet 1/1] This commit resolves:
created init provider method self.get_services
- accepts an array of filenames to exclude when retrieving services.
added unit tests to verify that I can specify files to exclude.
Signed-off-by: Dan Bode <d### @reductivelabs.com>
---
lib/puppet/provider/service/init.rb | 9 +++++--
lib/puppet/provider/service/redhat.rb | 5 ++++
spec/unit/provider/service/init_spec.rb | 35
+++++++++++++++++++++++++++++
spec/unit/provider/service/redhat_spec.rb | 19 +++++++++++++++
4 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/lib/puppet/provider/service/init.rb
b/lib/puppet/provider/service/init.rb
index c05a326..58b7f91 100755
--- a/lib/puppet/provider/service/init.rb
+++ b/lib/puppet/provider/service/init.rb
@@ -28,11 +28,13 @@ Puppet::Type.type(:service).provide :init, :parent
=> :base do
# List all services of this type.
def self.instances
- self.defpath = [self.defpath] unless self.defpath.is_a? Array
+ get_services(self.defpath)
+ end
+ def self.get_services(defpath, exclude=[])
+ defpath = [defpath] unless defpath.is_a? Array
instances = []
-
- self.defpath.each do |path|
+ defpath.each do |path|
unless FileTest.directory?(path)
Puppet.debug "Service path %s does not exist" % path
next
@@ -47,6 +49,7 @@ Puppet::Type.type(:service).provide :init, :parent =>
:base do
Dir.entries(path).each do |name|
fullpath = File.join(path, name)
next if name =~ /^\./
+ next if exclude.include? name
next if not FileTest.executable?(fullpath)
instances << new(:name => name, :path =>
path)
end
diff --git a/lib/puppet/provider/service/redhat.rb
b/lib/puppet/provider/service/redhat.rb
index 45a9074..065efe6 100755
--- a/lib/puppet/provider/service/redhat.rb
+++ b/lib/puppet/provider/service/redhat.rb
@@ -11,6 +11,11 @@ Puppet::Type.type(:service).provide :redhat, :parent
=> :init, :source => :init
defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos,
:sles, :oel, :ovm]
+ def self.instances
+ # this exclude list is all from /sbin/service (5.x), but I did
not exclude kudzu
+ self.get_services(['/etc/init.d/'], ['functions', 'halt',
'killall', 'single', 'linuxconf'])
+ end
+
def self.defpath
superclass.defpath
end
diff --git a/spec/unit/provider/service/init_spec.rb
b/spec/unit/provider/service/init_spec.rb
index 32bfaa2..cabd090 100755
--- a/spec/unit/provider/service/init_spec.rb
+++ b/spec/unit/provider/service/init_spec.rb
@@ -10,6 +10,7 @@ provider_class =
Puppet::Type.type(:service).provider(:init)
describe provider_class do
before :each do
+ @class = Puppet::Type.type(:service).provider(:init)
@resource = stub 'resource'
@resource.stubs(:[]).returns(nil)
@resource.stubs(:[]).with(:name).returns "myservice"
@@ -22,6 +23,40 @@ describe provider_class do
@provider.resource = @resource
end
+ describe "when getting all service instances" do
+ before :each do
+ @services = ['one', 'two', 'three', 'four']
+ Dir.stubs(:entries).returns @services
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:executable?).returns(true)
+ @class.stubs(:defpath).returns('tmp')
+ end
+ it "should return instances for all services" do
+ @services.each do |inst|
+ @class.expects(:new).with({:name => inst, :path =>
@class.defpath}).returns("#{inst}_instance")
+ end
+ results = @services.collect {|x| "#{x}_instance"}
+ @class.instances.should == results
+ end
+ it "should omit an array of services from exclude list" do
+ exclude = ['two', 'four']
+ (@services-exclude).each do |inst|
+ @class.expects(:new).with({:name => inst, :path =>
@class.defpath}).returns("#{inst}_instance")
+ end
+ results = (@services-exclude).collect {|x| "#{x}_instance"}
+ @class.get_services(@class.defpath, exclude).should ==
results
+ end
+ it "should omit a single service from the exclude list" do
+ exclude = 'two'
+ (@services-exclude.to_a).each do |inst|
+ @class.expects(:new).with({:name => inst, :path =>
@class.defpath}).returns("#{inst}_instance")
+ end
+ results = @services.reject{|x| x==exclude }.collect {|x|
"#{x}_instance"}
+ @class.get_services(@class.defpath, exclude).should ==
results
+ end
+ it "should use defpath" do
+ end
+ end
describe "when searching for the init script" do
it "should discard paths that do not exist" do
diff --git a/spec/unit/provider/service/redhat_spec.rb
b/spec/unit/provider/service/redhat_spec.rb
index 47997dc..840b192 100755
--- a/spec/unit/provider/service/redhat_spec.rb
+++ b/spec/unit/provider/service/redhat_spec.rb
@@ -10,6 +10,7 @@ provider_class =
Puppet::Type.type(:service).provider(:redhat)
describe provider_class do
before :each do
+ @class = Puppet::Type.type(:service).provider(:redhat)
@resource = stub 'resource'
@resource.stubs(:[]).returns(nil)
@resource.stubs(:[]).with(:name).returns "myservice"
@@ -19,6 +20,24 @@ describe provider_class do
FileTest.stubs(:file?).with('/sbin/service').returns true
FileTest.stubs(:executable?).with('/sbin/service').returns true
end
+
+ # test self.instances
+ describe "when getting all service instances" do
+ before :each do
+ @services = ['one', 'two', 'three', 'four', 'kudzu',
'functions', 'halt', 'killall', 'single', 'linuxconf']
+ @not_services = ['functions', 'halt', 'killall', 'single',
'linuxconf']
+ Dir.stubs(:entries).returns @services
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:executable?).returns(true)
+ end
+ it "should return instances for all services" do
+ (@services-@not_services).each do |inst|
+ @class.expects(:new).with({:name => inst, :path =>
'/etc/init.d/'}).returns("#{inst}_instance")
+ end
+ results = (@services-@not_services).collect {|x|
"#{x}_instance"}
+ @class.instances.should == results
+ end
+ end
it "should have an enabled? method" do
@provider.should respond_to(:enabled?)
PATCH/puppet 1/1] Fix for 4314 -- Need to allow '-' in class name for refs
I almost changed this to correspond to the lexer pattern ([a-z0-9][-\w]*)
but
that isn't quite right either (it would reintroduce the '::' problem).
Another
option I considered was [^\[]+, but that has it's own problems. In the
end I
just made the minimal change, adding '-' to the acceptable characters.
Signed-off-by: Markus Roberts <Mar### @reality.com>
---
lib/puppet/resource/catalog.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/puppet/resource/catalog.rb
b/lib/puppet/resource/catalog.rb
index 4b4342d..a8668d8 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -57,7 +57,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
end
def title_key_for_ref( ref )
- ref =~ /^([\w:]+)\[(.*)\]$/m
+ ref =~ /^([-\w:]+)\[(.*)\]$/m
[$1, $2]
end
PATCH/puppet 1/1] [#4108] Added queueing to the log
The log will now queue any log messages created when there is no
destination, and will flush the queue when a destination is added.
Signed-off-by: Nick Lewis <nic### @puppetlabs.com>
---
lib/puppet/util/log.rb | 17 +++++++++++++++++
spec/unit/util/log_spec.rb | 6 ++++++
spec/unit/util/logging_spec.rb | 6 ++++++
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index ba23e12..64a8d14 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -31,6 +31,8 @@ class Puppet::Util::Log
@destinations = {}
+ @queued = []
+
class << self
include Puppet::Util
include Puppet::Util::ClassGen
@@ -145,6 +147,7 @@ class Puppet::Util::Log
else
@destinations[dest] = type.new()
end
+ flushqueue
rescue => detail
if Puppet[:debug]
puts detail.backtrace
@@ -167,6 +170,8 @@ class Puppet::Util::Log
return
end
+ queuemessage(msg) if @destinations.count == 0
+
@destinations.each do |name, dest|
threadlock(dest) do
dest.handle(msg)
@@ -174,6 +179,18 @@ class Puppet::Util::Log
end
end
+ def Log.queuemessage(msg)
+ @queued.push(msg)
+ end
+
+ def Log.flushqueue
+ return unless @destinations.size >= 1
+ @queued.each do |msg|
+ Log.newmessage(msg)
+ end
+ @queued.clear
+ end
+
def Log.sendlevel?(level)
@levels.index(level) >= @loglevel
end
diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb
index 7aaa580..c72078f 100755
--- a/spec/unit/util/log_spec.rb
+++ b/spec/unit/util/log_spec.rb
@@ -84,6 +84,12 @@ describe Puppet::Util::Log do
Puppet::Util::Log.new(:level => :notice, :message =>
:foo).message.should == "foo"
end
+ it "should write queued logs when the first destination is
specified" do
+ Hash.any_instance.stubs(:[]=)
+ Puppet::Util::Log.expects(:flushqueue)
+ Puppet::Util::Log.newdestination(:console)
+ end
+
it "should convert the level to a symbol if it's passed in as a
string" do
Puppet::Util::Log.new(:level => "notice", :message =>
:foo).level.should == :notice
end
diff --git a/spec/unit/util/logging_spec.rb
b/spec/unit/util/logging_spec.rb
index aee308e..41b07d4 100755
--- a/spec/unit/util/logging_spec.rb
+++ b/spec/unit/util/logging_spec.rb
@@ -40,6 +40,12 @@ describe Puppet::Util::Logging do
@logger.notice "foo"
end
+ it "should queue logs sent without a specified destination" do
+ Puppet::Util::Log.expects(:queuemessage)
+
+ @logger.notice "foo"
+ end
+
it "should use the path of any provided resource type" do
resource = Puppet::Type.type(:mount).new :name => "foo"
It compiles with no errors , but something missing ?
Jul 14, 2010 SKU112.cab missing for windows office 2007 Jun 14, 2010 Redirect Sub domain to Root Jul 22, 2010 Dynamic Subdomains use domain root Jul 25, 2010 rewrite index.php to root again... with a difference Jul 22, 2010 Multi element maths, which square root Jun 13, 2010 | |||||
(177 lines) Jul 29, 2010 15:56