summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordheerajd-msys <dheeraj.dubey@msystechnologies.com>2018-07-24 18:57:42 +0530
committerdheerajd-msys <dheeraj.dubey@msystechnologies.com>2018-07-26 17:34:37 +0530
commitd00357daa06cf6300d21962566311f121c64d415 (patch)
tree4dc938a0fe2fec2c16aeeeb7e62ff242117651fe
parentc209ef456f6538b5cb3998958e73f7e7944058d1 (diff)
downloadchef-d00357daa06cf6300d21962566311f121c64d415.tar.gz
added functional test
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
-rw-r--r--lib/chef/provider/windows_task.rb14
-rw-r--r--lib/chef/resource/windows_task.rb6
-rw-r--r--spec/functional/resource/windows_task_spec.rb84
-rw-r--r--spec/unit/resource/windows_task_spec.rb8
4 files changed, 97 insertions, 15 deletions
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb
index f3e92b18f1..98dd8795fa 100644
--- a/lib/chef/provider/windows_task.rb
+++ b/lib/chef/provider/windows_task.rb
@@ -327,14 +327,12 @@ class Chef
def task_needs_update?(task)
flag = false
if new_resource.frequency == :none
- # require "byebug"
- # byebug
flag = (task.account_information != new_resource.user ||
task.application_name != new_resource.command ||
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_on_battery ||
- task.settings[:stop_if_going_on_batteries] != new_resource.stop_on_battery)
+ task.settings[:disallow_start_if_on_batteries] != new_resource.disallow_start_if_on_batteries ||
+ task.settings[:stop_if_going_on_batteries] != new_resource.stop_if_going_on_batteries)
else
current_task_trigger = task.trigger(0)
new_task_trigger = trigger
@@ -358,8 +356,8 @@ class Chef
task.principals[:logon_type] != logon_type ||
task.principals[:run_level] != run_level ||
PRIORITY[task.priority] != new_resource.priority ||
- task.settings[:disallow_start_if_on_batteries] != new_resource.disallow_start_on_battery ||
- task.settings[:stop_if_going_on_batteries] != new_resource.stop_on_battery
+ task.settings[:disallow_start_if_on_batteries] != new_resource.disallow_start_if_on_batteries ||
+ task.settings[:stop_if_going_on_batteries] != new_resource.stop_if_going_on_batteries
if trigger_type == TaskScheduler::MONTHLYDATE
flag = true if current_task_trigger[:run_on_last_day_of_month] != new_task_trigger[:run_on_last_day_of_month]
end
@@ -557,8 +555,8 @@ class Chef
settings[:idle_duration] = new_resource.idle_time if new_resource.idle_time
settings[:run_only_if_idle] = true if new_resource.idle_time
settings[:priority] = new_resource.priority
- settings[:disallow_start_if_on_batteries] = new_resource.disallow_start_on_battery
- settings[:stop_if_going_on_batteries] = new_resource.stop_on_battery
+ settings[:disallow_start_if_on_batteries] = new_resource.disallow_start_if_on_batteries
+ settings[:stop_if_going_on_batteries] = new_resource.stop_if_going_on_batteries
settings
end
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 37205d7cc2..3dea434a33 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -61,10 +61,10 @@ class Chef
property :minutes_interval, [String, Integer]
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 } }
- property :disallow_start_on_battery, [TrueClass, FalseClass], default: false,
+ property :disallow_start_if_on_batteries, [TrueClass, FalseClass], default: false,
introduced: "14.4",
- description: "Scheduled task option when system is on AC power."
- property :stop_on_battery, [TrueClass, FalseClass], default: false,
+ description: "Disallow start of the task if the system is running on battery power."
+ property :stop_if_going_on_batteries, [TrueClass, FalseClass], default: false,
introduced: "14.4",
description: "Scheduled task option when system is switching on battery."
diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb
index 02c84d5229..a2cd4b97d7 100644
--- a/spec/functional/resource/windows_task_spec.rb
+++ b/spec/functional/resource/windows_task_spec.rb
@@ -1096,6 +1096,90 @@ describe Chef::Resource::WindowsTask, :windows_only do
end
end
+ context "when battery options are passed" do
+ subject do
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
+ new_resource.command task_name
+ new_resource.run_level :highest
+ new_resource.execution_time_limit = 259200 / 60 # converting "PT72H" into minutes and passing here since win32-taskscheduler accespts this
+ new_resource
+ end
+
+ it "sets the default if options are not provided" do
+ subject.frequency :minute
+ call_for_create_action
+ # loading current resource again to check new task is created and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.stop_if_going_on_batteries).to eql(false)
+ expect(current_resource.disallow_start_if_on_batteries).to eql(false)
+ end
+
+ it "sets disallow_start_if_on_batteries to true" do
+ subject.frequency :minute
+ subject.disallow_start_if_on_batteries true
+ call_for_create_action
+ # loading current resource again to check new task is created and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(true)
+ end
+
+ it "sets disallow_start_if_on_batteries to false" do
+ subject.frequency :minute
+ subject.disallow_start_if_on_batteries false
+ call_for_create_action
+ # loading current resource again to check new task is created and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(false)
+ end
+
+ it "sets stop_if_going_on_batteries to true" do
+ subject.frequency :minute
+ subject.stop_if_going_on_batteries true
+ 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.settings[:stop_if_going_on_batteries]).to eql(true)
+ end
+
+ it "sets stop_if_going_on_batteries to false" do
+ subject.frequency :minute
+ subject.stop_if_going_on_batteries false
+ call_for_create_action
+ # loading current resource again to check new task is created and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.settings[:stop_if_going_on_batteries]).to eql(false)
+ end
+
+ it "sets the default if options are nil" do
+ subject.frequency :minute
+ subject.stop_if_going_on_batteries nil
+ subject.disallow_start_if_on_batteries nil
+ call_for_create_action
+ # loading current resource again to check new task is created and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.settings[:stop_if_going_on_batteries]).to eql(false)
+ expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(false)
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.frequency :minute
+ subject.stop_if_going_on_batteries true
+ subject.disallow_start_if_on_batteries false
+ subject.run_action(:create)
+ subject.frequency :minute
+ subject.stop_if_going_on_batteries true
+ subject.disallow_start_if_on_batteries false
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+ end
+
context "frequency :none" do
subject do
new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 135193fbea..76e2a86ee8 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -53,12 +53,12 @@ describe Chef::Resource::WindowsTask, :windows_only do
expect(resource.frequency_modifier).to eql(1)
end
- it "sets the default value for disallow_start_on_battery as false" do
- expect(resource.disallow_start_on_battery).to eql(false)
+ it "sets the default value for disallow_start_if_on_batteries as false" do
+ expect(resource.disallow_start_if_on_batteries).to eql(false)
end
- it "sets the default value for stop_on_battery as false" do
- expect(resource.stop_on_battery).to eql(false)
+ it "sets the default value for stop_if_going_on_batteries as false" do
+ expect(resource.stop_if_going_on_batteries).to eql(false)
end
context "when frequency is not provided" do