diff options
author | nimisha <nimisha.sharad@msystechnologies.com> | 2017-03-23 19:12:29 +0530 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2017-04-03 13:06:20 -0400 |
commit | 8f4bd4a8260c0840d89b5177a28832d7aacff174 (patch) | |
tree | cba711c2e8be699f5c292108573178cab5adb666 | |
parent | c56f62140187b1d67dacd40212134659be5753db (diff) | |
download | chef-8f4bd4a8260c0840d89b5177a28832d7aacff174.tar.gz |
Using chcp 437 and fixed some bugs
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | chef-universal-mingw32.gemspec | 1 | ||||
-rw-r--r-- | lib/chef/provider/windows_task.rb | 12 | ||||
-rw-r--r-- | lib/chef/resource/windows_task.rb | 10 |
5 files changed, 17 insertions, 9 deletions
@@ -18,7 +18,6 @@ gem "chef-config", path: File.expand_path("../chef-config", __FILE__) if File.ex gem "rake" gem "bundler" gem "cheffish" # required for rspec tests -gem "iso8601" group(:omnibus_package) do gem "appbundler" diff --git a/Gemfile.lock b/Gemfile.lock index c366f406f8..138e4260ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -153,6 +153,7 @@ PATH ffi-yajl (~> 2.2) highline (~> 1.6, >= 1.6.9) iniparse (~> 1.4) + iso8601 (~> 0.9.1) mixlib-archive (~> 0.4) mixlib-authentication (~> 1.4) mixlib-cli (~> 1.7) @@ -310,6 +311,7 @@ GEM i18n (0.8.1) iniparse (1.4.2) ipaddress (0.8.3) + iso8601 (0.9.1) jmespath (1.3.1) json (2.0.3) kitchen-docker (2.6.0) diff --git a/chef-universal-mingw32.gemspec b/chef-universal-mingw32.gemspec index 449f909bb2..226572e00a 100644 --- a/chef-universal-mingw32.gemspec +++ b/chef-universal-mingw32.gemspec @@ -15,6 +15,7 @@ gemspec.add_dependency "win32-process", "~> 0.8.2" gemspec.add_dependency "win32-service", "~> 0.8.7" gemspec.add_dependency "windows-api", "~> 0.4.4" gemspec.add_dependency "wmi-lite", "~> 1.0" +gemspec.add_dependency "iso8601", "~> 0.9.1" gemspec.extensions << "ext/win32-eventlog/Rakefile" gemspec.files += %w{ext/win32-eventlog/Rakefile ext/win32-eventlog/chef-log.man} diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 3f3e88db0d..0147e47a55 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -172,7 +172,7 @@ class Chef def task_need_update?
# gsub needed as schtasks converts single quotes to double quotes on creation
@current_resource.command != @new_resource.command.tr("'", '"') ||
- @current_resource.user != @new_resource.user ||
+ @current_resource.user.encode('external') != @new_resource.user ||
@current_resource.run_level != @new_resource.run_level ||
@current_resource.cwd != @new_resource.cwd ||
@current_resource.frequency_modifier != @new_resource.frequency_modifier ||
@@ -251,7 +251,7 @@ 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
- output = shell_out("schtasks /Query /FO LIST /V /TN \"#{task_name}\"").stdout
+ output = shell_out("chcp 65001 >nul 2>&1 && schtasks /Query /FO LIST /V /TN \"#{task_name}\"").stdout.force_encoding('UTF-8')
if output.empty?
task = false
else
@@ -266,13 +266,15 @@ class Chef end
end
end
- task.merge!(load_task_xml task_name) if task
+
+ task_xml = load_task_xml task_name
+ task.merge!(task_xml) if task && task_xml
task
end
def load_task_xml task_name
- xml_cmd = shell_out("schtasks /Query /TN \"#{task_name}\" /XML")
+ xml_cmd = shell_out("chcp 65001 >nul 2>&1 && schtasks /Query /TN \"#{task_name}\" /XML")
return if xml_cmd.exitstatus != 0
doc = REXML::Document.new(xml_cmd.stdout)
@@ -386,7 +388,7 @@ class Chef @current_resource.frequency(:once) if task_hash[:once]
end
- def set_idle_time(idle_time)
+ def set_current_idle_time(idle_time)
duration = ISO8601::Duration.new(idle_time)
@current_resource.idle_time(duration.minutes.atom.to_i)
end
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index b307ff67c3..c8701eacbf 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -88,14 +88,14 @@ class Chef validate_create_frequency_modifier(frequency, frequency_modifier)
validate_create_day(day, frequency) if day
validate_create_months(months, frequency) if months
- validate_idle_time(idle_time) if frequency == :on_idle
+ validate_idle_time(idle_time, frequency) if idle_time
end
private
def validate_random_delay(random_delay, frequency)
if [:once, :on_logon, :onstart, :on_idle].include? frequency
- raise ArgumentError, "`random_delay` property is not supported with frequency: #{frequency}"
+ raise ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly"
end
raise ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as a String e.g. '60'." if random_delay.to_i == 0
@@ -187,7 +187,11 @@ class Chef end
end
- def validate_idle_time(idle_time)
+ def validate_idle_time(idle_time, frequency)
+ unless [:on_idle].include?(frequency)
+ raise 'idle_time attribute is only valid for tasks that run on_idle'
+ end
+
unless idle_time.to_i > 0 && idle_time.to_i <= 999
raise "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999."
end
|