summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2019-05-07 16:15:39 -0700
committerGitHub <noreply@github.com>2019-05-07 16:15:39 -0700
commit64ccb8c4830265de395dcbab16dd3db30a851e25 (patch)
tree2ac2ce90e11d06f37f789c8ffd87b78ef1068765
parent0487d0d05ec9760cd4a7c3f7ca6c0e303baae648 (diff)
parenta8198cc042869b34937873db8f371cff77748f33 (diff)
downloadchef-64ccb8c4830265de395dcbab16dd3db30a851e25.tar.gz
Merge pull request #8480 from chef/lcg/target-mode-tweaks
Target mode code tweaks
-rw-r--r--lib/chef/dsl/universal.rb1
-rw-r--r--lib/chef/guard_interpreter/default_guard_interpreter.rb7
-rw-r--r--lib/chef/mixin/train_or_shell.rb29
3 files changed, 21 insertions, 16 deletions
diff --git a/lib/chef/dsl/universal.rb b/lib/chef/dsl/universal.rb
index 256bc2820d..7e4843adcb 100644
--- a/lib/chef/dsl/universal.rb
+++ b/lib/chef/dsl/universal.rb
@@ -55,6 +55,7 @@ class Chef
include Chef::Mixin::PowershellExec
include Chef::Mixin::PowershellOut
include Chef::Mixin::ShellOut
+ include Chef::Mixin::TrainOrShell
extend Chef::Mixin::LazyModuleInclude
end
end
diff --git a/lib/chef/guard_interpreter/default_guard_interpreter.rb b/lib/chef/guard_interpreter/default_guard_interpreter.rb
index 402f05f288..740e8e3f2c 100644
--- a/lib/chef/guard_interpreter/default_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/default_guard_interpreter.rb
@@ -16,24 +16,19 @@
# limitations under the License.
#
-require "chef/mixin/shell_out"
require "chef/mixin/train_or_shell"
+require "chef/exceptions"
class Chef
class GuardInterpreter
class DefaultGuardInterpreter
- include Chef::Mixin::ShellOut
include Chef::Mixin::TrainOrShell
- protected
-
def initialize(command, opts)
@command = command
@command_opts = opts
end
- public
-
def evaluate
result = train_or_shell(@command, default_env: false, **@command_opts)
Chef::Log.debug "Command failed: #{result.stderr}" unless result.status.success?
diff --git a/lib/chef/mixin/train_or_shell.rb b/lib/chef/mixin/train_or_shell.rb
index c976094b14..6a47d52a1d 100644
--- a/lib/chef/mixin/train_or_shell.rb
+++ b/lib/chef/mixin/train_or_shell.rb
@@ -17,20 +17,16 @@
#
require "ostruct"
+require "chef/mixin/shell_out"
+require "chef/mixin/powershell_out"
+require "chef/config"
class Chef
module Mixin
module TrainOrShell
- #
- # Train #run_command returns a Train::Extras::CommandResult which
- # includes `exit_status` but Mixlib::Shellout returns exitstatus
- # This wrapper makes the result look like Mixlib::ShellOut to make it
- # easier to swap providers from #shell_out to #train_or_shell
- #
- def train_to_shellout_result(stdout, stderr, exit_status)
- status = OpenStruct.new(success?: ( exit_status == 0 ))
- OpenStruct.new(stdout: stdout, stderr: stderr, exitstatus: exit_status, status: status)
- end
+
+ include Chef::Mixin::ShellOut
+ include Chef::Mixin::PowershellOut
def train_or_shell(*args, **opts)
if Chef::Config.target_mode?
@@ -69,6 +65,19 @@ class Chef
powershell_out!(*args)
end
end
+
+ private
+
+ #
+ # Train #run_command returns a Train::Extras::CommandResult which
+ # includes `exit_status` but Mixlib::Shellout returns exitstatus
+ # This wrapper makes the result look like Mixlib::ShellOut to make it
+ # easier to swap providers from #shell_out to #train_or_shell
+ #
+ def train_to_shellout_result(stdout, stderr, exit_status)
+ status = OpenStruct.new(success?: ( exit_status == 0 ))
+ OpenStruct.new(stdout: stdout, stderr: stderr, exitstatus: exit_status, status: status)
+ end
end
end
end