summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-09-09 13:14:04 -0700
committerGitHub <noreply@github.com>2021-09-09 13:14:04 -0700
commitaa008fc4d173049eb299e54d28a244467d863bd0 (patch)
tree545f24a401dc0765fe98e7748e51125263b0d4ab
parent813869f9aadf2445c115f9f4c01ddb029eb93840 (diff)
parentb631de23222e034d0254be9b3c0437852c579223 (diff)
downloadchef-aa008fc4d173049eb299e54d28a244467d863bd0.tar.gz
Merge pull request #12014 from gholtiii/gh/add_priority_to_windows_task
[chef-client] Enable chef_client_scheduled_task resource to leverage …
-rw-r--r--lib/chef/resource/chef_client_scheduled_task.rb5
-rw-r--r--spec/unit/resource/chef_client_scheduled_task_spec.rb14
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/resource/chef_client_scheduled_task.rb b/lib/chef/resource/chef_client_scheduled_task.rb
index 6f88460d73..8b251b2441 100644
--- a/lib/chef/resource/chef_client_scheduled_task.rb
+++ b/lib/chef/resource/chef_client_scheduled_task.rb
@@ -129,6 +129,10 @@ class Chef
description: "An array of options to pass to the #{ChefUtils::Dist::Infra::CLIENT} command.",
default: []
+ property :priority, Integer,
+ description: "Use to set Priority Levels range from 0 to 10.",
+ default: 7, callbacks: { "should be in range of 0 to 10" => proc { |v| v >= 0 && v <= 10 } }
+
action :add, description: "Add a Windows Scheduled Task that runs #{ChefUtils::Dist::Infra::PRODUCT}." do
# TODO: Replace this with a :create_if_missing action on directory when that exists
unless Dir.exist?(new_resource.log_directory)
@@ -153,6 +157,7 @@ class Chef
start_day new_resource.start_date unless new_resource.start_date.nil?
random_delay new_resource.splay if frequency_supports_random_delay?
disallow_start_if_on_batteries new_resource.splay unless new_resource.run_on_battery
+ priority new_resource.priority
action %i{create enable}
end
end
diff --git a/spec/unit/resource/chef_client_scheduled_task_spec.rb b/spec/unit/resource/chef_client_scheduled_task_spec.rb
index b3c663cdae..0acc268a10 100644
--- a/spec/unit/resource/chef_client_scheduled_task_spec.rb
+++ b/spec/unit/resource/chef_client_scheduled_task_spec.rb
@@ -73,6 +73,20 @@ describe Chef::Resource::ChefClientScheduledTask do
expect(resource.chef_binary_path).to eql("C:/opscode/chef/bin/chef-client")
end
+ context "priority" do
+ it "default value is 7" do
+ expect(resource.priority).to eq(7)
+ end
+
+ it "raise error when priority value less than 0" do
+ expect { resource.priority(-1) }.to raise_error(Chef::Exceptions::ValidationFailed, "Option priority's value -1 should be in range of 0 to 10!")
+ end
+
+ it "raise error when priority values is greater than 10" do
+ expect { resource.priority 11 }.to raise_error(Chef::Exceptions::ValidationFailed, "Option priority's value 11 should be in range of 0 to 10!")
+ end
+ end
+
it "supports :add and :remove actions" do
expect { resource.action :add }.not_to raise_error
expect { resource.action :remove }.not_to raise_error