diff options
author | Matt Robinson <matt@puppetlabs.com> | 2010-06-30 12:19:29 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-01 13:48:03 -0700 |
commit | 75e0662168936da8255507a10bccad8889326947 (patch) | |
tree | 93e30eb595a8d49f00c02634cfa5be3d4dc6f14a | |
parent | 3cd48d836c9ffe4e59bca78f1033020cecf63354 (diff) | |
download | puppet-75e0662168936da8255507a10bccad8889326947.tar.gz puppet-75e0662168936da8255507a10bccad8889326947.tar.xz puppet-75e0662168936da8255507a10bccad8889326947.zip |
[#4090] Rename mode (:master, :agent, :user) to run_mode
Mode is a terribly overused word. Files use it, puppetdoc uses it, and
certs use it, and those are just the places that I happened to
stumble upon. It makes reading code very confusing and finding things
in code difficult. I know namespacing allows us to reuse words for
method and variable names, but that doesn't mean we should.
-rw-r--r-- | lib/puppet.rb | 6 | ||||
-rw-r--r-- | lib/puppet/application.rb | 14 | ||||
-rw-r--r-- | lib/puppet/application/agent.rb | 2 | ||||
-rw-r--r-- | lib/puppet/application/cert.rb | 2 | ||||
-rw-r--r-- | lib/puppet/application/doc.rb | 2 | ||||
-rw-r--r-- | lib/puppet/application/master.rb | 2 | ||||
-rw-r--r-- | lib/puppet/defaults.rb | 10 | ||||
-rw-r--r-- | lib/puppet/indirector/catalog/compiler.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/file.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/yaml.rb | 2 | ||||
-rw-r--r-- | lib/puppet/network/http/webrick.rb | 2 | ||||
-rw-r--r-- | lib/puppet/ssl/certificate_authority.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/run_mode.rb (renamed from lib/puppet/util/mode.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/util/settings.rb | 18 | ||||
-rwxr-xr-x | spec/unit/application/doc_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/indirector/file_spec.rb | 8 | ||||
-rwxr-xr-x | spec/unit/indirector/yaml_spec.rb | 10 | ||||
-rwxr-xr-x | spec/unit/network/http/webrick_spec.rb | 8 | ||||
-rwxr-xr-x | spec/unit/ssl/certificate_authority_spec.rb | 10 | ||||
-rwxr-xr-x | spec/unit/util/settings_spec.rb | 22 |
20 files changed, 65 insertions, 65 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index a039d258b..4e496e7ba 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -91,9 +91,9 @@ module Puppet @@settings end - def self.mode - require 'puppet/util/mode' - $puppet_application_mode ||= Puppet::Util::Mode.new( :user ) + def self.run_mode + require 'puppet/util/run_mode' + $puppet_application_mode ||= Puppet::Util::RunMode.new( :user ) end def self.application_name diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 97d2c95c1..f74b37573 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -155,7 +155,7 @@ class Application [:restart_requested, :stop_requested].include? run_status end - # Indicates that Puppet::Application believes that it's in usual running mode (no stop/restart request + # Indicates that Puppet::Application believes that it's in usual running run_mode (no stop/restart request # currently active). def clear? run_status.nil? @@ -221,10 +221,10 @@ class Application find(name).new end - def mode( mode_name = nil) - @mode ||= mode_name || @mode || :user - require 'puppet/util/mode' - Puppet::Util::Mode.new( @mode ) + def run_mode( mode_name = nil) + @run_mode ||= mode_name || @run_mode || :user + require 'puppet/util/run_mode' + Puppet::Util::RunMode.new( @run_mode ) end end @@ -266,10 +266,10 @@ class Application def initialize(command_line = nil) require 'puppet/util/command_line' @command_line = command_line || Puppet::Util::CommandLine.new - @mode = self.class.mode + @run_mode = self.class.run_mode @options = {} - $puppet_application_mode = @mode + $puppet_application_mode = @run_mode $puppet_application_name = name require 'puppet' end diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index f0693f94b..a754ed399 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -3,7 +3,7 @@ require 'puppet/application' class Puppet::Application::Agent < Puppet::Application should_parse_config - mode :agent + run_mode :agent attr_accessor :explicit_waitforcert, :args, :agent, :daemon, :host diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb index acbafb2d0..b368728b8 100644 --- a/lib/puppet/application/cert.rb +++ b/lib/puppet/application/cert.rb @@ -3,7 +3,7 @@ require 'puppet/application' class Puppet::Application::Cert < Puppet::Application should_parse_config - mode :server + run_mode :server attr_accessor :cert_mode, :all, :ca, :digest, :signed diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index ba010022d..a28cac21b 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -3,7 +3,7 @@ require 'puppet/application' class Puppet::Application::Doc < Puppet::Application should_not_parse_config - mode :master + run_mode :master attr_accessor :unknown_args, :manifest diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb index 5d597a69b..fdcd7d34f 100644 --- a/lib/puppet/application/master.rb +++ b/lib/puppet/application/master.rb @@ -3,7 +3,7 @@ require 'puppet/application' class Puppet::Application::Master < Puppet::Application should_parse_config - mode :master + run_mode :master option("--debug", "-d") option("--verbose", "-v") diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 94e446604..bfc18d8aa 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -1,17 +1,17 @@ # The majority of the system configuration parameters are set in this file. module Puppet setdefaults(:main, - :confdir => [Puppet.mode.conf_dir, "The main Puppet configuration directory. The default for this parameter is calculated based on the user. If the process + :confdir => [Puppet.run_mode.conf_dir, "The main Puppet configuration directory. The default for this parameter is calculated based on the user. If the process is running as root or the user that ``puppet master`` is supposed to run as, it defaults to a system directory, but if it's running as any other user, it defaults to being in ``~``."], - :vardir => [Puppet.mode.var_dir, "Where Puppet stores dynamic and growing data. The default for this parameter is calculated specially, like `confdir`_."], + :vardir => [Puppet.run_mode.var_dir, "Where Puppet stores dynamic and growing data. The default for this parameter is calculated specially, like `confdir`_."], :name => [Puppet.application_name.to_s, "The name of the application, if we are running as one. The default is essentially $0 without the path or ``.rb``."], - :mode => [Puppet.mode.name.to_s, "The name of the application, if we are running as one. The + :run_mode => [Puppet.run_mode.name.to_s, "The name of the application, if we are running as one. The default is essentially $0 without the path or ``.rb``."] ) - setdefaults(:main, :logdir => Puppet.mode.logopts) + setdefaults(:main, :logdir => Puppet.run_mode.logopts) setdefaults(:main, :trace => [false, "Whether to print stack traces on some errors"], @@ -26,7 +26,7 @@ module Puppet might result in spurious service restarts)." }, :rundir => { - :default => Puppet.mode.run_dir, + :default => Puppet.run_mode.run_dir, :mode => 01777, :desc => "Where Puppet PID files are kept." }, diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 0dccf3613..b1c9df7c4 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -53,7 +53,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code # Is our compiler part of a network, or are we just local? def networked? - Puppet.mode.master? + Puppet.run_mode.master? end private diff --git a/lib/puppet/indirector/file.rb b/lib/puppet/indirector/file.rb index 0aedccf91..a035f0dac 100644 --- a/lib/puppet/indirector/file.rb +++ b/lib/puppet/indirector/file.rb @@ -4,7 +4,7 @@ require 'puppet/indirector/terminus' class Puppet::Indirector::File < Puppet::Indirector::Terminus # Where do we store our data? def data_directory - name = Puppet.mode.master? ? :server_datadir : :client_datadir + name = Puppet.run_mode.master? ? :server_datadir : :client_datadir File.join(Puppet.settings[name], self.class.indirection_name.to_s) end diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 710246686..39d4751fc 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -45,7 +45,7 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus # Get the yaml directory def base - Puppet.mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] + Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] end # Return the path to a given node's file. diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb index a97add0c0..c0b736d44 100644 --- a/lib/puppet/network/http/webrick.rb +++ b/lib/puppet/network/http/webrick.rb @@ -70,7 +70,7 @@ class Puppet::Network::HTTP::WEBrick # Make sure the settings are all ready for us. Puppet.settings.use(:main, :ssl, Puppet[:name]) - if Puppet.mode.master? + if Puppet.run_mode.master? file = Puppet[:masterhttplog] else file = Puppet[:httplog] diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb index bd081c914..aa1ccf936 100644 --- a/lib/puppet/ssl/certificate_authority.rb +++ b/lib/puppet/ssl/certificate_authority.rb @@ -33,7 +33,7 @@ class Puppet::SSL::CertificateAuthority def self.ca? return false unless Puppet[:ca] - return false unless Puppet.mode.master? + return false unless Puppet.run_mode.master? return true end diff --git a/lib/puppet/util/mode.rb b/lib/puppet/util/run_mode.rb index 16ea44e2c..08f2c851f 100644 --- a/lib/puppet/util/mode.rb +++ b/lib/puppet/util/run_mode.rb @@ -1,6 +1,6 @@ module Puppet module Util - class Mode + class RunMode def initialize(name) @name = name.to_sym end diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 780461d4b..398fa482c 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -17,7 +17,7 @@ class Puppet::Util::Settings attr_accessor :file attr_reader :timer - ReadOnly = [:mode, :name] + ReadOnly = [:run_mode, :name] # Retrieve a config value def [](param) @@ -285,8 +285,8 @@ class Puppet::Util::Settings end # Figure out the section name for the mode. - def mode - convert(@config[:mode].default).intern if @config[:mode] + def run_mode + convert(@config[:run_mode].default).intern if @config[:run_mode] end # Return all of the parameters associated with a given section. @@ -443,9 +443,9 @@ class Puppet::Util::Settings # The order in which to search for values. def searchpath(environment = nil) if environment - [:cli, :memory, environment, :mode, :main] + [:cli, :memory, environment, :run_mode, :main] else - [:cli, :memory, :mode, :main] + [:cli, :memory, :run_mode, :main] end end @@ -499,7 +499,7 @@ class Puppet::Util::Settings legacy_to_mode = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair| app, legacy = pair command_line.require_application app - hash[legacy.to_sym] = Puppet::Application.find(app).mode.name + hash[legacy.to_sym] = Puppet::Application.find(app).run_mode.name hash end if new_type = legacy_to_mode[type] @@ -602,8 +602,8 @@ Generated on #{Time.now}. }.gsub(/^/, "# ") # Add a section heading that matches our name. - if @config.include?(:mode) - str += "[%s]\n" % self[:mode] + if @config.include?(:run_mode) + str += "[%s]\n" % self[:run_mode] end eachsection do |section| persection(section) do |obj| @@ -827,7 +827,7 @@ Generated on #{Time.now}. def each_source(environment) searchpath(environment).each do |source| # Modify the source as necessary. - source = self.mode if source == :mode + source = self.run_mode if source == :run_mode yield source end end diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index db805fe7e..0c2e7b4a2 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -223,8 +223,8 @@ describe Puppet::Application::Doc do end end - it "should operate in master mode" do - @doc.class.mode.name.should == :master + it "should operate in master run_mode" do + @doc.class.run_mode.name.should == :master @doc.setup_rdoc end diff --git a/spec/unit/indirector/file_spec.rb b/spec/unit/indirector/file_spec.rb index 207d897bf..2505a0cd5 100755 --- a/spec/unit/indirector/file_spec.rb +++ b/spec/unit/indirector/file_spec.rb @@ -30,15 +30,15 @@ describe Puppet::Indirector::File do @searcher.should respond_to(:find) end - it "should use the server data directory plus the indirection name if the process mode is master" do - Puppet.mode.expects(:master?).returns true + it "should use the server data directory plus the indirection name if the run_mode is master" do + Puppet.run_mode.expects(:master?).returns true Puppet.settings.expects(:value).with(:server_datadir).returns "/my/dir" @searcher.data_directory.should == File.join("/my/dir", "mystuff") end - it "should use the client data directory plus the indirection name if the process mode is not master" do - Puppet.mode.expects(:master?).returns false + it "should use the client data directory plus the indirection name if the run_mode is not master" do + Puppet.run_mode.expects(:master?).returns false Puppet.settings.expects(:value).with(:client_datadir).returns "/my/dir" @searcher.data_directory.should == File.join("/my/dir", "mystuff") diff --git a/spec/unit/indirector/yaml_spec.rb b/spec/unit/indirector/yaml_spec.rb index 37c33f0cb..44ecf96d6 100755 --- a/spec/unit/indirector/yaml_spec.rb +++ b/spec/unit/indirector/yaml_spec.rb @@ -22,20 +22,20 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @dir = "/what/ever" Puppet.settings.stubs(:value).returns("fakesettingdata") Puppet.settings.stubs(:value).with(:clientyamldir).returns(@dir) - Puppet.mode.stubs(:master?).returns false + Puppet.run_mode.stubs(:master?).returns false @request = stub 'request', :key => :me, :instance => @subject end describe Puppet::Indirector::Yaml, " when choosing file location" do - it "should use the server_datadir if the mode is master" do - Puppet.mode.expects(:master?).returns true + it "should use the server_datadir if the run_mode is master" do + Puppet.run_mode.expects(:master?).returns true Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" @store.path(:me).should =~ %r{^/server/yaml/dir} end - it "should use the client yamldir if the mode is not master" do - Puppet.mode.expects(:master?).returns false + it "should use the client yamldir if the run_mode is not master" do + Puppet.run_mode.expects(:master?).returns false Puppet.settings.expects(:value).with(:clientyamldir).returns "/client/yaml/dir" @store.path(:me).should =~ %r{^/client/yaml/dir} end diff --git a/spec/unit/network/http/webrick_spec.rb b/spec/unit/network/http/webrick_spec.rb index aaab53b0c..34abc6909 100755 --- a/spec/unit/network/http/webrick_spec.rb +++ b/spec/unit/network/http/webrick_spec.rb @@ -211,8 +211,8 @@ describe Puppet::Network::HTTP::WEBrick do @server.setup_logger end - it "should use the masterlog if the process mode is master" do - Puppet.mode.stubs(:master?).returns(true) + it "should use the masterlog if the run_mode is master" do + Puppet.run_mode.stubs(:master?).returns(true) Puppet.settings.expects(:value).with(:masterhttplog).returns "/master/log" File.expects(:open).with("/master/log", "a+").returns @filehandle @@ -220,8 +220,8 @@ describe Puppet::Network::HTTP::WEBrick do @server.setup_logger end - it "should use the httplog if the process mode is not master" do - Puppet.mode.stubs(:master?).returns(false) + it "should use the httplog if the run_mode is not master" do + Puppet.run_mode.stubs(:master?).returns(false) Puppet.settings.expects(:value).with(:httplog).returns "/other/log" File.expects(:open).with("/other/log", "a+").returns @filehandle diff --git a/spec/unit/ssl/certificate_authority_spec.rb b/spec/unit/ssl/certificate_authority_spec.rb index 3b1b9486f..db812b278 100755 --- a/spec/unit/ssl/certificate_authority_spec.rb +++ b/spec/unit/ssl/certificate_authority_spec.rb @@ -24,10 +24,10 @@ describe Puppet::SSL::CertificateAuthority do end describe "when finding an existing instance" do - describe "and the host is a CA host and the mode is master" do + describe "and the host is a CA host and the run_mode is master" do before do Puppet.settings.stubs(:value).with(:ca).returns true - Puppet.mode.stubs(:master?).returns true + Puppet::Util::RunMode.any_instance.stubs(:master?).returns true @ca = mock('ca') Puppet::SSL::CertificateAuthority.stubs(:new).returns @ca @@ -45,7 +45,7 @@ describe Puppet::SSL::CertificateAuthority do describe "and the host is not a CA host" do it "should return nil" do Puppet.settings.stubs(:value).with(:ca).returns false - Puppet.mode.stubs(:master?).returns true + Puppet.run_mode.stubs(:master?).returns true ca = mock('ca') Puppet::SSL::CertificateAuthority.expects(:new).never @@ -53,10 +53,10 @@ describe Puppet::SSL::CertificateAuthority do end end - describe "and the mode is not master" do + describe "and the run_mode is not master" do it "should return nil" do Puppet.settings.stubs(:value).with(:ca).returns true - Puppet.mode.stubs(:master?).returns false + Puppet.run_mode.stubs(:master?).returns false ca = mock('ca') Puppet::SSL::CertificateAuthority.expects(:new).never diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 3e70cb581..1e694a407 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -199,15 +199,15 @@ describe Puppet::Util::Settings do lambda{ @settings[:name] = "foo" }.should raise_error(ArgumentError) end - it "should raise an error if we try to set 'mode'" do - lambda{ @settings[:mode] = "foo" }.should raise_error(ArgumentError) + it "should raise an error if we try to set 'run_mode'" do + lambda{ @settings[:run_mode] = "foo" }.should raise_error(ArgumentError) end it "should warn and use [master] if we ask for [puppetmasterd]" do Puppet.expects(:warning) @settings.set_value(:myval, "foo", :puppetmasterd) - @settings.stubs(:mode).returns(:master) + @settings.stubs(:run_mode).returns(:master) @settings.value(:myval).should == "foo" end @@ -215,7 +215,7 @@ describe Puppet::Util::Settings do Puppet.expects(:warning) @settings.set_value(:myval, "foo", :puppetd) - @settings.stubs(:mode).returns(:agent) + @settings.stubs(:run_mode).returns(:agent) @settings.value(:myval).should == "foo" end end @@ -274,11 +274,11 @@ describe Puppet::Util::Settings do @settings.value(:one, "env2").should == "twoval" end - it "should have a mode determined by the 'mode' parameter that cannot be edited" do - @settings.setdefaults(:whatever, :mode => ["something", "yayness"]) - @settings.mode.should == :something + it "should have a run_mode determined by the 'run_mode' parameter that cannot be edited" do + @settings.setdefaults(:whatever, :run_mode => ["something", "yayness"]) + @settings.run_mode.should == :something - lambda{ @settings[:mode] = :other }.should raise_error + lambda{ @settings[:run_mode] = :other }.should raise_error end end @@ -286,9 +286,9 @@ describe Puppet::Util::Settings do before do @settings = Puppet::Util::Settings.new @settings.setdefaults :section, - :config => ["/my/file", "a"], - :one => ["ONE", "a"], - :mode => ["mymode", "w"] + :config => ["/my/file", "a"], + :one => ["ONE", "a" ], + :run_mode => ["mymode", "w" ] FileTest.stubs(:exist?).returns true end |