Skip to content

Commit

Permalink
Merge pull request #67 from ralfbosz/release
Browse files Browse the repository at this point in the history
Add the parameter 'release' to rhsm_register
waveclaw authored Oct 28, 2018
2 parents 7fa27bd + b2c6954 commit 3e448d5
Showing 8 changed files with 60 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -216,6 +216,7 @@ register. Both cannot be provided and will cause an error.
- **lifecycleenv**: which lifecycle environment to join at registration time (incompatible with using activation keys)
- **autosubscribe**: Enable automatic subscription to repositories based on default Pool settings. Must be false when using an activation key unless specifying a service level.
- **servicelevel**: provide automatic attachment to a service level in Satellite. Not applicable to katello installations.
- **release**: The release command sets a sticky OS version to use when installing or updating packages. This sets a preference for the minor version of the OS, such as 6.2 or 6.3. This can prevent unplanned or unsupported operating system version upgrades when an IT environment must maintain a certified configuration.
- **force**: Should the registration be forced. Use this option with caution, setting it true will cause the system to be unregistered before running 'subscription-manager register'. Default value `false`.

### rhsm_register Examples
File renamed without changes.
52 changes: 28 additions & 24 deletions lib/puppet/provider/rhsm_register/subscription_manager.rb
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ def subscription_attach
Puppet.debug("This server will be attached to a service level")
begin
subscription_manager(['attach',
"--servicelevel=#{@resource[:servicelevel]}", '--auto'])
"--servicelevel=#{@resource[:servicelevel]}", '--auto'])
rescue Puppet::ExecutionFailure => e
Puppet.debug("Auto-attach returned: #{e}")
end
@@ -43,15 +43,15 @@ def subscription_attach
# This builds the command using a helper method and attempts to
# deal with expected non-zero return codes from subscription-manager.
def register
Puppet.debug("This server will be registered")
# Command will fail with various return codes on re-registration
# RETCODE 1 for new registrations to new servers with an old registration
# RETCODE 2 for re-registrations to the same server after unregister
begin
subscription_manager(build_register_parameters)
rescue Puppet::ExecutionFailure => e
Puppet.debug("Registration returned: #{e}")
end
Puppet.debug("This server will be registered")
# Command will fail with various return codes on re-registration
# RETCODE 1 for new registrations to new servers with an old registration
# RETCODE 2 for re-registrations to the same server after unregister
begin
subscription_manager(build_register_parameters)
rescue Puppet::ExecutionFailure => e
Puppet.debug("Registration returned: #{e}")
end
end

# Completely remove the registration locally and attempt to notify the server.
@@ -69,7 +69,7 @@ def unregister
def flush
if exists?
if self.identity.nil? or self.identity == :absent
# no valid registration
# no valid registration
register
subscription_attach
elsif @property_hash[:name] and @property_hash[:name] != @resource[:name]
@@ -81,9 +81,9 @@ def flush
# trying to re-register
if (@property_hash[:force].nil? or @property_hash[:force] == :absent or
@property_hash[:force] == false) and
(@resource[:force].nil? or @resource[:force] == :absent or
@resource[:force] == false)
self.fail("Require force => true to register already registered server")
(@resource[:force].nil? or @resource[:force] == :absent or
@resource[:force] == false)
self.fail("Require force => true to register already registered server")
end
register
subscription_attach
@@ -168,14 +168,15 @@ def build_register_parameters
params = []
user = @resource[:username]
key = @resource[:activationkey]
release = @resource[:release]
if (user.nil? and key.nil?) or (user == :absent and key == :absent) or (user == '' and key == '')
self.fail("Need an activation key or a username and password. Was given user '#{user}' and key '#{key}'")
end
if bothset(user, key)
self.fail("Only provide an activation key or username and password not both. Was given user '#{user}' and key '#{key}'")
end
self.fail("Need an activation key or a username and password. Was given user '#{user}' and key '#{key}'")
end
if bothset(user, key)
self.fail("Only provide an activation key or username and password not both. Was given user '#{user}' and key '#{key}'")
end
if (@resource[:org].nil? or @resource[:org] == :absent)
self.fail("The 'org' paramater is required to register the system")
self.fail("The 'org' paramater is required to register the system")
end
params << "register"
params << "--force" if @resource[:force] and @resource[:force] != :absent
@@ -190,10 +191,13 @@ def build_register_parameters
# no autosubscribe with keys, see attach step instead
end
if ((!@resource[:lifecycleenv].nil? and !@resource[:lifecycleenv] == :absent) and
(@resource[:activationkey].nil? or @resource[:activationkey] == :absent))
params << "--environment" << @resource[:lifecycleenv]
(@resource[:activationkey].nil? or @resource[:activationkey] == :absent))
params << "--environment" << @resource[:lifecycleenv]
end
params << "--org" << @resource[:org]
if !release.nil?
params << "--release" << release
end
return params
end

