def test_SYSTEM_TASK_ABS_CPU_conversion(value, converted_value, cpu_capacity): with mock.patch('django.conf.settings') as mock_settings: mock_settings.SYSTEM_TASK_ABS_CPU = value mock_settings.SYSTEM_TASK_FORKS_CPU = 4 assert convert_cpu_str_to_decimal_cpu(value) == converted_value assert get_corrected_cpu(-1) == converted_value assert get_cpu_effective_capacity(-1) == cpu_capacity
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 update_fields.append('last_seen') if uuid is not None and self.uuid != uuid: if self.uuid is not None: logger.warning( f'Self-reported uuid of {self.hostname} changed from {self.uuid} to {uuid}' ) self.uuid = uuid update_fields.append('uuid') if version is not None and self.version != version: self.version = version update_fields.append('version') new_cpu = get_corrected_cpu(cpu) if new_cpu != self.cpu: self.cpu = new_cpu update_fields.append('cpu') new_memory = get_corrected_memory(memory) if new_memory != self.memory: self.memory = new_memory update_fields.append('memory') if not errors: self.refresh_capacity_fields() self.errors = '' else: self.mark_offline(perform_save=False, errors=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 with disable_activity_stream(): self.save(update_fields=update_fields)
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'] if update_last_seen: self.last_seen = self.last_health_check update_fields.append('last_seen') if uuid is not None and self.uuid != uuid: if self.uuid is not None: logger.warn( f'Self-reported uuid of {self.hostname} changed from {self.uuid} to {uuid}' ) self.uuid = uuid update_fields.append('uuid') if self.version != version: self.version = version update_fields.append('version') new_cpu = get_corrected_cpu(cpu) if new_cpu != self.cpu: self.cpu = new_cpu update_fields.append('cpu') new_memory = get_corrected_memory(memory) if new_memory != self.memory: self.memory = new_memory update_fields.append('memory') if not errors: self.refresh_capacity_fields() self.errors = '' else: self.mark_offline(perform_save=False, errors=errors) update_fields.extend( ['cpu_capacity', 'mem_capacity', 'capacity', 'errors']) self.save(update_fields=update_fields)