Skip to content

Commit

Permalink
Merge branch 'ticket/3.x/16189-run_mode-not-working-for-faces' into 3.x
Browse files Browse the repository at this point in the history
* ticket/3.x/16189-run_mode-not-working-for-faces:
  (#16189) Make --run_mode a global option and not a setting
  • Loading branch information
zaphod42 committed Sep 14, 2012
2 parents 285ea80 + f4e229e commit d41ac79
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 192 deletions.
2 changes: 1 addition & 1 deletion lib/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.run_mode
# (rather than using a global variable, as we did previously...). Would be good to revisit this at some point.
#
# --cprice 2012-03-16
Puppet::Util::RunMode[@@settings.run_mode]
Puppet::Util::RunMode[@@settings.preferred_run_mode]
end

# Load all of the configuration parameters.
Expand Down
11 changes: 5 additions & 6 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,18 @@ def [](name)
find(name).new
end

#
# I think that it would be nice to look into changing this into two methods (getter/setter); however,
# it sounds like this is a desirable feature of our ruby DSL. --cprice 2012-03-06
#

# Sets or gets the run_mode name. Sets the run_mode name if a mode_name is
# passed. Otherwise, gets the run_mode or a default run_mode
#
def run_mode( mode_name = nil)
if mode_name
Puppet.settings.preferred_run_mode = mode_name
end

return @run_mode if @run_mode and not mode_name

require 'puppet/util/run_mode'
@run_mode = Puppet::Util::RunMode[ mode_name || :user ]
@run_mode = Puppet::Util::RunMode[ mode_name || Puppet.settings.preferred_run_mode ]
end
end

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/application/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ def setup
# I'd prefer if this could be dealt with differently; ideally, run_mode should be set as
# part of a class definition, and should not be modifiable beyond that. This is one of
# the cases where that isn't currently possible.
# Perhaps a separate issue, but related, is that the run_mode probably shouldn't be a
# normal 'setting' like the rest of the config stuff; I left some notes in settings.rb
# and defaults.rb discussing this. --cprice 2012-03-22
Puppet.settings.set_value(:run_mode, :master, :application_defaults)
Puppet.settings.preferred_run_mode = "master"
end

super
Expand Down
12 changes: 0 additions & 12 deletions lib/puppet/application/face_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'pp'

class Puppet::Application::FaceBase < Puppet::Application
run_mode :agent

option("--debug", "-d") do |arg|
Puppet::Util::Log.level = :debug
end
Expand All @@ -18,16 +16,6 @@ class Puppet::Application::FaceBase < Puppet::Application
self.render_as = format.to_sym
end

# This seems like a bad thing; it seems like--in an ideal world--a given app/face should have one constant run mode.
# This isn't currently possible because of issues relating to the certificate authority, but I've left some notes
# about "run_mode" in settings.rb and defaults.rb, and if we are able to tighten up the behavior / implementation
# of that setting, we might want to revisit this. --cprice 2012-03-16
option("--mode RUNMODE", "-r") do |arg|
raise "Invalid run mode #{arg}; supported modes are user, agent, master" unless %w{user agent master}.include?(arg)
self.class.run_mode(arg.to_sym)
end


attr_accessor :face, :action, :type, :arguments, :render_as

def render_as=(format)
Expand Down
14 changes: 0 additions & 14 deletions lib/puppet/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ module Puppet
:default => nil,
:desc => "The name of the application, if we are running as one. The\n" +
"default is essentially $0 without the path or `.rb`.",
},

## This setting needs to go away. As a first step, we could just make it a first-class property of the Settings
## class, instead of treating it as a normal setting. There are places where the Settings class tries to use
## the value of run_mode to help in resolving other values, and that is no good for nobody. It would cause
## infinite recursion and stack overflows without some chicanery... so, it needs to be cleaned up.
##
## As a longer term goal I think we should be looking into getting rid of run_mode altogether, but that is going
## to be a larger undertaking, as it is being branched on in a lot of places in the current code.
##
## --cprice 2012-03-16
:run_mode => {
:default => nil,
:desc => "The effective 'run mode' of the application: master, agent, or user.",
}
)

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/face/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
EOT
notes <<-'EOT'
By default, this action reads the configuration in agent mode.
Use the '--mode' and '--environment' flags to examine other
Use the '--run_mode' and '--environment' flags to examine other
configuration domains.
EOT
examples <<-'EOT'
Expand All @@ -32,7 +32,7 @@
Get a list of important directories from the master's config:
$ puppet config print all --mode master | grep -E "(path|dir)"
$ puppet config print all --run_mode master | grep -E "(path|dir)"
EOT