@@ -203,9 +207,9 @@ def build_register_parameters
def self.certified?
if File.exists?('/etc/pki/consumer/cert.pem') or
File.exists?('/etc/pki/consumer/key.pem')
true
true
else
false
false
end
end

4 changes: 4 additions & 0 deletions lib/puppet/type/rhsm_register.rb
Original file line number Diff line number Diff line change
@@ -86,6 +86,10 @@
desc "A service level for automatic attachement with Satellite servers."
end

newparam(:release) do
desc "The release command sets a sticky OS version to use when installing or updating packages."
end

newparam(:org) do
desc "The organization the system should be assigned to."
validate do |value|
17 changes: 10 additions & 7 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -20,12 +20,13 @@
if $::subscription_manager::activationkey != undef and
$::subscription_manager::activationkey != '' {
$_settings = {
'pool' => $::subscription_manager::pool,
'autosubscribe' => $::subscription_manager::autosubscribe,
'force' => $::subscription_manager::force,
'org' => $::subscription_manager::org,
'servicelevel' => $::subscription_manager::servicelevel,
'activationkey' => $::subscription_manager::activationkey,
'pool' => $::subscription_manager::pool,
'autosubscribe' => $::subscription_manager::autosubscribe,
'force' => $::subscription_manager::force,
'org' => $::subscription_manager::org,
'servicelevel' => $::subscription_manager::servicelevel,
'activationkey' => $::subscription_manager::activationkey,
'release' => $::subscription_manager::release,
}
} else {
if $::subscription_manager::username != undef and
@@ -40,7 +41,9 @@
'servicelevel' => $::subscription_manager::servicelevel,
'username' => $::subscription_manager::username,
'password' => $::subscription_manager::password,
'lifecycleenv' => $::subscription_manager::lifecycleenv, }
'lifecycleenv' => $::subscription_manager::lifecycleenv,
'release' => $::subscription_manager::release,
}
} else {
$_settings = {}
}
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@
# An activation key to use for registration of the agent to the server.
# Conflicts with the username and password registration method.
#
# @param release pin a certain release when registering a server
# * `release`
# The release command sets a sticky OS version to use when installing or updating packages.
#
# @param pool a pool or RedHat Entitlement to automatically use
# * `pool`
# A subscription pool or RedHat Entitlement to associate with this system.
@@ -124,6 +128,7 @@
String $username = '',
String $password = '',
String $activationkey = '',
String $release = '',
String $pool = '',
String $lifecycleenv = 'library',
Variant[String, Boolean, Enum['yes','no']] $autosubscribe = false,
11 changes: 11 additions & 0 deletions spec/unit/provider/rhsm_register/subscription_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -213,6 +213,17 @@
["register", "--force", "--username", "foo", "--password", "bar",
"--autosubscribe", "--org", "foo"])
end
it 'should build a command with a release' do
res = Puppet::Type.type(:rhsm_register).new(
:name => title,
:ensure => :present,
:activationkey => fake_key,
:org => 'foo',
:release => '7.3',
:provider => :subscription_manager,)
expect(res.provider.build_register_parameters).to eq(
["register", "--activationkey", "1-my-activation-key", "--org", "foo", "--release", "7.3"])
end
end

describe 'self.instances' do
2 changes: 1 addition & 1 deletion spec/unit/type/rhsm_register_spec.rb
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
end

[ :username, :password, :org, :activationkey, :lifecycleenv,
:pool, :servicelevel ].each { |params|
:pool, :servicelevel, :release ].each { |params|
context "for #{params}" do
it "should be of type paramter" do
expect(described_class.attrtype(params)).to eq(:param)

0 comments on commit 3e448d5

Please sign in to comment.