summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkapil chouhan <kapil.chouhan@msystechnologies.com>2018-10-25 09:19:49 +0000
committerKapil Chouhan <kapil.chouhan@msystechnologies.com>2018-10-30 16:26:09 +0530
commitc61bcb5ff071400ca90f0db125ef7eab3bb1fe4f (patch)
tree992f6875b3426d88f14fd6cf1916037a63f9690a
parentc6f0eb055601ac50c9b1c24ba815329bccfc7605 (diff)
downloadchef-c61bcb5ff071400ca90f0db125ef7eab3bb1fe4f.tar.gz
- Added `description` property on windows_task resource
Signed-off-by: kapil chouhan <kapil.chouhan@msystechnologies.com>
-rw-r--r--lib/chef/provider/windows_task.rb8
-rw-r--r--lib/chef/resource/windows_task.rb4
-rw-r--r--spec/functional/resource/windows_task_spec.rb39
3 files changed, 51 insertions, 0 deletions
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb
index d2ac9fdc59..122a571d56 100644
--- a/lib/chef/provider/windows_task.rb
+++ b/lib/chef/provider/windows_task.rb
@@ -147,6 +147,7 @@ class Chef
task.configure_principals(principal_settings)
task.set_account_information(new_resource.user, new_resource.password)
task.creator = new_resource.user
+ task.description = new_resource.description unless new_resource.description.nil?
task.activate(new_resource.task_name)
end
end
@@ -252,6 +253,7 @@ class Chef
task.trigger = trigger unless new_resource.frequency == :none
task.configure_settings(config_settings)
task.creator = new_resource.user
+ task.description = new_resource.description unless new_resource.description.nil?
task.configure_principals(principal_settings)
end
end
@@ -329,6 +331,7 @@ class Chef
if new_resource.frequency == :none
flag = (task.account_information != new_resource.user ||
task.application_name != new_resource.command ||
+ description_needs_update?(task) ||
task.parameters != new_resource.command_arguments.to_s ||
task.principals[:run_level] != run_level ||
task.settings[:disallow_start_if_on_batteries] != new_resource.disallow_start_if_on_batteries ||
@@ -351,6 +354,7 @@ class Chef
current_task_trigger[:minutes_interval].to_i != new_task_trigger[:minutes_interval].to_i ||
task.account_information != new_resource.user ||
task.application_name != new_resource.command ||
+ description_needs_update?(task) ||
task.parameters != new_resource.command_arguments.to_s ||
task.working_directory != new_resource.cwd.to_s ||
task.principals[:logon_type] != logon_type ||
@@ -567,6 +571,10 @@ class Chef
settings
end
+ def description_needs_update?(task)
+ task.description != new_resource.description unless new_resource.description.nil?
+ end
+
def logon_type
# Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383566(v=vs.85).aspx
# if nothing is passed as logon_type the TASK_LOGON_SERVICE_ACCOUNT is getting set as default so using that for comparision.
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 405846cb9e..f871708ea2 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -116,6 +116,10 @@ class Chef
introduced: "14.4", default: false,
description: "Scheduled task option when system is switching on battery."
+ property :description, String,
+ introduced: "14.7",
+ description: "The task description."
+
attr_accessor :exists, :task, :command_arguments
VALID_WEEK_DAYS = %w{ mon tue wed thu fri sat sun * }.freeze
diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb
index cb14da80d8..9b355d37ed 100644
--- a/spec/functional/resource/windows_task_spec.rb
+++ b/spec/functional/resource/windows_task_spec.rb
@@ -132,6 +132,45 @@ describe Chef::Resource::WindowsTask, :windows_only do
end
end
+ context "when description is passed" do
+ subject do
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
+ new_resource.execution_time_limit = 259200 / 60 # converting "PT72H" into minutes and passing here since win32-taskscheduler accespts this
+ new_resource.command task_name
+ # Make sure MM/DD/YYYY is accepted
+ new_resource.start_day "09/20/2017"
+ new_resource.frequency :hourly
+ new_resource
+ end
+
+ let(:some_description) { "this is test description" }
+
+ it "create the task and sets its description" do
+ subject.description some_description
+ call_for_create_action
+ # loading current resource again to check new task is creted and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.description).to eq(some_description)
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.description some_description
+ subject.run_action(:create)
+ subject.description some_description
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "updates task with new description if task already exist" do
+ subject.description some_description
+ subject.run_action(:create)
+ subject.description "test description"
+ subject.run_action(:create)
+ expect(subject).to be_updated_by_last_action
+ end
+ end
+
context "when frequency_modifier are not passed" do
subject do
new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)