summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2022-02-07 15:59:07 -0800
committerGitHub <noreply@github.com>2022-02-07 15:59:07 -0800
commit21858edc362dd31b131f22192445f1efa269c00e (patch)
tree83fee54ce2037d41cf4b92dcdcab8cc8c7b149fd
parent2d6853eff6a4690eba0a3d47a74ecd16607210b9 (diff)
parenteabefb31445edd4862f1ad36c791d7b324841c22 (diff)
downloadchef-21858edc362dd31b131f22192445f1efa269c00e.tar.gz
Merge pull request #12552 from chef/lcg/eager-load-ffi-libarchive
Eager load ffi-libarchive to resolve centos-7 failures
-rw-r--r--lib/chef/resource/archive_file.rb12
-rw-r--r--spec/functional/resource/archive_file_spec.rb5
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/unit/resource/archive_file_spec.rb3
4 files changed, 10 insertions, 12 deletions
diff --git a/lib/chef/resource/archive_file.rb b/lib/chef/resource/archive_file.rb
index 9acec4213c..1a27786336 100644
--- a/lib/chef/resource/archive_file.rb
+++ b/lib/chef/resource/archive_file.rb
@@ -20,6 +20,12 @@
require_relative "../resource"
require "fileutils" unless defined?(FileUtils)
+begin
+ # ffi-libarchive must be eager loaded see: https://github.com/chef/chef/issues/12228
+ require "ffi-libarchive" unless defined?(Archive::Reader)
+rescue LoadError
+ STDERR.puts "ffi-libarchive could not be loaded, libarchive is probably not installed on system, archive_file will not be available"
+end
class Chef
class Resource
@@ -92,8 +98,6 @@ class Chef
action :extract, description: "Extract and archive file." do
- require_libarchive
-
unless ::File.exist?(new_resource.path)
raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue."
end
@@ -131,10 +135,6 @@ class Chef
end
action_class do
- def require_libarchive
- require "ffi-libarchive"
- end
-
def define_resource_requirements
if new_resource.mode.is_a?(Integer)
Chef.deprecated(:archive_file_integer_file_mode, "The mode property should be passed to archive_file resources as a String and not an Integer to ensure the value is properly interpreted.")
diff --git a/spec/functional/resource/archive_file_spec.rb b/spec/functional/resource/archive_file_spec.rb
index 27815cb319..94da76c4f2 100644
--- a/spec/functional/resource/archive_file_spec.rb
+++ b/spec/functional/resource/archive_file_spec.rb
@@ -18,8 +18,9 @@
require "spec_helper"
require "tmpdir"
-# Exclude this test on platforms where ffi-libarchive loading is broken
-describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
+# AIX is broken, see https://github.com/chef/omnibus-software/issues/1566
+# Windows tests are disbled since we'd need libarchive on windows testers in buildkite for PRs
+describe Chef::Resource::ArchiveFile, :not_supported_on_aix, :not_supported_on_windows do
include RecipeDSLHelper
let(:tmp_path) { Dir.mktmpdir }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5cd04437be..2aa3b2a1cd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -187,8 +187,6 @@ RSpec.configure do |config|
config.filter_run_excluding not_rhel7: true if rhel7?
config.filter_run_excluding not_intel_64bit: true if intel_64bit?
- config.filter_run_excluding libarchive_loading_broken: true if aix? || amazon_linux? || rhel7?
-
# these let us use chef: ">= 13" or ruby: "~> 2.0.0" or any other Gem::Dependency-style constraint
config.filter_run_excluding chef: DependencyProc.with(Chef::VERSION)
config.filter_run_excluding ruby: DependencyProc.with(RUBY_VERSION)
diff --git a/spec/unit/resource/archive_file_spec.rb b/spec/unit/resource/archive_file_spec.rb
index 88cbe94629..7818a31516 100644
--- a/spec/unit/resource/archive_file_spec.rb
+++ b/spec/unit/resource/archive_file_spec.rb
@@ -29,8 +29,7 @@ rescue LoadError
end
end
-# Exclude this test on platforms where ffi-libarchive loading is broken
-describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
+describe Chef::Resource::ArchiveFile, :not_supported_on_aix do
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let(:run_context) { Chef::RunContext.new(node, {}, events) }