summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2022-06-24 19:03:23 -0700
committerJohn McCrae <john.mccrae@progress.com>2022-06-24 19:03:23 -0700
commit6348db235a97a196593f9be38fc08d324a428761 (patch)
treec7b52b24127ca6026c6e8a14baa7f88fa534c11f
parent2227d02c8d99ee4c0e4978f1c824860ebb8b48bc (diff)
downloadchef-6348db235a97a196593f9be38fc08d324a428761.tar.gz
Added a new test, discovered a new bug in the tests and corrected that. All tests passing locally
Signed-off-by: John McCrae <john.mccrae@progress.com>
-rw-r--r--lib/chef/resource/windows_pagefile.rb5
-rw-r--r--spec/functional/resource/windows_pagefile_spec.rb21
2 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/resource/windows_pagefile.rb b/lib/chef/resource/windows_pagefile.rb
index 80cbfc05c5..543170a70e 100644
--- a/lib/chef/resource/windows_pagefile.rb
+++ b/lib/chef/resource/windows_pagefile.rb
@@ -246,14 +246,13 @@ class Chef
# @param [String] min the minimum size of the pagefile
# @param [String] max the minimum size of the pagefile
def set_custom_size(pagefile, min, max)
+ unset_automatic_managed
converge_by("set #{pagefile} to InitialSize=#{min} & MaximumSize=#{max}") do
logger.trace("Set-CimInstance -Property @{InitialSize = #{min} MaximumSize = #{max}")
powershell_exec! <<~EOD
$page_file = "#{pagefile}"
$driveLetter = $page_file.split(':')[0]
- Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($driveLetter):'" -ErrorAction Stop | Set-CimInstance -Property @{
- InitialSize = #{min}
- MaximumSize = #{max}}
+ Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($driveLetter):'" -ErrorAction Stop | Set-CimInstance -Property @{InitialSize = #{min}; MaximumSize = #{max};}
EOD
end
end
diff --git a/spec/functional/resource/windows_pagefile_spec.rb b/spec/functional/resource/windows_pagefile_spec.rb
index a947d5b40e..9767f7eeb1 100644
--- a/spec/functional/resource/windows_pagefile_spec.rb
+++ b/spec/functional/resource/windows_pagefile_spec.rb
@@ -49,6 +49,15 @@ describe Chef::Resource::WindowsPagefile, :windows_only do
powershell_exec!(powershell_code)
end
+ def set_automatic_managed_to_true
+ powershell_code = <<~EOH
+ $computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges;
+ $computersys.AutomaticManagedPagefile = $True;
+ $computersys.Put();
+ EOH
+ powershell_exec!(powershell_code)
+ end
+
describe "Setting Up Pagefile Management" do
context "Disable Automatic Management" do
it "Verifies Automatic Management is Disabled" do
@@ -65,6 +74,14 @@ describe Chef::Resource::WindowsPagefile, :windows_only do
subject.run_action(:set)
expect(subject).to be_updated_by_last_action
end
+
+ it "Disables Automatic Management" do
+ set_automatic_managed_to_true
+ subject.path c_path
+ subject.automatic_managed false
+ subject.run_action(:set)
+ expect(subject).to be_updated_by_last_action
+ end
end
end
@@ -79,8 +96,8 @@ describe Chef::Resource::WindowsPagefile, :windows_only do
context "Update a pagefile" do
it "Changes a pagefile to use custom sizes" do
subject.path c_path
- subject.initial_size 20000
- subject.maximum_size 80000
+ subject.initial_size 128
+ subject.maximum_size 512
subject.run_action(:set)
expect(subject).to be_updated_by_last_action
end