summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Barnett <jason.w.barnett@gmail.com>2020-03-24 09:58:41 -0400
committerJason Barnett <jason.w.barnett@gmail.com>2020-03-24 19:13:23 -0400
commit9e4e5ec0fb14b9e28d402b4d0e80f2ad79e88541 (patch)
treefa58ea0e76288186ede84259a1491bafae5800f4
parent4d4c85435ba49cea68113838c7113bb22d9ba88c (diff)
downloadchef-9e4e5ec0fb14b9e28d402b4d0e80f2ad79e88541.tar.gz
Add :https_for_ca_consumer property to rhsm_register resource
Signed-off-by: Jason Barnett <jason.w.barnett@gmail.com>
-rw-r--r--lib/chef/resource/rhsm_register.rb13
-rw-r--r--spec/unit/resource/rhsm_register_spec.rb24
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb
index aa3f47780e..263950e717 100644
--- a/lib/chef/resource/rhsm_register.rb
+++ b/lib/chef/resource/rhsm_register.rb
@@ -16,6 +16,7 @@
#
require_relative "../resource"
+require_relative "../dist"
require "shellwords" unless defined?(Shellwords)
class Chef
@@ -61,6 +62,11 @@ class Chef
description: "If true, the system will be registered even if it is already registered. Normally, any register operations will fail if the machine has already been registered.",
default: false, desired_state: false
+ property :https_for_ca_consumer, [TrueClass, FalseClass],
+ description: "If true, #{Chef::Dist::PRODUCT} will fetch the katello-ca-consumer-latest.noarch.rpm from the satellite_host using HTTPS.",
+ default: false, desired_state: false,
+ introduced: "15.9"
+
action :register do
description "Register the node with RHSM."
@@ -74,7 +80,7 @@ class Chef
end
remote_file "#{Chef::Config[:file_cache_path]}/katello-package.rpm" do
- source "http://#{new_resource.satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm"
+ source ca_consumer_package_source
action :create
notifies :install, "#{package_resource}[katello-ca-consumer-latest]", :immediately
not_if { katello_cert_rpm_installed? }
@@ -133,6 +139,11 @@ class Chef
!cmd.stdout.match(/katello-ca-consumer/).nil?
end
+ 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"
+ end
+
def register_command
command = %w{subscription-manager register}
diff --git a/spec/unit/resource/rhsm_register_spec.rb b/spec/unit/resource/rhsm_register_spec.rb
index 3c39bba131..7bb49888e0 100644
--- a/spec/unit/resource/rhsm_register_spec.rb
+++ b/spec/unit/resource/rhsm_register_spec.rb
@@ -179,6 +179,30 @@ describe Chef::Resource::RhsmRegister do
end
end
+ describe "#ca_consumer_package_source" do
+ let(:satellite_host) { "sat-host" }
+
+ before do
+ resource.satellite_host = satellite_host
+ end
+
+ context "when https_for_ca_consumer is true" do
+ before { resource.https_for_ca_consumer true }
+
+ it "returns url with https" do
+ expect(provider.ca_consumer_package_source).to eq("https://#{satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm")
+ end
+ end
+
+ context "when https_for_ca_consumer is false" do
+ before { resource.https_for_ca_consumer false }
+
+ it "returns url with http" do
+ expect(provider.ca_consumer_package_source).to eq("http://#{satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm")
+ end
+ end
+ end
+
describe "#registered_with_rhsm?" do
let(:cmd) { double("cmd") }