summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-09-18 12:26:30 -0700
committerGitHub <noreply@github.com>2019-09-18 12:26:30 -0700
commit1dd794ec5d5f2253a2a2c99bc6a78d7f672f913f (patch)
treef376f729070b5e6551e5891df750bb4c3ce51071
parenta3cd3e022cbe7e3bc0adf3aa26e0315bc67242cd (diff)
parent6eda63f6f19ded01f12f7a0609b9392e834645cd (diff)
downloadchef-1dd794ec5d5f2253a2a2c99bc6a78d7f672f913f.tar.gz
Merge pull request #8894 from atward/backport-dnf-rhel8
dnf_package fixes for RHEL8 backport to chef-14
-rw-r--r--lib/chef/provider/package/dnf/dnf_helper.py16
-rw-r--r--lib/chef/resource/dnf_package.rb4
-rw-r--r--spec/functional/resource/dnf_package_spec.rb10
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/platform_helpers.rb8
5 files changed, 32 insertions, 8 deletions
diff --git a/lib/chef/provider/package/dnf/dnf_helper.py b/lib/chef/provider/package/dnf/dnf_helper.py
index 501d6fceee..0859348212 100644
--- a/lib/chef/provider/package/dnf/dnf_helper.py
+++ b/lib/chef/provider/package/dnf/dnf_helper.py
@@ -14,8 +14,22 @@ def get_sack():
global base
if base is None:
base = dnf.Base()
+ conf = base.conf
+ conf.read()
+ conf.installroot = '/'
+ subst = conf.substitutions
+ subst.update_from_etc(conf.installroot)
+ try:
+ base.init_plugins()
+ base.pre_configure_plugins()
+ except AttributeError:
+ pass
base.read_all_repos()
- base.fill_sack()
+ try:
+ base.configure_plugins()
+ except AttributeError:
+ pass
+ base.fill_sack(load_system_repo='auto')
return base.sack
# FIXME: leaks memory and does not work
diff --git a/lib/chef/resource/dnf_package.rb b/lib/chef/resource/dnf_package.rb
index 3b40a6dffb..c5672f8f69 100644
--- a/lib/chef/resource/dnf_package.rb
+++ b/lib/chef/resource/dnf_package.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016-2017, Chef Software Inc.
+# Copyright:: Copyright 2016-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -72,7 +72,7 @@ class Chef
if !arg.nil?
Chef.deprecated(:dnf_package_allow_downgrade, "the allow_downgrade property on the dnf_package provider is not used, DNF supports downgrades by default.")
end
- false
+ true
end
end
end
diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb
index 392c3d4012..0e7009f003 100644
--- a/spec/functional/resource/dnf_package_spec.rb
+++ b/spec/functional/resource/dnf_package_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -190,8 +190,8 @@ describe Chef::Resource::RpmPackage, :requires_root, external: exclude_test do
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
- it "matches with a vr glob" do
- pending "doesn't work on command line either"
+ # only works on rhel >= 8, was broken on old dnf
+ it "matches with a vr glob", :rhel_gte_8 do
flush_cache
dnf_package.package_name("chef_rpm")
dnf_package.version("1.10-1*")
@@ -200,8 +200,8 @@ describe Chef::Resource::RpmPackage, :requires_root, external: exclude_test do
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
- it "matches with an evr glob" do
- pending "doesn't work on command line either"
+ # only works on rhel >= 8, was broken on old dnf
+ it "matches with an evr glob", :rhel_gte_8 do
flush_cache
dnf_package.package_name("chef_rpm")
dnf_package.version("0:1.10-1*")
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5ed5e73506..582e183b36 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -190,6 +190,8 @@ RSpec.configure do |config|
config.filter_run_excluding rhel5: true unless rhel5?
config.filter_run_excluding rhel6: true unless rhel6?
config.filter_run_excluding rhel7: true unless rhel7?
+ config.filter_run_excluding rhel8: true unless rhel8?
+ config.filter_run_excluding rhel_gte_8: true unless rhel_gte_8?
config.filter_run_excluding intel_64bit: true unless intel_64bit?
config.filter_run_excluding not_rhel: true if rhel?
config.filter_run_excluding not_rhel6: true if rhel6?
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index f446a30862..43b3500e46 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -183,6 +183,14 @@ def rhel7?
rhel? && !!(ohai[:platform_version].to_i == 7)
end
+def rhel8?
+ rhel? && !!(ohai[:platform_version].to_i == 8)
+end
+
+def rhel_gte_8?
+ rhel? && !!(ohai[:platform_version].to_i >= 8)
+end
+
def debian_family?
!!(ohai[:platform_family] == "debian")
end