Fill in errors for hop nodes when Last Seen is out of date, and clear them when not (#11714)

* Process unresponsive and newly responsive hop nodes

* Use more natural way to zero hop node capacity, add test

* Use warning as opposed to warn for log messages
This commit is contained in:
Alan Rominger
2022-03-09 13:21:32 -05:00
committed by GitHub
parent 4c9d028a35
commit 99bbc347ec
3 changed files with 38 additions and 22 deletions

View File

@@ -233,13 +233,19 @@ class Instance(HasPolicyEditsMixin, BaseModel):
def refresh_capacity_fields(self):
"""Update derived capacity fields from cpu and memory (no save)"""
self.cpu_capacity = get_cpu_effective_capacity(self.cpu)
self.mem_capacity = get_mem_effective_capacity(self.memory)
if self.node_type == 'hop':
self.cpu_capacity = 0
self.mem_capacity = 0 # formula has a non-zero offset, so we make sure it is 0 for hop nodes
else:
self.cpu_capacity = get_cpu_effective_capacity(self.cpu)
self.mem_capacity = get_mem_effective_capacity(self.memory)
self.set_capacity_value()
def save_health_data(self, version, cpu, memory, uuid=None, update_last_seen=False, errors=''):
self.last_health_check = now()
update_fields = ['last_health_check']
def save_health_data(self, version=None, cpu=0, memory=0, uuid=None, update_last_seen=False, errors=''):
update_fields = ['errors']
if self.node_type != 'hop':
self.last_health_check = now()
update_fields.append('last_health_check')
if update_last_seen:
self.last_seen = self.last_health_check
@@ -251,7 +257,7 @@ class Instance(HasPolicyEditsMixin, BaseModel):
self.uuid = uuid
update_fields.append('uuid')
if self.version != version:
if version is not None and self.version != version:
self.version = version
update_fields.append('version')
@@ -270,7 +276,7 @@ class Instance(HasPolicyEditsMixin, BaseModel):
self.errors = ''
else:
self.mark_offline(perform_save=False, errors=errors)
update_fields.extend(['cpu_capacity', 'mem_capacity', 'capacity', 'errors'])
update_fields.extend(['cpu_capacity', 'mem_capacity', 'capacity'])
# disabling activity stream will avoid extra queries, which is important for heatbeat actions
from awx.main.signals import disable_activity_stream