diff options
author | nimisha <nimisha.sharad@msystechnologies.com> | 2017-04-04 19:09:18 +0530 |
---|---|---|
committer | nimisha <nimisha.sharad@msystechnologies.com> | 2017-04-05 14:44:04 +0530 |
commit | 5a2d46086b5caf59ce3d3325f1048b51efc94468 (patch) | |
tree | 4fc6224f833d2b9407f6dc5d01c84fa2e73183dd | |
parent | 2ff65b4f07617dbb1255b7b8f4795d69a35dcb39 (diff) | |
download | chef-5a2d46086b5caf59ce3d3325f1048b51efc94468.tar.gz |
Removed config file and chcp command
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
-rw-r--r-- | .bundle/config | 3 | ||||
-rw-r--r-- | lib/chef/provider/windows_task.rb | 16 | ||||
-rw-r--r-- | spec/unit/provider/windows_task_spec.rb | 5 |
3 files changed, 15 insertions, 9 deletions
diff --git a/.bundle/config b/.bundle/config deleted file mode 100644 index 711b4ff216..0000000000 --- a/.bundle/config +++ /dev/null @@ -1,3 +0,0 @@ ---- -BUNDLE_FROZEN: "1" -BUNDLE_WITHOUT: "omnibus_package:test:pry:integration:docgen:maintenance:travis:aix:bsd:linux:mac_os_x:solaris:windows:development" diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 0621da6d45..ae77e8421a 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -213,8 +213,11 @@ class Chef Chef::Log.debug "looking for existing tasks" - # we use shell_out here instead of shell_out! because a failure implies that the task does not exist - xml_cmd = shell_out("schtasks /Query /TN \"#{@new_resource.task_name}\" /XML") + task_script = <<-EOH + [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 + schtasks /Query /TN \"#{@new_resource.task_name}\" /XML + EOH + xml_cmd = powershell_out(task_script) return if xml_cmd.exitstatus != 0 @@ -264,7 +267,7 @@ class Chef schtasks /Query /FO LIST /V /TN \"#{task_name}\" EOH - output = powershell_out("#{task_script}").stdout.force_encoding("UTF-8") + output = powershell_out(task_script).stdout.force_encoding("UTF-8") if output.empty? task = false else @@ -287,7 +290,12 @@ class Chef end def load_task_xml(task_name) - xml_cmd = shell_out("chcp 65001 >nul 2>&1 && schtasks /Query /TN \"#{task_name}\" /XML") + task_script = <<-EOH + [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 + schtasks /Query /TN \"#{task_name}\" /XML + EOH + xml_cmd = powershell_out(task_script) + return if xml_cmd.exitstatus != 0 doc = REXML::Document.new(xml_cmd.stdout) diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb index 5ca359833d..80038aa6db 100644 --- a/spec/unit/provider/windows_task_spec.rb +++ b/spec/unit/provider/windows_task_spec.rb @@ -340,14 +340,14 @@ describe Chef::Provider::WindowsTask do it "does nothing if the task doesn't exist" do task_xml = double("xml", :exitstatus => 1) - allow(provider).to receive(:shell_out).with("schtasks /Query /TN \"#{new_resource.task_name}\" /XML").and_return(task_xml) + allow(provider).to receive(:powershell_out).and_return(task_xml) output = provider.send(:update_task_xml, ["random_delay"]) expect(output).to be(nil) end it "updates the task XML if random_delay is passed" do shell_out_obj = double("xml", :exitstatus => 0, :stdout => task_xml) - allow(provider).to receive(:shell_out).with("schtasks /Query /TN \"#{new_resource.task_name}\" /XML").and_return(shell_out_obj) + allow(provider).to receive(:powershell_out).and_return(shell_out_obj) expect(::File).to receive(:join) expect(::File).to receive(:open) expect(::File).to receive(:delete) @@ -359,6 +359,7 @@ describe Chef::Provider::WindowsTask do describe "#load_task_hash" do it "returns false if the task doesn't exist" do allow(provider).to receive_message_chain(:powershell_out, :stdout, :force_encoding).and_return("") + allow(provider).to receive(:load_task_xml) expect(provider.send(:load_task_hash, "chef-client")).to be(false) end |