summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-06-05 10:05:40 -0700
committerGitHub <noreply@github.com>2020-06-05 10:05:40 -0700
commit894080b8fe068ad2fec94a6deefa2ad0fea38dde (patch)
tree991c4b6b350d99b49e51c8faa70a7191e272b715
parent3622a21df1c7e0cef0beca6b1d1fd40bbadc7031 (diff)
parentcc35e6bafa4ce87e3fbe80d8c4561a0fe6e0f425 (diff)
downloadchef-894080b8fe068ad2fec94a6deefa2ad0fea38dde.tar.gz
Merge pull request #9920 from chef-davin/master
Update to the chef_client_scheduled_task resource frequency_modify default functionality
-rw-r--r--lib/chef/resource/chef_client_scheduled_task.rb14
-rw-r--r--spec/unit/resource/chef_client_scheduled_task_spec.rb20
2 files changed, 28 insertions, 6 deletions
diff --git a/lib/chef/resource/chef_client_scheduled_task.rb b/lib/chef/resource/chef_client_scheduled_task.rb
index f5a7e5a4e7..cdbf6420ac 100644
--- a/lib/chef/resource/chef_client_scheduled_task.rb
+++ b/lib/chef/resource/chef_client_scheduled_task.rb
@@ -48,6 +48,16 @@ class Chef
daemon_options ["--override-runlist mycorp_base::default"]
end
```
+
+ **Run #{Chef::Dist::PRODUCT} daily at 01:00 am, specifying a named run-list**:
+
+ ```ruby
+ chef_client_scheduled_task "Run chef-client named run-list daily" do
+ frequency 'daily'
+ start_time '01:00'
+ daemon_options ['-n audit_only']
+ end
+ ```
DOC
resource_name :chef_client_scheduled_task
@@ -72,7 +82,8 @@ class Chef
coerce: proc { |x| Integer(x) },
callbacks: { "should be a positive number" => proc { |v| v > 0 } },
description: "Numeric value to go with the scheduled task frequency",
- default: 30
+ default: lazy { frequency == "minute" ? 30 : 1 },
+ default_description: "30 if frequency is 'minute', 1 otherwise"
property :accept_chef_license, [true, false],
description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement/>",
@@ -129,6 +140,7 @@ class Chef
# According to https://docs.microsoft.com/en-us/windows/desktop/taskschd/schtasks,
# the :once, :onstart, :onlogon, and :onidle schedules don't accept schedule modifiers
+
windows_task new_resource.task_name do
run_level :highest
command full_command
diff --git a/spec/unit/resource/chef_client_scheduled_task_spec.rb b/spec/unit/resource/chef_client_scheduled_task_spec.rb
index 4b59c0861f..b3c663cdae 100644
--- a/spec/unit/resource/chef_client_scheduled_task_spec.rb
+++ b/spec/unit/resource/chef_client_scheduled_task_spec.rb
@@ -43,6 +43,16 @@ describe Chef::Resource::ChefClientScheduledTask do
expect(resource.frequency_modifier).to eql(10)
end
+ it "expects default frequency modifier to be 30 when frequency is set to 'minute'" do
+ resource.frequency "minute"
+ expect(resource.frequency_modifier).to eql(30)
+ end
+
+ it "expects default frequency modifier to be 1 when frequency is set to 'daily'" do
+ resource.frequency "daily"
+ expect(resource.frequency_modifier).to eql(1)
+ end
+
it "validates the start_time property input" do
expect { resource.start_time("8:00 am") }.to raise_error(Chef::Exceptions::ValidationFailed)
expect { resource.start_time("8:00") }.to raise_error(Chef::Exceptions::ValidationFailed)
@@ -70,12 +80,12 @@ describe Chef::Resource::ChefClientScheduledTask do
describe "#client_cmd" do
it "creates a valid command if using all default properties" do
- expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb")
+ expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb") | eql("C:/opscode/chef/bin/chef-client -L C:\\chef/log/client.log -c C:\\chef/client.rb")
end
it "uses daemon_options if set" do
resource.daemon_options ["--foo 1", "--bar 2"]
- expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb --foo 1 --bar 2")
+ expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb --foo 1 --bar 2") | eql("C:/opscode/chef/bin/chef-client -L C:\\chef/log/client.log -c C:\\chef/client.rb --foo 1 --bar 2")
end
it "uses custom config dir if set" do
@@ -86,17 +96,17 @@ describe Chef::Resource::ChefClientScheduledTask do
it "uses custom log files / paths if set" do
resource.log_file_name "my-client.log"
resource.log_directory "C:/foo/bar"
- expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L C:/foo/bar/my-client.log -c /etc/chef/client.rb")
+ expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L C:/foo/bar/my-client.log -c /etc/chef/client.rb") | eql("C:/opscode/chef/bin/chef-client -L C:/foo/bar/my-client.log -c C:\\chef/client.rb")
end
it "uses custom chef-client binary if set" do
resource.chef_binary_path "C:/foo/bar/chef-client"
- expect(provider.client_cmd).to eql("C:/foo/bar/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb")
+ expect(provider.client_cmd).to eql("C:/foo/bar/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb") | eql("C:/foo/bar/chef-client -L C:\\chef/log/client.log -c C:\\chef/client.rb")
end
it "sets the license acceptance flag if set" do
resource.accept_chef_license true
- expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb --chef-license accept")
+ expect(provider.client_cmd).to eql("C:/opscode/chef/bin/chef-client -L /etc/chef/log/client.log -c /etc/chef/client.rb --chef-license accept") | eql("C:/opscode/chef/bin/chef-client -L C:\\chef/log/client.log -c C:\\chef/client.rb --chef-license accept")
end
end
end