From 3b53bfcd0dd20a43c751b2b0d5dbb0e3463ef47b Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Mon, 18 Oct 2010 14:25:17 -0700 Subject: Fix for #5022 -- Escaped newlines should be elided This was a regression, not covered by a test; previously the string "foo\ bar" would be interpreded as "foobar" but this was changed to "foo\\\nbar" in 2.6.x with my string interpolation refactor. This change restores the behaviour. --- lib/puppet/parser/lexer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 9036d652e..31d39ae2f 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -522,13 +522,14 @@ class Puppet::Parser::Lexer # backslash; the caret is there to match empty strings str = @scanner.scan_until(/([^\\]|^|[^\\])([\\]{2})*[#{terminators}]/) or lex_error "Unclosed quote after '#{last}' in '#{rest}'" @line += str.count("\n") # literal carriage returns add to the line count. - str.gsub!(/\\(.)/) { + str.gsub!(/\\(.)/m) { ch = $1 if escapes.include? ch case ch when 'n'; "\n" when 't'; "\t" when 's'; " " + when "\n": '' else ch end else -- cgit From 65ef24e5c1c33b7d42012891d368917fd6aaf68c Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 8 Oct 2010 15:26:28 -0700 Subject: (#4534/#4778) -- Normalize parameterized classes This is a reconciliation/melding of Paul's (#4534) Class inheritance with parameterized classes is no longer ignored and Markus's Fix for #4778 -- evaluate parameterized classes when they are instantiated Extracted the code from Resource::Type#mk_plain_resource that evaluates parents and tags the catalog, and moved that into a new method called instantiate_resource. Instantiate_resource is now also called from Parser::Ast::Resource#evaluate, so that the notation "class { classname: }" now executes this code too. Likewise adds class evaluation so that it behaves the same (with regard to lazy / strict evaluation) as include classname --- lib/puppet/parser/ast/resource.rb | 7 ++++--- lib/puppet/parser/compiler.rb | 4 ++-- lib/puppet/resource/type.rb | 31 ++++++++++++++++++------------- 3 files changed, 24 insertions(+), 18 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index 6909c85c2..b019e6aac 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -49,10 +49,11 @@ class Resource < AST::ResourceReference :strict => true ) - # And then store the resource in the compiler. - # At some point, we need to switch all of this to return - # resources instead of storing them like this. + if resource.resource_type.is_a? Puppet::Resource::Type + resource.resource_type.instantiate_resource(scope, resource) + end scope.compiler.add_resource(scope, resource) + scope.compiler.evaluate_classes([resource_title],scope,false) if fully_qualified_type == 'class' resource end }.reject { |resource| resource.nil? } diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index e1227e753..c60e1d4fb 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -144,7 +144,7 @@ class Puppet::Parser::Compiler if klass = scope.find_hostclass(name) found << name and next if scope.class_scope(klass) - resource = klass.mk_plain_resource(scope) + resource = klass.ensure_in_catalog(scope) # If they've disabled lazy evaluation (which the :include function does), # then evaluate our resource immediately. @@ -220,7 +220,7 @@ class Puppet::Parser::Compiler # Create a resource to model this node, and then add it to the list # of resources. - resource = astnode.mk_plain_resource(topscope) + resource = astnode.ensure_in_catalog(topscope) resource.evaluate diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 7b21e55dc..d40adc145 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -138,21 +138,15 @@ class Puppet::Resource::Type end end - # Make an instance of our resource type. This is only possible - # for those classes and nodes that don't have any arguments, and is - # only useful for things like the 'include' function. - def mk_plain_resource(scope) + # Make an instance of the resource type, and place it in the catalog + # if it isn't in the catalog already. This is only possible for + # classes and nodes. No parameters are be supplied--if this is a + # parameterized class, then all parameters take on their default + # values. + def ensure_in_catalog(scope) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node - # Make sure our parent class has been evaluated, if we have one. - if parent - parent_resource = scope.catalog.resource(resource_type, parent) - unless parent_resource - parent_type(scope).mk_plain_resource(scope) - end - end - # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. @@ -161,11 +155,22 @@ class Puppet::Resource::Type end resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) + instantiate_resource(scope, resource) scope.compiler.add_resource(scope, resource) - scope.catalog.tag(*resource.tags) resource end + def instantiate_resource(scope, resource) + # Make sure our parent class has been evaluated, if we have one. + if parent && !scope.catalog.resource(resource.type, parent) + parent_type(scope).ensure_in_catalog(scope) + end + + if ['Class', 'Node'].include? resource.type + scope.catalog.tag(*resource.tags) + end + end + def name return @name unless @name.is_a?(Regexp) @name.source.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'') -- cgit From 31118fe85aca4ee46903b17a3eb7aee07b8c0d69 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 23 Oct 2010 08:26:24 -0700 Subject: Kludge for #5048 -- serialization compatibility with 0.25.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 0.25.x the type & title of a resource were wrapped in a Puppet::Resource::Reference object whereas in 2.6.x they are attributes of the resource itself without the additional indirection (see 7089446697ad550c22012bc2b5572030727d67e1). When pson serialization is used this isn’t a problem but with formats in which we just blindly emit the structure either because we have no choice (marshal) or because we just use the default (yaml) it is a compatibility-breaking change. This patch resoloves the problem by adding a dummy reference object to cause the "correct" serialization; it is intended as a stop-gap for 2.6.x and should NOT be merged into next. --- lib/puppet/resource.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 39803b077..7dea270e8 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -154,6 +154,14 @@ class Puppet::Resource end end + # This stub class is only needed for serialization compatibility with 0.25.x + class Reference + attr_accessor :type,:title + def initialize(type,title) + @type,@title = type,title + end + end + # Create our resource. def initialize(type, title = nil, attributes = {}) @parameters = {} @@ -180,6 +188,8 @@ class Puppet::Resource tag(self.type) tag(self.title) if valid_tag?(self.title) + @reference = Reference.new(@type,@title) # for serialization compatibility with 0.25.x + raise ArgumentError, "Invalid resource type #{type}" if strict? and ! resource_type end -- cgit From 776ea2a17de7834ecdaded9fcaabc48446d2f29d Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 28 Oct 2010 20:10:59 +1100 Subject: Fixed #5137 - Removed no longer required TOC references --- lib/puppet/util/reference.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb index 99458aa57..ab201cde4 100644 --- a/lib/puppet/util/reference.rb +++ b/lib/puppet/util/reference.rb @@ -32,7 +32,6 @@ class Puppet::Util::Reference section = reference(name) or raise "Could not find section #{name}" depth = section.depth if section.depth < depth end - text = "* TOC text.\n{:toc}\n\n" end def self.pdf(text) @@ -141,7 +140,6 @@ class Puppet::Util::Reference # First the header text = h(@title, 1) text += "\n\n**This page is autogenerated; any changes will get overwritten** *(last generated on #{Time.now.to_s})*\n\n" - text += "* TOC Text.\n{:toc}\n\n" if withcontents text += @header -- cgit From 76ac1f88ce2a13cabbda38eb56ed21a43e6923a7 Mon Sep 17 00:00:00 2001 From: donavan Date: Wed, 27 Oct 2010 17:57:03 -0700 Subject: Fixed #5112 - Launchd Service broke in 2.6.2 with OS X 10.4 Clients. Just to follow up on 5112 I have a dirty patch that appears to work. Nominally tested it on 10.4, 10.5, & 10.6. 10.4 now applies catalogs instead of failing. All versions successfully manage a test services state as well. Does anyone have a better suggestion than '-o /dev/stdout'? Seems a mite hacky to me. Also I think that the 10.4 machines are going to a have a \ ( slash ) file in whatever puppets working dir was. plutil seems to have been interpreting as literal file name. --- lib/puppet/provider/service/launchd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/service/launchd.rb b/lib/puppet/provider/service/launchd.rb index b296e0a38..1632edabf 100644 --- a/lib/puppet/provider/service/launchd.rb +++ b/lib/puppet/provider/service/launchd.rb @@ -56,7 +56,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do # Read a plist, whether its format is XML or in Apple's "binary1" # format. def self.read_plist(path) - Plist::parse_xml(plutil('-convert', 'xml1', '-o', '-', path)) + Plist::parse_xml(plutil('-convert', 'xml1', '-o', '/dev/stdout', path)) end # returns a label => path map for either all jobs, or just a single -- cgit