Fix cert-mon PriorityQueue regression in python3

In python3 the PriorityQueue raises an exception
due to

TypeError: '<' not supported between
        instances of 'SubcloudAuditData' and 'SubcloudAuditData'

The fix is to include a __lt__ method in SubcloudAuditData.
A timestamp field is added (primarily used in the tuple added to the
queue, but easy enough to include here) in order to aid in the sorting.

Test Plan:

PASS: trigger cert-mon audit for subclouds. Verify that the exception
is not raised, and that subclouds are properly enqueued for audit.

Closes-Bug: 1992680
Change-Id: Ibaa9a421eb809edc434793bc7e8ae92691be021f
Signed-off-by: Kyle MacLeod <kyle.macleod@windriver.com>
This commit is contained in:
Kyle MacLeod 2022-10-12 12:54:18 -04:00
parent 94045cefc1
commit da21e1f9f7

View File

@ -25,15 +25,19 @@ LOG = log.getLogger(__name__)
class SubcloudAuditData(object):
"""Representation of a subcloud under audit.
The 'name' field is used for all comparisons.
"""
def __init__(self, name, audit_count=0):
self.name = name
self.audit_count = audit_count
self.timestamp = 0
def __eq__(self, other):
return self.name == other.name
def __lt__(self, other):
"""Used in sorting the PriorityQueue"""
return self.timestamp < other.timestamp
def __hash__(self):
return hash(self.name)
@ -81,6 +85,7 @@ class SubcloudAuditPriorityQueue(PriorityQueue):
# this PriorityQueue is ordered by the next timestamp:
sc_audit_item.audit_count += 1
sc_audit_item.timestamp = timestamp
self.put(
(timestamp, sc_audit_item)
)