when_invoked do |*args|
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/face/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Query a DB-backed inventory directly (bypassing the REST API):
$ puppet facts find somenode.puppetlabs.lan --terminus inventory_active_record --mode master
$ puppet facts find somenode.puppetlabs.lan --terminus inventory_active_record --run_mode master
EOT

get_action(:destroy).summary "Invalid for this subcommand."
Expand Down
1 change: 0 additions & 1 deletion lib/puppet/face/help/action.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RETURNS: <%= action.returns.strip %>
<% end -%>
OPTIONS:
<%# Remove these options once we can introspect them normally. -%>
--mode MODE - The run mode to use (user, agent, or master).
--render-as FORMAT - The rendering format to use.
--verbose - Whether to log verbosely.
--debug - Whether to log debug information.
Expand Down
1 change: 0 additions & 1 deletion lib/puppet/face/help/face.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ USAGE: <%= face.synopsis %>

OPTIONS:
<%# Remove these options once we can introspect them normally. -%>
--mode MODE - The run mode to use (user, agent, or master).
--render-as FORMAT - The rendering format to use.
--verbose - Whether to log verbosely.
--debug - Whether to log debug information.
Expand Down
9 changes: 3 additions & 6 deletions lib/puppet/face/help/man.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@ OPTIONS
-------
Note that any configuration parameter that's valid in the configuration
file is also a valid long argument, although it may or may not be
relevant to the present action. For example, `server` is a valid
configuration parameter, so you can specify `--server <servername>` as
an argument.
relevant to the present action. For example, `server` and `run_mode` are valid
configuration parameters, so you can specify `--server <servername>`, or
`--run_mode <runmode>` as an argument.

See the configuration file documentation at
<http://docs.puppetlabs.com/references/stable/configuration.html> for the
full list of acceptable parameters. A commented list of all
configuration options can also be generated by running puppet with
`--genconfig`.

* --mode MODE:
The run mode to use for the current action. Valid modes are `user`, `agent`,
and `master`.
* --render-as FORMAT:
The format in which to render output. The most common formats are `json`,
`s` (string), `yaml`, and `console`, but other options such as `dot` are
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/face/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Retrieve a node using the puppet master's configured ENC:
$ puppet node find somenode.puppetlabs.lan --terminus exec --mode master --render-as yaml
$ puppet node find somenode.puppetlabs.lan --terminus exec --run_mode master --render-as yaml
Retrieve the same node from the puppet master:
Expand Down
14 changes: 7 additions & 7 deletions lib/puppet/face/node/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
options = args.last
raise "At least one node should be passed" if nodes.empty? || nodes == options



# This seems really bad; run_mode should be set as part of a class definition, and should
# not be modifiable beyond that. This is one of the only places left in the code that
# tries to manipulate it. I would like to get rid of it but I'm not entirely familiar
# with what we are trying to do here, so I'm postponing for now... --cprice 2012-03-16
Puppet.settings.set_value(:run_mode, :master, :application_defaults)
# This seems really bad; run_mode should be set as part of a class
# definition, and should not be modifiable beyond that. This is one of
# the only places left in the code that tries to manipulate it. Other
# parts of code that handle certificates behave differently if the the
# run_mode is master. Those other behaviors are needed for cleaning the
# certificates correctly.
Puppet.settings.preferred_run_mode = "master"

if Puppet::SSL::CertificateAuthority.ca?
Puppet::SSL::Host.ca_location = :local
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/indirector/face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def call_indirection_method(method, key, options)
description <<-EOT
Prints the default terminus class for this subcommand. Note that different
run modes may have different default termini; when in doubt, specify the
run mode with the '--mode' option.
run mode with the '--run_mode' option.
EOT

when_invoked do |options|
Expand Down

0 comments on commit d41ac79

Please sign in to comment.