From 557767b164376d0e61875646715d3ec96401b96c Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 19 Apr 2011 12:53:16 -0700 Subject: maint: Remove unused faces code Looks like in renaming faces to face we just missed some files. They got copied, not moved. Paired-with: Max Martin --- lib/puppet/faces/help/action.erb | 3 --- lib/puppet/faces/help/face.erb | 7 ------- lib/puppet/faces/help/global.erb | 20 -------------------- 3 files changed, 30 deletions(-) delete mode 100644 lib/puppet/faces/help/action.erb delete mode 100644 lib/puppet/faces/help/face.erb delete mode 100644 lib/puppet/faces/help/global.erb diff --git a/lib/puppet/faces/help/action.erb b/lib/puppet/faces/help/action.erb deleted file mode 100644 index eaf131464..000000000 --- a/lib/puppet/faces/help/action.erb +++ /dev/null @@ -1,3 +0,0 @@ -Use: puppet <%= face.name %> [options] <%= action.name %> [options] - -Summary: <%= action.summary %> diff --git a/lib/puppet/faces/help/face.erb b/lib/puppet/faces/help/face.erb deleted file mode 100644 index efe5fd809..000000000 --- a/lib/puppet/faces/help/face.erb +++ /dev/null @@ -1,7 +0,0 @@ -Use: puppet <%= face.name %> [options] [options] - -Available actions: -% face.actions.each do |actionname| -% action = face.get_action(actionname) - <%= action.name.to_s.ljust(16) %> <%= action.summary %> -% end diff --git a/lib/puppet/faces/help/global.erb b/lib/puppet/faces/help/global.erb deleted file mode 100644 index e123367a2..000000000 --- a/lib/puppet/faces/help/global.erb +++ /dev/null @@ -1,20 +0,0 @@ -puppet [options] [options] - -Available subcommands, from Puppet Faces: -% Puppet::Faces.faces.sort.each do |name| -% face = Puppet::Faces[name, :current] - <%= face.name.to_s.ljust(16) %> <%= face.summary %> -% end - -% unless legacy_applications.empty? then # great victory when this is true! -Available applications, soon to be ported to Faces: -% legacy_applications.each do |appname| -% summary = horribly_extract_summary_from appname - <%= appname.to_s.ljust(16) %> <%= summary %> -% end -% end - -See 'puppet help ' for help on a specific subcommand action. -See 'puppet help ' for help on a specific subcommand. -See 'puppet man ' for the full man page. -Puppet v<%= Puppet::PUPPETVERSION %> -- cgit From c87d6c98ec1a315d435be38e7eb2258984c7d88c Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 20 Apr 2011 02:35:40 +1000 Subject: Fixed #7166 - Replaced deprecated stomp "send" method with "publish" The "send" method in the stomp gem has been deprecated since: http://gitorious.org/stomp/mainline/commit/d542a976028cb4c5badcbb69e3383e746721e44c It's been replaced with the "publish" method. Also renamed the send_message method to publish_message more in keeping with language used in queuing. --- lib/puppet/indirector/queue.rb | 2 +- lib/puppet/util/queue.rb | 2 +- lib/puppet/util/queue/stomp.rb | 4 ++-- spec/integration/indirector/catalog/queue_spec.rb | 4 ++-- spec/unit/indirector/queue_spec.rb | 8 ++++---- spec/unit/util/queue/stomp_spec.rb | 20 ++++++++++---------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/puppet/indirector/queue.rb b/lib/puppet/indirector/queue.rb index fd089f431..85ffacacc 100644 --- a/lib/puppet/indirector/queue.rb +++ b/lib/puppet/indirector/queue.rb @@ -36,7 +36,7 @@ class Puppet::Indirector::Queue < Puppet::Indirector::Terminus def save(request) result = nil benchmark :info, "Queued #{indirection.name} for #{request.key}" do - result = client.send_message(queue, request.instance.render(:pson)) + result = client.publish_message(queue, request.instance.render(:pson)) end result rescue => detail diff --git a/lib/puppet/util/queue.rb b/lib/puppet/util/queue.rb index 02357742a..636bdcf2e 100644 --- a/lib/puppet/util/queue.rb +++ b/lib/puppet/util/queue.rb @@ -30,7 +30,7 @@ require 'puppet/util/instance_loader' # # The client plugins are expected to implement an interface similar to that of Stomp::Client: # * new should return a connected, ready-to-go client instance. Note that no arguments are passed in. -# * send_message(queue, message) should send the _message_ to the specified _queue_. +# * publish_message(queue, message) should publish the _message_ to the specified _queue_. # * subscribe(queue) _block_ subscribes to _queue_ and executes _block_ upon receiving a message. # * _queue_ names are simple names independent of the message broker or client library. No "/queue/" prefixes like in Stomp::Client. module Puppet::Util::Queue diff --git a/lib/puppet/util/queue/stomp.rb b/lib/puppet/util/queue/stomp.rb index c18edae6a..cabc56627 100644 --- a/lib/puppet/util/queue/stomp.rb +++ b/lib/puppet/util/queue/stomp.rb @@ -28,8 +28,8 @@ class Puppet::Util::Queue::Stomp end end - def send_message(target, msg) - stomp_client.send(stompify_target(target), msg, :persistent => true) + def publish_message(target, msg) + stomp_client.publish(stompify_target(target), msg, :persistent => true) end def subscribe(target) diff --git a/spec/integration/indirector/catalog/queue_spec.rb b/spec/integration/indirector/catalog/queue_spec.rb index 569f096bf..940c8bab8 100755 --- a/spec/integration/indirector/catalog/queue_spec.rb +++ b/spec/integration/indirector/catalog/queue_spec.rb @@ -19,13 +19,13 @@ describe "Puppet::Resource::Catalog::Queue", :if => Puppet.features.pson? do after { Puppet.settings.clear } - it "should render catalogs to pson and send them via the queue client when catalogs are saved" do + it "should render catalogs to pson and publish them via the queue client when catalogs are saved" do terminus = Puppet::Resource::Catalog.indirection.terminus(:queue) client = mock 'client' terminus.stubs(:client).returns client - client.expects(:send_message).with(:catalog, @catalog.to_pson) + client.expects(:publish_message).with(:catalog, @catalog.to_pson) request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog) diff --git a/spec/unit/indirector/queue_spec.rb b/spec/unit/indirector/queue_spec.rb index b84ed2aea..eba136bbc 100755 --- a/spec/unit/indirector/queue_spec.rb +++ b/spec/unit/indirector/queue_spec.rb @@ -60,20 +60,20 @@ describe Puppet::Indirector::Queue, :if => Puppet.features.pson? do describe "when saving" do it 'should render the instance using pson' do @subject.expects(:render).with(:pson) - @store.client.stubs(:send_message) + @store.client.stubs(:publish_message) @store.save(@request) end - it "should send the rendered message to the appropriate queue on the client" do + it "should publish the rendered message to the appropriate queue on the client" do @subject.expects(:render).returns "mypson" - @store.client.expects(:send_message).with(:my_queue, "mypson") + @store.client.expects(:publish_message).with(:my_queue, "mypson") @store.save(@request) end it "should catch any exceptions raised" do - @store.client.expects(:send_message).raises ArgumentError + @store.client.expects(:publish_message).raises ArgumentError lambda { @store.save(@request) }.should raise_error(Puppet::Error) end diff --git a/spec/unit/util/queue/stomp_spec.rb b/spec/unit/util/queue/stomp_spec.rb index f67189cf5..99c77d0b4 100755 --- a/spec/unit/util/queue/stomp_spec.rb +++ b/spec/unit/util/queue/stomp_spec.rb @@ -63,26 +63,26 @@ describe 'Puppet::Util::Queue::Stomp', :if => Puppet.features.stomp? do end end - describe "when sending a message" do + describe "when publishing a message" do before do @client = stub 'client' Stomp::Client.stubs(:new).returns @client @queue = Puppet::Util::Queue::Stomp.new end - it "should send it to the queue client instance" do - @client.expects(:send).with { |queue, msg, options| msg == "Smite!" } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it to the queue client instance" do + @client.expects(:publish).with { |queue, msg, options| msg == "Smite!" } + @queue.publish_message('fooqueue', 'Smite!') end - it "should send it to the transformed queue name" do - @client.expects(:send).with { |queue, msg, options| queue == "/queue/fooqueue" } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it to the transformed queue name" do + @client.expects(:publish).with { |queue, msg, options| queue == "/queue/fooqueue" } + @queue.publish_message('fooqueue', 'Smite!') end - it "should send it as a persistent message" do - @client.expects(:send).with { |queue, msg, options| options[:persistent] == true } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it as a persistent message" do + @client.expects(:publish).with { |queue, msg, options| options[:persistent] == true } + @queue.publish_message('fooqueue', 'Smite!') end end -- cgit From 33b5580ef6b6c851beb6852e56659afea8bb0b04 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 18:22:03 -0700 Subject: maint: move method comments outside the comment. The comment discussing the purpose of the wrapper and related details rightly belongs outside the method; move it there so it doesn't perturb the functional changes that follow. Reviewed-By: Max Martin --- lib/puppet/interface/action.rb | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index 23366b407..e644d8999 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -129,27 +129,26 @@ class Puppet::Interface::Action # @face.send(name, *args, &block) # end + + # We need to build an instance method as a wrapper, using normal code, to be + # able to expose argument defaulting between the caller and definer in the + # Ruby API. An extra method is, sadly, required for Ruby 1.8 to work since + # it doesn't expose bind on a block. + # + # Hopefully we can improve this when we finally shuffle off the last of Ruby + # 1.8 support, but that looks to be a few "enterprise" release eras away, so + # we are pretty stuck with this for now. + # + # Patches to make this work more nicely with Ruby 1.9 using runtime version + # checking and all are welcome, provided that they don't change anything + # outside this little ol' bit of code and all. + # + # Incidentally, we though about vendoring evil-ruby and actually adjusting + # the internal C structure implementation details under the hood to make + # this stuff work, because it would have been cleaner. Which gives you an + # idea how motivated we were to make this cleaner. Sorry. + # --daniel 2011-03-31 def when_invoked=(block) - # We need to build an instance method as a wrapper, using normal code, to - # be able to expose argument defaulting between the caller and definer in - # the Ruby API. An extra method is, sadly, required for Ruby 1.8 to work. - # - # In future this also gives us a place to hook in additional behaviour - # such as calling out to the action instance to validate and coerce - # parameters, which avoids any exciting context switching and all. - # - # Hopefully we can improve this when we finally shuffle off the last of - # Ruby 1.8 support, but that looks to be a few "enterprise" release eras - # away, so we are pretty stuck with this for now. - # - # Patches to make this work more nicely with Ruby 1.9 using runtime - # version checking and all are welcome, but they can't actually help if - # the results are not totally hidden away in here. - # - # Incidentally, we though about vendoring evil-ruby and actually adjusting - # the internal C structure implementation details under the hood to make - # this stuff work, because it would have been cleaner. Which gives you an - # idea how motivated we were to make this cleaner. Sorry. --daniel 2011-03-31 internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym file = __FILE__ + "+eval" -- cgit From 5d7ef5caf30a0c5b3253340c5f2722e51c56c75e Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 20:23:27 -0700 Subject: (#7062) better argument handling in the action wrapper methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We previously used *args to collect all arguments to the action when_invoked block, then tried vaguely to massage some little bits of them into the right shape. Methods defined with blocks, in Ruby 1.8, also have some fun behaviours. The most special is that if you pass more than one argument to a block defined with only one Ruby will automatically coerce the arguments into an array – and this is preserved when it is bound to a method. This led to routine situations where we would pass the wrong number of arguments to the block because, say, the user gave an extra argument on the command line. Instead of failing this would transmogrify the arguments in counterintuitive ways, and end up with horrible stack traces when that interacted badly with the code as written. Now, instead, we work out the right argument format based on the arguments that the when_invoked block takes. This gives much better (albeit perhaps not so user friendly) behaviour at the interface level. Which is, at least, consistent with other Ruby API. Reviewed-By: Max Martin --- lib/puppet/interface/action.rb | 38 ++++++++++++++++++++------ spec/unit/interface/action_spec.rb | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index e644d8999..08bc0a345 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -151,15 +151,37 @@ class Puppet::Interface::Action def when_invoked=(block) internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym - file = __FILE__ + "+eval" - line = __LINE__ + 1 + + arity = block.arity + if arity == 0 then + # This will never fire on 1.8.7, which treats no arguments as "*args", + # but will on 1.9.2, which treats it as "no arguments". Which bites, + # because this just begs for us to wind up in the horrible situation + # where a 1.8 vs 1.9 error bites our end users. --daniel 2011-04-19 + raise ArgumentError, "action when_invoked requires at least one argument (options)" + elsif arity > 0 then + range = Range.new(1, arity - 1) + decl = range.map { |x| "arg#{x}" } << "options = {}" + optn = "" + args = "[" + (range.map { |x| "arg#{x}" } << "options").join(", ") + "]" + else + range = Range.new(1, arity.abs - 1) + decl = range.map { |x| "arg#{x}" } << "*rest" + optn = "rest << {} unless rest.last.is_a?(Hash)" + if arity == -1 then + args = "rest" + else + args = "[" + range.map { |x| "arg#{x}" }.join(", ") + "] + rest" + end + end + + file = __FILE__ + "+eval[wrapper]" + line = __LINE__ + 2 # <== points to the same line as 'def' in the wrapper. wrapper = < Date: Tue, 19 Apr 2011 20:43:47 -0700 Subject: maint: remove redundant context from the test. We had a block of tests in a describe block inside a describe block; they were literally one hundred percent overlap. Eliminate that and just keep the outer. Reviewed-By: Max Martin --- spec/unit/application/face_base_spec.rb | 204 ++++++++++++++++---------------- 1 file changed, 101 insertions(+), 103 deletions(-) diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index 5403608cf..7dbe59fd7 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -40,126 +40,124 @@ describe Puppet::Application::FaceBase do app.command_line.stubs(:args).returns %w{} end - describe "parsing the command line" do - context "with just an action" do - before :all do - # We have to stub Signal.trap to avoid a crazy mess where we take - # over signal handling and make it impossible to cancel the test - # suite run. - # - # It would be nice to fix this elsewhere, but it is actually hard to - # capture this in rspec 2.5 and all. :( --daniel 2011-04-08 - Signal.stubs(:trap) - app.command_line.stubs(:args).returns %w{foo} - app.preinit - app.parse_options - end - - it "should set the face based on the type" do - app.face.name.should == :basetest - end - - it "should find the action" do - app.action.should be - app.action.name.should == :foo - end + context "with just an action" do + before :all do + # We have to stub Signal.trap to avoid a crazy mess where we take + # over signal handling and make it impossible to cancel the test + # suite run. + # + # It would be nice to fix this elsewhere, but it is actually hard to + # capture this in rspec 2.5 and all. :( --daniel 2011-04-08 + Signal.stubs(:trap) + app.command_line.stubs(:args).returns %w{foo} + app.preinit + app.parse_options end - it "should use the default action if not given any arguments" do - app.command_line.stubs(:args).returns [] - action = stub(:options => []) - Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) - app.stubs(:main) - app.run - app.action.should == action - app.arguments.should == [ { } ] + it "should set the face based on the type" do + app.face.name.should == :basetest end - it "should use the default action if not given a valid one" do - app.command_line.stubs(:args).returns %w{bar} - action = stub(:options => []) - Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) - app.stubs(:main) - app.run - app.action.should == action - app.arguments.should == [ 'bar', { } ] + it "should find the action" do + app.action.should be + app.action.name.should == :foo end + end - it "should have no action if not given a valid one and there is no default action" do - app.command_line.stubs(:args).returns %w{bar} - Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil) - app.stubs(:main) - app.run - app.action.should be_nil - app.arguments.should == [ 'bar', { } ] - end + it "should use the default action if not given any arguments" do + app.command_line.stubs(:args).returns [] + action = stub(:options => []) + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) + app.stubs(:main) + app.run + app.action.should == action + app.arguments.should == [ { } ] + end - it "should report a sensible error when options with = fail" do - app.command_line.stubs(:args).returns %w{--action=bar foo} - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::InvalidOption, /invalid option: --action/ - end + it "should use the default action if not given a valid one" do + app.command_line.stubs(:args).returns %w{bar} + action = stub(:options => []) + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) + app.stubs(:main) + app.run + app.action.should == action + app.arguments.should == [ 'bar', { } ] + end - it "should fail if an action option is before the action" do - app.command_line.stubs(:args).returns %w{--action foo} - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::InvalidOption, /invalid option: --action/ - end + it "should have no action if not given a valid one and there is no default action" do + app.command_line.stubs(:args).returns %w{bar} + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil) + app.stubs(:main) + app.run + app.action.should be_nil + app.arguments.should == [ 'bar', { } ] + end - it "should fail if an unknown option is before the action" do - app.command_line.stubs(:args).returns %w{--bar foo} - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::InvalidOption, /invalid option: --bar/ - end + it "should report a sensible error when options with = fail" do + app.command_line.stubs(:args).returns %w{--action=bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --action/ + end - it "should fail if an unknown option is after the action" do - app.command_line.stubs(:args).returns %w{foo --bar} - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::InvalidOption, /invalid option: --bar/ - end + it "should fail if an action option is before the action" do + app.command_line.stubs(:args).returns %w{--action foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --action/ + end + + it "should fail if an unknown option is before the action" do + app.command_line.stubs(:args).returns %w{--bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end + + it "should fail if an unknown option is after the action" do + app.command_line.stubs(:args).returns %w{foo --bar} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end + + it "should accept --bar as an argument to a mandatory option after action" do + app.command_line.stubs(:args).returns %w{foo --mandatory --bar} + app.preinit + app.parse_options + app.action.name.should == :foo + app.options.should == { :mandatory => "--bar" } + end + + it "should accept --bar as an argument to a mandatory option before action" do + app.command_line.stubs(:args).returns %w{--mandatory --bar foo} + app.preinit + app.parse_options + app.action.name.should == :foo + app.options.should == { :mandatory => "--bar" } + end + + it "should not skip when --foo=bar is given" do + app.command_line.stubs(:args).returns %w{--mandatory=bar --bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end - it "should accept --bar as an argument to a mandatory option after action" do - app.command_line.stubs(:args).returns %w{foo --mandatory --bar} + { "boolean options before" => %w{--trace foo}, + "boolean options after" => %w{foo --trace} + }.each do |name, args| + it "should accept global boolean settings #{name} the action" do + app.command_line.stubs(:args).returns args app.preinit app.parse_options - app.action.name.should == :foo - app.options.should == { :mandatory => "--bar" } + Puppet[:trace].should be_true end + end - it "should accept --bar as an argument to a mandatory option before action" do - app.command_line.stubs(:args).returns %w{--mandatory --bar foo} + { "before" => %w{--syslogfacility user1 foo}, + " after" => %w{foo --syslogfacility user1} + }.each do |name, args| + it "should accept global settings with arguments #{name} the action" do + app.command_line.stubs(:args).returns args app.preinit app.parse_options - app.action.name.should == :foo - app.options.should == { :mandatory => "--bar" } - end - - it "should not skip when --foo=bar is given" do - app.command_line.stubs(:args).returns %w{--mandatory=bar --bar foo} - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::InvalidOption, /invalid option: --bar/ - end - - { "boolean options before" => %w{--trace foo}, - "boolean options after" => %w{foo --trace} - }.each do |name, args| - it "should accept global boolean settings #{name} the action" do - app.command_line.stubs(:args).returns args - app.preinit - app.parse_options - Puppet[:trace].should be_true - end - end - - { "before" => %w{--syslogfacility user1 foo}, - " after" => %w{foo --syslogfacility user1} - }.each do |name, args| - it "should accept global settings with arguments #{name} the action" do - app.command_line.stubs(:args).returns args - app.preinit - app.parse_options - Puppet[:syslogfacility].should == "user1" - end + Puppet[:syslogfacility].should == "user1" end end end -- cgit From a1db58528f2baf7867202058d80e66f23fb447e0 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 20:52:52 -0700 Subject: maint: fix gratuitous whitespace in the code. We had some stray spacing between variables and the '=' sign from when there was another variable in place; it got deleted, but the code wasn't closed up. Reviewed-By: Max Martin --- lib/puppet/application/face_base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 9da48af55..fabe71896 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -92,8 +92,8 @@ class Puppet::Application::FaceBase < Puppet::Application # REVISIT: These should be configurable versions, through a global # '--version' option, but we don't implement that yet... --daniel 2011-03-29 - @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym - @face = Puppet::Face[@type, :current] + @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym + @face = Puppet::Face[@type, :current] # Now, walk the command line and identify the action. We skip over # arguments based on introspecting the action and all, and find the first -- cgit From 379b46d4b9e2a57f954ff178956ca6850c3c56f7 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 21:08:05 -0700 Subject: (#7116) Handle application-level options in parse_options We hid another layer of per-application option in the class backing the application, which wasn't correctly handled in the parse_options method. They are now found and handled, so that global flags like --debug work as expected on the left of the action, not just the right. Reviewed-By: Max Martin --- lib/puppet/application/face_base.rb | 17 +++++++++++++++++ spec/unit/application/face_base_spec.rb | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index fabe71896..7bebd18bb 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -122,6 +122,8 @@ class Puppet::Application::FaceBase < Puppet::Application # a mandatory argument. --daniel 2011-04-05 index += 1 # ...so skip the argument. end + elsif option = find_application_argument(item) then + index += 1 if (option[:argument] and option[:optional]) else raise OptionParser::InvalidOption.new(item.sub(/=.*$/, '')) end @@ -158,6 +160,21 @@ class Puppet::Application::FaceBase < Puppet::Application return nil # nothing found. end + def find_application_argument(item) + self.class.option_parser_commands.each do |options, function| + options.each do |option| + next unless option =~ /^-/ + pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/ + next unless pattern.match(item) + return { + :argument => option =~ /[ =]/, + :optional => option =~ /[ =]\[/ + } + end + end + return nil # not found + end + def setup Puppet::Util::Log.newdestination :console diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index 7dbe59fd7..f7c55c556 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -40,7 +40,7 @@ describe Puppet::Application::FaceBase do app.command_line.stubs(:args).returns %w{} end - context "with just an action" do + describe "with just an action" do before :all do # We have to stub Signal.trap to avoid a crazy mess where we take # over signal handling and make it impossible to cancel the test @@ -160,6 +160,13 @@ describe Puppet::Application::FaceBase do Puppet[:syslogfacility].should == "user1" end end + + it "should handle application-level options" do + app.command_line.stubs(:args).returns %w{help --verbose help} + app.preinit + app.parse_options + app.face.name.should == :basetest + end end describe "#setup" do -- cgit From 220f3086e0254fb681a8dfece5238d0dff861f6f Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Wed, 20 Apr 2011 14:54:48 -0700 Subject: Move tests from Puppet-acceptance repo --- .../ticket_4149_parseonly_should_not_fail.rb | 18 ++++ ...return_true_for_unrealized_virtual_resources.rb | 24 +++++ ...ionship_syntax_should_work_with_title_arrays.rb | 15 ++++ .../tests/apply/classes/parameterized_classes.rb | 56 ++++++++++++ .../apply/classes/should_allow_param_override.rb | 20 +++++ .../classes/should_allow_param_undef_override.rb | 29 ++++++ .../classes/should_include_resources_from_class.rb | 11 +++ ...should_not_auto_include_resources_from_class.rb | 6 ++ .../apply/conditionals/should_evaluate_else.rb | 15 ++++ .../apply/conditionals/should_evaluate_elsif.rb | 15 ++++ .../apply/conditionals/should_evaluate_empty.rb | 12 +++ .../apply/conditionals/should_evaluate_false.rb | 12 +++ .../tests/apply/conditionals/should_evaluate_if.rb | 15 ++++ .../conditionals/should_evaluate_strings_true.rb | 13 +++ .../apply/conditionals/should_evaluate_undef.rb | 11 +++ .../tests/apply/hashes/should_not_reassign.rb | 10 +++ acceptance/tests/apply/virtual/should_realize.rb | 22 +++++ .../apply/virtual/should_realize_complex_query.rb | 36 ++++++++ .../tests/apply/virtual/should_realize_many.rb | 22 +++++ .../tests/apply/virtual/should_realize_query.rb | 24 +++++ .../apply/virtual/should_realize_query_array.rb | 24 +++++ .../tests/doc/should_print_function_reference.rb | 5 ++ .../ticket_4120_cannot_generate_type_reference.rb | 5 ++ acceptance/tests/file_hello_world.rb | 22 +++++ acceptance/tests/jeff_append_to_array.rb | 19 ++++ .../tests/key_compare_puppet_conf_configprint.rb | 65 ++++++++++++++ ...file_should_create_a_file_and_report_the_md5.rb | 16 ++++ acceptance/tests/puppet_apply_basics.rb | 15 ++++ .../tests/puppet_apply_should_show_a_notice.rb | 5 ++ ...pet_master_help_should_mention_puppet_master.rb | 4 + .../tests/resource/cron/should_create_cron.rb | 31 +++++++ .../tests/resource/cron/should_match_existing.rb | 40 +++++++++ .../tests/resource/cron/should_remove_cron.rb | 36 ++++++++ .../tests/resource/cron/should_remove_matching.rb | 36 ++++++++ .../tests/resource/cron/should_update_existing.rb | 42 +++++++++ .../exec/should_not_run_command_creates.rb | 34 +++++++ .../tests/resource/exec/should_run_command.rb | 31 +++++++ acceptance/tests/resource/exec/should_set_path.rb | 16 ++++ .../tests/resource/file/content_attribute.rb | 37 ++++++++ .../tests/resource/file/should_create_directory.rb | 15 ++++ .../tests/resource/file/should_create_empty.rb | 15 ++++ .../tests/resource/file/should_create_symlink.rb | 27 ++++++ .../tests/resource/file/should_remove_dir.rb | 21 +++++ .../tests/resource/file/should_remove_file.rb | 12 +++ .../tests/resource/file/source_attribtute.rb | 100 +++++++++++++++++++++ acceptance/tests/resource/group/should_create.rb | 20 +++++ acceptance/tests/resource/group/should_destroy.rb | 14 +++ .../tests/resource/group/should_modify_gid.rb | 23 +++++ .../resource/group/should_not_create_existing.rb | 15 ++++ .../resource/group/should_not_destoy_unexisting.rb | 13 +++ acceptance/tests/resource/group/should_query.rb | 15 ++++ .../tests/resource/group/should_query_all.rb | 30 +++++++ acceptance/tests/resource/host/should_create.rb | 15 ++++ .../tests/resource/host/should_create_aliases.rb | 16 ++++ acceptance/tests/resource/host/should_destroy.rb | 19 ++++ .../tests/resource/host/should_modify_alias.rb | 19 ++++ acceptance/tests/resource/host/should_modify_ip.rb | 19 ++++ .../resource/host/should_not_create_existing.rb | 17 ++++ acceptance/tests/resource/host/should_query.rb | 15 ++++ acceptance/tests/resource/host/should_query_all.rb | 26 ++++++ .../ticket_4131_should_not_create_without_ip.rb | 21 +++++ .../ticket_4123_should_list_all_running_redhat.rb | 12 +++ .../ticket_4123_should_list_all_running_redhat.sh | 36 ++++++++ .../ticket_4124_should_list_all_disabled.rb | 12 +++ .../ticket_4124_should_list_all_disabled.sh | 37 ++++++++ acceptance/tests/resource/user/should_create.rb | 20 +++++ .../tests/resource/user/should_create_with_gid.rb | 30 +++++++ acceptance/tests/resource/user/should_destroy.rb | 19 ++++ .../tests/resource/user/should_modify_gid.rb | 41 +++++++++ .../resource/user/should_not_create_existing.rb | 6 ++ .../resource/user/should_not_destoy_unexisting.rb | 11 +++ acceptance/tests/resource/user/should_query.rb | 15 ++++ acceptance/tests/resource/user/should_query_all.rb | 30 +++++++ ...ppet_kick_with_hostnames_on_the_command_line.rb | 7 ++ ...ket_3360_allow_duplicate_csr_with_option_set.rb | 50 +++++++++++ .../ticket_3656_requiring_multiple_resources.rb | 8 ++ .../ticket_3961_puppet_ca_should_produce_certs.rb | 29 ++++++ .../tests/ticket_4059_ralsh_can_change_settings.rb | 20 +++++ ...should_not_create_a_user_that_already_exists.rb | 5 ++ .../tests/ticket_4233_resource_with_a_newline.rb | 13 +++ ...ource_fail_when_name_defined_instead_of_path.rb | 17 ++++ ...h_when_function_call_used_in_an_if_statement.rb | 13 +++ ..._should_recognize_OEL_operatingsystemrelease.rb | 21 +++++ ..._4293_define_and_use_a_define_within_a_class.rb | 22 +++++ ...llow_stage_main_on_left_side_of_relationship.rb | 21 +++++ ...423_cannot_declare_two_parameterized_classes.rb | 50 +++++++++++ .../tests/ticket_5027_warn_on_dynamic_scope.rb | 28 ++++++ .../tests/ticket_5477_master_not_dectect_sitepp.rb | 43 +++++++++ .../tests/ticket_6418_file_recursion_and_audit.rb | 22 +++++ .../tests/ticket_6541_invalid_filebucket_files.rb | 26 ++++++ acceptance/tests/ticket_6734_6256_5530_5503.rb | 16 ++++ .../tests/ticket_6928_puppet_master_parse_fails.rb | 38 ++++++++ 92 files changed, 2074 insertions(+) create mode 100644 acceptance/pending/ticket_4149_parseonly_should_not_fail.rb create mode 100644 acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb create mode 100644 acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb create mode 100755 acceptance/tests/apply/classes/parameterized_classes.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_override.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_undef_override.rb create mode 100755 acceptance/tests/apply/classes/should_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_else.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_elsif.rb create mode 100644 acceptance/tests/apply/conditionals/should_evaluate_empty.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_false.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_if.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_undef.rb create mode 100755 acceptance/tests/apply/hashes/should_not_reassign.rb create mode 100755 acceptance/tests/apply/virtual/should_realize.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_complex_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_many.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query_array.rb create mode 100644 acceptance/tests/doc/should_print_function_reference.rb create mode 100755 acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb create mode 100644 acceptance/tests/file_hello_world.rb create mode 100644 acceptance/tests/jeff_append_to_array.rb create mode 100644 acceptance/tests/key_compare_puppet_conf_configprint.rb create mode 100644 acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb create mode 100644 acceptance/tests/puppet_apply_basics.rb create mode 100644 acceptance/tests/puppet_apply_should_show_a_notice.rb create mode 100644 acceptance/tests/puppet_master_help_should_mention_puppet_master.rb create mode 100644 acceptance/tests/resource/cron/should_create_cron.rb create mode 100755 acceptance/tests/resource/cron/should_match_existing.rb create mode 100755 acceptance/tests/resource/cron/should_remove_cron.rb create mode 100755 acceptance/tests/resource/cron/should_remove_matching.rb create mode 100755 acceptance/tests/resource/cron/should_update_existing.rb create mode 100644 acceptance/tests/resource/exec/should_not_run_command_creates.rb create mode 100644 acceptance/tests/resource/exec/should_run_command.rb create mode 100644 acceptance/tests/resource/exec/should_set_path.rb create mode 100644 acceptance/tests/resource/file/content_attribute.rb create mode 100755 acceptance/tests/resource/file/should_create_directory.rb create mode 100755 acceptance/tests/resource/file/should_create_empty.rb create mode 100755 acceptance/tests/resource/file/should_create_symlink.rb create mode 100755 acceptance/tests/resource/file/should_remove_dir.rb create mode 100755 acceptance/tests/resource/file/should_remove_file.rb create mode 100644 acceptance/tests/resource/file/source_attribtute.rb create mode 100755 acceptance/tests/resource/group/should_create.rb create mode 100755 acceptance/tests/resource/group/should_destroy.rb create mode 100755 acceptance/tests/resource/group/should_modify_gid.rb create mode 100755 acceptance/tests/resource/group/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/group/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/group/should_query.rb create mode 100755 acceptance/tests/resource/group/should_query_all.rb create mode 100755 acceptance/tests/resource/host/should_create.rb create mode 100755 acceptance/tests/resource/host/should_create_aliases.rb create mode 100755 acceptance/tests/resource/host/should_destroy.rb create mode 100755 acceptance/tests/resource/host/should_modify_alias.rb create mode 100755 acceptance/tests/resource/host/should_modify_ip.rb create mode 100755 acceptance/tests/resource/host/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/host/should_query.rb create mode 100755 acceptance/tests/resource/host/should_query_all.rb create mode 100755 acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh create mode 100755 acceptance/tests/resource/user/should_create.rb create mode 100755 acceptance/tests/resource/user/should_create_with_gid.rb create mode 100755 acceptance/tests/resource/user/should_destroy.rb create mode 100755 acceptance/tests/resource/user/should_modify_gid.rb create mode 100755 acceptance/tests/resource/user/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/user/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/user/should_query.rb create mode 100755 acceptance/tests/resource/user/should_query_all.rb create mode 100644 acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb create mode 100644 acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb create mode 100644 acceptance/tests/ticket_3656_requiring_multiple_resources.rb create mode 100644 acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb create mode 100644 acceptance/tests/ticket_4059_ralsh_can_change_settings.rb create mode 100644 acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb create mode 100644 acceptance/tests/ticket_4233_resource_with_a_newline.rb create mode 100644 acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb create mode 100644 acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb create mode 100644 acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb create mode 100644 acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb create mode 100644 acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb create mode 100644 acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb create mode 100644 acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb create mode 100644 acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb create mode 100644 acceptance/tests/ticket_6418_file_recursion_and_audit.rb create mode 100644 acceptance/tests/ticket_6541_invalid_filebucket_files.rb create mode 100644 acceptance/tests/ticket_6734_6256_5530_5503.rb create mode 100644 acceptance/tests/ticket_6928_puppet_master_parse_fails.rb diff --git a/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb b/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb new file mode 100644 index 000000000..228dec307 --- /dev/null +++ b/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb @@ -0,0 +1,18 @@ +test_name "#4149: parseonly should do the right thing" + +step "test with a manifest with syntax errors" +manifest = 'class someclass { notify { "hello, world" } }' +apply_manifest_on(agents, manifest, :parseonly => true, :acceptable_exit_codes => [1]) { + stdout =~ /Could not parse for .*: Syntax error/ or + fail_test("didn't get a reported systax error") +} + +step "test with a manifest with correct syntax" +apply_manifest_on agents,'class someclass { notify("hello, world") }', :parseonly => true + +# REVISIT: This tests the current behaviour, which is IMO not actually the +# correct behaviour. On the other hand, if we change this we might +# unexpectedly break things out in the wild, so better to be warned than to be +# surprised by it. --daniel 2010-12-22 +step "test with a class with an invalid attribute" +apply_manifest_on agents, 'file { "/tmp/whatever": fooble => 1 }', :parseonly => true diff --git a/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb b/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb new file mode 100644 index 000000000..2da392a62 --- /dev/null +++ b/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb @@ -0,0 +1,24 @@ +test_name "#4151: defined function should not return true for unrealized virtual resources" + +# Jeff McCune +# 2010-07-06 +# +# This script is expected to exit non-zero if ticket 4151 has not been +# fixed. +# +# The expected behavior is for defined() to only return true if a virtual +# resource has been realized. +# +# This test creates a virtual resource, does NOT realize it, then calls +# the defined() function against it. If defined returns true, there will +# be an error since Notify["goodbye"] will require a resource which has +# not been realized. + + +manifest1 = %q{ + @notify { "hello": } + if (defined(Notify["hello"])) { $requires = [ Notify["hello"] ] } + notify { "goodbye": require => $requires } +} + +apply_manifest_on(agents, manifest1) diff --git a/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb b/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb new file mode 100644 index 000000000..60da19e45 --- /dev/null +++ b/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb @@ -0,0 +1,15 @@ +test_name "#6710: Relationship syntax should work with title arraysA" + +# Jeff McCune +# 2011-03-14 +# +# If bug 6710 is closed, then this manifests should apply cleanly. +# There should be a many-to-many relationship established. +# + +apply_manifest_on agents, %q{ + notify { [ left_one, left_two ]: } -> notify { [ right_one, right_two ]: } + notify { left: } -> notify { right: } + notify { left_one_to_many: } -> notify { [ right_one_to_many_1, right_one_to_many_2 ]: } +} + diff --git a/acceptance/tests/apply/classes/parameterized_classes.rb b/acceptance/tests/apply/classes/parameterized_classes.rb new file mode 100755 index 000000000..9a7029425 --- /dev/null +++ b/acceptance/tests/apply/classes/parameterized_classes.rb @@ -0,0 +1,56 @@ +test_name "parametrized classes" + +######################################################################## +step "should allow param classes" +manifest = %q{ +class x($y, $z) { + notice("${y}-${z}") +} +class {x: y => '1', z => '2'} +} + +apply_manifest_on(agents, manifest) do + fail_test "inclusion after parameterization failed" unless stdout.include? "1-2" +end + +######################################################################## +# REVISIT: This was ported from the old set of tests, but I think that +# the desired behaviour has recently changed. --daniel 2010-12-23 +step "should allow param class post inclusion" +manifest = %q{ +class x($y, $z) { + notice("${y}-${z}") +} +class {x: y => '1', z => '2'} +include x +} + +apply_manifest_on(agents, manifest) do + fail_test "inclusion after parameterization failed" unless stdout.include? "1-2" +end + +######################################################################## +step "should allow param classes defaults" +manifest = %q{ +class x($y, $z='2') { + notice("${y}-${z}") +} +class {x: y => '1'} +} + +apply_manifest_on(agents, manifest) do + fail_test "the default didn't apply as expected" unless stdout.include? "1-2" +end + +######################################################################## +step "should allow param class defaults to be overriden" +manifest = %q{ +class x($y, $z='2') { + notice("${y}-${z}") +} +class {x: y => '1', z => '3'} +} + +apply_manifest_on(agents, manifest) do + fail_test "the override didn't happen as we expected" unless stdout.include? "1-3" +end diff --git a/acceptance/tests/apply/classes/should_allow_param_override.rb b/acceptance/tests/apply/classes/should_allow_param_override.rb new file mode 100755 index 000000000..09592ec8b --- /dev/null +++ b/acceptance/tests/apply/classes/should_allow_param_override.rb @@ -0,0 +1,20 @@ +test_name "should allow param override" + +manifest = %q{ +class parent { + notify { 'msg': + message => parent, + } +} +class child inherits parent { + Notify['msg'] {message => 'child'} +} +include parent +include child +} + +apply_manifest_on(agents, manifest) do + fail_test "parameter override didn't work" unless + stdout.include? "defined 'message' as 'child'" +end + diff --git a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb new file mode 100755 index 000000000..a4f37cba1 --- /dev/null +++ b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb @@ -0,0 +1,29 @@ +test_name "should allow overriding a parameter to undef in inheritence" + +out = "/tmp/class_undef_override_out-#{$$}" +manifest = %Q{ + class parent { + file { 'test': + path => '#{out}', + source => '/tmp/class_undef_override_test-#{$$}', + } + } + class child inherits parent { + File['test'] { + source => undef, + content => 'hello new world!', + } + } + include parent + include child +} + +step "prepare the target file on all systems" +on(agents, "echo 'hello world!' > #{out}") +step "apply the manifest" +apply_manifest_on(agents, manifest) +step "verify the file content" +on(agents, "cat #{out}") do + fail_test "the file was not touched" if stdout.include? "hello world!" + fail_test "the file was not updated" unless stdout.include? "hello new world" +end diff --git a/acceptance/tests/apply/classes/should_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_include_resources_from_class.rb new file mode 100755 index 000000000..b78be6cec --- /dev/null +++ b/acceptance/tests/apply/classes/should_include_resources_from_class.rb @@ -0,0 +1,11 @@ +test_name "resources declared in a class can be applied with include" +manifest = %q{ +class x { + notify{'a':} +} +include x +} +apply_manifest_on(agents, manifest) do + fail_test "the resource did not apply" unless + stdout.include? "defined 'message' as 'a'" +end diff --git a/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb new file mode 100755 index 000000000..25721eb4c --- /dev/null +++ b/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb @@ -0,0 +1,6 @@ +test_name "resources declared in classes are not applied without include" +manifest = %q{ class x { notify { 'test': message => 'never invoked' } } } +apply_manifest_on(agents, manifest) do + fail_test "found the notify despite not including it" if + stdout.include? "never invoked" +end diff --git a/acceptance/tests/apply/conditionals/should_evaluate_else.rb b/acceptance/tests/apply/conditionals/should_evaluate_else.rb new file mode 100755 index 000000000..7bdceb1d1 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_else.rb @@ -0,0 +1,15 @@ +test_name "else clause will be reached if no expressions match" +manifest = %q{ +if( 1 == 2) { + notice('if') +} elsif(2 == 3) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "the else clause did not evaluate" unless stdout.include? 'else' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb b/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb new file mode 100755 index 000000000..027e247c9 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb @@ -0,0 +1,15 @@ +test_name "should evaluate the elsif block in a conditional" +manifest = %q{ +if( 1 == 3) { + notice('if') +} elsif(2 == 2) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate elsif" unless stdout.include? 'elsif' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_empty.rb b/acceptance/tests/apply/conditionals/should_evaluate_empty.rb new file mode 100644 index 000000000..85b0792b4 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_empty.rb @@ -0,0 +1,12 @@ +test_name "ensure that undefined variables evaluate as false" +manifest = %q{ +if $undef_var { +} else { + notice('undef') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "did not evaluate as expected" unless stdout.include? 'undef' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_false.rb b/acceptance/tests/apply/conditionals/should_evaluate_false.rb new file mode 100755 index 000000000..9a64e1663 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_false.rb @@ -0,0 +1,12 @@ +test_name "test that false evaluates to false" +manifest = %q{ +if false { +} else { + notice('false') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate false correcly" unless stdout.include? 'false' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_if.rb b/acceptance/tests/apply/conditionals/should_evaluate_if.rb new file mode 100755 index 000000000..d0113e518 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_if.rb @@ -0,0 +1,15 @@ +test_name = "should evaluate an if block correctly" +manifest = %q{ +if( 1 == 1) { + notice('if') +} elsif(2 == 2) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate correctly" unless stdout.include? 'if' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb b/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb new file mode 100755 index 000000000..14b753085 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb @@ -0,0 +1,13 @@ +test_name "test that the string 'false' evaluates to true" +manifest = %q{ +if 'false' { + notice('true') +} else { + notice('false') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "string 'false' didn't evaluate as true" unless + stdout.include? 'true' +end diff --git a/acceptance/tests/apply/conditionals/should_evaluate_undef.rb b/acceptance/tests/apply/conditionals/should_evaluate_undef.rb new file mode 100755 index 000000000..ba5d6403e --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_undef.rb @@ -0,0 +1,11 @@ +test_name "empty string should evaluate as false" +manifest = %q{ +if '' { +} else { + notice('empty') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate as false" unless stdout.include? 'empty' +end diff --git a/acceptance/tests/apply/hashes/should_not_reassign.rb b/acceptance/tests/apply/hashes/should_not_reassign.rb new file mode 100755 index 000000000..2b0f9cc13 --- /dev/null +++ b/acceptance/tests/apply/hashes/should_not_reassign.rb @@ -0,0 +1,10 @@ +test_name "hash reassignment should fail" +manifest = %q{ +$my_hash = {'one' => '1', 'two' => '2' } +$my_hash['one']='1.5' +} + +apply_manifest_on(agents, manifest, :acceptable_exit_codes => [1]) do + fail_test "didn't find the failure" unless + stderr.include? "Assigning to the hash 'my_hash' with an existing key 'one'" +end diff --git a/acceptance/tests/apply/virtual/should_realize.rb b/acceptance/tests/apply/virtual/should_realize.rb new file mode 100755 index 000000000..fd32ad859 --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize.rb @@ -0,0 +1,22 @@ +test_name "should realize" +out = "/tmp/hosts-#{Time.new.to_i}" +name = "test-#{Time.new.to_i}-host" + +manifest = %Q{ + @host{'#{name}': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} + realize(Host['#{name}']) +} + +step "clean the system ready for testing" +on agents, "rm -f #{out}" + +step "realize the resource on the hosts" +apply_manifest_on agents, manifest + +step "verify the content of the file" +on(agents, "cat #{out}") do + fail_test "missing host definition" unless stdout.include? name +end + +step "final cleanup of the system" +on agents, "rm -f #{out}" diff --git a/acceptance/tests/apply/virtual/should_realize_complex_query.rb b/acceptance/tests/apply/virtual/should_realize_complex_query.rb new file mode 100755 index 000000000..9782bbfac --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_complex_query.rb @@ -0,0 +1,36 @@ +test_name "should realize with complex query" +out = "/tmp/hosts-#{Time.new.to_i}" +name = "test-#{Time.new.to_i}-host" + +manifest = %Q{ + @host { '#{name}1': + ip => '127.0.0.2', + target => '#{out}', + host_aliases => ['one', 'two', 'three'], + ensure => present, + } + @host { '#{name}2': + ip => '127.0.0.3', + target => '#{out}', + host_aliases => 'two', + ensure => present, + } + Host<| host_aliases == 'two' and ip == '127.0.0.3' |> +} + +step "clean up target system for test" +on agents, "rm -f #{out}" + +step "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "second host not found in output" unless + stdout.include? "#{name}2" + fail_test "first host was found in output" if + stdout.include? "#{name}1" +end + +step "clean up system after testing" +on agents, "rm -f #{out}" diff --git a/acceptance/tests/apply/virtual/should_realize_many.rb b/acceptance/tests/apply/virtual/should_realize_many.rb new file mode 100755 index 000000000..8f53caefe --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_many.rb @@ -0,0 +1,22 @@ +test_name "test that realize function takes a list" +out = "/tmp/hosts-#{Time.new.to_i}" +name = "test-#{Time.new.to_i}-host" + +manifest = %Q{ + @host{'#{name}1': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} + @host{'#{name}2': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} + realize(Host['#{name}1'], Host['#{name}2']) +} + + +step "clean up target system for test" +on agents, "rm -f #{out}" + +step "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "first host not found in output" unless stdout.include? "#{name}1" + fail_test "second host not found in output" unless stdout.include? "#{name}2" +end diff --git a/acceptance/tests/apply/virtual/should_realize_query.rb b/acceptance/tests/apply/virtual/should_realize_query.rb new file mode 100755 index 000000000..24d323373 --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_query.rb @@ -0,0 +1,24 @@ +test_name "should realize query" +out = "/tmp/hosts-#{Time.new.to_i}" +name = "test-#{Time.new.to_i}-host" + +manifest = %Q{ + @host { '#{name}': + ip => '127.0.0.2', + target => '#{out}', + host_aliases => 'alias', + ensure => present, + } + Host<| ip == '127.0.0.2' |> +} + +step "clean up target system for test" +on agents, "rm -f #{out}" + +step "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "host not found in output" unless stdout.include? name +end diff --git a/acceptance/tests/apply/virtual/should_realize_query_array.rb b/acceptance/tests/apply/virtual/should_realize_query_array.rb new file mode 100755 index 000000000..137d93b1a --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_query_array.rb @@ -0,0 +1,24 @@ +test_name "should realize query array" +out = "/tmp/hosts-#{Time.new.to_i}" +name = "test-#{Time.new.to_i}-host" + +manifest = %Q{ + @host { '#{name}': + ip => '127.0.0.2', + target => '#{out}', + host_aliases => ['one', 'two', 'three'], + ensure => present, + } + Host<| host_aliases == 'two' |> +} + +step "clean up target system for test" +on agents, "rm -f #{out}" + +step "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "host not found in output" unless stdout.include? name +end diff --git a/acceptance/tests/doc/should_print_function_reference.rb b/acceptance/tests/doc/should_print_function_reference.rb new file mode 100644 index 000000000..3ffcf8097 --- /dev/null +++ b/acceptance/tests/doc/should_print_function_reference.rb @@ -0,0 +1,5 @@ +test_name "verify we can print the function reference" +on(agents, puppet_doc("-r", "function")) do + fail_test "didn't print function reference" unless + stdout.include? 'Function Reference' +end diff --git a/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb b/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb new file mode 100755 index 000000000..7f721c272 --- /dev/null +++ b/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb @@ -0,0 +1,5 @@ +test_name "verify we can print the function reference" +on(agents, puppet_doc("-r", "type")) do + fail_test "didn't print type reference" unless + stdout.include? 'Type Reference' +end diff --git a/acceptance/tests/file_hello_world.rb b/acceptance/tests/file_hello_world.rb new file mode 100644 index 000000000..683ff4672 --- /dev/null +++ b/acceptance/tests/file_hello_world.rb @@ -0,0 +1,22 @@ +# Verify that a trivial manifest can be run to completion. + +filename = "/tmp/hello-world.txt" +content = "Hello, World" +manifest = "file { '#{filename}': content => '#{content}' }" + +test_name "The challenging 'Hello, World' manifest" + +step "ensure we are clean before testing..." +on agents, "rm -f #{filename}" + +step "run the manifest itself" +apply_manifest_on(agents, manifest) do + fail_test "the expected notice of action was missing" unless + stdout.index 'File[/tmp/hello-world.txt]/ensure: defined content as' +end + +step "verify the content of the generated files." +on agents, "grep '#{content}' #{filename}" + +step "clean up after our test run." +on agents, "rm -f #{filename}" diff --git a/acceptance/tests/jeff_append_to_array.rb b/acceptance/tests/jeff_append_to_array.rb new file mode 100644 index 000000000..415d59fe8 --- /dev/null +++ b/acceptance/tests/jeff_append_to_array.rb @@ -0,0 +1,19 @@ +# Ported from the acceptance test suite. +test_name "Jeff: Append to Array" + +manifest = %q{ + class parent { + $arr1 = [ "parent array element" ] + } + class parent::child inherits parent { + $arr1 += [ "child array element" ] + notify { $arr1: } + } + include parent::child +} + +apply_manifest_on(agents, manifest) do + stdout =~ /notice: parent array element/ or fail_test("parent missing") + stdout =~ /notice: child array element/ or fail_test("child missing") +end + diff --git a/acceptance/tests/key_compare_puppet_conf_configprint.rb b/acceptance/tests/key_compare_puppet_conf_configprint.rb new file mode 100644 index 000000000..b986d8831 --- /dev/null +++ b/acceptance/tests/key_compare_puppet_conf_configprint.rb @@ -0,0 +1,65 @@ +# Check for the existance of keys found in puppet.conf in +# --configprint all output +# +# Checking against key=>val pairs will cause erroneous errors: +# +# classfile +# Puppet.conf --configprint +# $vardir/classes.txt /var/opt/lib/pe-puppet/classes.txt + +test_name "Validate keys found in puppet.conf vs.--configprint all" + +puppet_conf_h = Hash.new +config_print_h = Hash.new + +# Run tests against Master first +step "Master: get puppet.conf file contents" +on master, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + puppet_conf_h[k]=v + end +end + +step "Master: get --configprint all output" +on master, puppet_master("--configprint all | tr -d \" \"") do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + config_print_h[k]=v + end +end + +step "Master: compare puppet.conf to --configprint output" +puppet_conf_h.each do |k,v| + puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}" + fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k) + # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] ) +end + +# Run test on Agents +agents.each { |agent| + puppet_conf_h.clear + config_print_h.clear + step "Agent #{agent}: get puppet.conf file contents" + on agent, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + puppet_conf_h[k]=v + end + end + + step "Agent #{agent}: get --configprint all output" + on agent, puppet_agent("--configprint all | tr -d \" \"") do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + config_print_h[k]=v + end + end + + step "Agent #{agent}: compare puppet.conf to --configprint output" + puppet_conf_h.each do |k,v| + puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}" + fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k) + # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] ) + end +} diff --git a/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb b/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb new file mode 100644 index 000000000..abb06fbaf --- /dev/null +++ b/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb @@ -0,0 +1,16 @@ +test_name "puppet apply should create a file and report an MD5" + +file = "/tmp/hello.world.#{Time.new.to_i}.txt" +manifest = "file{'#{file}': content => 'test'}" + +step "clean up #{file} for testing" +on agents, "rm -f #{file}" + +step "run the manifest and verify MD5 was printed" +apply_manifest_on(agents, manifest) do + fail_test "didn't find the content MD5 on output" unless + stdout.include? "defined content as '{md5}098f6bcd4621d373cade4e832627b4f6'" +end + +step "clean up #{file} after testing" +on agents, "rm -f #{file}" diff --git a/acceptance/tests/puppet_apply_basics.rb b/acceptance/tests/puppet_apply_basics.rb new file mode 100644 index 000000000..bbbdefc15 --- /dev/null +++ b/acceptance/tests/puppet_apply_basics.rb @@ -0,0 +1,15 @@ +# Ported from a collection of small spec tests in acceptance. +# +# Unified into a single file because they are literally one-line tests! + +test_name "Trivial puppet tests" + +step "check that puppet apply displays notices" +apply_manifest_on(agents, "notice 'Hello World'") do + stdout =~ /notice:.*Hello World/ or fail_test("missing notice!") +end + +step "verify help displays something for puppet master" +on master, puppet_master("--help") do + stdout =~ /puppet master/ or fail_test("improper help output") +end diff --git a/acceptance/tests/puppet_apply_should_show_a_notice.rb b/acceptance/tests/puppet_apply_should_show_a_notice.rb new file mode 100644 index 000000000..af6f41ca7 --- /dev/null +++ b/acceptance/tests/puppet_apply_should_show_a_notice.rb @@ -0,0 +1,5 @@ +test_name "puppet apply should show a notice" +apply_manifest_on(agents, "notice 'Hello World'") do + fail_test "the notice didn't show" unless + stdout =~ /notice: .*: Hello World/ +end diff --git a/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb b/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb new file mode 100644 index 000000000..ba7b39cb0 --- /dev/null +++ b/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb @@ -0,0 +1,4 @@ +test_name "puppet master help should mention puppet master" +on master, puppet_master('--help') do + fail_test "puppet master wasn't mentioned" unless stdout.include? 'puppet master' +end diff --git a/acceptance/tests/resource/cron/should_create_cron.rb b/acceptance/tests/resource/cron/should_create_cron.rb new file mode 100644 index 000000000..e45561491 --- /dev/null +++ b/acceptance/tests/resource/cron/should_create_cron.rb @@ -0,0 +1,31 @@ +test_name "should create cron" + +tmpuser = "cron-test-#{Time.new.to_i}" +tmpfile = "/tmp/cron-test-#{Time.new.to_i}" + +create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" +delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "apply the resource on the host using puppet resource" + on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", + "command=/bin/true", "ensure=present")) do + fail_test "didn't notice creation of the cron stuff" unless + stdout.include? 'created' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't find the command as expected" unless + stdout.include? "* * * * * /bin/true" + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{tmpuser}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/cron/should_match_existing.rb b/acceptance/tests/resource/cron/should_match_existing.rb new file mode 100755 index 000000000..b34a0498c --- /dev/null +++ b/acceptance/tests/resource/cron/should_match_existing.rb @@ -0,0 +1,40 @@ + + +tmpuser = "cron-test-#{Time.new.to_i}" +tmpfile = "/tmp/cron-test-#{Time.new.to_i}" + +create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" +delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "echo '* * * * * /bin/true' | crontab -u #{tmpuser} -" + + step "apply the resource on the host using puppet resource" + on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", + "command=/bin/true", "ensure=present")) do + # REVISIT: This is ported from the original test, which seems to me a + # weak test, but I don't want to improve it now. --daniel 2010-12-23 + # + # This is a weak/fragile test. The output has changed + # causing this test to fail erronously. Changed to the correct + # output to match, but this code should be re-feactored. + fail_test "didn't see the output we expected..." unless + stdout.include? 'present' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't find the command as expected" unless + stdout.include? "* * * * * /bin/true" + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{tmpuser}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/cron/should_remove_cron.rb b/acceptance/tests/resource/cron/should_remove_cron.rb new file mode 100755 index 000000000..035a0f7b9 --- /dev/null +++ b/acceptance/tests/resource/cron/should_remove_cron.rb @@ -0,0 +1,36 @@ +test_name "puppet should remove a crontab entry as expected" + +tmpuser = "cron-test-#{Time.new.to_i}" +tmpfile = "/tmp/cron-test-#{Time.new.to_i}" + +create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" +delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "printf '# Puppet Name: crontest\n* * * * * /bin/true\n' | crontab -u #{tmpuser} -" + + step "apply the resource on the host using puppet resource" + on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", + "command=/bin/true", "ensure=absent")) do + # REVISIT: This is ported from the original test, which seems to me a + # weak test, but I don't want to improve it now. --daniel 2010-12-23 + fail_test "didn't see the output we expected..." unless + stdout.include? 'removed' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't found the command we tried to remove" if + stdout.include? "/bin/true" + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{tmpuser}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/cron/should_remove_matching.rb b/acceptance/tests/resource/cron/should_remove_matching.rb new file mode 100755 index 000000000..e669f2959 --- /dev/null +++ b/acceptance/tests/resource/cron/should_remove_matching.rb @@ -0,0 +1,36 @@ +test_name "puppet should remove a crontab entry based on command matching" + +tmpuser = "cron-test-#{Time.new.to_i}" +tmpfile = "/tmp/cron-test-#{Time.new.to_i}" + +cron = '# Puppet Name: crontest\n* * * * * /bin/true\n1 1 1 1 1 /bin/true\n' + +create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" +delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "printf '#{cron}' | crontab -u #{tmpuser} -" + + step "apply the resource change on the host" + on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}", + "command=/bin/true", "ensure=absent")) do + fail_test "didn't see the output we expected..." unless + stdout.include? 'removed' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + count = stdout.scan("/bin/true").length + fail_test "found /bin/true the wrong number of times (#{count})" unless count == 1 + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{tmpuser}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/cron/should_update_existing.rb b/acceptance/tests/resource/cron/should_update_existing.rb new file mode 100755 index 000000000..3a2a53769 --- /dev/null +++ b/acceptance/tests/resource/cron/should_update_existing.rb @@ -0,0 +1,42 @@ +test_name "puppet should update existing crontab entry" + +tmpuser = "cron-test-#{Time.new.to_i}" +tmpfile = "/tmp/cron-test-#{Time.new.to_i}" + +cron = '# Puppet Name: crontest\n* * * * * /bin/true\n' + +create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" +delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "printf '#{cron}' | crontab -u #{tmpuser} -" + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't find the content in the crontab" unless + stdout.include? '* * * * * /bin/true' + end + + step "apply the resource change on the host" + on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", + "command=/bin/true", "ensure=present", "hour='0-6'")) do + fail_test "didn't update the time as expected" unless + stdout.include? "defined 'hour' as '0-6'" + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't find the content in the crontab" unless + stdout.include? '* 0-6 * * * /bin/true' + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{tmpuser}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/exec/should_not_run_command_creates.rb b/acceptance/tests/resource/exec/should_not_run_command_creates.rb new file mode 100644 index 000000000..583ae4306 --- /dev/null +++ b/acceptance/tests/resource/exec/should_not_run_command_creates.rb @@ -0,0 +1,34 @@ +test_name "should not run command creates" + +touch = "/tmp/touched-#{Time.new.to_i}" +donottouch = "/tmp/not-touched-#{Time.new.to_i}" + +manifest = %Q{ + exec { "test#{Time.new.to_i}": command => '/bin/touch #{donottouch}', creates => "#{touch}"} +} + +step "prepare the agents for the test" +on agents, "touch #{touch} ; rm -f #{donottouch}" + +step "test using puppet apply" +apply_manifest_on(agents, manifest) do + fail_test "looks like the thing executed, which it shouldn't" if + stdout.include? 'executed successfully' +end + +step "verify the file didn't get created" +on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1] + +step "prepare the agents for the second part of the test" +on agents, "touch #{touch} ; rm -f #{donottouch}" + +step "test using puppet resource" +on(agents, puppet_resource('exec', "test#{Time.new.to_i}", + "command='/bin/touch #{donottouch}'", + "creates='#{touch}'")) do + fail_test "looks like the thing executed, which it shouldn't" if + stdout.include? 'executed successfully' +end + +step "verify the file didn't get created the second time" +on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1] diff --git a/acceptance/tests/resource/exec/should_run_command.rb b/acceptance/tests/resource/exec/should_run_command.rb new file mode 100644 index 000000000..b7156c6c9 --- /dev/null +++ b/acceptance/tests/resource/exec/should_run_command.rb @@ -0,0 +1,31 @@ +test_name "tests that puppet correctly runs an exec." +# original author: Dan Bode --daniel 2010-12-23 + +$touch = "/tmp/test-exec-#{Time.new.to_i}" + +def before + step "file to be touched should not exist." + on agents, "rm -f #{$touch}" +end + +def after + step "checking the output worked" + on agents, "test -f #{$touch}" + + step "clean up the system" + on agents, "rm -f #{$touch}" +end + +before +apply_manifest_on(agents, "exec {'test': command=>'/bin/touch #{$touch}'}") do + fail_test "didn't seem to run the command" unless + stdout.include? 'executed successfully' +end +after + +before +on(agents, puppet_resource('-d', 'exec', 'test', "command='/bin/touch #{$touch}'")) do + fail_test "didn't seem to run the command" unless + stdout.include? 'executed successfully' +end +after diff --git a/acceptance/tests/resource/exec/should_set_path.rb b/acceptance/tests/resource/exec/should_set_path.rb new file mode 100644 index 000000000..4d9ccb060 --- /dev/null +++ b/acceptance/tests/resource/exec/should_set_path.rb @@ -0,0 +1,16 @@ +test_name "the path statement should work to locate commands" + +file = "/tmp/touched-should-set-path-#{Time.new.to_i}" + +step "clean up the system for the test" +on agents, "rm -f #{file}" + +step "invoke the exec resource with a path set" +on(agents, puppet_resource('exec', 'test', + "command='touch #{file}'", 'path="/bin:/usr/bin"')) + +step "verify that the files were created" +on agents, "test -f #{file}" + +step "clean up the system after testing" +on agents, "rm -f #{file}" diff --git a/acceptance/tests/resource/file/content_attribute.rb b/acceptance/tests/resource/file/content_attribute.rb new file mode 100644 index 000000000..4458e07a4 --- /dev/null +++ b/acceptance/tests/resource/file/content_attribute.rb @@ -0,0 +1,37 @@ +test_name "The content attribute" +pass_test "Pass forced pending test failure investigation" + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/content_file_test.txt' + +step "When using raw content" + +manifest = "file { '/tmp/content_file_test.txt': content => 'This is the test file content', ensure => present }" +apply_manifest_on agents, manifest + +on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the test file content"' + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/content_file_test.txt' + +step "When using a filebucket checksum from filebucket" + +on agents, "echo 'This is the checksum file contents' > /tmp/checksum_test_file.txt" +on agents, "puppet filebucket backup --local /tmp/checksum_test_file.txt" + +get_remote_option(agents, 'filebucket', 'bucketdir') do |bucketdir| + manifest = %Q| + filebucket { 'local': + path => '#{bucketdir}', + } + + file { '/tmp/content_file_test.txt': + content => '{md5}18571d3a04b2bb7ccfdbb2c44c72caa9', + ensure => present, + backup => local, + } + | + apply_manifest_on agents, manifest +end + +on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the checksum file contents"' diff --git a/acceptance/tests/resource/file/should_create_directory.rb b/acceptance/tests/resource/file/should_create_directory.rb new file mode 100755 index 000000000..859ebb3ba --- /dev/null +++ b/acceptance/tests/resource/file/should_create_directory.rb @@ -0,0 +1,15 @@ +test_name "should create directory" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target}" + +step "verify we can create a directory" +on(agents, puppet_resource("file", target, 'ensure=directory')) + +step "verify the directory was created" +on agents, "test -d #{target}" + +step "clean up after the test run" +on agents, "rm -vrf #{target}" diff --git a/acceptance/tests/resource/file/should_create_empty.rb b/acceptance/tests/resource/file/should_create_empty.rb new file mode 100755 index 000000000..a38c35c2d --- /dev/null +++ b/acceptance/tests/resource/file/should_create_empty.rb @@ -0,0 +1,15 @@ +test_name "should create empty file for 'present'" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target}" + +step "verify we can create an empty file" +on(agents, puppet_resource("file", target, 'ensure=present')) + +step "verify the target was created" +on agents, "test -f #{target} && ! test -s #{target}" + +step "clean up after the test run" +on agents, "rm -vrf #{target}" diff --git a/acceptance/tests/resource/file/should_create_symlink.rb b/acceptance/tests/resource/file/should_create_symlink.rb new file mode 100755 index 000000000..0e58d213b --- /dev/null +++ b/acceptance/tests/resource/file/should_create_symlink.rb @@ -0,0 +1,27 @@ +test_name "should create symlink" + +message = 'hello world' +target = "/tmp/test-#{Time.new.to_i}" +source = "/tmp/test-#{Time.new.to_i}-source" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target}" +on agents, "echo '#{message}' > #{source}" + +step "verify we can create a symlink" +on(agents, puppet_resource("file", target, "ensure=#{source}")) + +step "verify the symlink was created" +on agents, "test -L #{target} && test -f #{target}" +on agents, "test -f #{source}" + +step "verify the content is identical on both sides" +on(agents, "cat #{source}") do + fail_test "source missing content" unless stdout.include? message +end +on(agents, "cat #{target}") do + fail_test "target missing content" unless stdout.include? message +end + +step "clean up after the test run" +on agents, "rm -vrf #{target} #{source}" diff --git a/acceptance/tests/resource/file/should_remove_dir.rb b/acceptance/tests/resource/file/should_remove_dir.rb new file mode 100755 index 000000000..943410d20 --- /dev/null +++ b/acceptance/tests/resource/file/should_remove_dir.rb @@ -0,0 +1,21 @@ +test_name "should remove directory, but force required" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "test -e #{target} && rm -vrf #{target} ; mkdir -p #{target}" + +step "verify we can't remove a directory without 'force'" +on(agents, puppet_resource("file", target, 'ensure=absent')) do + fail_test "didn't tell us that force was required" unless + stdout.include? "Not removing directory; use 'force' to override" +end + +step "verify the directory still exists" +on agents, "test -d #{target}" + +step "verify we can remove a directory with 'force'" +on(agents, puppet_resource("file", target, 'ensure=absent', 'force=true')) + +step "verify that the directory is gone" +on agents, "test -d #{target}", :acceptable_exit_codes => [1] diff --git a/acceptance/tests/resource/file/should_remove_file.rb b/acceptance/tests/resource/file/should_remove_file.rb new file mode 100755 index 000000000..3ad7510ad --- /dev/null +++ b/acceptance/tests/resource/file/should_remove_file.rb @@ -0,0 +1,12 @@ +test_name "should remove file" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target} && touch #{target}" + +step "verify we can remove a file" +on(agents, puppet_resource("file", target, 'ensure=absent')) + +step "verify that the file is gone" +on agents, "test -e #{target}", :acceptable_exit_codes => [1] diff --git a/acceptance/tests/resource/file/source_attribtute.rb b/acceptance/tests/resource/file/source_attribtute.rb new file mode 100644 index 000000000..95a7f36b3 --- /dev/null +++ b/acceptance/tests/resource/file/source_attribtute.rb @@ -0,0 +1,100 @@ +test_name "The source attribute" + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/source_file_test.txt' + +# TODO: Add tests for puppet:// URIs with master/agent setups. +step "when using a puppet:/// URI with a master/agent setup" +step "when using a puppet://$server/ URI with a master/agent setup" + +step "when using a local file path" + +on agents, "echo 'Yay, this is the local file.' > /tmp/local_source_file_test.txt" + +manifest = "file { '/tmp/source_file_test.txt': source => '/tmp/local_source_file_test.txt', ensure => present }" + +apply_manifest_on agents, manifest + +on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the local file."' + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/source_file_test.txt' + +step "when using a puppet:/// URI with puppet apply" + +on agents, 'puppet agent --configprint modulepath' do + modulepath = stdout.split(':')[0] + modulepath = modulepath.chomp + on agents, "mkdir -p #{modulepath}/test_module/files" + on agents, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt" +end + +on agents, %q{echo "file { '/tmp/source_file_test.txt': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }" > /tmp/source_test_manifest.pp} +on agents, "puppet apply /tmp/source_test_manifest.pp" + +on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the puppet:/// file."' + +# Oops. We (Jesse & Jacob) ended up writing this before realizing that you +# can't actually specify "source => 'http://...'". However, we're leaving it +# here, since there have been feature requests to support doing this. +# -- Mon, 07 Mar 2011 16:12:56 -0800 +# +#step "Ensure the test environment is clean" +#on agents, 'rm -f /tmp/source_file_test.txt' +# +#step "when using an http:// file path" +# +#File.open '/tmp/puppet-acceptance-webrick-script.rb', 'w' do |file| +# file.puts %q{#!/usr/bin/env ruby +# +#require 'webrick' +# +#class Simple < WEBrick::HTTPServlet::AbstractServlet +# def do_GET(request, response) +# status, content_type, body = do_stuff_with(request) +# +# response.status = status +# response['Content-Type'] = content_type +# response.body = body +# end +# +# def do_stuff_with(request) +# return 200, "text/plain", "you got a page" +# end +#end +# +#class SimpleTwo < WEBrick::HTTPServlet::AbstractServlet +# def do_GET(request, response) +# status, content_type, body = do_stuff_with(request) +# +# response.status = status +# response['Content-Type'] = content_type +# response.body = body +# end +# +# def do_stuff_with(request) +# return 200, "text/plain", "you got a different page" +# end +#end +# +#server = WEBrick::HTTPServer.new :Port => 8081 +#trap "INT" do server.shutdown end +#trap "TERM" do server.shutdown end +#trap "QUIT" do server.shutdown end +# +#server.mount "/", SimpleTwo +#server.mount "/foo.txt", Simple +#server.start +#} +#end +# +#scp_to master, '/tmp/puppet-acceptance-webrick-script.rb', '/tmp' +#on master, "chmod +x /tmp/puppet-acceptance-webrick-script.rb && /tmp/puppet-acceptance-webrick-script.rb &" +# +#manifest = "file { '/tmp/source_file_test.txt': source => 'http://#{master}:8081/foo.txt', ensure => present }" +# +#apply_manifest_on agents, manifest +# +#on agents, 'test "$(cat /tmp/source_file_test.txt)" = "you got a page"' +# +#on master, "killall puppet-acceptance-webrick-script.rb" diff --git a/acceptance/tests/resource/group/should_create.rb b/acceptance/tests/resource/group/should_create.rb new file mode 100755 index 000000000..122c31a8f --- /dev/null +++ b/acceptance/tests/resource/group/should_create.rb @@ -0,0 +1,20 @@ +test_name "should create group" + +name = "test-group-#{Time.new.to_i}" + +def cleanup(name) + step "remove group #{name} if it exists" + on agents, "if getent group #{name}; then groupdel #{name}; fi" +end + +cleanup(name) + +step "create the group #{name} with the resource agent" +on(agents, puppet_resource('group', name, 'ensure=present')) + +step "verify the group #{name} was created" +on(agents, "getent group #{name}") do + fail_test "group information is not sensible" unless stdout =~ /^#{name}:x:[0-9]+:/ +end + +cleanup(name) diff --git a/acceptance/tests/resource/group/should_destroy.rb b/acceptance/tests/resource/group/should_destroy.rb new file mode 100755 index 000000000..1551abe75 --- /dev/null +++ b/acceptance/tests/resource/group/should_destroy.rb @@ -0,0 +1,14 @@ +test_name "should destroy a group" + +name = "test-group-#{Time.new.to_i}" + +step "ensure the group exists on the target system" +on agents, "getent group #{name} || groupadd #{name}" + +step "use puppet to remove the group" +on(agents, puppet_resource('group', name, 'ensure=absent')) + +step "verify that the group has been removed" +# REVISIT: I /think/ that exit code 2 is standard across Linux, but I have no +# idea what non-Linux platforms are going to return. --daniel 2010-12-24 +on agents, "getent group #{name}", :acceptable_exit_codes => [2] diff --git a/acceptance/tests/resource/group/should_modify_gid.rb b/acceptance/tests/resource/group/should_modify_gid.rb new file mode 100755 index 000000000..95405b24c --- /dev/null +++ b/acceptance/tests/resource/group/should_modify_gid.rb @@ -0,0 +1,23 @@ +test_name "should modify gid of existing group" + +name = "test-group-#{Time.new.to_i}" +gid = 12345 + +step "ensure that the group exists with gid #{gid}" +on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid}")) do + fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid}'/ +end + +step "ensure that we can modify the GID of the group to #{gid*2}" +on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid*2}")) do + fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid*2}'/ +end + +step "verify that the GID changed" +on(agents, "getent group #{name}") do + fail_test "gid is wrong through getent output" unless + stdout =~ /^#{name}:x:#{gid*2}:/ +end + +step "clean up the system after the test run" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_not_create_existing.rb b/acceptance/tests/resource/group/should_not_create_existing.rb new file mode 100755 index 000000000..ed4f54cdc --- /dev/null +++ b/acceptance/tests/resource/group/should_not_create_existing.rb @@ -0,0 +1,15 @@ +test_name "group should not create existing group" + +name = "test-group-#{Time.new.to_i}" + +step "ensure the group exists on the target node" +on(agents, puppet_resource('group', name, 'ensure=present')) + +step "verify that we don't try and create the existing group" +on(agents, puppet_resource('group', name, 'ensure=present')) do + fail_test "looks like we created the group" if + stdout.include? '/Group[bozo]/ensure: created' +end + +step "clean up the system after the test run" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb new file mode 100755 index 000000000..256a8f146 --- /dev/null +++ b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb @@ -0,0 +1,13 @@ +test_name "should not destroy a group that doesn't exist" + +name = "test-group-#{Time.new.to_i}" + +step "verify the group does not already exist" +on(agents, puppet_resource('group', name, 'ensure=absent')) + +step "verify that we don't remove the group when it doesn't exist" +on(agents, puppet_resource('group', name, 'ensure=absent')) do + fail_test "it looks like we tried to remove the group" if + stdout.include? "notice: /Group[#{name}]/ensure: removed" +end + diff --git a/acceptance/tests/resource/group/should_query.rb b/acceptance/tests/resource/group/should_query.rb new file mode 100755 index 000000000..3bbce071c --- /dev/null +++ b/acceptance/tests/resource/group/should_query.rb @@ -0,0 +1,15 @@ +test_name "group should query" + +name = "test-group-#{Time.new.to_i}" + +step "ensure the group exists on the target systems" +on agents, "getent group #{name} || groupadd #{name}" + +step "ensure that the resource agent sees the group" +on(agents, puppet_resource('group', name)) do + fail_test "missing group identifier" unless stdout.include? "group { '#{name}':" + fail_test "missing present attributed" unless stdout.include? "ensure => 'present'" +end + +step "clean up the system after the test" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_query_all.rb b/acceptance/tests/resource/group/should_query_all.rb new file mode 100755 index 000000000..9abcfed21 --- /dev/null +++ b/acceptance/tests/resource/group/should_query_all.rb @@ -0,0 +1,30 @@ +test_name "puppet resource should query all groups" + +agents.each do |host| + groups = {} + + step "collect the list of groups on #{host} with getent group" + on(host, "getent group") do + stdout.each_line do |line| groups[line[/^[^:]+/]] = 'getent' end + end + + step "collect the list of groups on #{host} with puppet resource" + on(host, puppet_resource('group')) do + stdout.each_line do |line| + match = line.match(/^group \{ '([^']+)'/) + if match then + name = match[1] + + if groups.include? name then + groups.delete name + else + fail_test "group #{name} found by puppet, not getent" + end + end + end + end + + groups.keys.each do |name| + fail_test "group #{name} found by getent, not puppet" + end +end diff --git a/acceptance/tests/resource/host/should_create.rb b/acceptance/tests/resource/host/should_create.rb new file mode 100755 index 000000000..d5bd9e6e7 --- /dev/null +++ b/acceptance/tests/resource/host/should_create.rb @@ -0,0 +1,15 @@ +test_name "host should create" + +target = "/tmp/host-#{Time.new.to_i}" + +step "clean up for the test" +on agents, "rm -vf #{target}" + +step "create the host record" +on(agents, puppet_resource("host", "test", "ensure=present", + "ip=127.0.0.1", "target=#{target}")) + +step "verify that the record was created" +on(agents, "cat #{target} ; rm -f #{target}") do + fail_test "record was not present" unless stdout =~ /^127\.0\.0\.1[[:space:]]+test/ +end diff --git a/acceptance/tests/resource/host/should_create_aliases.rb b/acceptance/tests/resource/host/should_create_aliases.rb new file mode 100755 index 000000000..4cc0014f6 --- /dev/null +++ b/acceptance/tests/resource/host/should_create_aliases.rb @@ -0,0 +1,16 @@ +test_name "host should create aliases" + +target = "/tmp/host-#{Time.new.to_i}" + +step "clean up the system for testing" +on agents, "rm -vf #{target}" + +step "create the record" +on(agents, puppet_resource('host', 'test', "ensure=present", + "ip=127.0.0.7", "target=#{target}", "host_aliases=alias")) + +step "verify that the aliases were added" +on(agents, "cat #{target} ; rm -f #{target}") do + fail_test "alias was missing" unless + stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/ +end diff --git a/acceptance/tests/resource/host/should_destroy.rb b/acceptance/tests/resource/host/should_destroy.rb new file mode 100755 index 000000000..451b2d061 --- /dev/null +++ b/acceptance/tests/resource/host/should_destroy.rb @@ -0,0 +1,19 @@ +test_name "should be able to remove a host record" + +file = "/tmp/hosts-#{Time.new.to_i}" +line = "127.0.0.7 test1" + +step "set up files for the test" +on agents, "printf '#{line}\n' > #{file}" + +step "delete the resource from the file" +on(agents, puppet_resource('host', 'test1', "target=#{file}", + 'ensure=absent', 'ip=127.0.0.7')) + +step "verify that the content was removed" +on(agents, "cat #{file}; rm -f #{file}") do + fail_test "the content was still present" if stdout.include? line +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_modify_alias.rb b/acceptance/tests/resource/host/should_modify_alias.rb new file mode 100755 index 000000000..312078fef --- /dev/null +++ b/acceptance/tests/resource/host/should_modify_alias.rb @@ -0,0 +1,19 @@ +test_name "should be able to modify a host alias" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up files for the test" +on agents, "printf '127.0.0.8 test alias\n' > #{file}" + +step "modify the resource" +on(agents, puppet_resource('host', 'test', "target=#{file}", + 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai')) + +step "verify that the content was updated" +on(agents, "cat #{file}; rm -f #{file}") do + fail_test "the alias was not updated" unless + stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/ +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_modify_ip.rb b/acceptance/tests/resource/host/should_modify_ip.rb new file mode 100755 index 000000000..b16db5979 --- /dev/null +++ b/acceptance/tests/resource/host/should_modify_ip.rb @@ -0,0 +1,19 @@ +test_name "should be able to modify a host address" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up files for the test" +on agents, "printf '127.0.0.9 test alias\n' > #{file}" + +step "modify the resource" +on(agents, puppet_resource('host', 'test', "target=#{file}", + 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias')) + +step "verify that the content was updated" +on(agents, "cat #{file}; rm -f #{file}") do + fail_test "the address was not updated" unless + stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/ +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_not_create_existing.rb b/acceptance/tests/resource/host/should_not_create_existing.rb new file mode 100755 index 000000000..c8a40df93 --- /dev/null +++ b/acceptance/tests/resource/host/should_not_create_existing.rb @@ -0,0 +1,17 @@ +test_name "should not create host if it exists" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up the system for the test" +on agents, "printf '127.0.0.2 test alias\n' > #{file}" + +step "tell puppet to ensure the host exists" +on(agents, puppet_resource('host', 'test', "target=#{file}", + 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do + fail_test "darn, we created the host record" if + stdout.include? 'notice: /Host[test1]/ensure: created' +end + +step "clean up after we created things" +on agents, "rm -vf #{file}" + diff --git a/acceptance/tests/resource/host/should_query.rb b/acceptance/tests/resource/host/should_query.rb new file mode 100755 index 000000000..983812ce0 --- /dev/null +++ b/acceptance/tests/resource/host/should_query.rb @@ -0,0 +1,15 @@ +test_name "should query hosts out of a hosts file" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up the system for the test" +on agents, "printf '127.0.0.1 localhost.local localhost\n' > #{file}" + +step "fetch the list of hosts from puppet" +on(agents, puppet_resource('host', 'localhost', "target=#{file}")) do + found = stdout.scan('present').length + fail_test "found #{found} hosts, not 1" if found != 1 +end + +step "clean up the system" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_query_all.rb b/acceptance/tests/resource/host/should_query_all.rb new file mode 100755 index 000000000..654883aa0 --- /dev/null +++ b/acceptance/tests/resource/host/should_query_all.rb @@ -0,0 +1,26 @@ +test_name "should query all hosts from hosts file" + +content = %q{127.0.0.1 test1 test1.local +127.0.0.2 test2 test2.local +127.0.0.3 test3 test3.local +127.0.0.4 test4 test4.local +} + +backup = "/tmp/hosts.backup-#{Time.new.to_i}" + +step "configure the system for testing (including file backups)" +on agents, "cp /etc/hosts #{backup}" +on agents, "cat > /etc/hosts", :stdin => content + +step "query all host records using puppet" +on(agents, puppet_resource('host')) do + found = stdout.scan(/host \{ '([^']+)'/).flatten.sort + fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless + found == %w{test1 test2 test3 test4} + + count = stdout.scan(/ensure\s+=>\s+'present'/).length + fail_test "found #{count} records, wanted 4" unless count == 4 +end + +step "clean up the system afterwards" +on agents, "mv -vf #{backup} /etc/hosts" diff --git a/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb b/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb new file mode 100755 index 000000000..9223da665 --- /dev/null +++ b/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb @@ -0,0 +1,21 @@ +test_name "#4131: should not create host without IP attribute" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "configure the target system for the test" +on agents, "rm -vrf #{file} ; touch #{file}" + +step "try to create the host, which should fail" +# REVISIT: This step should properly need to handle the non-zero exit code, +# and #5668 has been filed to record that. When it is fixed this test will +# start to fail, and this comment will tell you why. --daniel 2010-12-24 +on(agents, puppet_resource('host', 'test', "target=#{file}", + "host_aliases=alias")) do + fail_test "puppet didn't complain about the missing attribute" unless + stdout.include? 'ip is a required attribute for hosts' +end + +step "verify that the host was not added to the file" +on(agents, "cat #{file} ; rm -f #{file}") do + fail_test "the host was apparently added to the file" if stdout.include? 'test' +end diff --git a/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb new file mode 100755 index 000000000..b4c2bc14d --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb @@ -0,0 +1,12 @@ +test_name "#4123: should list all running services on Redhat/CentOS" +step "Validate services running agreement ralsh vs. OS service count" +# This will remotely exec: +# ticket_4123_should_list_all_running_redhat.sh + +hosts.each do |host| + unless host['platform'].include? 'centos' or host['platform'].include? 'redhat' + skip_test "Test not supported on this plaform" + else + run_script_on(host,'tests/acceptance/resource/service/ticket_4123_should_list_all_running_redhat.sh') + end +end diff --git a/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh new file mode 100755 index 000000000..1d5e49524 --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# A platform must be specified the only command line arg +# This will facilitate expansion of this tests to include +# the ability to test other OSes + +#if [ -z $1 ] ; then +# echo "No platform specified" +# exit 1 +#fi + +# redhat or centos only +#if echo $1 | grep -e centos -e redhat + RALSH_FILE=/tmp/ralsh-running-list-$$ + SERVICE_FILE=/tmp/service-running-list-$$ + + puppet resource service | egrep -B1 "ensure\s*=>\s*'running" | grep 'service {' | gawk -F"\'" '{print $2}' | sort > $RALSH_FILE + + if [ -e $SERVICE_FILE ]; then + rm $SERVICE_FILE + fi + SERVICEDIR='/etc/init.d' + for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do + if env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" status; then + echo $SERVICE >> $SERVICE_FILE + fi + done + + if diff $RALSH_FILE $SERVICE_FILE ; then + echo "Ralsh and system service count agree" + exit 0 + else + echo "Ralsh and system service count NOT in agreement" + exit 1 + fi +#fi # end redhat/centos diff --git a/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb new file mode 100755 index 000000000..4add108ff --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb @@ -0,0 +1,12 @@ +test_name "#4124: should list all disabled services on Redhat/CentOS" +step "Validate disabled services agreement ralsh vs. OS service count" +# This will remotely exec: +# ticket_4124_should_list_all_disabled.sh + +hosts.each do |host| + unless host['platform'].include? 'centos' or host['platform'].include? 'redhat' + skip_test "Test not supported on this plaform" + else + run_script_on(host,'tests/acceptance/resource/service/ticket_4124_should_list_all_disabled.sh') + end +end diff --git a/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh new file mode 100755 index 000000000..7cc463d5e --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# A platform must be specified the only command line arg +# This will facilitate expansion of this tests to include +# the ability to test other OSes + +#if [ -z $1 ] ; then +# echo "No platform specified" +# exit 1 +#fi + +# redhat or centos only +#if echo $1 | grep -e centos -e redhat + RALSH_FILE=/tmp/ralsh-disabled-list-$$ + SERVICE_FILE=/tmp/service-disabled-list-$$ + + # collect all service namevars + puppet resource service | egrep -B2 "enable\s*=>\s*'false" | grep "service {" | awk -F"'" '{print $2}' | sort > $RALSH_FILE + + if [ -e $SERVICE_FILE ]; then + rm $SERVICE_FILE + fi + SERVICEDIR='/etc/init.d' + for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do + if ! chkconfig $SERVICE; then + echo $SERVICE >> $SERVICE_FILE + fi + done + + if diff $RALSH_FILE $SERVICE_FILE ; then + echo "Ralsh and system service count agree" + exit 0 + else + echo "Ralsh and system service count NOT in agreement" + exit 1 + fi +#fi # end redhat/centos diff --git a/acceptance/tests/resource/user/should_create.rb b/acceptance/tests/resource/user/should_create.rb new file mode 100755 index 000000000..062883da3 --- /dev/null +++ b/acceptance/tests/resource/user/should_create.rb @@ -0,0 +1,20 @@ +test_name "should create a user, and the default matching group" +# REVISIT: This is a direct port of the original test, but it contains a +# non-portable assumption that "user private groups" are used by default by +# everything that we target. --daniel 2010-12-24 + +name = "test-user-#{Time.new.to_i}" + +step "ensure that the user and group #{name} do not exist" +on agents, "if getent passwd #{name}; then userdel #{name}; fi" +on agents, "if getent group #{name}; then groupdel #{name}; fi" + +step "ask puppet to create the user" +on(agents, puppet_resource('user', name, 'ensure=present')) + +step "verify that the user and group now exist" +on agents, "getent passwd #{name} && getent group #{name}" + +step "ensure that the user and group #{name} do not exist" +on agents, "if getent passwd #{name}; then userdel #{name}; fi" +on agents, "if getent group #{name}; then groupdel #{name}; fi" diff --git a/acceptance/tests/resource/user/should_create_with_gid.rb b/acceptance/tests/resource/user/should_create_with_gid.rb new file mode 100755 index 000000000..be36bf4e6 --- /dev/null +++ b/acceptance/tests/resource/user/should_create_with_gid.rb @@ -0,0 +1,30 @@ +test_name "verifies that puppet resource creates a user and assigns the correct group" + +user = "test-user-#{Time.new.to_i}" +group = "test-user-#{Time.new.to_i}-group" + +agents.each do |host| + step "user should not exist" + on host, "if getent passwd #{user}; then userdel #{user}; fi" + + step "group should exist" + on host, "if ! getent group #{group}; then groupadd #{group}; fi" + + step "create user with group" + on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) + + step "verify the group exists and find the gid" + on(host, "getent group #{group}") do + gid = stdout.split(':')[2] + + step "verify that the user has that as their gid" + on(host, "getent passwd #{user}") do + got = stdout.split(':')[3] + fail_test "wanted gid #{gid} but found #{got}" unless gid == got + end + end + + step "clean up after the test is done" + on(host, puppet_resource('user', user, 'ensure=absent')) + on(host, puppet_resource('group', group, 'ensure=absent')) +end diff --git a/acceptance/tests/resource/user/should_destroy.rb b/acceptance/tests/resource/user/should_destroy.rb new file mode 100755 index 000000000..8ba7ace41 --- /dev/null +++ b/acceptance/tests/resource/user/should_destroy.rb @@ -0,0 +1,19 @@ +test_name "verify that puppet resource correctly destroys users" + +user = "test-user-#{Time.new.to_i}" +group = user + +step "ensure that the user and associated group exist" +on(agents, puppet_resource('group', group, 'ensure=present')) +on(agents, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) + +step "try and delete the user" +on(agents, puppet_resource('user', user, 'ensure=absent')) + +step "verify that the user is no longer present" +on(agents, "getent passwd #{user}", :acceptable_exit_codes => [2]) do + fail_test "found the user in the output" if stdout.include? "#{user}:" +end + +step "remove the group as well..." +on(agents, puppet_resource('group', group, 'ensure=absent')) diff --git a/acceptance/tests/resource/user/should_modify_gid.rb b/acceptance/tests/resource/user/should_modify_gid.rb new file mode 100755 index 000000000..6aba4aa7a --- /dev/null +++ b/acceptance/tests/resource/user/should_modify_gid.rb @@ -0,0 +1,41 @@ +test_name "verify that we can modify the gid" + +user = "test-user-#{Time.new.to_i}" +group1 = "#{user}-old" +group2 = "#{user}-new" + +agents.each do |host| + step "ensure that the groups both exist" + on(host, puppet_resource('group', group1, 'ensure=present')) + on(host, puppet_resource('group', group2, 'ensure=present')) + + step "ensure the user exists and has the old group" + on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group1}")) + + step "verify that the user has the correct gid" + on(host, "getent group #{group1}") do + gid = stdout.split(':')[2] + on(host, "getent passwd #{user}") do + got = stdout.split(':')[3] + fail_test "didn't have the expected old GID, but #{got}" unless got == gid + end + end + + step "modify the GID of the user" + on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group2}")) + + + step "verify that the user has the updated gid" + on(host, "getent group #{group2}") do + gid = stdout.split(':')[2] + on(host, "getent passwd #{user}") do + got = stdout.split(':')[3] + fail_test "didn't have the expected old GID, but #{got}" unless got == gid + end + end + + step "ensure that we remove the things we made" + on(host, puppet_resource('user', user, 'ensure=absent')) + on(host, puppet_resource('group', group1, 'ensure=absent')) + on(host, puppet_resource('group', group2, 'ensure=absent')) +end diff --git a/acceptance/tests/resource/user/should_not_create_existing.rb b/acceptance/tests/resource/user/should_not_create_existing.rb new file mode 100755 index 000000000..2f33a94df --- /dev/null +++ b/acceptance/tests/resource/user/should_not_create_existing.rb @@ -0,0 +1,6 @@ +test_name "tests that user resource will not add users that already exist." + +step "verify that we don't try to create a user account that already exists" +on(agents, puppet_resource('user', 'root', 'ensure=present')) do + fail_test "tried to create 'root' user" if stdout.include? 'created' +end diff --git a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb new file mode 100755 index 000000000..ceeea7da1 --- /dev/null +++ b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb @@ -0,0 +1,11 @@ +test_name "ensure that puppet does not report removing a user that does not exist" + +name = "test-user-#{Time.new.to_i}" + +step "verify that user #{name} does not exist" +on agents, "getent passwd #{name}", :acceptable_exit_codes => [2] + +step "ensure absent doesn't try and do anything" +on(agents, puppet_resource('user', name, 'ensure=absent')) do + fail_test "tried to remove the user, apparently" if stdout.include? 'removed' +end diff --git a/acceptance/tests/resource/user/should_query.rb b/acceptance/tests/resource/user/should_query.rb new file mode 100755 index 000000000..6e2df534d --- /dev/null +++ b/acceptance/tests/resource/user/should_query.rb @@ -0,0 +1,15 @@ +test_name "test that we can query and find a user that exists." + +name = "test-user-#{Time.new.to_i}" + +step "ensure that our test user exists" +on(agents, puppet_resource('user', name, 'ensure=present')) + +step "query for the resource and verify it was found" +on(agents, puppet_resource('user', name)) do + fail_test "didn't find the user #{name}" unless stdout.include? 'present' +end + +step "clean up the user and group we added" +on(agents, puppet_resource('user', name, 'ensure=absent')) +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/user/should_query_all.rb b/acceptance/tests/resource/user/should_query_all.rb new file mode 100755 index 000000000..00d7b25c4 --- /dev/null +++ b/acceptance/tests/resource/user/should_query_all.rb @@ -0,0 +1,30 @@ +test_name "ensure that puppet queries the correct number of users" + +agents.each do |host| + users = [] + + step "collect the list of known users via getent" + on(host, "getent passwd") do + stdout.each_line do |line| + users << line.split(':')[0] + end + end + + step "collect the list of known users via puppet" + on(host, puppet_resource('user')) do + stdout.each_line do |line| + name = ( line.match(/^user \{ '([^']+)'/) or next )[1] + + # OK: Was this name found in the list of users? + if users.member? name then + users.delete name + else + fail_test "user #{name} found by puppet, not by getent" + end + end + end + + if users.length > 0 then + fail_test "#{users.length} users found with getent, not puppet: #{users.join(', ')}" + end +end diff --git a/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb b/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb new file mode 100644 index 000000000..436ce29fe --- /dev/null +++ b/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb @@ -0,0 +1,7 @@ +test_name "#3172: puppet kick with hostnames on the command line" +step "verify that we trigger our host" + +target = 'working.example.org' +on(agents, puppet_kick(target), :acceptable_exit_codes => [3]) { + fail_test "didn't trigger #{target}" unless stdout.include? "Triggering #{target}" +} diff --git a/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb new file mode 100644 index 000000000..ba02227ea --- /dev/null +++ b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb @@ -0,0 +1,50 @@ +test_name "#3360: Allow duplicate CSR when allow_duplicate_certs is on" + +agent_hostnames = agents.map {|a| a.to_s} + +# Kill running Puppet Master -- should not be running at this point +step "Master: kill running Puppet Master" +on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill || echo \"Puppet Master not running\"" + +step "Master: Start Puppet Master" +on master, puppet_master("--allow_duplicate_certs --certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop") + +step "Generate a certificate request for the agent" +on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + +step "Collect the original certs" +on master, puppet_cert("--sign --all") +original_certs = on master, puppet_cert("--list --all") + +old_certs = {} +original_certs.stdout.each_line do |line| + if line =~ /^\+ (\S+) \((.+)\)$/ + old_certs[$1] = $2 + puts "old cert: #{$1} #{$2}" + end +end + +step "Make another request with the same certname" +on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + +step "Collect the new certs" + +on master, puppet_cert("--sign --all") +new_cert_list = on master, puppet_cert("--list --all") + +new_certs = {} +new_cert_list.stdout.each_line do |line| + if line =~ /^\+ (\S+) \((.+)\)$/ + new_certs[$1] = $2 + puts "new cert: #{$1} #{$2}" + end +end + +step "Verify the certs have changed" +# using the agent name as the key may cause errors; +# agent name from cfg file is likely to have short name +# where certs might be signed with long names. +old_certs.each_key { |key| + next if key.include? master # skip the masters cert, only care about agents + fail_test("#{key} does not have a new signed certificate") if old_certs[key] == new_certs[key] +} diff --git a/acceptance/tests/ticket_3656_requiring_multiple_resources.rb b/acceptance/tests/ticket_3656_requiring_multiple_resources.rb new file mode 100644 index 000000000..754e6415b --- /dev/null +++ b/acceptance/tests/ticket_3656_requiring_multiple_resources.rb @@ -0,0 +1,8 @@ +test_name "#3656: requiring multiple resources" +apply_manifest_on agents, %q{ + notify { 'foo': } + notify { 'bar': } + notify { 'baz': + require => [Notify['foo'], Notify['bar']], + } +} diff --git a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb new file mode 100644 index 000000000..4b5bc377b --- /dev/null +++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb @@ -0,0 +1,29 @@ +test_name "#3961: puppet ca should produce certs spec" + +scratch = "/tmp/puppet-ssl-3961" +target = "working3961.example.org" + +options = { :confdir => scratch, :vardir => scratch, :ssldir => scratch } + +expect = ['notice: Signed certificate request for ca', + 'notice: Rebuilding inventory file', + 'notice: working3961.example.org has a waiting certificate request', + 'notice: Signed certificate request for working3961.example.org', + 'notice: Removing file Puppet::SSL::CertificateRequest working3961.example.org'] + + +step "removing the SSL scratch directory..." +on agents, "rm -vrf #{scratch}" + +step "generate a certificate in #{scratch}" +on(agents,puppet_cert('--trace', '--generate', target, options)) do + expect.each do |line| + stdout.index(line) or fail_test("missing line in output: #{line}") + end +end + +step "verify the certificate for #{target} exists" +on agents, "test -f #{scratch}/certs/#{target}.pem" + +step "verify the private key for #{target} exists" +on agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/private_keys/#{target}.pem" diff --git a/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb new file mode 100644 index 000000000..c97bbdbe6 --- /dev/null +++ b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb @@ -0,0 +1,20 @@ +test_name "#4059: ralsh can change settings" + +target = "/tmp/hosts-#4059" +content = "host example.com ensure=present ip=127.0.0.1 target=#{target}" + +step "cleanup the target file" +on agents, "rm -f #{target}" + +step "run the resource agent" +on(agents, puppet_resource(content)) do + stdout.index('Host[example.com]/ensure: created') or + fail_test("missing notice about host record creation") +end +on(agents, "cat #{target}") do + stdout =~ /^127\.0\.0\.1\s+example\.com/ or + fail_test("missing host record in #{target}") +end + +step "cleanup at the end of the test" +on agents, "rm -f #{target}" diff --git a/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb b/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb new file mode 100644 index 000000000..9704250d9 --- /dev/null +++ b/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb @@ -0,0 +1,5 @@ +test_name "#4110: puppet apply should not create a user that already exists" + +apply_manifest_on(agents, "user { 'root': ensure => 'present' }") do + fail_test("we tried to create root on this host") if stdout =~ /created/ +end diff --git a/acceptance/tests/ticket_4233_resource_with_a_newline.rb b/acceptance/tests/ticket_4233_resource_with_a_newline.rb new file mode 100644 index 000000000..7bb7dc3c3 --- /dev/null +++ b/acceptance/tests/ticket_4233_resource_with_a_newline.rb @@ -0,0 +1,13 @@ +test_name "#4233: resource with a newline" + +# 2010-07-22 Jeff McCune +# AffectedVersion: 2.6.0rc3 +# FixedVersion: 2.6.0 + +# JJM We expect 2.6.0rc3 to return an error +# and 2.6.0 final to not return an error line. +# Look for the line in the output and fail the test +# if we find it. +apply_manifest_on(agents, 'exec { \'/bin/echo -e "\nHello World\n"\': }') do + stdout =~ /err:/ and fail_test("error report in output, sorry") +end diff --git a/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb b/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb new file mode 100644 index 000000000..d2297fbc4 --- /dev/null +++ b/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb @@ -0,0 +1,17 @@ +test_name "Bug #4285: ArgumentError: Cannot alias File[mytitle] to [nil]" + +manifest = %q{ + file { "file1": + name => '/tmp/file1', + source => "/tmp/", + } + + file { "file2": + name => '/tmp/file2', + source => "/tmp/", + } +} + +apply_manifest_on(agents, manifest) do + fail_test "found the bug report output" if stdout =~ /Cannot alias/ +end diff --git a/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb new file mode 100644 index 000000000..e9a17df36 --- /dev/null +++ b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb @@ -0,0 +1,13 @@ +test_name "Bug #4287: undefined method 'evaluate_match' when function call used in an 'if' statement" + +manifest = %q{ + $foo='abc' + if $foo != regsubst($foo,'abc','def') { + notify { 'No issue here...': } + } +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't get the expected notice" unless + stdout.include? 'notice: No issue here...' +end diff --git a/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb b/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb new file mode 100644 index 000000000..653fcb274 --- /dev/null +++ b/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb @@ -0,0 +1,21 @@ +# 2010-08-02 Nan Liu +# +# http://projects.puppetlabs.com/issues/4289 +# +# NL: Facter should return OS version instead of kernel version for OEL +# test script only applicable to OEL, provided based on ticked info, not verified. + +test_name "#4289: facter should recognize OEL operatingsystemrelease" + +# REVISIT: We don't actually have support for this yet - we need a "not +# applicable" option, I guess, that can be based on detected stuff, which is +# cleaner than this is... --daniel 2010-12-22 +agents.each do |host| + step "determine the operating system of #{host}" + on host, facter("operatingsystem") + if stdout =~ /oel/i then + step "test operatingsystemrelease fact on OEL host #{host}" + on host, facter("operatingsystemrelease") + stdout =~ /^\d\.\d$/ or fail_test "operatingsystemrelease not as expected" + end +end diff --git a/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb new file mode 100644 index 000000000..830da99b4 --- /dev/null +++ b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb @@ -0,0 +1,22 @@ +# 2010-07-22 Jeff McCune +# +# AffectedVersion: 2.6.0rc4 +# FixedVersion: 2.6.0 +# +# Description: using a defined type in the class it's declared in +# causes an error. + +manifest = < "a_message_for_you" } +} +include foo +PP + +apply_manifest_on(agents, manifest) do + stdout =~ /notice.*?Foo::Do_notify.*?a_message_for_you/ or + fail_test("the notification didn't show up in stdout") +end diff --git a/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb b/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb new file mode 100644 index 000000000..db7d5a4d3 --- /dev/null +++ b/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb @@ -0,0 +1,21 @@ +# Jeff McCune +# 2010-07-29 +# +# AffectedVersion: <= 2.6.0rc1 +# FixedVersion: +# +# This specification makes sure the syntax: +# Stage[main] -> Stage[last] +# works as expected + +apply_manifest_on agents, %q{ + stage { [ "pre", "post" ]: } + Stage["pre"] -> Stage["main"] -> Stage["post"] + class one { notify { "class one, first stage": } } + class two { notify { "class two, second stage": } } + class three { notify { "class three, third stage": } } + class { "one": stage => pre } + class { "two": } + class { "three": stage => post } +} + diff --git a/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb b/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb new file mode 100644 index 000000000..4c4111dfb --- /dev/null +++ b/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb @@ -0,0 +1,50 @@ +# Jeff McCune +# 2010-07-31 +# +# AffectedVersion: 2.6.0, 2.6.1rc1 +# FixedVersion: +# +# Make sure two parameterized classes are able to be declared. + +test_name "#4423: cannot declare two parameterized classes" + +class1 = %q{ + class rainbow($color) { + notify { "color": message => "Color is [${color}]" } + } + class { "rainbow": color => "green" } +} + +class2 = %q{ + class planet($moons) { + notify { "planet": message => "Moons are [${moons}]" } + } + class { "planet": moons => "1" } +} + +step "Declaring one parameterized class works just fine" +apply_manifest_on(agents, class1) + +step "Make sure we try both classes stand-alone" +apply_manifest_on(agents, class2) + +step "Putting both classes in the same manifest should work." +apply_manifest_on agents, class1 + class2 + +step "Putting both classes in the same manifest should work." +apply_manifest_on agents, class1+class2+%q{ + + class rainbow::location($prism=false, $water=true) { + notify { "${name}": + message => "prism:[${prism}] water:[${water}]"; + } + } + class { "rainbow::location": prism => true, water => false; } + + class rainbow::type($pretty=true, $ugly=false) { + notify { "${name}": + message => "pretty:[${pretty}] ugly:[${ugly}]"; + } + } + class { "rainbow::type": pretty => false, ugly => true; } +} diff --git a/acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb b/acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb new file mode 100644 index 000000000..a918f0788 --- /dev/null +++ b/acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb @@ -0,0 +1,28 @@ +test_name "#5027: Issue warnings when using dynamic scope" + +step "Apply dynamic scoping manifest on agents" +apply_manifest_on agents, %q{ + $foo = 'foo_value' + + class a { + $bar = 'bar_value' + + include b + } + + class b inherits c { + notify { $baz: } # should not generate a warning -- inherited from class c + notify { $bar: } # should generate a warning -- uses dynamic scoping + notify { $foo: } # should not generate a warning -- comes from top scope + } + + class c { + $baz = 'baz_value' + } + + include a +} + +step "Verify deprecation warning" +fail_test "Deprecation warning not issued" unless + stdout.include? 'warning: Dynamic lookup' diff --git a/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb new file mode 100644 index 000000000..d05735e50 --- /dev/null +++ b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb @@ -0,0 +1,43 @@ +# In 2.6, compile does not fail when site.pp does not exist. +# +# However, if a catalog is compiled when site.pp does not exist, +# puppetmaster does not detect when site.pp is created. This requires a restart +# + +test_name "Ticket 5477, Puppet Master does not detect newly created site.pp file" + +# Kill running Puppet Master +step "Master: kill running Puppet Master" +on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill" + +# Run tests against Master first +step "Master: mv site.pp file to /tmp, if existing" +on master, "if [ -e /etc/puppet/manifests/site.pp ] ; then mv /etc/puppet/manifests/site.pp /tmp/site.pp-5477 ; fi" + +# Start Puppet Master +#step "Master: Run Puppet Master in verbose mode" +#on master, puppet_master("--verbose") +step "Master: Start Puppet Master" +on master, puppet_master("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose") + +# Allow puppet server to start accepting conections +sleep 10 + +# Run test on Agents +step "Agent: agent --test" +agents.each { |agent| + on agent, puppet_agent("--test") +} + +# Create a new site.pp +step "Master: create basic site.pp file" +on master, "echo 'notify{ticket_5477_notify:}' > /etc/puppet/manifests/site.pp" + +sleep 20 + +step "Agent: puppet agent --test" +agents.each { |agent| + on agent, "puppet agent -t", :acceptable_exit_codes => [2] + fail_test "Site.pp not detect at Master?" unless + stdout.include? 'ticket_5477_notify' +} diff --git a/acceptance/tests/ticket_6418_file_recursion_and_audit.rb b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb new file mode 100644 index 000000000..f0a55d029 --- /dev/null +++ b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb @@ -0,0 +1,22 @@ +# 2011-02-23 +# +# AffectedVersion: 2.6.0-2.6.5 +# FixedVersion: +# + +test_name "#6418: file recursion and audit" + +on agents, "rm -f /var/lib/puppet/state/state.yaml " +manifest = %q{ + file { "/tmp/6418": ensure => directory } + file { "/tmp/6418/dir": ensure => directory} + file { "/tmp/6418/dir/dir": ensure => directory} + file { "/tmp/6418/dir/dir/dir": ensure => directory} + file { "/tmp/6418-copy": ensure => present, source => "/tmp/6418/" } + + File["/tmp/6418"] -> File["/tmp/6418/dir"] -> File["/tmp/6418/dir/dir"] -> File["/tmp/6418/dir/dir/dir"] -> File["/tmp/6418-copy"] +} + +step "Apply the manifest" +apply_manifest_on agents, manifest +on agents, "! grep ensure.*directory /var/lib/puppet/state/state.yaml" diff --git a/acceptance/tests/ticket_6541_invalid_filebucket_files.rb b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb new file mode 100644 index 000000000..25bcff452 --- /dev/null +++ b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb @@ -0,0 +1,26 @@ +test_name "start with a file" +manifest = "file { '/tmp/6541': content => 'some text' }" +apply_manifest_on(agents, manifest) + +test_name "verify invalid hashes should not change the file" +manifest = "file { '/tmp/6541': content => '{md5}notahash' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" if + stdout =~ /content changed/ +end + +test_name "verify valid but unbucketed hashes should not change the file" +manifest = "file { '/tmp/6541': content => '{md5}13ad7345d56b566a4408ffdcd877bc78' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" if + stdout =~ /content changed/ +end + +on(agents, puppet_filebucket("backup -l /dev/null") ) + +test_name "verify that an empty file can be retrieved from the filebucket" +manifest = "file { '/tmp/6541': content => '{md5}d41d8cd98f00b204e9800998ecf8427e' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" unless + stdout =~ /content changed '\{md5\}552e21cd4cd9918678e3c1a0df491bc3' to '\{md5\}d41d8cd98f00b204e9800998ecf8427e'/ +end diff --git a/acceptance/tests/ticket_6734_6256_5530_5503.rb b/acceptance/tests/ticket_6734_6256_5530_5503.rb new file mode 100644 index 000000000..fe8866901 --- /dev/null +++ b/acceptance/tests/ticket_6734_6256_5530_5503.rb @@ -0,0 +1,16 @@ +# Puppet master fails to start due to impropper +# permissons on the puppet/ dir. Specially, the rrd +# sub dir is not created when puppet master starts + +test_name "Tickets 6734 6256 5530 5503i Puppet Master fails to start" + +# Kill running Puppet Master +step "Check for running Puppet Master" +on master, "ps -ef | grep puppet" + fail_test "Puppet Master not running" unless + stdout.include? 'master' + +step "Check permissions on puppet/rrd/" +on master, "ls -l /var/lib/puppet | grep rrd | awk '{print $3\" \"$4}'" + fail_test "puppet/rrd does not exist/wrong permission" unless + stdout.include? 'puppet puppet' diff --git a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb new file mode 100644 index 000000000..aac53138a --- /dev/null +++ b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb @@ -0,0 +1,38 @@ +test_name "#6928: Puppet --parseonly should return deprication message" + +# Create good and bad formatted manifests +step "Master: create valid, invalid formatted manifests" +create_remote_file(master, '/tmp/good.pp', %w{notify{good:}} ) +create_remote_file(master, '/tmp/bad.pp', 'notify{bad:') + +step "Master: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning" +on master, puppet_master( %w{--parseonly /tmp/bad.pp} ), :acceptable_exit_codes => [ 1 ] + fail_test "Deprecation warning not issued for --parseonly" unless + stdout.include? '--parseonly has been removed. Please use \'puppet parser validate \'' + +step "Agents: create valid, invalid formatted manifests" +agents.each do |host| + create_remote_file(host, '/tmp/good.pp', %w{notify{good:}} ) + create_remote_file(host, '/tmp/bad.pp', 'notify{bad:') +end + +step "Agents: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning" +agents.each do |host| + on(host, "puppet --parseonly /tmp/bad.pp}", :acceptable_exit_codes => [ 1 ]) do + fail_test "Deprecation warning not issued for --parseonly" unless + stdout.include? '--parseonly has been removed. Please use \'puppet parser validate \'' + end +end + +step "Test Face for ‘parser validate’ with good manifest -- should pass" +agents.each do |host| + on(host, "puppet parser validate /tmp/good.pp", :acceptable_exit_codes => [ 0 ]) +end + +step "Test Face for ‘parser validate’ with bad manifest -- should fail" +agents.each do |host| + on(host, "puppet parser validate /tmp/bad.pp", :acceptable_exit_codes => [ 1 ]) do + fail_test "Bad manifest detection failed" unless + stderr.include? 'Could not run: Could not parse for environment production' + end +end -- cgit From 7b3744cd363c817c515f865ccdf45bdfbdb5796b Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 20 Apr 2011 15:22:57 -0700 Subject: maint: stop stubbing log level setting. The underlying problem turned up when another test (as a side effect) changed the logging level to be more verbose, and a very distant test broke. This revealed that we didn't preserve that global state around tests. Fixing that further revealed that we stubbed setting that log level all over the place, as a point fix for the same problem, and to assert the operation of various tools. So, additionally, we strip out all that stubbing, and assert on the desired effect rather than the mechanism for achieving it. Reviewed-By: Max Martin --- spec/spec_helper.rb | 3 +++ spec/unit/application/agent_spec.rb | 9 ++------- spec/unit/application/apply_spec.rb | 10 ++-------- spec/unit/application/cert_spec.rb | 10 ++-------- spec/unit/application/device_spec.rb | 10 ++-------- spec/unit/application/doc_spec.rb | 8 ++------ spec/unit/application/filebucket_spec.rb | 10 ++-------- spec/unit/application/kick_spec.rb | 10 ++-------- spec/unit/application/master_spec.rb | 10 ++-------- spec/unit/application/queue_spec.rb | 9 ++------- spec/unit/application/resource_spec.rb | 10 ++-------- spec/unit/application_spec.rb | 4 +--- 12 files changed, 24 insertions(+), 79 deletions(-) mode change 100644 => 100755 spec/unit/application/device_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1187c1caf..b04ec6ffd 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,6 +50,8 @@ RSpec.configure do |config| @logs = [] Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) + + @log_level = Puppet::Util::Log.level end config.after :each do @@ -62,6 +64,7 @@ RSpec.configure do |config| @logs.clear Puppet::Util::Log.close_all + Puppet::Util::Log.level = @log_level GC.enable end diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index 03cf14429..b30a8cc6c 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -18,7 +18,6 @@ describe Puppet::Application::Agent do Puppet::Agent.stubs(:new).returns(@agent) @puppetd.preinit Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) Puppet::Node.indirection.stubs(:terminus_class=) Puppet::Node.indirection.stubs(:cache_class=) @@ -223,18 +222,14 @@ describe Puppet::Application::Agent do it "should set log level to debug if --debug was passed" do @puppetd.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Util::Log.expects(:level=).with(:debug) - @puppetd.setup_logs + Puppet::Util::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @puppetd.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Util::Log.expects(:level=).with(:info) - @puppetd.setup_logs + Puppet::Util::Log.level.should == :info end [:verbose, :debug].each do |level| diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index dca2a4156..ec3f083db 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -9,7 +9,6 @@ describe Puppet::Application::Apply do before :each do @apply = Puppet::Application[:apply] Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) end [:debug,:loadclasses,:verbose,:use_nodes,:detailed_exitcodes].each do |option| @@ -51,7 +50,6 @@ describe Puppet::Application::Apply do before :each do Puppet::Log.stubs(:newdestination) - Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) @@ -84,18 +82,14 @@ describe Puppet::Application::Apply do it "should set log level to debug if --debug was passed" do @apply.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Log.expects(:level=).with(:debug) - @apply.setup + Puppet::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @apply.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Log.expects(:level=).with(:info) - @apply.setup + Puppet::Log.level.should == :info end it "should print puppet config if asked to in Puppet config" do diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb index a1b5eb19a..4a91c1e6c 100755 --- a/spec/unit/application/cert_spec.rb +++ b/spec/unit/application/cert_spec.rb @@ -6,7 +6,6 @@ describe Puppet::Application::Cert do before :each do @cert_app = Puppet::Application[:cert] Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) end it "should operate in master run_mode" do @@ -28,22 +27,17 @@ describe Puppet::Application::Cert do end it "should set log level to info with the --verbose option" do - - Puppet::Log.expects(:level=).with(:info) - @cert_app.handle_verbose(0) + Puppet::Log.level.should == :info end it "should set log level to debug with the --debug option" do - - Puppet::Log.expects(:level=).with(:debug) - @cert_app.handle_debug(0) + Puppet::Log.level.should == :debug end it "should set the fingerprint digest with the --digest option" do @cert_app.handle_digest(:digest) - @cert_app.digest.should == :digest end diff --git a/spec/unit/application/device_spec.rb b/spec/unit/application/device_spec.rb old mode 100644 new mode 100755 index 086e321e9..832b7e55b --- a/spec/unit/application/device_spec.rb +++ b/spec/unit/application/device_spec.rb @@ -10,10 +10,8 @@ require 'puppet/configurer' describe Puppet::Application::Device do before :each do @device = Puppet::Application[:device] -# @device.stubs(:puts) @device.preinit Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) Puppet::Node.indirection.stubs(:terminus_class=) Puppet::Node.indirection.stubs(:cache_class=) @@ -144,18 +142,14 @@ describe Puppet::Application::Device do it "should set log level to debug if --debug was passed" do @device.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Util::Log.expects(:level=).with(:debug) - @device.setup_logs + Puppet::Util::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @device.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Util::Log.expects(:level=).with(:info) - @device.setup_logs + Puppet::Util::Log.level.should == :info end [:verbose, :debug].each do |level| diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index 66a833b9d..43a4b9849 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -11,7 +11,6 @@ describe Puppet::Application::Doc do @doc.stubs(:puts) @doc.preinit Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) end it "should ask Puppet::Application to not parse Puppet configuration file" do @@ -186,7 +185,6 @@ describe Puppet::Application::Doc do before :each do @doc.options.stubs(:[]).returns(false) Puppet.stubs(:parse_config) - Puppet::Util::Log.stubs(:level=) Puppet::Util::Log.stubs(:newdestination) end @@ -232,16 +230,14 @@ describe Puppet::Application::Doc do it "should set log level to debug if --debug" do @doc.options.stubs(:[]).with(:debug).returns(true) - Puppet::Util::Log.expects(:level=).with(:debug) - @doc.setup_rdoc + Puppet::Util::Log.level.should == :debug end it "should set log level to info if --verbose" do @doc.options.stubs(:[]).with(:verbose).returns(true) - Puppet::Util::Log.expects(:level=).with(:info) - @doc.setup_rdoc + Puppet::Util::Log.level.should == :info end it "should set log destination to console if --verbose" do diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb index 8ba86be9e..92bc0410a 100755 --- a/spec/unit/application/filebucket_spec.rb +++ b/spec/unit/application/filebucket_spec.rb @@ -41,7 +41,6 @@ describe Puppet::Application::Filebucket do before :each do Puppet::Log.stubs(:newdestination) Puppet.stubs(:settraps) - Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) @filebucket.options.stubs(:[]).with(any_parameters) @@ -62,18 +61,14 @@ describe Puppet::Application::Filebucket do it "should set log level to debug if --debug was passed" do @filebucket.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Log.expects(:level=).with(:debug) - @filebucket.setup + Puppet::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @filebucket.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Log.expects(:level=).with(:info) - @filebucket.setup + Puppet::Log.level.should == :info end it "should Parse puppet config" do @@ -140,7 +135,6 @@ describe Puppet::Application::Filebucket do before :each do Puppet::Log.stubs(:newdestination) Puppet.stubs(:settraps) - Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) @filebucket.options.stubs(:[]).with(any_parameters) diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb index 29e4caea4..742c0fff6 100755 --- a/spec/unit/application/kick_spec.rb +++ b/spec/unit/application/kick_spec.rb @@ -10,7 +10,6 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything) @kick = Puppet::Application[:kick] Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) end describe ".new" do @@ -120,7 +119,6 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do @kick.classes = [] @kick.tags = [] @kick.hosts = [] - Puppet::Log.stubs(:level=) @kick.stubs(:trap) @kick.stubs(:puts) Puppet.stubs(:parse_config) @@ -130,18 +128,14 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do it "should set log level to debug if --debug was passed" do @kick.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Log.expects(:level=).with(:debug) - @kick.setup + Puppet::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @kick.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Log.expects(:level=).with(:info) - @kick.setup + Puppet::Log.level.should == :info end it "should Parse puppet config" do diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb index ea5d3f518..2a24086f3 100755 --- a/spec/unit/application/master_spec.rb +++ b/spec/unit/application/master_spec.rb @@ -11,7 +11,6 @@ describe Puppet::Application::Master do @daemon = stub_everything 'daemon' Puppet::Daemon.stubs(:new).returns(@daemon) Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) Puppet::Node.indirection.stubs(:terminus_class=) Puppet::Node.indirection.stubs(:cache_class=) @@ -111,7 +110,6 @@ describe Puppet::Application::Master do before :each do Puppet::Log.stubs(:newdestination) Puppet.stubs(:settraps) - Puppet::Log.stubs(:level=) Puppet::SSL::CertificateAuthority.stubs(:instance) Puppet::SSL::CertificateAuthority.stubs(:ca?) Puppet.settings.stubs(:use) @@ -121,18 +119,14 @@ describe Puppet::Application::Master do it "should set log level to debug if --debug was passed" do @master.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Log.expects(:level=).with(:debug) - @master.setup + Puppet::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @master.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Log.expects(:level=).with(:info) - @master.setup + Puppet::Log.level.should == :info end it "should set console as the log destination if no --logdest and --daemonize" do diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb index 87713ca97..d71c879a9 100755 --- a/spec/unit/application/queue_spec.rb +++ b/spec/unit/application/queue_spec.rb @@ -10,7 +10,6 @@ describe Puppet::Application::Queue do @queue.stubs(:puts) @daemon = stub_everything 'daemon', :daemonize => nil Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) Puppet::Resource::Catalog.indirection.stubs(:terminus_class=) end @@ -113,18 +112,14 @@ describe Puppet::Application::Queue do it "should set log level to debug if --debug was passed" do @queue.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Util::Log.expects(:level=).with(:debug) - @queue.setup_logs + Puppet::Util::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @queue.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Util::Log.expects(:level=).with(:info) - @queue.setup_logs + Puppet::Util::Log.level.should == :info end [:verbose, :debug].each do |level| diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb index 673bd65d7..af60f12c1 100755 --- a/spec/unit/application/resource_spec.rb +++ b/spec/unit/application/resource_spec.rb @@ -7,7 +7,6 @@ describe Puppet::Application::Resource do before :each do @resource = Puppet::Application[:resource] Puppet::Util::Log.stubs(:newdestination) - Puppet::Util::Log.stubs(:level=) Puppet::Resource.indirection.stubs(:terminus_class=) end @@ -95,7 +94,6 @@ describe Puppet::Application::Resource do describe "during setup" do before :each do Puppet::Log.stubs(:newdestination) - Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) end @@ -108,19 +106,15 @@ describe Puppet::Application::Resource do it "should set log level to debug if --debug was passed" do @resource.options.stubs(:[]).with(:debug).returns(true) - - Puppet::Log.expects(:level=).with(:debug) - @resource.setup + Puppet::Log.level.should == :debug end it "should set log level to info if --verbose was passed" do @resource.options.stubs(:[]).with(:debug).returns(false) @resource.options.stubs(:[]).with(:verbose).returns(true) - - Puppet::Log.expects(:level=).with(:info) - @resource.setup + Puppet::Log.level.should == :info end it "should Parse puppet config" do diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index f46959092..de1ca1257 100755 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -369,10 +369,8 @@ describe Puppet::Application do it "should honor option #{level}" do @app.options.stubs(:[]).with(level).returns(true) Puppet::Util::Log.stubs(:newdestination) - - Puppet::Util::Log.expects(:level=).with(level == :verbose ? :info : :debug) - @app.setup + Puppet::Util::Log.level.should == (level == :verbose ? :info : :debug) end end -- cgit From 677752d44e180d7293fbae6594f51fe7d41fb3fc Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 20 Apr 2011 16:26:02 -0700 Subject: maint: handle face clear/reset sanely in the interface spec. We used to flush the loaded face cache, but not the list of 'require' things, which meant that these tests couldn't work with anything outside their own setup, which is actually pretty undesirable. Instead, port the code from the face_collection spec that handles this in a way that makes me less inclined to weep, and which lets the surrounding code work as designed. --- spec/unit/interface_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb index b4fef0307..5eb7922a2 100755 --- a/spec/unit/interface_spec.rb +++ b/spec/unit/interface_spec.rb @@ -5,16 +5,17 @@ require 'puppet/interface' describe Puppet::Interface do subject { Puppet::Interface } - before :all do - @faces = Puppet::Interface::FaceCollection.instance_variable_get("@faces").dup - end - before :each do + @faces = Puppet::Interface::FaceCollection. + instance_variable_get("@faces").dup + @dq = $".dup + $".delete_if do |path| path =~ %r{/face/.*\.rb$} end Puppet::Interface::FaceCollection.instance_variable_get("@faces").clear end - after :all do + after :each do Puppet::Interface::FaceCollection.instance_variable_set("@faces", @faces) + $".clear ; @dq.each do |item| $" << item end end describe "#[]" do -- cgit From eeb82361de00f86f0840c2fcdd30a5e84c49232d Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 20 Apr 2011 16:56:45 -0700 Subject: maint: better error report for a missing version of a face. We would report this: Could not find version 1.0.0 of Puppet::Face[:version_matching, "2.0.0"] That is not actually so helpful, not least because people wonder why it reports a version number they didn't ask for. Instead, we just report the requested name now. --- lib/puppet/interface.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index 5c8ade749..b48f963ec 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -53,7 +53,7 @@ class Puppet::Interface def [](name, version) unless face = Puppet::Interface::FaceCollection[name, version] if current = Puppet::Interface::FaceCollection[name, :current] - raise Puppet::Error, "Could not find version #{version} of #{current}" + raise Puppet::Error, "Could not find version #{version} of #{name}" else raise Puppet::Error, "Could not find Puppet Face #{name.inspect}" end -- cgit From 7db4793eac52cbbf9c5919597e8e3a6b0a7bbd38 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 20 Apr 2011 19:04:50 -0700 Subject: maint: clean up testing code a fraction... This rewrites a block of identical tests down to a little table, then applies the test over that. --- spec/unit/interface/face_collection_spec.rb | 32 +++++++++-------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb index f9498cbb8..c3e43435c 100755 --- a/spec/unit/interface/face_collection_spec.rb +++ b/spec/unit/interface/face_collection_spec.rb @@ -25,28 +25,16 @@ describe Puppet::Interface::FaceCollection do end describe "::validate_version" do - it 'should permit three number versions' do - subject.validate_version('10.10.10').should == true - end - - it 'should permit versions with appended descriptions' do - subject.validate_version('10.10.10beta').should == true - end - - it 'should not permit versions with more than three numbers' do - subject.validate_version('1.2.3.4').should == false - end - - it 'should not permit versions with only two numbers' do - subject.validate_version('10.10').should == false - end - - it 'should not permit versions with only one number' do - subject.validate_version('123').should == false - end - - it 'should not permit versions with text in any position but at the end' do - subject.validate_version('v1.1.1').should == false + { '10.10.10' => true, + '1.2.3.4' => false, + '10.10.10beta' => true, + '10.10' => false, + '123' => false, + 'v1.1.1' => false, + }.each do |input, result| + it "should#{result ? '' : ' not'} permit #{input.inspect}" do + subject.validate_version(input).should(result ? be_true : be_false) + end end end -- cgit From 03bd5595365b7d541d20ed614e9c8be6a7cba9c9 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 21 Apr 2011 10:38:25 -0700 Subject: maint: more robust listing of valid faces. We used to treat anything with a top level key in the faces hash as a valid face; it makes more sense to filter that only to things that have at least one implementation. Previously we had to be super-careful not to accidentally touch the top level for an invalid face, which set us up for future failure when someone wasn't careful enough; now we can cope with that. Paired-With: Max Martin --- lib/puppet/interface/face_collection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb index 591471d4b..49e007ec0 100644 --- a/lib/puppet/interface/face_collection.rb +++ b/lib/puppet/interface/face_collection.rb @@ -24,7 +24,7 @@ module Puppet::Interface::FaceCollection end end end - return @faces.keys + return @faces.keys.select {|name| @faces[name].length > 0 } end def self.validate_version(version) -- cgit From 7414ee7ebda1052f4c52f3e5565726f20de5a20b Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 21 Apr 2011 12:03:13 -0700 Subject: maint: better disabling of Signal#trap in our tests. We tried to stub out the trap method on signal to stop our application level signal handlers getting in the way, but it kept not sticking. Now, instead, we just stub it out globally at the module level in our spec helper. Less fun, but more effective. Until rspec starts installing a signal handler, at least. :) --- spec/monkey_patches/disable_signal_trap.rb | 5 +++++ spec/spec_helper.rb | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 spec/monkey_patches/disable_signal_trap.rb diff --git a/spec/monkey_patches/disable_signal_trap.rb b/spec/monkey_patches/disable_signal_trap.rb new file mode 100644 index 000000000..5159626e3 --- /dev/null +++ b/spec/monkey_patches/disable_signal_trap.rb @@ -0,0 +1,5 @@ +module Signal + def trap(*args) + # The goggles, they do nothing! + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b04ec6ffd..01ffabc48 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,6 +22,7 @@ require 'lib/puppet_spec/files' require 'lib/puppet_spec/fixtures' require 'monkey_patches/alias_should_to_must' require 'monkey_patches/publicize_methods' +require 'monkey_patches/disable_signal_trap' Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour| require behaviour.relative_path_from(Pathname.new(dir)) @@ -38,6 +39,10 @@ RSpec.configure do |config| # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil + + # REVISIT: I think this conceals other bad tests, but I don't have time to + # fully diagnose those right now. When you read this, please come tell me + # I suck for letting this float. --daniel 2011-04-21 Signal.stubs(:trap) # Set the confdir and vardir to gibberish so that tests -- cgit From f17f6bba87519db888854acf7017ddff61f635be Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 20 Apr 2011 15:51:39 -0700 Subject: (#7183) Implement "invisible glob" version matching for faces "Invisible glob", or "prefix", version matching means that when you specify a version string to use you can specify as little as one version number out of the semantic versioning spec. Matching is done on the prefix; an omitted number is treated as "anything" in that slot, and we return the highest matching versioned face by that spec. For example, given the set of versions: 1.0.0, 1.0.1, 1.1.0, 1.1.1, 2.0.0 The following would be matched: input matched 1 1.1.1 1.0 1.0.1 1.0.1 1.0.1 1.0.2 fail - no match 1.1 1.1.1 1.1.1 1.1.1 1.2 fail - no match --- lib/puppet/interface.rb | 13 +++---- lib/puppet/interface/face_collection.rb | 58 +++++++++++++++++------------ spec/lib/puppet/face/version_matching.rb | 10 +++++ spec/unit/interface/face_collection_spec.rb | 42 ++++++++++++--------- spec/unit/interface_spec.rb | 22 +++++++++++ 5 files changed, 98 insertions(+), 47 deletions(-) create mode 100644 spec/lib/puppet/face/version_matching.rb diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index b48f963ec..ced00863d 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -26,18 +26,13 @@ class Puppet::Interface Puppet::Interface::FaceCollection.faces end - def face?(name, version) - Puppet::Interface::FaceCollection.face?(name, version) - end - def register(instance) Puppet::Interface::FaceCollection.register(instance) end def define(name, version, &block) - if face?(name, version) - face = Puppet::Interface::FaceCollection[name, version] - else + face = Puppet::Interface::FaceCollection[name, version] + if face.nil? then face = self.new(name, version) Puppet::Interface::FaceCollection.register(face) # REVISIT: Shouldn't this be delayed until *after* we evaluate the @@ -50,6 +45,10 @@ class Puppet::Interface return face end + def face?(name, version) + Puppet::Interface::FaceCollection[name, version] + end + def [](name, version) unless face = Puppet::Interface::FaceCollection[name, version] if current = Puppet::Interface::FaceCollection[name, :current] diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb index 49e007ec0..6e6afc545 100644 --- a/lib/puppet/interface/face_collection.rb +++ b/lib/puppet/interface/face_collection.rb @@ -31,12 +31,14 @@ module Puppet::Interface::FaceCollection !!(SEMVER_VERSION =~ version.to_s) end + def self.semver_to_array(v) + parts = SEMVER_VERSION.match(v).to_a[1..4] + parts[0..2] = parts[0..2].map { |e| e.to_i } + parts + end + def self.cmp_semver(a, b) - a, b = [a, b].map do |x| - parts = SEMVER_VERSION.match(x).to_a[1..4] - parts[0..2] = parts[0..2].map { |e| e.to_i } - parts - end + a, b = [a, b].map do |x| semver_to_array(x) end cmp = a[0..2] <=> b[0..2] if cmp == 0 @@ -47,18 +49,38 @@ module Puppet::Interface::FaceCollection cmp end - def self.[](name, version) - @faces[underscorize(name)][version] if face?(name, version) + def self.prefix_match?(desired, target) + # Can't meaningfully do a prefix match with current on either side. + return false if desired == :current + return false if target == :current + + # REVISIT: Should probably fail if the matcher is not valid. + prefix = desired.split('.').map {|x| x =~ /^\d+$/ and x.to_i } + have = semver_to_array(target) + + while want = prefix.shift do + return false unless want == have.shift + end + return true end - def self.face?(name, version) + def self.[](name, version) name = underscorize(name) + get_face(name, version) or load_face(name, version) + end - # Note: be careful not to accidentally create the top level key, either, - # because it will result in confusion when people try to enumerate the - # list of valid faces later. --daniel 2011-04-11 - return true if @faces.has_key?(name) and @faces[name].has_key?(version) + # get face from memory, without loading. + def self.get_face(name, desired_version) + return nil unless @faces.has_key? name + return @faces[name][:current] if desired_version == :current + + found = @faces[name].keys.select {|v| prefix_match?(desired_version, v) }.sort.last + return @faces[name][found] + end + + # try to load the face, and return it. + def self.load_face(name, version) # We always load the current version file; the common case is that we have # the expected version and any compatibility versions in the same file, # the default. Which means that this is almost always the case. @@ -104,17 +126,7 @@ module Puppet::Interface::FaceCollection # ...guess we didn't find the file; return a much better problem. end - # Now, either we have the version in our set of faces, or we didn't find - # the version they were looking for. In the future we will support - # loading versioned stuff from some look-aside part of the Ruby load path, - # but we don't need that right now. - # - # So, this comment is a place-holder for that. --daniel 2011-04-06 - # - # Note: be careful not to accidentally create the top level key, either, - # because it will result in confusion when people try to enumerate the - # list of valid faces later. --daniel 2011-04-11 - return !! (@faces.has_key?(name) and @faces[name].has_key?(version)) + return get_face(name, version) end def self.register(face) diff --git a/spec/lib/puppet/face/version_matching.rb b/spec/lib/puppet/face/version_matching.rb new file mode 100644 index 000000000..bfd0013f7 --- /dev/null +++ b/spec/lib/puppet/face/version_matching.rb @@ -0,0 +1,10 @@ +require 'puppet/face' + +# The set of versions here are used explicitly in the interface_spec; if you +# change this you need to ensure that is still correct. --daniel 2011-04-21 +['1.0.0', '1.0.1', '1.1.0', '1.1.1', '2.0.0'].each do |version| + Puppet::Face.define(:version_matching, version) do + summary "version matching face #{version}" + script :version do version end + end +end diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb index c3e43435c..890e06a9e 100755 --- a/spec/unit/interface/face_collection_spec.rb +++ b/spec/unit/interface/face_collection_spec.rb @@ -24,6 +24,22 @@ describe Puppet::Interface::FaceCollection do $".clear ; @original_required.each do |item| $" << item end end + describe "::prefix_match?" do + # want have + { ['1.0.0', '1.0.0'] => true, + ['1.0', '1.0.0'] => true, + ['1', '1.0.0'] => true, + ['1.0.0', '1.1.0'] => false, + ['1.0', '1.1.0'] => false, + ['1', '1.1.0'] => true, + ['1.0.1', '1.0.0'] => false, + }.each do |data, result| + it "should return #{result.inspect} for prefix_match?(#{data.join(', ')})" do + subject.prefix_match?(*data).should == result + end + end + end + describe "::validate_version" do { '10.10.10' => true, '1.2.3.4' => false, @@ -56,12 +72,10 @@ describe Puppet::Interface::FaceCollection do subject.expects(:require).with('puppet/face/fozzie') subject['fozzie', :current] end - end - describe "::face?" do it "should return true if the face specified is registered" do subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 - subject.face?("foo", '0.0.1').should == true + subject["foo", '0.0.1'].should == 10 end it "should attempt to require the face if it is not registered" do @@ -69,24 +83,18 @@ describe Puppet::Interface::FaceCollection do subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true file == 'puppet/face/bar' end - subject.face?("bar", '0.0.1').should == true - end - - it "should return true if requiring the face registered it" do - subject.stubs(:require).with do - subject.instance_variable_get("@faces")[:bar]['0.0.1'] = 20 - end + subject["bar", '0.0.1'].should be_true end it "should return false if the face is not registered" do subject.stubs(:require).returns(true) - subject.face?("bar", '0.0.1').should be_false + subject["bar", '0.0.1'].should be_false end it "should return false if the face file itself is missing" do subject.stubs(:require). raises(LoadError, 'no such file to load -- puppet/face/bar') - subject.face?("bar", '0.0.1').should be_false + subject["bar", '0.0.1'].should be_false end it "should register the version loaded by `:current` as `:current`" do @@ -94,26 +102,26 @@ describe Puppet::Interface::FaceCollection do subject.instance_variable_get("@faces")[:huzzah]['2.0.1'] = :huzzah_face file == 'puppet/face/huzzah' end - subject.face?("huzzah", :current) + subject["huzzah", :current] subject.instance_variable_get("@faces")[:huzzah][:current].should == :huzzah_face end context "with something on disk" do it "should register the version loaded from `puppet/face/{name}` as `:current`" do - subject.should be_face "huzzah", '2.0.1' - subject.should be_face "huzzah", :current + subject["huzzah", '2.0.1'].should be + subject["huzzah", :current].should be Puppet::Face[:huzzah, '2.0.1'].should == Puppet::Face[:huzzah, :current] end it "should index :current when the code was pre-required" do subject.instance_variable_get("@faces")[:huzzah].should_not be_key :current require 'puppet/face/huzzah' - subject.face?(:huzzah, :current).should be_true + subject[:huzzah, :current].should be_true end end it "should not cause an invalid face to be enumerated later" do - subject.face?(:there_is_no_face, :current).should be_false + subject[:there_is_no_face, :current].should be_false subject.faces.should_not include :there_is_no_face end end diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb index 5eb7922a2..a1d70cf64 100755 --- a/spec/unit/interface_spec.rb +++ b/spec/unit/interface_spec.rb @@ -30,6 +30,28 @@ describe Puppet::Interface do it "should raise an exception when the requested face doesn't exist" do expect { subject[:burrble_toot, :current] }.should raise_error, Puppet::Error end + + describe "version matching" do + { '1' => '1.1.1', + '1.0' => '1.0.1', + '1.0.1' => '1.0.1', + '1.1' => '1.1.1', + '1.1.1' => '1.1.1' + }.each do |input, expect| + it "should match #{input.inspect} to #{expect.inspect}" do + face = subject[:version_matching, input] + face.should be + face.version.should == expect + end + end + + %w{1.0.2 1.2}.each do |input| + it "should not match #{input.inspect} to any version" do + expect { subject[:version_matching, input] }. + to raise_error Puppet::Error, /Could not find version/ + end + end + end end describe "#define" do -- cgit From a0de3288bad113c9be1190095b03e892e17000d2 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 21 Apr 2011 14:46:36 -0700 Subject: (#6928) backport Symbol#to_proc for Ruby < 1.8.7 We use the &:foo symbol-to-proc syntax in some of our code, so to avoid problems on Ruby earlier than 1.8.7 we should backport the support in our monkey-patch file. Reviewed-By: Max Martin --- lib/puppet/util/monkey_patches.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 10a268409..9ae0ca6a2 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -104,3 +104,12 @@ class Array end end unless method_defined? :combination end + + +if Symbol.instance_method(:to_proc).nil? + class Symbol + def to_proc + Proc.new { |*args| args.shift.__send__(self, *args) } + end + end +end -- cgit From de2199f3666ca9e26a0a36ec17b176300a4fa599 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 21 Apr 2011 15:01:38 -0700 Subject: (#6928) Don't blow up when the method is undefined... Use the same model for testing instance methods as the rest of the code. Reviewed-By: Max Martin --- lib/puppet/util/monkey_patches.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 9ae0ca6a2..bd954c665 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -106,10 +106,8 @@ class Array end -if Symbol.instance_method(:to_proc).nil? - class Symbol - def to_proc - Proc.new { |*args| args.shift.__send__(self, *args) } - end - end +class Symbol + def to_proc + Proc.new { |*args| args.shift.__send__(self, *args) } + end unless method_defined? :to_proc end -- cgit