diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-09-08 13:30:34 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-09-08 13:30:34 -0700 |
commit | b281decfcd763c42ac7ad8dda7a813d5158fb8e4 (patch) | |
tree | 7ebb3f425f0074ebcf0e37703ece3434c7666704 | |
parent | 224fdec365fd55d84a3f2f1d85e5285f322b7d7a (diff) | |
download | chef-b281decfcd763c42ac7ad8dda7a813d5158fb8e4.tar.gz |
rhsm_register: Avoid potentially checking if we need to register twice
Switch to shell_out
Use include? instead of a regex
Add some simple YARD
Memoize the rhsm registration check
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/rhsm_register.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb index 7188cecbad..9f2df963b0 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 katello-ca-consumer installed + # 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 | grep katello-ca-consumer").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" |