Skip to content

Commit

Permalink
update the ID in the rhsm_pool type to be a "parameter" instead of "p…
Browse files Browse the repository at this point in the history
…roperty" for puppet/type.rb
  • Loading branch information
waveclaw committed Dec 1, 2018
1 parent 06234ae commit b65cae3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 3 additions & 4 deletions lib/puppet/provider/rhsm_pool/subscription_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def self.consumed_pools
value = m[1].strip
subscription[:id] = value
# this creates a 'fake' name resource to deal with the missing name parameter
subscription[:name] = value
next
end
m = %r{^\s*Active:\s*(.+)$}.match(line)
Expand Down Expand Up @@ -119,9 +118,9 @@ def self.instances

def self.prefetch(resources)
pools = instances
resources.keys.each do |name|
provider = pools.find { |pool| pool.name == name }
resources[name].provider = provider unless provider.nil?
resources.keys.each do |id|
provider = pools.find { |pool| pool.id == id }
resources[id].provider = provider unless provider.nil?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/rhsm_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
end

# Note that this shows up as the 'name' field due to a peculiarity of the resource API
newproperty(:id, namevar: true) do
newparam(:id, namevar: true) do
desc 'An Entitlement Pool to which the server is subscribed (Pool ID)'
validate do |value|
raise("Pool ID must be a hex number, was given #{value}") unless value.match?(%r{^[0-9a-fA-F]+$})
Expand Down
13 changes: 7 additions & 6 deletions spec/unit/provider/rhsm_pool/subscription_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@
System Type: Physical
EOD


title1 = '1a2b3c4d5e6f1234567890abcdef12345'
title2 = '1234abc'

properties = {
id: '1a2b3c4d5e6f1234567890abcdef12345',
subscription_name: 'Extra Packages for Enterprise Linux',
ensure: :present,
provides: 'Extra Packages for Enterprise Linux',
sku: '1234536789012',
contract: 'Fancy Widgets, LTD',
account: '1234-12-3456-0001',
serial: '1234567890123456789',
id: '1a2b3c4d5e6f1234567890abcdef12345',
name: '1a2b3c4d5e6f1234567890abcdef12345',
active: true,
quantity_used: 1,
service_level: 'STANDARD',
Expand All @@ -58,8 +61,6 @@
provider: :subscription_manager
}

title1 = '1a2b3c4d5e6f1234567890abcdef12345'
title2 = '1234abc'

provider_class = Puppet::Type.type(:rhsm_pool).provider(:subscrption_manager)

Expand Down Expand Up @@ -130,9 +131,9 @@
pools = provider.class.instances
expect(pools.size).to eq(2)
expect(pools[0]).to be_exists
expect(pools[0].name).to eq(title1)
expect(pools[0].id).to eq(title1)
expect(pools[1]).to be_exists
expect(pools[1].name).to eq(title2)
expect(pools[1].id).to eq(title2)
end
context 'should parse the expected values for properties' do
properties.keys.each do |key|
Expand Down

0 comments on commit b65cae3

Please sign in to comment.