diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-01 10:44:35 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 13:31:38 -0700 |
| commit | eb4c4fbdc3951c220a76ec01abc33a7654d89e53 (patch) | |
| tree | 513ca3fe7b5ad9e94ab8660a773c9f53f72297f3 | |
| parent | 8723b1c2102a181d23c9fe4ede7d58294f7c18ba (diff) | |
| download | puppet-eb4c4fbdc3951c220a76ec01abc33a7654d89e53.tar.gz puppet-eb4c4fbdc3951c220a76ec01abc33a7654d89e53.tar.xz puppet-eb4c4fbdc3951c220a76ec01abc33a7654d89e53.zip | |
(#6749) Start porting existing strings to the options API.
This provides a solid test of the new code, by migrating the existing strings
to match. This also gives us a chance to determine any weak points in the
code as written.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
| -rw-r--r-- | lib/puppet/application/configurer.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/application/string.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/string/action.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/string/catalog.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/string/catalog/select.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/string/certificate.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/string/config.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/string/configurer.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/string/facts.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/string/report.rb | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/unit/application/configurer_spec.rb | 0 | ||||
| -rwxr-xr-x | spec/unit/string/action_builder_spec.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/string/indirector_spec.rb | 4 | ||||
| -rw-r--r-- | spec/unit/string/option_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/string_spec.rb | 8 |
15 files changed, 23 insertions, 22 deletions
diff --git a/lib/puppet/application/configurer.rb b/lib/puppet/application/configurer.rb index b440098ee..be018338f 100644 --- a/lib/puppet/application/configurer.rb +++ b/lib/puppet/application/configurer.rb @@ -5,8 +5,8 @@ class Puppet::Application::Configurer < Puppet::Application should_parse_config run_mode :agent - option("--debug","-d") - option("--verbose","-v") + option("--debug", "-d") + option("--verbose", "-v") def setup if options[:debug] or options[:verbose] diff --git a/lib/puppet/application/string.rb b/lib/puppet/application/string.rb index aa369e669..0a6a798ce 100644 --- a/lib/puppet/application/string.rb +++ b/lib/puppet/application/string.rb @@ -83,7 +83,7 @@ class Puppet::Application::String < Puppet::Application def actions(indirection) return [] unless string = Puppet::String[indirection, '0.0.1'] string.load_actions - return string.actions.sort { |a,b| a.to_s <=> b.to_s } + return string.actions.sort { |a, b| a.to_s <=> b.to_s } end def load_applications diff --git a/lib/puppet/string/action.rb b/lib/puppet/string/action.rb index 9e82f4d5d..ff419c090 100644 --- a/lib/puppet/string/action.rb +++ b/lib/puppet/string/action.rb @@ -14,7 +14,7 @@ class Puppet::String::Action @string = string @name = name.to_sym @options = {} - attrs.each do |k,v| send("#{k}=", v) end + attrs.each do |k, v| send("#{k}=", v) end end # Initially, this was defined to allow the @action.invoke pattern, which is diff --git a/lib/puppet/string/catalog.rb b/lib/puppet/string/catalog.rb index 0ddd83176..c6de47708 100644 --- a/lib/puppet/string/catalog.rb +++ b/lib/puppet/string/catalog.rb @@ -2,7 +2,7 @@ require 'puppet/string/indirector' Puppet::String::Indirector.define(:catalog, '0.0.1') do action(:apply) do - invoke do |catalog| + invoke do |catalog, options| report = Puppet::Transaction::Report.new("apply") report.configuration_version = catalog.version @@ -23,7 +23,7 @@ Puppet::String::Indirector.define(:catalog, '0.0.1') do end action(:download) do - invoke do |certname,facts| + invoke do |certname, facts, options| Puppet::Resource::Catalog.terminus_class = :rest facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))} catalog = nil diff --git a/lib/puppet/string/catalog/select.rb b/lib/puppet/string/catalog/select.rb index 52c77d3ce..a8f4480cd 100644 --- a/lib/puppet/string/catalog/select.rb +++ b/lib/puppet/string/catalog/select.rb @@ -1,7 +1,7 @@ # Select and show a list of resources of a given type. Puppet::String.define(:catalog, '0.0.1') do action :select do - invoke do |host,type| + invoke do |host, type, options| catalog = Puppet::Resource::Catalog.indirection.find(host) catalog.resources.reject { |res| res.type != type }.each { |res| puts res } diff --git a/lib/puppet/string/certificate.rb b/lib/puppet/string/certificate.rb index 7b2e5f397..53f731e81 100644 --- a/lib/puppet/string/certificate.rb +++ b/lib/puppet/string/certificate.rb @@ -4,7 +4,7 @@ require 'puppet/ssl/host' Puppet::String::Indirector.define(:certificate, '0.0.1') do action :generate do - invoke do |name| + invoke do |name, options| host = Puppet::SSL::Host.new(name) host.generate_certificate_request host.certificate_request.class.indirection.save(host.certificate_request) @@ -12,7 +12,7 @@ Puppet::String::Indirector.define(:certificate, '0.0.1') do end action :list do - invoke do + invoke do |options| Puppet::SSL::Host.indirection.search("*", { :for => :certificate_request, }).map { |h| h.inspect } @@ -20,7 +20,7 @@ Puppet::String::Indirector.define(:certificate, '0.0.1') do end action :sign do - invoke do |name| + invoke do |name, options| Puppet::SSL::Host.indirection.save(Puppet::SSL::Host.new(name)) end end diff --git a/lib/puppet/string/config.rb b/lib/puppet/string/config.rb index ae1a408cf..49a1688fc 100644 --- a/lib/puppet/string/config.rb +++ b/lib/puppet/string/config.rb @@ -3,6 +3,7 @@ require 'puppet/string' Puppet::String.define(:config, '0.0.1') do action(:print) do invoke do |*args| + options = args.pop Puppet.settings[:configprint] = args.join(",") Puppet.settings.print_config_options nil diff --git a/lib/puppet/string/configurer.rb b/lib/puppet/string/configurer.rb index a6ea74b6a..2520d4188 100644 --- a/lib/puppet/string/configurer.rb +++ b/lib/puppet/string/configurer.rb @@ -2,7 +2,7 @@ require 'puppet/string' Puppet::String.define(:configurer, '0.0.1') do action(:synchronize) do - invoke do |certname| + invoke do |certname, options| facts = Puppet::String[:facts, '0.0.1'].find(certname) catalog = Puppet::String[:catalog, '0.0.1'].download(certname, facts) report = Puppet::String[:catalog, '0.0.1'].apply(catalog) diff --git a/lib/puppet/string/facts.rb b/lib/puppet/string/facts.rb index 73acb0df6..31298813b 100644 --- a/lib/puppet/string/facts.rb +++ b/lib/puppet/string/facts.rb @@ -6,7 +6,7 @@ Puppet::String::Indirector.define(:facts, '0.0.1') do # Upload our facts to the server action(:upload) do - invoke do |*args| + invoke do |options| Puppet::Node::Facts.indirection.terminus_class = :facter facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) Puppet::Node::Facts.indirection.terminus_class = :rest diff --git a/lib/puppet/string/report.rb b/lib/puppet/string/report.rb index 55a008533..5b617e49e 100644 --- a/lib/puppet/string/report.rb +++ b/lib/puppet/string/report.rb @@ -2,7 +2,7 @@ require 'puppet/string/indirector' Puppet::String::Indirector.define(:report, '0.0.1') do action(:submit) do - invoke do |report| + invoke do |report, options| begin Puppet::Transaction::Report.terminus_class = :rest report.save diff --git a/spec/unit/application/configurer_spec.rb b/spec/unit/application/configurer_spec.rb index 621039bcc..621039bcc 100644..100755 --- a/spec/unit/application/configurer_spec.rb +++ b/spec/unit/application/configurer_spec.rb diff --git a/spec/unit/string/action_builder_spec.rb b/spec/unit/string/action_builder_spec.rb index 0229fe44d..fde010d51 100755 --- a/spec/unit/string/action_builder_spec.rb +++ b/spec/unit/string/action_builder_spec.rb @@ -6,7 +6,7 @@ require 'puppet/string/action_builder' describe Puppet::String::ActionBuilder do describe "::build" do it "should build an action" do - action = Puppet::String::ActionBuilder.build(nil,:foo) do + action = Puppet::String::ActionBuilder.build(nil, :foo) do end action.should be_a(Puppet::String::Action) action.name.should == :foo @@ -24,7 +24,7 @@ describe Puppet::String::ActionBuilder do end it "should require a block" do - lambda { Puppet::String::ActionBuilder.build(nil,:foo) }. + lambda { Puppet::String::ActionBuilder.build(nil, :foo) }. should raise_error("Action :foo must specify a block") end diff --git a/spec/unit/string/indirector_spec.rb b/spec/unit/string/indirector_spec.rb index 89306c416..da5f569dc 100755 --- a/spec/unit/string/indirector_spec.rb +++ b/spec/unit/string/indirector_spec.rb @@ -33,8 +33,8 @@ describe Puppet::String::Indirector do Puppet::String::Indirector.should be_action(method) end - it "should just call the indirection method when the '#{method}' action is invoked" do - @instance.indirection.expects(method).with(:test, "myargs") + it "should call the indirection method when the '#{method}' action is invoked" do + @instance.indirection.expects(method).with(:test, "myargs", {}) @instance.send(method, :test, "myargs") end end diff --git a/spec/unit/string/option_spec.rb b/spec/unit/string/option_spec.rb index fc7b8329b..f4f62ec37 100644 --- a/spec/unit/string/option_spec.rb +++ b/spec/unit/string/option_spec.rb @@ -5,7 +5,7 @@ describe Puppet::String::Option do describe "#optparse_to_name" do ["", "=BAR", " BAR", "=bar", " bar"].each do |postfix| - { "--foo" => :foo, "-f" => :f,}.each do |base, expect| + { "--foo" => :foo, "-f" => :f }.each do |base, expect| input = base + postfix it "should map #{input.inspect} to #{expect.inspect}" do option = Puppet::String::Option.new(string, input) diff --git a/spec/unit/string_spec.rb b/spec/unit/string_spec.rb index 7f7489e2e..ddf855475 100755 --- a/spec/unit/string_spec.rb +++ b/spec/unit/string_spec.rb @@ -41,7 +41,7 @@ describe Puppet::String do end it "should instance-eval any provided block" do - face = Puppet::String.new(:string_test_block,'0.0.1') do + face = Puppet::String.new(:string_test_block, '0.0.1') do action(:something) do invoke { "foo" } end @@ -52,15 +52,15 @@ describe Puppet::String do end it "should have a name" do - Puppet::String.new(:me,'0.0.1').name.should == :me + Puppet::String.new(:me, '0.0.1').name.should == :me end it "should stringify with its own name" do - Puppet::String.new(:me,'0.0.1').to_s.should =~ /\bme\b/ + Puppet::String.new(:me, '0.0.1').to_s.should =~ /\bme\b/ end it "should allow overriding of the default format" do - face = Puppet::String.new(:me,'0.0.1') + face = Puppet::String.new(:me, '0.0.1') face.set_default_format :foo face.default_format.should == :foo end |
