Merge "Point patch current health check to use USM"

This commit is contained in:
Zuul 2024-05-22 14:24:10 +00:00 committed by Gerrit Code Review
commit 46321c2402
2 changed files with 23 additions and 36 deletions

View File

@ -16,6 +16,7 @@ from sysinv.common import constants
from sysinv.common import exception
from sysinv.common import kubernetes
from sysinv.common import utils
from sysinv.common import usm_service
from sysinv.common.fm import fmclient
from sysinv.common.storage_backend_conf import StorageBackendConfig
from sysinv.cert_alarm.audit import CertAlarmAudit
@ -75,32 +76,23 @@ class Health(object):
success = not config_host_list
return success, config_host_list
def _check_patch_current(self, hosts):
"""Checks that each host is patch current"""
system = self._dbapi.isystem_get_one()
response = patch_api.patch_query_hosts(token=None, timeout=60,
region_name=system.region_name)
patch_hosts = response['data']
not_patch_current_hosts = []
hostnames = []
for host in hosts:
hostnames.append(host['hostname'])
def _check_patch_current(self):
"""Checks if hosts are patch current"""
success = True
from_release = None
to_release = None
for host in patch_hosts:
# There may be instances where the patching db returns
# hosts that have been recently deleted. We will continue if a host
# is the patching db but not sysinv
try:
hostnames.remove(host['hostname'])
except ValueError:
LOG.info('Host %s found in patching but not in sysinv. '
'Continuing' % host['hostname'])
else:
if not host['patch_current']:
not_patch_current_hosts.append(host['hostname'])
# from stx-11 onwards patching is handled by USM, so the system
# is patch current if there is no deployment in progress in USM
# TODO(heitormatsui): change the logic when there is a USM endpoint
# to return data per-host
deploy_in_progress = usm_service.get_platform_upgrade(self._dbapi, usm_only=True)
if deploy_in_progress:
success = False
from_release = deploy_in_progress.from_load
to_release = deploy_in_progress.to_load
success = not not_patch_current_hosts and not hostnames
return success, not_patch_current_hosts, hostnames
return success, from_release, to_release
def _check_alarms(self, context, force=False, alarm_ignore_list=None):
"""Checks that no alarms are active"""
@ -618,16 +610,11 @@ class Health(object):
health_ok = health_ok and success
success, error_hosts, missing_hosts = self._check_patch_current(hosts)
success, from_release, to_release = self._check_patch_current()
output += _('All hosts are patch current: [%s]\n') \
% (Health.SUCCESS_MSG if success else Health.FAIL_MSG)
if not success:
if error_hosts:
output += _('Hosts not patch current: %s\n') \
% ', '.join(error_hosts)
if missing_hosts:
output += _('Hosts without patch data: %s\n') \
% ', '.join(missing_hosts)
output += _('Deployment in progress: %s to %s\n' % (from_release, to_release))
health_ok = health_ok and success

View File

@ -23,9 +23,9 @@ LOG = log.getLogger(__name__)
# completes.
class UsmUpgrade(object):
def __init__(self, state, from_load, to_load):
self.state = None
self.from_load = None
self.to_load = None
self.state = state
self.from_load = from_load
self.to_load = to_load
def __eq__(self, other):
return self.state == other.state and \
@ -52,7 +52,7 @@ def get_software_upgrade(token, region_name, timeout=30):
return response
def get_platform_upgrade(dbapi):
def get_platform_upgrade(dbapi, usm_only=False):
"""
Get upgrade object from either sysinv db or USM service.
Upgrade object is from USM service if the service is present,
@ -73,7 +73,7 @@ def get_platform_upgrade(dbapi):
# it is ok, legacy upgrade does not have usm service available
pass
if upgrade is None:
if upgrade is None and not usm_only:
upgrade = dbapi.software_upgrade_get_one()
return upgrade