summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapil Chouhan <kapil.chouhan@msystechnologies.com>2018-11-19 10:00:25 +0000
committerKapil Chouhan <kapil.chouhan@msystechnologies.com>2018-11-27 08:33:39 +0000
commita322f0cb65dc0d8f8b7ba5bc25a882df8d5e6023 (patch)
treed71bb7adfcdef1a8a41915656611583dc1eccc11
parenta97e5da2e9dc3218da8df80eb905013effc85ca9 (diff)
downloadchef-a322f0cb65dc0d8f8b7ba5bc25a882df8d5e6023.tar.gz
Chef client should be fail appropriately when specified package is not applicable to image
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
-rw-r--r--lib/chef/provider/package/cab.rb8
-rw-r--r--spec/functional/resource/msu_package_spec.rb14
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/chef/provider/package/cab.rb b/lib/chef/provider/package/cab.rb
index 79292293d2..cfc629b9ef 100644
--- a/lib/chef/provider/package/cab.rb
+++ b/lib/chef/provider/package/cab.rb
@@ -74,9 +74,13 @@ class Chef
end
def dism_command(command)
- shellout = Mixlib::ShellOut.new("dism.exe /Online /English #{command} /NoRestart", timeout: new_resource.timeout)
with_os_architecture(nil) do
- shellout.run_command
+ result = shell_out("dism.exe /Online /English #{command} /NoRestart", { timeout: new_resource.timeout })
+ if result.exitstatus == -2146498530
+ raise Chef::Exceptions::Package, "The specified package is not applicable to this image." if result.stdout.include?("0x800f081e")
+ result.error!
+ end
+ result
end
end
diff --git a/spec/functional/resource/msu_package_spec.rb b/spec/functional/resource/msu_package_spec.rb
index 23342be6ae..d6811d99e7 100644
--- a/spec/functional/resource/msu_package_spec.rb
+++ b/spec/functional/resource/msu_package_spec.rb
@@ -76,6 +76,20 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
end
end
+ context "when an msu package is not applicable to the image." do
+ def package_name
+ "Package_for_KB4019990"
+ end
+
+ def package_source
+ "http://download.windowsupdate.com/c/msdownload/update/software/updt/2017/05/windows8-rt-kb4019990-x64_a77f4e3e1f2d47205824763e7121bb11979c2716.msu"
+ end
+
+ it "raises error while installing" do
+ expect { subject.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /The specified package is not applicable to this image./)
+ end
+ end
+
def remove_package
pkg_to_remove = Chef::Resource::MsuPackage.new(package_name, run_context)
pkg_to_remove.source = package_source