diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2015-10-05 12:39:42 -0700 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2015-10-05 12:39:42 -0700 |
commit | def2fe69b82fb8f0f5feb6634f63d6a3dc78ca85 (patch) | |
tree | b4654a78a78ad4c1c223f6fe1acc34e7b091bacd | |
parent | c762d1b21477f5d57c2ff5e5e2c7b04a2d5cf934 (diff) | |
parent | e413ea35bba2ad36453b3d428c343ab3f0bce23a (diff) | |
download | chef-def2fe69b82fb8f0f5feb6634f63d6a3dc78ca85.tar.gz |
Merge pull request #4032 from chef/mcquin/nano/disable-32-bit
Raise error when running 32-bit scripts on Windows Nano.
-rw-r--r-- | lib/chef/resource/windows_script.rb | 8 | ||||
-rw-r--r-- | spec/functional/resource/powershell_script_spec.rb | 17 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/shared/functional/windows_script.rb | 14 | ||||
-rw-r--r-- | spec/unit/resource/powershell_script_spec.rb | 30 |
5 files changed, 49 insertions, 21 deletions
diff --git a/lib/chef/resource/windows_script.rb b/lib/chef/resource/windows_script.rb index 48e2b535a8..2bbd01d5aa 100644 --- a/lib/chef/resource/windows_script.rb +++ b/lib/chef/resource/windows_script.rb @@ -16,6 +16,7 @@ # limitations under the License. # +require 'chef/platform/query_helpers' require 'chef/resource/script' require 'chef/mixin/windows_architecture_helper' @@ -51,9 +52,12 @@ class Chef protected def assert_architecture_compatible!(desired_architecture) - if ! node_supports_windows_architecture?(node, desired_architecture) + if desired_architecture == :i386 && Chef::Platform.windows_nano_server? raise Chef::Exceptions::Win32ArchitectureIncorrect, - "cannot execute script with requested architecture '#{desired_architecture.to_s}' on a system with architecture '#{node_windows_architecture(node)}'" + "cannot execute script with requested architecture 'i386' on Windows Nano Server" + elsif ! node_supports_windows_architecture?(node, desired_architecture) + raise Chef::Exceptions::Win32ArchitectureIncorrect, + "cannot execute script with requested architecture '#{desired_architecture.to_s}' on a system with architecture '#{node_windows_architecture(node)}'" end end end diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index ba0f867fcc..91b74fd752 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -314,9 +314,7 @@ configuration LCM expect(source_contains_case_insensitive_content?( get_script_output, 'AMD64' )).to eq(true) end - it "executes a script with a 32-bit process if :i386 arch is specified" do - pending "executing scripts with a 32-bit process should raise an error on nano" if Chef::Platform.windows_nano_server? - + it "executes a script with a 32-bit process if :i386 arch is specified", :not_supported_on_nano do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:i386) resource.returns(0) @@ -324,6 +322,12 @@ configuration LCM expect(source_contains_case_insensitive_content?( get_script_output, 'x86' )).to eq(true) end + + it "raises an error when executing a script with a 32-bit process on Windows Nano Server", :windows_nano_only do + resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") + expect{ resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, + "cannot execute script with requested architecture 'i386' on Windows Nano Server") + end end describe "when executing guards" do @@ -577,6 +581,13 @@ configuration LCM resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'" expect(resource.should_skip?(:run)).to be_truthy end + + it "raises an error when a 32-bit guard is used on Windows Nano Server", :windows_nano_only do + resource.only_if "$true", :architecture => :i386 + expect{resource.run_action(:run)}.to raise_error( + Chef::Exceptions::Win32ArchitectureIncorrect, + /cannot execute script with requested architecture 'i386' on Windows Nano Server/) + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3a1d116d79..4f7fde8eaf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -133,6 +133,7 @@ RSpec.configure do |config| config.filter_run_excluding :windows_2008r2_or_later => true unless windows_2008r2_or_later? config.filter_run_excluding :windows64_only => true unless windows64? config.filter_run_excluding :windows32_only => true unless windows32? + config.filter_run_excluding :windows_nano_only => true unless windows_nano_server? config.filter_run_excluding :ruby64_only => true unless ruby_64bit? config.filter_run_excluding :ruby32_only => true unless ruby_32bit? config.filter_run_excluding :windows_powershell_dsc_only => true unless windows_powershell_dsc? diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index b6fc2a98ad..70fb2d8578 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -103,16 +103,24 @@ shared_context Chef::Resource::WindowsScript do end end - context "when the guard's architecture is specified as 32-bit" do + context "when the guard's architecture is specified as 32-bit", :not_supported_on_nano do let (:guard_architecture) { :i386 } it "executes a 32-bit guard" do - pending "executing scripts with a 32-bit process should raise an error on nano" if Chef::Platform.windows_nano_server? - resource.only_if resource_guard_command, :architecture => guard_architecture resource.run_action(:run) expect(get_guard_process_architecture).to eq('x86') end end + + context "when the guard's architecture is specified as 32-bit", :windows_nano_only do + let (:guard_architecture) { :i386 } + it "raises an error" do + resource.only_if resource_guard_command, :architecture => guard_architecture + expect{ resource.run_action(:run) }.to raise_error( + Chef::Exceptions::Win32ArchitectureIncorrect, + /cannot execute script with requested architecture 'i386' on Windows Nano Server/) + end + end end end diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index 2505c4a3d7..42fcd61a58 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -30,24 +30,28 @@ describe Chef::Resource::PowershellScript do run_context = Chef::RunContext.new(node, nil, nil) @resource = Chef::Resource::PowershellScript.new("powershell_unit_test", run_context) - end - it "should create a new Chef::Resource::PowershellScript" do + it "creates a new Chef::Resource::PowershellScript" do expect(@resource).to be_a_kind_of(Chef::Resource::PowershellScript) end - it "should set convert_boolean_return to false by default" do + it "sets convert_boolean_return to false by default" do expect(@resource.convert_boolean_return).to eq(false) end - it "should return the value for convert_boolean_return that was set" do + it "returns the value for convert_boolean_return that was set" do @resource.convert_boolean_return true expect(@resource.convert_boolean_return).to eq(true) @resource.convert_boolean_return false expect(@resource.convert_boolean_return).to eq(false) end + it "raises an error when architecture is i386 on Windows Nano Server" do + allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true) + expect{@resource.architecture(:i386)}.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture 'i386' on Windows Nano Server") + end + context "when using guards" do let(:resource) { @resource } before(:each) do @@ -62,32 +66,32 @@ describe Chef::Resource::PowershellScript do expect(inherited_difference).to eq([]) end - it "should allow guard interpreter to be set to Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::Script" do resource.guard_interpreter(:script) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should allow guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do resource.guard_interpreter(:bash) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should allow guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do resource.guard_interpreter(:powershell_script) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should enable convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do + it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {}) resource.only_if("$true") end - it "should enable convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do + it "enables convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do node = Chef::Node.new run_context = Chef::RunContext.new(node, nil, nil) file_resource = Chef::Resource::File.new('idontexist', run_context) @@ -98,21 +102,21 @@ describe Chef::Resource::PowershellScript do resource.only_if("$true") end - it "should enable convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do + it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64} allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end - it "should pass convert_boolean_return as true if it was specified as true in a guard parameter" do + it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do guard_parameters = {:cwd => '/etc/chef', :convert_boolean_return => true, :architecture => :x86_64} allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end - it "should pass convert_boolean_return as false if it was specified as true in a guard parameter" do + it "passes convert_boolean_return as false if it was specified as true in a guard parameter" do other_guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64} parameters_with_boolean_disabled = other_guard_parameters.merge({:convert_boolean_return => false, :code => "$true"}) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( @@ -127,6 +131,6 @@ describe Chef::Resource::PowershellScript do let(:resource_name) { :powershell_script } let(:interpreter_file_name) { 'powershell.exe' } - it_should_behave_like "a Windows script resource" + it_behaves_like "a Windows script resource" end end |