summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/dsl/reboot_pending.rb3
-rw-r--r--spec/functional/dsl/reboot_pending_spec.rb76
-rw-r--r--spec/unit/dsl/reboot_pending_spec.rb16
3 files changed, 46 insertions, 49 deletions
diff --git a/lib/chef/dsl/reboot_pending.rb b/lib/chef/dsl/reboot_pending.rb
index c577118dd4..3d84b29ec5 100644
--- a/lib/chef/dsl/reboot_pending.rb
+++ b/lib/chef/dsl/reboot_pending.rb
@@ -49,7 +49,8 @@ class Chef
# The mere existence of the UpdateExeVolatile key should indicate a pending restart for certain updates
# http://support.microsoft.com/kb/832475
- (registry_key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
+ Chef::Platform.windows_server_2003? &&
+ (registry_key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
!registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0].nil? &&
[1,2,3].include?(registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0][:data]))
elsif platform?("ubuntu")
diff --git a/spec/functional/dsl/reboot_pending_spec.rb b/spec/functional/dsl/reboot_pending_spec.rb
index 14dd9412d5..1d11f38dbc 100644
--- a/spec/functional/dsl/reboot_pending_spec.rb
+++ b/spec/functional/dsl/reboot_pending_spec.rb
@@ -30,13 +30,6 @@ describe Chef::DSL::RebootPending, :windows_only do
ohai
end
- def registry_unsafe?
- registry.value_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { :name => 'PendingFileRenameOperations' }) ||
- registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired')
- registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired') ||
- registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile')
- end
-
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let!(:ohai) { run_ohai } # Ensure we have necessary node data
@@ -45,76 +38,73 @@ describe Chef::DSL::RebootPending, :windows_only do
let(:registry) { Chef::Win32::Registry.new(run_context) }
describe "reboot_pending?" do
+ let(:reg_key) { nil }
+ let(:original_set) { false }
- describe "when there is nothing to indicate a reboot is pending" do
- it "should return false" do
- skip "Found existing registry keys" if registry_unsafe?
- expect(recipe.reboot_pending?).to be_falsey
- end
- end
+ before(:all) { @any_flag = Hash.new }
+
+ after { @any_flag[reg_key] = original_set }
describe 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations' do
+ let(:reg_key) { 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager' }
+ let(:original_set) { registry.value_exists?(reg_key, { :name => 'PendingFileRenameOperations' }) }
+
it "returns true if the registry value exists" do
- skip "Found existing registry keys" if registry_unsafe?
- registry.set_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager',
+ skip 'found existing registry key' if original_set
+ registry.set_value(reg_key,
{ :name => 'PendingFileRenameOperations', :type => :multi_string, :data => ['\??\C:\foo.txt|\??\C:\bar.txt'] })
expect(recipe.reboot_pending?).to be_truthy
end
after do
- unless registry_unsafe?
- registry.delete_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { :name => 'PendingFileRenameOperations' })
+ unless original_set
+ registry.delete_value(reg_key, { :name => 'PendingFileRenameOperations' })
end
end
end
- describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' do
+ describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired' do
+ let(:reg_key) { 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired' }
+ let(:original_set) { registry.key_exists?(reg_key) }
+
it "returns true if the registry key exists" do
- skip "Found existing registry keys" if registry_unsafe?
- registry.create_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired', false)
+ skip 'found existing registry key' if original_set
+ pending "Permissions are limited to 'TrustedInstaller' by default"
+ registry.create_key(reg_key, false)
expect(recipe.reboot_pending?).to be_truthy
end
after do
- unless registry_unsafe?
- registry.delete_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired', false)
+ unless original_set
+ registry.delete_key(reg_key, false)
end
end
end
- describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired' do
+ describe 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' do
+ let(:reg_key) { 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' }
+ let(:original_set) { registry.key_exists?(reg_key) }
+
it "returns true if the registry key exists" do
- pending "Permissions are limited to 'TrustedInstaller' by default"
- skip "Found existing registry keys" if registry_unsafe?
- registry.create_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired', false)
+ skip 'found existing registry key' if original_set
+ registry.create_key(reg_key, false)
expect(recipe.reboot_pending?).to be_truthy
end
after do
- unless registry_unsafe?
- registry.delete_key('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired', false)
+ unless original_set
+ registry.delete_key(reg_key, false)
end
end
end
- describe 'HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile\Flags' do
- it "returns true if the registry key exists" do
- skip "Found existing registry keys" if registry_unsafe?
- registry.create_key('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', true)
- registry.set_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile',
- { :name => 'Flags', :type => :dword, :data => 3 })
-
- expect(recipe.reboot_pending?).to be_truthy
- end
-
- after do
- unless registry_unsafe?
- registry.delete_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', { :name => 'Flags' })
- registry.delete_key('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile', false)
- end
+ describe "when there is nothing to indicate a reboot is pending" do
+ it "should return false" do
+ skip 'reboot pending' if @any_flag.any? { |_,v| v == true }
+ expect(recipe.reboot_pending?).to be_falsey
end
end
end
diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb
index a55f91d5e6..6705820e17 100644
--- a/spec/unit/dsl/reboot_pending_spec.rb
+++ b/spec/unit/dsl/reboot_pending_spec.rb
@@ -50,11 +50,17 @@ describe Chef::DSL::RebootPending do
expect(recipe.reboot_pending?).to be_truthy
end
- it 'should return true if value "HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile" contains specific data' do
- allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(true)
- allow(recipe).to receive(:registry_get_values).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(
- [{:name => "Flags", :type => :dword, :data => 3}])
- expect(recipe.reboot_pending?).to be_truthy
+ context "version is server 2003" do
+ before do
+ allow(Chef::Platform).to receive(:windows_server_2003?).and_return(true)
+ end
+
+ it 'should return true if value "HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile" contains specific data on 2k3' do
+ allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(true)
+ allow(recipe).to receive(:registry_get_values).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(
+ [{:name => "Flags", :type => :dword, :data => 3}])
+ expect(recipe.reboot_pending?).to be_truthy
+ end
end
end