diff options
author | Lamont Granquist <454857+lamont-granquist@users.noreply.github.com> | 2021-11-02 12:37:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-02 12:37:54 -0700 |
commit | 88935078dcbb693b59fc1c7be12ac2b8ac1d87c7 (patch) | |
tree | 691aa1fc944d6f85c99b05efc838f14b8eef6d5a | |
parent | 94f3dc70bf6ecf716eab9a716efe29c7a5de24e1 (diff) | |
parent | 8ea3396aed1e6f7c1beafd5e320e95a9b2ba9f5d (diff) | |
download | chef-88935078dcbb693b59fc1c7be12ac2b8ac1d87c7.tar.gz |
Merge pull request #12233 from collinmcneese/cmcneese/rhsm_register
-rw-r--r-- | cspell.json | 3 | ||||
-rw-r--r-- | lib/chef/resource/rhsm_register.rb | 31 | ||||
-rw-r--r-- | spec/unit/resource/rhsm_register_spec.rb | 42 |
3 files changed, 76 insertions, 0 deletions
diff --git a/cspell.json b/cspell.json index 7a5b51b510..06118297c8 100644 --- a/cspell.json +++ b/cspell.json @@ -96,6 +96,7 @@ "basearch", "basenames", "basepath", + "baseurl", "baseurls", "Bcast", "bcast", @@ -1132,8 +1133,10 @@ "SERENUM", "sertelon", "servername", + "serverurl", "SERVERR", "servicecheck", + "servicelevel", "SERVICENAME", "SESS", "SESSIONCHANGE", diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb index 3e1d251e76..2f4b5fa6f5 100644 --- a/lib/chef/resource/rhsm_register.rb +++ b/lib/chef/resource/rhsm_register.rb @@ -79,6 +79,23 @@ class Chef default: false, desired_state: false, introduced: "15.9" + property :server_url, String, + description: "The hostname of the subscription service to use. The default is for Customer Portal Subscription Management, subscription.rhn.redhat.com. If this option is not used, the system is registered with Customer Portal Subscription Management.", + introduced: "17.8" + + property :base_url, String, + description: "The hostname of the content delivery server to use to receive updates. Both Customer Portal Subscription Management and Subscription Asset Manager use Red Hat's hosted content delivery services, with the URL https://cdn.redhat.com. Since Satellite 6 hosts its own content, the URL must be used for systems registered with Satellite 6.", + introduced: "17.8" + + property :service_level, String, + description: "Sets the service level to use for subscriptions on the registering machine. This is only used with the auto_attach option.", + introduced: "17.8" + + property :release, + [Float, String], + description: "Sets the operating system minor release to use for subscriptions for the system. Products and updates are limited to the specified minor release version. This is used only used with the auto_attach option. For example, `release '6.4'` will append `--release=6.4` to the register command.", + introduced: "17.8" + action :register, description: "Register the node with RHSM." do package "subscription-manager" @@ -170,6 +187,8 @@ class Chef command << new_resource.activation_key.map { |key| "--activationkey=#{Shellwords.shellescape(key)}" } command << "--org=#{Shellwords.shellescape(new_resource.organization)}" command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name + command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url + command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url command << "--force" if new_resource.force return command.join(" ") @@ -179,11 +198,23 @@ class Chef if new_resource.username && new_resource.password raise "Unable to register - you must specify environment when using username/password" if new_resource.environment.nil? && using_satellite_host? + if new_resource.service_level + raise "Unable to register - 'auto_attach' must be enabled when using property `service_level`." unless new_resource.auto_attach + end + + if new_resource.release + raise "Unable to register - `auto_attach` must be enabled when using property `release`." unless new_resource.auto_attach + end + command << "--username=#{Shellwords.shellescape(new_resource.username)}" command << "--password=#{Shellwords.shellescape(new_resource.password)}" command << "--environment=#{Shellwords.shellescape(new_resource.environment)}" if using_satellite_host? command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name + command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url + command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url command << "--auto-attach" if new_resource.auto_attach + command << "--servicelevel=#{Shellwords.shellescape(new_resource.service_level)}" if new_resource.service_level + command << "--release=#{Shellwords.shellescape(new_resource.release)}" if new_resource.release command << "--force" if new_resource.force return command.join(" ") diff --git a/spec/unit/resource/rhsm_register_spec.rb b/spec/unit/resource/rhsm_register_spec.rb index 7ce76ad908..7094046066 100644 --- a/spec/unit/resource/rhsm_register_spec.rb +++ b/spec/unit/resource/rhsm_register_spec.rb @@ -158,6 +158,48 @@ describe Chef::Resource::RhsmRegister do end end + context "when a server_url is provided" do + it "returns a command containing the server url" do + allow(resource).to receive(:server_url).and_return("https://fqdn.example") + expect(provider.register_command).to match("--serverurl=https://fqdn.example") + end + end + + context "when a base_url is provided" do + it "returns a command containing the base url" do + allow(resource).to receive(:base_url).and_return("https://fqdn.example") + expect(provider.register_command).to match("--baseurl=https://fqdn.example") + end + end + + context "when a service_level is provided" do + it "returns a command containing the service level" do + allow(resource).to receive(:service_level).and_return("None") + allow(resource).to receive(:auto_attach).and_return(true) + expect(provider.register_command).to match("--servicelevel=None") + end + + it "raises an exception if auto_attach is not set" do + allow(resource).to receive(:service_level).and_return("None") + allow(resource).to receive(:auto_attach).and_return(nil) + expect { provider.register_command }.to raise_error(RuntimeError) + end + end + + context "when a release is provided" do + it "returns a command containing the release" do + allow(resource).to receive(:release).and_return("8.4") + allow(resource).to receive(:auto_attach).and_return(true) + expect(provider.register_command).to match("--release=8.4") + end + + it "raises an exception if auto_attach is not set" do + allow(resource).to receive(:release).and_return("8.4") + allow(resource).to receive(:auto_attach).and_return(nil) + expect { provider.register_command }.to raise_error(RuntimeError) + end + end + context "when a system_name is not provided" do it "returns a command containing the system name" do allow(resource).to receive(:system_name).and_return(nil) |