summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--acceptance/tests/ticket_7101_template_compile.rb25
-rw-r--r--lib/puppet/interface.rb8
-rw-r--r--lib/puppet/interface/action.rb2
-rw-r--r--lib/puppet/interface/action_builder.rb28
-rw-r--r--lib/puppet/parser/templatewrapper.rb2
-rwxr-xr-xspec/unit/interface/action_spec.rb4
6 files changed, 46 insertions, 23 deletions
diff --git a/acceptance/tests/ticket_7101_template_compile.rb b/acceptance/tests/ticket_7101_template_compile.rb
new file mode 100644
index 000000000..d2ebecd13
--- /dev/null
+++ b/acceptance/tests/ticket_7101_template_compile.rb
@@ -0,0 +1,25 @@
+test_name "#7101: template compile"
+
+manifest = %q{
+$bar = 'test 7101'
+file { '/tmp/file_7101.erb':
+ content => template('/tmp/template_7101.erb')
+}
+}
+
+
+step "Agents: Create template file"
+agents.each do |host|
+ create_remote_file(host, '/tmp/template_7101.erb', %w{<%= bar %>} )
+end
+
+step "Run manifest referencing template file"
+apply_manifest_on(agents, manifest)
+
+
+step "Agents: Verify file is created with correct contents "
+agents.each do |host|
+ on(host, "cat /tmp/file_7101.erb") do
+ assert_match(/test 7101/, stdout, "File /tmp/file_7101.erb not created with correct contents on #{host}" )
+ end
+end
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 4a735069f..c7a167d3a 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -155,12 +155,10 @@ class Puppet::Interface
action.get_option(name).__decoration_name(type)
end
+ # Exceptions here should propagate up; this implements a hook we can use
+ # reasonably for option validation.
methods.each do |hook|
- begin
- respond_to? hook and self.__send__(hook, action, passed_args, passed_options)
- rescue => e
- Puppet.warning("invoking #{action} #{type} hook: #{e}")
- end
+ respond_to? hook and self.__send__(hook, action, passed_args, passed_options)
end
end
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 177df81f2..ac66d2946 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -259,7 +259,7 @@ WRAPPER
end.select(&:required?).collect(&:name) - args.last.keys
return if required.empty?
- raise ArgumentError, "missing required options (#{required.join(', ')})"
+ raise ArgumentError, "The following options are required: #{required.join(', ')}"
end
########################################################################
diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb
index 2ffa38709..afc49e945 100644
--- a/lib/puppet/interface/action_builder.rb
+++ b/lib/puppet/interface/action_builder.rb
@@ -9,13 +9,6 @@ class Puppet::Interface::ActionBuilder
new(face, name, &block).action
end
- private
- def initialize(face, name, &block)
- @face = face
- @action = Puppet::Interface::Action.new(face, name)
- instance_eval(&block)
- end
-
# Ideally the method we're defining here would be added to the action, and a
# method on the face would defer to it, but we can't get scope correct, so
# we stick with this. --daniel 2011-03-24
@@ -56,18 +49,25 @@ class Puppet::Interface::ActionBuilder
# Metaprogram the simple DSL from the target class.
Puppet::Interface::Action.instance_methods.grep(/=$/).each do |setter|
next if setter =~ /^=/
- dsl = setter.sub(/=$/, '')
+ property = setter.sub(/=$/, '')
- unless private_instance_methods.include? dsl
+ unless public_instance_methods.include? property
# Using eval because the argument handling semantics are less awful than
# when we use the define_method/block version. The later warns on older
# Ruby versions if you pass the wrong number of arguments, but carries
# on, which is totally not what we want. --daniel 2011-04-18
- eval <<METHOD
-def #{dsl}(value)
- @action.#{dsl} = value
-end
-METHOD
+ eval <<-METHOD
+ def #{property}(value)
+ @action.#{property} = value
+ end
+ METHOD
end
end
+
+ private
+ def initialize(face, name, &block)
+ @face = face
+ @action = Puppet::Interface::Action.new(face, name)
+ instance_eval(&block)
+ end
end
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 180a03dc9..27d75bf92 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -20,7 +20,7 @@ class Puppet::Parser::TemplateWrapper
def script_line
# find which line in the template (if any) we were called from
- caller.find { |l| l =~ /#{file}:/ }.first[/:(\d+):/,1]
+ (caller.find { |l| l =~ /#{file}:/ }||"")[/:(\d+):/,1]
end
# Should return true if a variable is defined, false if it is not
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index 24826a6ef..23d0de490 100755
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -237,7 +237,7 @@ describe Puppet::Interface::Action do
when_invoked { }
end
end
- expect { face.bar }.to raise_error ArgumentError, /missing required options \(foo\)/
+ expect { face.bar }.to raise_error ArgumentError, /The following options are required: foo/
end
it "should fail when a required face option is not provided" do
@@ -245,7 +245,7 @@ describe Puppet::Interface::Action do
option('--foo') { required }
action(:bar) { when_invoked { } }
end
- expect { face.bar }.to raise_error ArgumentError, /missing required options \(foo\)/
+ expect { face.bar }.to raise_error ArgumentError, /The following options are required: foo/
end
end