summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-07-19 19:59:01 -0700
committerJesse Wolfe <jes5199@gmail.com>2010-07-19 19:59:04 -0700
commit2af27160b94efa4755187efd99c86d1659683b29 (patch)
treee478abb994e64164061be7d6adc1f2c8147ec9eb
parent21efa7b282080c69760a17576dff60c01821a963 (diff)
parentd87a2e39d1a6104c52b1213a654ec9d58d0bff7f (diff)
downloadpuppet-2af27160b94efa4755187efd99c86d1659683b29.tar.gz
puppet-2af27160b94efa4755187efd99c86d1659683b29.tar.xz
puppet-2af27160b94efa4755187efd99c86d1659683b29.zip
Merge branch 'master' into next
This is the code for 2.6 RC4
-rw-r--r--CHANGELOG18
-rw-r--r--conf/suse/client.init5
-rw-r--r--conf/suse/puppet.spec36
-rw-r--r--conf/suse/server.init5
-rw-r--r--lib/puppet/dsl/resource_api.rb2
-rw-r--r--lib/puppet/indirector/catalog/compiler.rb4
-rw-r--r--lib/puppet/node.rb4
-rw-r--r--lib/puppet/parser/ast/comparison_operator.rb15
-rw-r--r--lib/puppet/parser/ast/leaf.rb3
-rw-r--r--lib/puppet/parser/compiler.rb23
-rw-r--r--lib/puppet/parser/lexer.rb16
-rw-r--r--lib/puppet/parser/parser_support.rb2
-rw-r--r--lib/puppet/parser/resource.rb9
-rw-r--r--lib/puppet/parser/type_loader.rb28
-rw-r--r--lib/puppet/rails/resource.rb6
-rw-r--r--lib/puppet/resource.rb5
-rw-r--r--lib/puppet/resource/catalog.rb2
-rw-r--r--lib/puppet/resource/type_collection.rb6
-rw-r--r--lib/puppet/type.rb10
-rw-r--r--lib/puppet/type/file.rb2
-rwxr-xr-xlib/puppet/type/file/source.rb2
-rwxr-xr-xspec/unit/indirector/catalog/compiler_spec.rb10
-rwxr-xr-xspec/unit/indirector/node/exec_spec.rb9
-rwxr-xr-xspec/unit/parser/ast/comparison_operator_spec.rb72
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb21
-rwxr-xr-xspec/unit/parser/compiler_spec.rb2
-rwxr-xr-xspec/unit/parser/lexer_spec.rb8
-rw-r--r--spec/unit/parser/type_loader_spec.rb26
-rwxr-xr-xspec/unit/rails/resource_spec.rb16
-rwxr-xr-xspec/unit/resource/catalog_spec.rb9
-rwxr-xr-xspec/unit/resource_spec.rb6
-rwxr-xr-xspec/unit/type/file_spec.rb14
-rwxr-xr-xspec/unit/type_spec.rb21
33 files changed, 272 insertions, 145 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fd315f35f..74a5470b8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,23 @@
+2.6.0rc4
+========
+cf597d7 [#4233] Ruby regexps are not multiline by default, but Resource titles can be multiline
+d6cbb21 Fix for #4234 -- ruby DSL fails on second resource
+4822de3 Fix for #4236 -- Only interpolate $ if followed by a variable
+b509032 Fix #4238 - if should match undef as ''
+8c8c146 Minimal fix for #4243 -- import isn't thread safe
+d319da4 [#4247] storeconfigs was calling Puppet::Parser::Resource.new with the wrong arguments
+9f91540 [#4256] External nodes parameters can now be assigned to nodes
+680dd1a Fix for #4257 -- problems resolving ::-prefixed classes
+6e07a19 Fix #4262 - Puppetmaster used to log compilation time
+5b68afe Fix for #4255 -- misleading diagnostic message
+dd03ac9 Partial fix for #4278 -- the performance aspects
+4ce33fd Fixed #4249 - Updated SUSE packaging specifications
+91185c6 New man pages for 2.6.0
+1cda7c5 Fixes errant Trac references in documentation
+
2.6.0rc3
========
+f60b6a0 Updated CHANGELOG for 2.6.0rc3
9df87e9 [#4219] Install misses command_line dir, puppet $app --help fails
0422852 conf/redhat: Consistently pass pidfile option to daemon, killproc, and status
63bf037 conf/redhat: Update conf/init files for single binary
diff --git a/conf/suse/client.init b/conf/suse/client.init
index b81869b55..d72b09b2c 100644
--- a/conf/suse/client.init
+++ b/conf/suse/client.init
@@ -14,8 +14,9 @@
### BEGIN INIT INFO
# Provides: puppet
# Required-Start: $local_fs $network $syslog
-# Should-Start:
-# Required-Stop:
+# Should-Start: $null
+# Required-Stop: $null
+# Should-Stop: $null
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: puppet
diff --git a/conf/suse/puppet.spec b/conf/suse/puppet.spec
index 15a9b9e5b..2a0e6e359 100644
--- a/conf/suse/puppet.spec
+++ b/conf/suse/puppet.spec
@@ -43,7 +43,6 @@ for f in bin/* ; do
done
%install
-%{__rm} -rf %{buildroot}
%{__install} -d -m0755 %{buildroot}%{_sbindir}
%{__install} -d -m0755 %{buildroot}%{_bindir}
%{__install} -d -m0755 %{buildroot}%{ruby_sitelibdir}
@@ -52,36 +51,41 @@ done
%{__install} -d -m0755 %{buildroot}%{_localstatedir}/lib/puppet
%{__install} -d -m0755 %{buildroot}%{_localstatedir}/run/puppet
%{__install} -d -m0755 %{buildroot}%{_localstatedir}/log/puppet
-%{__install} -Dp -m0755 %{pbuild}/bin/* %{pbuild}/sbin/* %{buildroot}%{_sbindir}
+%{__install} -Dp -m0755 %{pbuild}/bin/* %{buildroot}%{_sbindir}
+%{__install} -Dp -m0755 %{pbuild}/sbin/* %{buildroot}%{_sbindir}
%{__mv} %{buildroot}%{_sbindir}/puppet %{buildroot}%{_bindir}/puppet
%{__mv} %{buildroot}%{_sbindir}/puppetrun %{buildroot}%{_bindir}/puppetrun
-%{__mv} %{buildroot}%{_sbindir}/pi %{buildroot}%{_bindir}/pi
-%{__mv} %{buildroot}%{_sbindir}/filebucket %{buildroot}%{_bindir}/filebucket
%{__install} -Dp -m0644 %{pbuild}/lib/puppet.rb %{buildroot}%{ruby_sitelibdir}/puppet.rb
%{__cp} -a %{pbuild}/lib/puppet %{buildroot}%{ruby_sitelibdir}
-find %{buildroot}%{ruby_sitelibdir} -type f -perm +ugo+x -print0 | xargs -0 -r %{__chmod} a-x
-%{__install} -Dp -m0644 %{confdir}/client.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/puppet
-%{__install} -Dp -m0755 %{suseconfdir}/client.init %{buildroot}%{_initrddir}/puppet
-%{__install} -Dp -m0644 %{confdir}/server.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/puppetmaster
-%{__install} -Dp -m0755 %{suseconfdir}/server.init %{buildroot}%{_initrddir}/puppetmaster
+find %{buildroot}%{ruby_sitelibdir} -type f -perm +ugo+x -exec chmod a-x '{}' \;
+%{__install} -Dp -m0644 %{confdir}/client.sysconfig %{buildroot}/var/adm/fillup-templates/sysconfig.puppet
+%{__install} -Dp -m0755 %SOURCE1 %{buildroot}%{_initrddir}/puppet
+%{__install} -Dp -m0644 %{confdir}/server.sysconfig %{buildroot}/var/adm/fillup-templates/sysconfig.puppetmaster
+%{__install} -Dp -m0755 %SOURCE2 %{buildroot}%{_initrddir}/puppetmaster
%{__install} -Dp -m0644 %{confdir}/fileserver.conf %{buildroot}%{_sysconfdir}/puppet/fileserver.conf
%{__install} -Dp -m0644 %{confdir}/puppet.conf %{buildroot}%{_sysconfdir}/puppet/puppet.conf
+#%{__ln_s} puppet.conf %{buildroot}%{_sysconfdir}/puppet/puppetmasterd.conf
+#%{__ln_s} puppet.conf %{buildroot}%{_sysconfdir}/puppet/puppetca.conf
%{__install} -Dp -m0644 %{confdir}/logrotate %{buildroot}%{_sysconfdir}/logrotate.d/puppet
+%{__ln_s} %{_initrddir}/puppet %{buildroot}%{_sbindir}/rcpuppet
+%{__ln_s} %{_initrddir}/puppetmaster %{buildroot}%{_sbindir}/rcpuppetmaster
%files
%defattr(-, root, root, 0755)
%{_bindir}/puppet
-%{_bindir}/pi
-%{_bindir}/filebucket
+%{_sbindir}/filebucket
%{_sbindir}/ralsh
%{_sbindir}/puppetd
+%{_sbindir}/rcpuppet
+%{_sbindir}/pi
%{ruby_sitelibdir}/*
%{_initrddir}/puppet
-%config(noreplace) %{_sysconfdir}/sysconfig/puppet
+/var/adm/fillup-templates/sysconfig.puppet
%config(noreplace) %{_sysconfdir}/puppet/puppet.conf
%doc CHANGELOG COPYING LICENSE README examples
%exclude %{_sbindir}/puppetdoc
%config(noreplace) %{_sysconfdir}/logrotate.d/puppet
+%dir %{_sysconfdir}/puppet
# These need to be owned by puppet so the server can
# write to them
%attr(-, puppet, puppet) %{_localstatedir}/run/puppet
@@ -152,7 +156,7 @@ fi
* Mon Jun 19 2006 David Lutterkort <dlutter@redhat.com> - 0.18.0-1
- Patch config for LSB compliance (lsb-config.patch)
-- Changed config moves /var/puppet to /var/lib/puppet, /etc/puppet/ssl
+- Changed config moves /var/puppet to /var/lib/puppet, /etc/puppet/ssl
to /var/lib/puppet, /etc/puppet/clases.txt to /var/lib/puppet/classes.txt,
/etc/puppet/localconfig.yaml to /var/lib/puppet/localconfig.yaml
@@ -175,7 +179,7 @@ fi
- Rebuilt for new version
* Wed Mar 22 2006 David Lutterkort <dlutter@redhat.com> - 0.15.1-1
-- Patch0: Run puppetmaster as root; running as puppet is not ready
+- Patch0: Run puppetmaster as root; running as puppet is not ready
for primetime
* Mon Mar 13 2006 David Lutterkort <dlutter@redhat.com> - 0.15.0-1
@@ -190,7 +194,7 @@ fi
allocate the puppet uid/gid dynamically
* Sun Feb 19 2006 David Lutterkort <dlutter@redhat.com> - 0.13.0-4
-- Use fedora-usermgmt to create puppet user/group. Use uid/gid 24. Fixed
+- Use fedora-usermgmt to create puppet user/group. Use uid/gid 24. Fixed
problem with listing fileserver.conf and puppetmaster.conf twice
* Wed Feb 8 2006 David Lutterkort <dlutter@redhat.com> - 0.13.0-3
@@ -215,7 +219,7 @@ problem with listing fileserver.conf and puppetmaster.conf twice
- Added basic fileserver.conf
* Wed Jan 11 2006 David Lutterkort <dlutter@redhat.com> - 0.10.1-1
-- Updated. Moved installation of library files to sitelibdir. Pulled
+- Updated. Moved installation of library files to sitelibdir. Pulled
initscripts into separate files. Folded tools rpm into server
* Thu Nov 24 2005 Duane Griffin <d.griffin@psenterprise.com>
diff --git a/conf/suse/server.init b/conf/suse/server.init
index cc4194b62..e3a1d902a 100644
--- a/conf/suse/server.init
+++ b/conf/suse/server.init
@@ -12,8 +12,9 @@
### BEGIN INIT INFO
# Provides: puppetmaster
# Required-Start: $local_fs $network $syslog
-# Should-Start:
-# Required-Stop:
+# Should-Start: $null
+# Required-Stop: $null
+# Should-Stop: $null
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: puppetmaster
diff --git a/lib/puppet/dsl/resource_api.rb b/lib/puppet/dsl/resource_api.rb
index 9aa1ea07a..d82373b0e 100644
--- a/lib/puppet/dsl/resource_api.rb
+++ b/lib/puppet/dsl/resource_api.rb
@@ -37,7 +37,7 @@ class Puppet::DSL::ResourceAPI
super
ensure
- @searching_for_method = true
+ @searching_for_method = false
end
def set_instance_variables
diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb
index e85608ed1..c50022fff 100644
--- a/lib/puppet/indirector/catalog/compiler.rb
+++ b/lib/puppet/indirector/catalog/compiler.rb
@@ -72,9 +72,9 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
loglevel = networked? ? :notice : :none
- benchmark(loglevel, "Compiled catalog for #{node.name}") do
+ benchmark(loglevel, str) do
begin
- return Puppet::Parser::Compiler.compile(node)
+ config = Puppet::Parser::Compiler.compile(node)
rescue Puppet::Error => detail
Puppet.err(detail.to_s) if networked?
raise
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 1fc615410..2453cd1d5 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -16,8 +16,8 @@ class Puppet::Node
indirects :node, :terminus_setting => :node_terminus, :doc => "Where to find node information.
A node is composed of its name, its facts, and its environment."
- attr_accessor :name, :classes, :source, :ipaddress
- attr_reader :time, :parameters
+ attr_accessor :name, :classes, :source, :ipaddress, :parameters
+ attr_reader :time
def environment
return super if @environment
diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb
index c8694bbff..039c81df8 100644
--- a/lib/puppet/parser/ast/comparison_operator.rb
+++ b/lib/puppet/parser/ast/comparison_operator.rb
@@ -16,17 +16,16 @@ class Puppet::Parser::AST
def evaluate(scope)
# evaluate the operands, should return a boolean value
lval = @lval.safeevaluate(scope)
- rval = @rval.safeevaluate(scope)
- # convert to number if operands are number
- lval = Puppet::Parser::Scope.number?(lval) || lval
- rval = Puppet::Parser::Scope.number?(rval) || rval
+ case @operator
+ when "==","!="
+ @rval.evaluate_match(lval, scope) ? @operator == '==' : @operator == '!='
+ else
+ rval = @rval.safeevaluate(scope)
+ rval = Puppet::Parser::Scope.number?(rval) || rval
+ lval = Puppet::Parser::Scope.number?(lval) || lval
- # return result
- unless @operator == '!='
lval.send(@operator,rval)
- else
- lval != rval
end
end
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 3b9163d9c..49f430278 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -17,6 +17,9 @@ class Puppet::Parser::AST
obj = obj.downcase if obj.respond_to?(:downcase)
value = value.downcase if value.respond_to?(:downcase)
+ obj = Puppet::Parser::Scope.number?(obj) || obj
+ value = Puppet::Parser::Scope.number?(value) || value
+
# "" == undef for case/selector/if
obj == value or (obj == "" and value == :undef)
end
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 85980722c..a901c0dd6 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -251,19 +251,7 @@ class Puppet::Parser::Compiler
# evaluate_generators loop.
def evaluate_definitions
exceptwrap do
- if ary = unevaluated_resources
- evaluated = false
- ary.each do |resource|
- if not resource.virtual?
- resource.evaluate
- evaluated = true
- end
- end
- # If we evaluated, let the loop know.
- return evaluated
- else
- return false
- end
+ !unevaluated_resources.each { |resource| resource.evaluate }.empty?
end
end
@@ -482,12 +470,7 @@ class Puppet::Parser::Compiler
# Return an array of all of the unevaluated resources. These will be definitions,
# which need to get evaluated into native resources.
def unevaluated_resources
- ary = resources.reject { |resource| resource.builtin? or resource.evaluated? }
-
- if ary.empty?
- return nil
- else
- return ary
- end
+ # The order of these is significant for speed due to short-circuting
+ resources.reject { |resource| resource.evaluated? or resource.virtual? or resource.builtin_type? }
end
end
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 6a9f1cfc4..1e10ff96c 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -540,15 +540,17 @@ class Puppet::Parser::Lexer
[ str[0..-2],str[-1,1] ]
end
- def tokenize_interpolated_string(token_type)
+ def tokenize_interpolated_string(token_type,preamble='')
value,terminator = slurpstring('"$')
- token_queue << [TOKENS[token_type[terminator]],value]
- while terminator == '$' and not @scanner.scan(/\{/)
- token_queue << [TOKENS[:VARIABLE],@scanner.scan(%r{(\w*::)*\w+|[0-9]})]
- value,terminator = slurpstring('"$')
- token_queue << [TOKENS[DQ_continuation_token_types[terminator]],value]
+ token_queue << [TOKENS[token_type[terminator]],preamble+value]
+ if terminator != '$' or @scanner.scan(/\{/)
+ token_queue.shift
+ elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]})
+ token_queue << [TOKENS[:VARIABLE],var_name]
+ tokenize_interpolated_string(DQ_continuation_token_types)
+ else
+ tokenize_interpolated_string(token_type,token_queue.pop.last + terminator)
end
- token_queue.shift
end
# just parse a string, not a whole file
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 4f3a4ddff..c0fd37178 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -111,7 +111,7 @@ class Puppet::Parser::Parser
end
def import(file)
- known_resource_types.loader.import(file, @lexer.file)
+ known_resource_types.loader.import_if_possible(file, @lexer.file)
end
def initialize(env)
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3cccf4f3e..c956a1106 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -32,12 +32,9 @@ class Puppet::Parser::Resource < Puppet::Resource
end
# Set up some boolean test methods
- [:translated, :override, :evaluated].each do |method|
- newmeth = (method.to_s + "?").intern
- define_method(newmeth) do
- self.send(method)
- end
- end
+ def translated?; !!@translated; end
+ def override?; !!@override; end
+ def evaluated?; !!@evaluated; end
def [](param)
param = symbolize(param)
diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index cb8657f0c..c33f90d11 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -70,7 +70,7 @@ class Puppet::Parser::TypeLoader
def initialize(env)
self.environment = env
- @loaded = []
+ @loaded = {}
@loading = Helper.new
@imported = {}
@@ -79,10 +79,13 @@ class Puppet::Parser::TypeLoader
def load_until(namespaces, name)
return nil if name == "" # special-case main.
name2files(namespaces, name).each do |filename|
- modname = nil
- import_if_possible(filename) do
- modname = import(filename)
- @loaded << filename
+ modname = begin
+ import_if_possible(filename)
+ rescue Puppet::ImportError => detail
+ # We couldn't load the item
+ # I'm not convienced we should just drop these errors, but this
+ # preserves existing behaviours.
+ nil
end
if result = yield(filename)
Puppet.info "Automatically imported #{name} from #{filename}"
@@ -124,23 +127,18 @@ class Puppet::Parser::TypeLoader
parser.parse
end
- private
-
# 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, &blk)
- return if @loaded.include?(file)
- begin
+ def import_if_possible(file, current_file = nil)
+ @loaded[file] || begin
case @loading.owner_of(file)
when :this_thread
- return
+ nil
when :another_thread
- return import_if_possible(file, &blk)
+ import_if_possible(file,current_file)
when :nobody
- blk.call
+ @loaded[file] = import(file,current_file)
end
- rescue Puppet::ImportError => detail
- # We couldn't load the item
ensure
@loading.done_with(file)
end
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index a5cdd0c13..582cdd41a 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.delete("type"), hash.delete("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 31237e3b1..55874aec8 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -199,7 +199,7 @@ class Puppet::Resource
end
def resource_type
- case type
+ @resource_type ||= case type
when "Class"; find_hostclass(title)
when "Node"; find_node(title)
else
@@ -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/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index d163fc17e..4ac99eeea 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 =~ /^(.+)\[(.*)\]/
+ ref =~ /^(.+)\[(.*)\]/m
[$1, $2]
end
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index 58e8b9497..9ed27332d 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -198,11 +198,7 @@ class Puppet::Resource::TypeCollection
private
def find_fully_qualified(name, type)
- return nil unless name =~ /^::/
-
- name = name.sub(/^::/, '')
-
- send(type, name)
+ send(type, name.sub(/^::/, ''))
end
def find_partially_qualified(namespace, name, type)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index d0fea9731..880711066 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -193,7 +193,7 @@ class Type
when 0; []
when 1;
identity = lambda {|x| x}
- [ [ /(.*)/, [ [key_attributes.first, identity ] ] ] ]
+ [ [ /(.*)/m, [ [key_attributes.first, identity ] ] ] ]
else
raise Puppet::DevError,"you must specify title patterns when there are two or more key attributes"
end
@@ -1874,12 +1874,8 @@ class Type
self.to_trans.to_resource
end
- %w{exported virtual}.each do |m|
- define_method(m+"?") do
- self.send(m)
- end
- end
-
+ def virtual?; !!@virtual; end
+ def exported?; !!@exported; end
end
end
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 195e8c86f..71f2756bc 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -25,7 +25,7 @@ Puppet::Type.newtype(:file) do
native resource to support what you are doing."
def self.title_patterns
- [ [ /^(.*?)\/?$/, [ [ :path, lambda{|x| x} ] ] ] ]
+ [ [ /^(.*?)\/*\Z/m, [ [ :path, lambda{|x| x} ] ] ] ]
end
newparam(:path) do
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 05da79b3d..2eaf4a33f 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -106,8 +106,6 @@ module Puppet
next if metadata_method == :checksum and metadata.ftype == "directory"
if resource[param_name].nil? or resource[param_name] == :absent
- v = metadata.send(metadata_method)
- resource.info "Setting #{param_name} to #{v}"
resource[param_name] = metadata.send(metadata_method)
end
end
diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb
index 755509f53..2ae5f6ff3 100755
--- a/spec/unit/indirector/catalog/compiler_spec.rb
+++ b/spec/unit/indirector/catalog/compiler_spec.rb
@@ -137,6 +137,16 @@ describe Puppet::Resource::Catalog::Compiler do
Puppet::Parser::Compiler.stubs(:compile)
@compiler.find(@request)
end
+
+ it "should log the benchmark result" do
+ Puppet::Node.stubs(:find).returns(@node)
+ @compiler.stubs(:networked?).returns(true)
+ Puppet::Parser::Compiler.stubs(:compile)
+
+ Puppet.expects(:notice).with { |msg| msg =~ /Compiled catalog/ }
+
+ @compiler.find(@request)
+ end
end
describe "when extracting facts from the request" do
diff --git a/spec/unit/indirector/node/exec_spec.rb b/spec/unit/indirector/node/exec_spec.rb
index d5299ad16..d214a5ef6 100755
--- a/spec/unit/indirector/node/exec_spec.rb
+++ b/spec/unit/indirector/node/exec_spec.rb
@@ -25,8 +25,9 @@ describe Puppet::Node::Exec do
describe "when handling the results of the command" do
before do
- @node = stub 'node', :fact_merge => nil
@name = "yay"
+ @node = Puppet::Node.new(@name)
+ @node.stubs(:fact_merge)
Puppet::Node.expects(:new).with(@name).returns(@node)
@result = {}
# Use a local variable so the reference is usable in the execute definition.
@@ -45,14 +46,14 @@ describe Puppet::Node::Exec do
it "should set the resulting parameters as the node parameters" do
@result[:parameters] = {"a" => "b", "c" => "d"}
- @node.expects(:parameters=).with "a" => "b", "c" => "d"
@searcher.find(@request)
+ @node.parameters.should == {"a" => "b", "c" => "d"}
end
it "should set the resulting classes as the node classes" do
@result[:classes] = %w{one two}
- @node.expects(:classes=).with %w{one two}
@searcher.find(@request)
+ @node.classes.should == [ 'one', 'two' ]
end
it "should merge the node's facts with its parameters" do
@@ -62,8 +63,8 @@ describe Puppet::Node::Exec do
it "should set the node's environment if one is provided" do
@result[:environment] = "yay"
- @node.expects(:environment=).with "yay"
@searcher.find(@request)
+ @node.environment.to_s.should == 'yay'
end
end
end
diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb
index 724b6c6f7..931f936df 100755
--- a/spec/unit/parser/ast/comparison_operator_spec.rb
+++ b/spec/unit/parser/ast/comparison_operator_spec.rb
@@ -5,21 +5,22 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe Puppet::Parser::AST::ComparisonOperator do
before :each do
@scope = Puppet::Parser::Scope.new
- @one = stub 'one', :safeevaluate => "1"
- @two = stub 'two', :safeevaluate => "2"
+ @one = Puppet::Parser::AST::Leaf.new(:value => "1")
+ @two = Puppet::Parser::AST::Leaf.new(:value => "2")
+
+ @lval = Puppet::Parser::AST::Leaf.new(:value => "one")
+ @rval = Puppet::Parser::AST::Leaf.new(:value => "two")
end
- it "should evaluate both branches" do
- lval = stub "lval"
- lval.expects(:safeevaluate).with(@scope)
- rval = stub "rval"
- rval.expects(:safeevaluate).with(@scope)
+ it "should evaluate both values" do
+ @lval.expects(:safeevaluate).with(@scope)
+ @rval.expects(:safeevaluate).with(@scope)
- operator = Puppet::Parser::AST::ComparisonOperator.new :lval => lval, :operator => "==", :rval => rval
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @lval, :operator => "==", :rval => @rval
operator.evaluate(@scope)
end
- it "should convert arguments strings to numbers if they are" do
+ it "should convert the arguments to numbers if they are numbers in string" do
Puppet::Parser::Scope.expects(:number?).with("1").returns(1)
Puppet::Parser::Scope.expects(:number?).with("2").returns(2)
@@ -27,25 +28,48 @@ describe Puppet::Parser::AST::ComparisonOperator do
operator.evaluate(@scope)
end
- %w{< > <= >= ==}.each do |oper|
+ %w{< > <= >=}.each do |oper|
it "should use string comparison #{oper} if operands are strings" do
- lval = stub 'one', :safeevaluate => "one"
- rval = stub 'two', :safeevaluate => "two"
- Puppet::Parser::Scope.stubs(:number?).with("one").returns(nil)
- Puppet::Parser::Scope.stubs(:number?).with("two").returns(nil)
-
- operator = Puppet::Parser::AST::ComparisonOperator.new :lval => lval, :operator => oper, :rval => rval
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @lval, :operator => oper, :rval => @rval
operator.evaluate(@scope).should == "one".send(oper,"two")
end
end
- it "should fail with arguments of different types" do
- lval = stub 'one', :safeevaluate => "one"
- rval = stub 'two', :safeevaluate => "2"
- Puppet::Parser::Scope.stubs(:number?).with("one").returns(nil)
- Puppet::Parser::Scope.stubs(:number?).with("2").returns(2)
+ describe "with string comparison" do
+ it "should use matching" do
+ @rval.expects(:evaluate_match).with("one", @scope)
- operator = Puppet::Parser::AST::ComparisonOperator.new :lval => lval, :operator => ">", :rval => rval
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @lval, :operator => "==", :rval => @rval
+ operator.evaluate(@scope)
+ end
+
+ it "should return true for :undef to '' equality" do
+ astundef = Puppet::Parser::AST::Leaf.new(:value => :undef)
+ empty = Puppet::Parser::AST::Leaf.new(:value => '')
+
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => astundef, :operator => "==", :rval => empty
+ operator.evaluate(@scope).should be_true
+ end
+
+ [true, false].each do |result|
+ it "should return #{(result).inspect} with '==' when matching return #{result.inspect}" do
+ @rval.expects(:evaluate_match).with("one", @scope).returns result
+
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @lval, :operator => "==", :rval => @rval
+ operator.evaluate(@scope).should == result
+ end
+
+ it "should return #{(!result).inspect} with '!=' when matching return #{result.inspect}" do
+ @rval.expects(:evaluate_match).with("one", @scope).returns result
+
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @lval, :operator => "!=", :rval => @rval
+ operator.evaluate(@scope).should == !result
+ end
+ end
+ end
+
+ it "should fail with arguments of different types" do
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @one, :operator => ">", :rval => @rval
lambda { operator.evaluate(@scope) }.should raise_error(ArgumentError)
end
@@ -81,8 +105,8 @@ describe Puppet::Parser::AST::ComparisonOperator do
# see ticket #1759
%w{< > <= >=}.each do |oper|
it "should return the correct result of using '#{oper}' to compare 10 and 9" do
- ten = stub 'one', :safeevaluate => "10"
- nine = stub 'two', :safeevaluate => "9"
+ ten = Puppet::Parser::AST::Leaf.new(:value => "10")
+ nine = Puppet::Parser::AST::Leaf.new(:value => "9")
operator = Puppet::Parser::AST::ComparisonOperator.new :lval => ten, :operator => oper, :rval => nine
operator.evaluate(@scope).should == 10.send(oper,9)
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index 379cbfde7..d21cbf573 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -35,6 +35,27 @@ describe Puppet::Parser::AST::Leaf do
@leaf.evaluate_match("value", @scope)
end
+ it "should convert values to number" do
+ @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
+ Puppet::Parser::Scope.expects(:number?).with(@value).returns(2)
+ Puppet::Parser::Scope.expects(:number?).with("23").returns(23)
+
+ @leaf.evaluate_match("23", @scope)
+ end
+
+ it "should compare 'numberized' values" do
+ @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
+ two = stub_everything 'two'
+ one = stub_everything 'one'
+
+ Puppet::Parser::Scope.stubs(:number?).with(@value).returns(one)
+ Puppet::Parser::Scope.stubs(:number?).with("2").returns(two)
+
+ one.expects(:==).with(two)
+
+ @leaf.evaluate_match("2", @scope)
+ end
+
it "should match undef if value is an empty string" do
@leaf.stubs(:safeevaluate).with(@scope).returns("")
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index a3fe56c0e..e8c06dd0b 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -23,7 +23,7 @@ class CompilerTestResource
@evaluated
end
- def builtin?
+ def builtin_type?
@builtin
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 81e76a388..d3d2a0a31 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -426,7 +426,13 @@ describe Puppet::Parser::Lexer,"when lexing strings" do
%q{a hardest "scanner \"test\""} => [[:NAME,"a"],[:NAME,"hardest"],[:STRING,'scanner "test"']],
%Q{a hardestest "scanner \\"test\\"\n"} => [[:NAME,"a"],[:NAME,"hardestest"],[:STRING,%Q{scanner "test"\n}]],
%q{function("call")} => [[:NAME,"function"],[:LPAREN,"("],[:STRING,'call'],[:RPAREN,")"]],
- %q["string with ${(3+5)/4} nested math."] => [[:DQPRE,"string with "],:LPAREN,[:NAME,"3"],:PLUS,[:NAME,"5"],:RPAREN,:DIV,[:NAME,"4"],[:DQPOST," nested math."]]
+ %q["string with ${(3+5)/4} nested math."] => [[:DQPRE,"string with "],:LPAREN,[:NAME,"3"],:PLUS,[:NAME,"5"],:RPAREN,:DIV,[:NAME,"4"],[:DQPOST," nested math."]],
+ %q["$$$$"] => [[:STRING,"$$$$"]],
+ %q["$variable"] => [[:DQPRE,""],[:VARIABLE,"variable"],[:DQPOST,""]],
+ %q["$var$other"] => [[:DQPRE,""],[:VARIABLE,"var"],[:DQMID,""],[:VARIABLE,"other"],[:DQPOST,""]],
+ %q["foo$bar$"] => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]],
+ %q["foo$$bar"] => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]],
+ %q[""] => [[:STRING,""]],
}.each { |src,expected_result|
it "should handle #{src} correctly" do
tokens_scanned_from(src).should be_like(*expected_result)
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index db72a236e..8f005d551 100644
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -38,16 +38,16 @@ describe Puppet::Parser::TypeLoader do
it "should attempt to import each generated name" do
@loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo")
- @loader.expects(:import).with("bar")
+ @loader.expects(:import).with("foo",nil)
+ @loader.expects(:import).with("bar",nil)
@loader.load_until(["foo"], "bar") { |f| false }
end
it "should yield after each import" do
yielded = []
@loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo")
- @loader.expects(:import).with("bar")
+ @loader.expects(:import).with("foo",nil)
+ @loader.expects(:import).with("bar",nil)
@loader.load_until(["foo"], "bar") { |f| yielded << f; false }
yielded.should == %w{foo bar}
end
@@ -55,31 +55,31 @@ describe Puppet::Parser::TypeLoader do
it "should stop importing when the yielded block returns true" do
yielded = []
@loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo")
- @loader.expects(:import).with("bar")
- @loader.expects(:import).with("baz").never
+ @loader.expects(:import).with("foo",nil)
+ @loader.expects(:import).with("bar",nil)
+ @loader.expects(:import).with("baz",nil).never
@loader.load_until(["foo"], "bar") { |f| true if f == "bar" }
end
it "should return the result of the block" do
yielded = []
@loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo")
- @loader.expects(:import).with("bar")
- @loader.expects(:import).with("baz").never
+ @loader.expects(:import).with("foo",nil)
+ @loader.expects(:import).with("bar",nil)
+ @loader.expects(:import).with("baz",nil).never
@loader.load_until(["foo"], "bar") { |f| 10 if f == "bar" }.should == 10
end
it "should return nil if the block never returns true" do
@loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo")
- @loader.expects(:import).with("bar")
+ @loader.expects(:import).with("foo",nil)
+ @loader.expects(:import).with("bar",nil)
@loader.load_until(["foo"], "bar") { |f| false }.should be_nil
end
it "should know when a given name has been loaded" do
@loader.expects(:name2files).returns %w{file}
- @loader.expects(:import).with("file")
+ @loader.expects(:import).with("file",nil)
@loader.load_until(["foo"], "bar") { |f| true }
@loader.should be_loaded("file")
end
diff --git a/spec/unit/rails/resource_spec.rb b/spec/unit/rails/resource_spec.rb
index ac7469355..08deda65e 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/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb
index b6f96f094..10cff91a3 100755
--- a/spec/unit/resource/catalog_spec.rb
+++ b/spec/unit/resource/catalog_spec.rb
@@ -1066,4 +1066,13 @@ describe Puppet::Resource::Catalog, "when converting from pson" do
lambda { PSON.parse @pson.to_pson }.should raise_error(ArgumentError)
end
+
+ describe "#title_key_for_ref" do
+ it "should parse a resource ref string into a pair" do
+ @catalog.title_key_for_ref("Title[name]").should == ["Title", "name"]
+ end
+ it "should parse a resource ref string into a pair, even if there's a newline inside the name" do
+ @catalog.title_key_for_ref("Title[na\nme]").should == ["Title", "na\nme"]
+ end
+ end
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 95f0dd04b..204a2b02e 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
diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb
index 845bf3d8b..7d93dfd64 100755
--- a/spec/unit/type/file_spec.rb
+++ b/spec/unit/type/file_spec.rb
@@ -1053,4 +1053,18 @@ describe Puppet::Type.type(:file) do
file.retrieve
end
end
+
+ describe ".title_patterns" do
+ before do
+ @type_class = Puppet::Type.type(:file)
+ end
+
+ it "should have a regexp that captures the entire string, except for a terminating slash" do
+ patterns = @type_class.title_patterns
+ string = "abc/\n\tdef/"
+ patterns[0][0] =~ string
+ $1.should == "abc/\n\tdef"
+ end
+ end
+
end
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index 683529d8a..71d415dc6 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -406,6 +406,27 @@ describe Puppet::Type do
end
end
+ describe ".title_patterns" do
+ describe "when there's one namevar" do
+ before do
+ @type_class = Puppet::Type.type(:notify)
+ @type_class.stubs(:key_attributes).returns([:one])
+ end
+
+ it "should have a default pattern for when there's one namevar" do
+ patterns = @type_class.title_patterns
+ patterns.length.should == 1
+ patterns[0].length.should == 2
+ end
+
+ it "should have a regexp that captures the entire string" do
+ patterns = @type_class.title_patterns
+ string = "abc\n\tdef"
+ patterns[0][0] =~ string
+ $1.should == "abc\n\tdef"
+ end
+ end
+ end
describe "when in a catalog" do
before do