summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-09-08 19:00:42 -0700
committerGitHub <noreply@github.com>2020-09-08 19:00:42 -0700
commit8cac887c99a5f5c24ea02d52c70fd951c7b3a09a (patch)
tree4f13b250e3af3f49b952e9611eea810de919d188
parentd5c93d7c14d145b73f782c895c301caf046dea1a (diff)
parenteefbb39c33394ca8210fd5424eca3539d8adf3ed (diff)
downloadchef-8cac887c99a5f5c24ea02d52c70fd951c7b3a09a.tar.gz
Merge pull request #10395 from chef/faster_rhsm
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/rhsm_register.rb22
-rw-r--r--spec/unit/resource/rhsm_register_spec.rb44
2 files changed, 40 insertions, 26 deletions
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb
index 7188cecbad..ae031f8c50 100644
--- a/lib/chef/resource/rhsm_register.rb
+++ b/lib/chef/resource/rhsm_register.rb
@@ -121,24 +121,30 @@ class Chef
end
action_class do
+ #
+ # @return [Symbol] dnf_package or yum_package depending on OS release
+ #
def package_resource
node["platform_version"].to_i >= 8 ? :dnf_package : :yum_package
end
+ #
+ # @return [Boolean] is the node registered with RHSM
+ #
def registered_with_rhsm?
- # FIXME: use shell_out
- cmd = Mixlib::ShellOut.new("subscription-manager status", env: { LANG: "en_US" })
- cmd.run_command
- !cmd.stdout.match(/Overall Status: Unknown/)
+ @registered ||= !shell_out("subscription-manager status").stdout.include?("Overall Status: Unknown")
end
+ #
+ # @return [Boolean] is katello-ca-consumer installed
+ #
def katello_cert_rpm_installed?
- # FIXME: use shell_out
- cmd = Mixlib::ShellOut.new("rpm -qa | grep katello-ca-consumer")
- cmd.run_command
- !cmd.stdout.match(/katello-ca-consumer/).nil?
+ shell_out("rpm -qa").stdout.include?("katello-ca-consumer")
end
+ #
+ # @return [String] The URI to fetch katello-ca-consumer-latest.noarch.rpm from
+ #
def ca_consumer_package_source
protocol = new_resource.https_for_ca_consumer ? "https" : "http"
"#{protocol}://#{new_resource.satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm"
diff --git a/spec/unit/resource/rhsm_register_spec.rb b/spec/unit/resource/rhsm_register_spec.rb
index 79cf694b5f..50e95cd11e 100644
--- a/spec/unit/resource/rhsm_register_spec.rb
+++ b/spec/unit/resource/rhsm_register_spec.rb
@@ -41,23 +41,34 @@ describe Chef::Resource::RhsmRegister do
end
describe "#katello_cert_rpm_installed?" do
- let(:cmd) { double("cmd") }
-
- before do
- allow(Mixlib::ShellOut).to receive(:new).and_return(cmd)
- allow(cmd).to receive(:run_command)
- end
-
context "when the output contains katello-ca-consumer" do
+ let(:with_katello) { double("shell_out", stdout: <<~RPM) }
+ libevent-2.0.21-4.el7.x86_64
+ gettext-libs-0.19.8.1-3.el7.x86_64
+ yum-metadata-parser-1.1.4-10.el7.x86_64
+ pyliblzma-0.5.3-11.el7.x86_64
+ python-IPy-0.75-6.el7.noarch
+ grubby-8.28-26.el7.x86_64
+ fipscheck-lib-1.4.1-6.el7.x86_64
+ centos-logos-70.0.6-3.el7.centos.noarch
+ nss-tools-3.44.0-7.el7_7.x86_64
+ katello-ca-consumer-somehostname-1.0-1.el7.x86_64
+ rpm-4.11.3-43.el7.x86_64
+ gpgme-1.3.2-5.el7.x86_64
+ libnfsidmap-0.25-19.el7.x86_64
+ RPM
+
it "returns true" do
- allow(cmd).to receive(:stdout).and_return("katello-ca-consumer-somehostname-1.0-1")
+ allow(provider).to receive(:shell_out).and_return(with_katello)
expect(provider.katello_cert_rpm_installed?).to eq(true)
end
end
context "when the output does not contain katello-ca-consumer" do
+ let(:without_katello) { double("shell_out", stdout: "") }
+
it "returns false" do
- allow(cmd).to receive(:stdout).and_return("katello-agent-but-not-the-ca")
+ allow(provider).to receive(:shell_out).and_return(without_katello)
expect(provider.katello_cert_rpm_installed?).to eq(false)
end
end
@@ -204,23 +215,20 @@ describe Chef::Resource::RhsmRegister do
end
describe "#registered_with_rhsm?" do
- let(:cmd) { double("cmd") }
-
- before do
- allow(Mixlib::ShellOut).to receive(:new).and_return(cmd)
- allow(cmd).to receive(:run_command)
- end
-
context "when the status is Unknown" do
+ let(:unknown_status) { double("shell_out", stdout: "Overall Status: Unknown") }
+
it "returns false" do
- allow(cmd).to receive(:stdout).and_return("Overall Status: Unknown")
+ allow(provider).to receive(:shell_out).and_return(unknown_status)
expect(provider.registered_with_rhsm?).to eq(false)
end
end
context "when the status is anything else" do
+ let(:known_status) { double("shell_out", stdout: "Overall Status: Insufficient") }
+
it "returns true" do
- allow(cmd).to receive(:stdout).and_return("Overall Status: Insufficient")
+ allow(provider).to receive(:shell_out).and_return(known_status)
expect(provider.registered_with_rhsm?).to eq(true)
end
end