summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@msystechnologies.com>2019-01-28 15:29:37 +0530
committerVasu1105 <vasundhara.jagdale@msystechnologies.com>2019-01-30 12:50:45 +0530
commit047fd4980dfbd6199e8ae9a5dbfe2f6793f76c4e (patch)
tree6593069ccd6d6d279c2c257f1019455cf9473e1f
parentdcb6b50efda2bf85eb6330263a9ec63a7713239d (diff)
downloadchef-047fd4980dfbd6199e8ae9a5dbfe2f6793f76c4e.tar.gz
Conver execute_resource to use properties.
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
-rw-r--r--lib/chef/provider/execute.rb40
-rw-r--r--lib/chef/resource/execute.rb19
2 files changed, 25 insertions, 34 deletions
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index 02db7cb593..055aaeb9b5 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -18,24 +18,22 @@
require "chef/log"
require "chef/provider"
-require "forwardable"
class Chef
class Provider
class Execute < Chef::Provider
- extend Forwardable
-
provides :execute
- def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env
+ def initialize(new_resource, run_context)
+ super
+ end
def load_current_resource
current_resource = Chef::Resource::Execute.new(new_resource.name)
- current_resource
end
def define_resource_requirements
- if creates && creates_relative? && !cwd
+ if new_resource.creates && creates_relative? && !new_resource.cwd
# FIXME? move this onto the resource?
raise Chef::Exceptions::Execute, "Please either specify a full path for the creates property, or specify a cwd property to the #{new_resource} resource"
end
@@ -48,14 +46,14 @@ class Chef
end
def action_run
- if creates && sentinel_file.exist?
+ if new_resource.creates && sentinel_file.exist?
logger.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do")
return false
end
converge_by("execute #{description}") do
begin
- shell_out!(command, opts)
+ shell_out!(new_resource.command, opts)
rescue Mixlib::ShellOut::ShellCommandFailed
if sensitive?
ex = Mixlib::ShellOut::ShellCommandFailed.new("Command execution failed. STDOUT/STDERR suppressed for sensitive resource")
@@ -89,15 +87,15 @@ class Chef
def opts
opts = {}
opts[:timeout] = timeout
- opts[:returns] = returns if returns
- opts[:environment] = environment if environment
- opts[:user] = user if user
- opts[:domain] = domain if domain
- opts[:password] = password if password
- opts[:group] = group if group
- opts[:cwd] = cwd if cwd
- opts[:umask] = umask if umask
- opts[:default_env] = default_env
+ opts[:returns] = new_resource.returns if new_resource.returns
+ opts[:environment] = new_resource.environment if new_resource.environment
+ opts[:user] = new_resource.user if new_resource.user
+ opts[:domain] = new_resource.domain if new_resource.domain
+ opts[:password] = new_resource.password if new_resource.password
+ opts[:group] = new_resource.group if new_resource.group
+ opts[:cwd] = new_resource.cwd if new_resource.cwd
+ opts[:umask] = new_resource.umask if new_resource.umask
+ opts[:default_env] = new_resource.default_env
opts[:log_level] = :info
opts[:log_tag] = new_resource.to_s
if (logger.info? || live_stream?) && !sensitive?
@@ -107,21 +105,21 @@ class Chef
opts[:live_stream] = STDOUT
end
end
- opts[:elevated] = elevated if elevated
+ opts[:elevated] = new_resource.elevated if new_resource.elevated
opts
end
def description
- sensitive? ? "sensitive resource" : command
+ sensitive? ? "sensitive resource" : new_resource.command
end
def creates_relative?
- Pathname(creates).relative?
+ Pathname(new_resource.creates).relative?
end
def sentinel_file
Pathname.new(Chef::Util::PathHelper.cleanpath(
- ( cwd && creates_relative? ) ? ::File.join(cwd, creates) : creates
+ ( new_resource.cwd && creates_relative? ) ? ::File.join(new_resource.cwd, new_resource.creates) : new_resource.creates
))
end
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 9eb86a2fef..dbae8d3a4a 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -23,10 +23,6 @@ class Chef
class Resource
class Execute < Chef::Resource
resource_name :execute
- provides :execute
-
- identity_attr :command
-
description "Use the execute resource to execute a single command. Commands that"\
" are executed with this resource are (by their nature) not idempotent,"\
" as they are typically unique to the environment in which they are run."\
@@ -48,13 +44,10 @@ class Chef
@is_guard_interpreter = false
end
- def command(arg = nil)
- set_or_return(
- :command,
- arg,
- kind_of: [ String, Array ]
- )
- end
+ property :command, [ String, Array ],
+ name_property: true, identity: true,
+ description: "An optional proeprty to set the command to be executed if it differs from the resource block's name."
+
property :umask, [ String, Integer ],
description: "The file mode creation mask, or umask."
@@ -67,8 +60,6 @@ class Chef
property :environment, Hash,
description: "A Hash of environment variables in the form of ({'ENV_VARIABLE' => 'VALUE'})."
- alias :env :environment
-
property :group, [ String, Integer ],
description: "The group name or group ID that must be changed before running a command."
@@ -106,6 +97,8 @@ class Chef
description: "Determines whether the script will run with elevated permissions to circumvent User Access Control (UAC) interactively blocking the process.\nThis will cause the process to be run under a batch login instead of an interactive login. The user running Chef needs the “Replace a process level token” and “Adjust Memory Quotas for a process” permissions. The user that is running the command needs the “Log on as a batch job” permission.\nBecause this requires a login, the user and password properties are required.",
introduced: "13.3"
+ alias :env :environment
+
def self.set_guard_inherited_attributes(*inherited_attributes)
@class_inherited_attributes = inherited_attributes
end