1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix #5313: redhat_subscription module is not idempotent when pool_ids (#5319) (#5330)

This fix ensures the idempotency of the redhat_subscription module when pool_ids are used. The main problem was, that a 'None' quantity was not properly handled and that the quantity check compared a string with an integer.

Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de>

Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de>
Co-authored-by: Christoph Fiehe <c.fiehe@eurodata.de>
(cherry picked from commit 6fe2a84e87)

Co-authored-by: cfiehe <cfiehe@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-10-03 20:36:35 +02:00 committed by GitHub
parent 7aec01190a
commit 264c98189c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- redhat_subscription - make module idempotent when ``pool_ids`` are used (https://github.com/ansible-collections/community.general/issues/5313).

View file

@ -593,15 +593,22 @@ class Rhsm(RegistrationBase):
consumed_pools = RhsmPools(self.module, consumed=True) consumed_pools = RhsmPools(self.module, consumed=True)
existing_pools = {} existing_pools = {}
serials_to_remove = []
for p in consumed_pools: for p in consumed_pools:
existing_pools[p.get_pool_id()] = p.QuantityUsed pool_id = p.get_pool_id()
quantity_used = p.get_quantity_used()
existing_pools[pool_id] = quantity_used
quantity = pool_ids.get(pool_id, 0)
if quantity is not None and quantity != quantity_used:
serials_to_remove.append(p.Serial)
serials_to_remove = [p.Serial for p in consumed_pools if pool_ids.get(p.get_pool_id(), 0) != p.QuantityUsed]
serials = self.unsubscribe(serials=serials_to_remove) serials = self.unsubscribe(serials=serials_to_remove)
missing_pools = {} missing_pools = {}
for pool_id, quantity in sorted(pool_ids.items()): for pool_id, quantity in sorted(pool_ids.items()):
if existing_pools.get(pool_id, 0) != quantity: quantity_used = existing_pools.get(pool_id, 0)
if quantity is None and quantity_used == 0 or quantity not in (None, 0, quantity_used):
missing_pools[pool_id] = quantity missing_pools[pool_id] = quantity
self.subscribe_by_pool_ids(missing_pools) self.subscribe_by_pool_ids(missing_pools)
@ -635,6 +642,9 @@ class RhsmPool(object):
def get_pool_id(self): def get_pool_id(self):
return getattr(self, 'PoolId', getattr(self, 'PoolID')) return getattr(self, 'PoolId', getattr(self, 'PoolID'))
def get_quantity_used(self):
return int(getattr(self, 'QuantityUsed'))
def subscribe(self): def subscribe(self):
args = "subscription-manager attach --pool %s" % self.get_pool_id() args = "subscription-manager attach --pool %s" % self.get_pool_id()
rc, stdout, stderr = self.module.run_command(args, check_rc=True) rc, stdout, stderr = self.module.run_command(args, check_rc=True)