summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@msystechnologies.com>2017-12-11 11:38:27 +0000
committerVasu1105 <vasundhara.jagdale@msystechnologies.com>2017-12-11 11:38:27 +0000
commite228bdf9fa5340dfd03c29243448c2ec5fc8d176 (patch)
tree9de30c75cf04a1c8acc930698474726f7008893b
parent35eac8934a51d86bf9e12131b40148642d0b06cf (diff)
downloadchef-e228bdf9fa5340dfd03c29243448c2ec5fc8d176.tar.gz
[MSYS-731] Fix for [chef] windows_task resource isn't idempotent for any command
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
-rw-r--r--lib/chef/provider/windows_task.rb12
-rw-r--r--spec/unit/provider/windows_task_spec.rb15
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb
index 937d28cf4b..023f79b1c0 100644
--- a/lib/chef/provider/windows_task.rb
+++ b/lib/chef/provider/windows_task.rb
@@ -20,6 +20,7 @@ require "chef/mixin/shell_out"
require "rexml/document"
require "iso8601"
require "chef/mixin/powershell_out"
+require 'pry'
class Chef
class Provider
@@ -207,8 +208,14 @@ class Chef
def run_schtasks(task_action, options = {})
cmd = "schtasks /#{task_action} /TN \"#{new_resource.task_name}\" "
options.keys.each do |option|
- cmd += "/#{option} "
- cmd += "\"#{options[option].to_s.gsub('"', "\\\"")}\" " unless options[option] == ""
+ unless option == "TR"
+ cmd += "/#{option} "
+ cmd += "\"#{options[option].to_s.gsub('"', "\\\"")}\" " unless options[option] == ""
+ end
+ end
+ # Appending Task Run [TR] option at the end since appending causing sometimes to append other options in option["TR"] value
+ if options["TR"]
+ cmd += "/TR \"#{options["TR"]} \" " unless task_action == "DELETE"
end
Chef::Log.debug("running: ")
Chef::Log.debug(" #{cmd}")
@@ -361,7 +368,6 @@ class Chef
options["RP"] = new_resource.password if new_resource.password
options["IT"] = "" if new_resource.interactive_enabled
options["XML"] = temp_task_file
-
run_schtasks("DELETE", "F" => "")
run_schtasks("CREATE", options)
ensure
diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb
index d45531f3dc..04326f1b51 100644
--- a/spec/unit/provider/windows_task_spec.rb
+++ b/spec/unit/provider/windows_task_spec.rb
@@ -40,7 +40,7 @@ describe Chef::Provider::WindowsTask do
:LastRunTime => "3/30/2017 2:27:00 PM",
:LastResult => "1",
:Author => "Administrator",
- :TaskToRun => "chef-client",
+ :TaskToRun => "chef-client -L C:\\tmp\\",
:StartIn => "N/A",
:Comment => "N/A",
:ScheduledTaskState => "Enabled",
@@ -91,7 +91,7 @@ describe Chef::Provider::WindowsTask do
allow(provider).to receive(:load_task_hash).and_return(task_hash)
current_resource = provider.load_current_resource
expect(current_resource.exists).to be(true)
- expect(current_resource.command).to eq("chef-client")
+ expect(current_resource.command).to eq("chef-client -L C:\\tmp\\")
expect(current_resource.user).to eq("SYSTEM")
expect(current_resource.run_level).to eq(:highest)
expect(current_resource.frequency).to eq(:minute)
@@ -312,7 +312,7 @@ describe Chef::Provider::WindowsTask do
before do
@task_action = "CREATE"
@options = { "F" => "", "SC" => :minute, "MO" => 15, "TR" => "chef-client", "RU" => "SYSTEM", "RL" => "HIGHEST" }
- @cmd = "schtasks /CREATE /TN \"sample_task\" /F /SC \"minute\" /MO \"15\" /TR \"chef-client\" /RU \"SYSTEM\" /RL \"HIGHEST\" "
+ @cmd = "schtasks /CREATE /TN \"sample_task\" /F /SC \"minute\" /MO \"15\" /RU \"SYSTEM\" /RL \"HIGHEST\" /TR \"chef-client \" "
end
it "forms the command properly from the given options" do
@@ -363,7 +363,7 @@ describe Chef::Provider::WindowsTask do
allow(provider).to receive(:get_system_short_date_format).and_return("MM/dd/yyyy")
provider.load_current_resource
- new_resource.command "chef-client"
+ new_resource.command "chef-client -L C:\\tmp\\"
new_resource.run_level :highest
new_resource.frequency :minute
new_resource.frequency_modifier 15
@@ -406,6 +406,13 @@ describe Chef::Provider::WindowsTask do
expect(provider.send(:task_need_update?)).to be(true)
end
end
+
+ context "when command updated" do
+ it "return true" do
+ new_resource.command "chef-client"
+ expect(provider.send(:task_need_update?)).to be(true)
+ end
+ end
end
end