diff options
author | Jason Barnett <jason.w.barnett@gmail.com> | 2020-09-10 11:55:40 -0400 |
---|---|---|
committer | Jason Barnett <jason.w.barnett@gmail.com> | 2020-09-10 12:27:50 -0400 |
commit | 6fdb6d11135fae47617be1edb869866360acefc0 (patch) | |
tree | 27cbdf69bc02534b2fe37c9225dfe6047b6def29 | |
parent | 8f60110bfa9485eb31e33df7c27e2646fb3bcc31 (diff) | |
download | chef-6fdb6d11135fae47617be1edb869866360acefc0.tar.gz |
Add system_name property to rhsm_register resource
Signed-off-by: Jason Barnett <jason.w.barnett@gmail.com>
-rw-r--r-- | lib/chef/resource/rhsm_register.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/rhsm_register_spec.rb | 30 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb index ae031f8c50..80cf62e169 100644 --- a/lib/chef/resource/rhsm_register.rb +++ b/lib/chef/resource/rhsm_register.rb @@ -47,6 +47,10 @@ class Chef property :password, String, description: "The password to use when registering. This property is not applicable if using an activation key. If specified, username and environment are also required." + property :system_name, String, + description: "The name of the system to register, defaults to the hostname.", + introduced: "16.5" + property :auto_attach, [TrueClass, FalseClass], description: "If true, RHSM will attempt to automatically attach the host to applicable subscriptions. It is generally better to use an activation key with the subscriptions pre-defined.", @@ -159,6 +163,7 @@ 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 << "--force" if new_resource.force return command.join(" ") @@ -171,6 +176,7 @@ class Chef 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 << "--auto-attach" if new_resource.auto_attach command << "--force" if new_resource.force diff --git a/spec/unit/resource/rhsm_register_spec.rb b/spec/unit/resource/rhsm_register_spec.rb index 50e95cd11e..7ce76ad908 100644 --- a/spec/unit/resource/rhsm_register_spec.rb +++ b/spec/unit/resource/rhsm_register_spec.rb @@ -100,6 +100,22 @@ describe Chef::Resource::RhsmRegister do end end + context "when a system_name is provided" do + it "returns a command containing the system name" do + allow(resource).to receive(:organization).and_return("myorg") + allow(resource).to receive(:system_name).and_return("myname") + expect(provider.register_command).to match("--name=myname") + end + end + + context "when a system_name is not provided" do + it "returns a command containing the system name" do + allow(resource).to receive(:organization).and_return("myorg") + allow(resource).to receive(:system_name).and_return(nil) + expect(provider.register_command).not_to match("--name") + end + end + context "when auto_attach is true" do it "does not return a command with --auto-attach since it is not supported with activation keys" do allow(resource).to receive(:organization).and_return("myorg") @@ -135,6 +151,20 @@ describe Chef::Resource::RhsmRegister do end end + context "when a system_name is provided" do + it "returns a command containing the system name" do + allow(resource).to receive(:system_name).and_return("myname") + expect(provider.register_command).to match("--name=myname") + 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) + expect(provider.register_command).not_to match("--name") + end + end + context "when auto_attach is nil" do it "returns a command that does not contain --auto-attach" do allow(resource).to receive(:auto_attach).and_return(nil) |