Rename max_cpu_frequency and max_cpu_default ihost attributes

Rename max_cpu_frequency to max_cpu_mhz_configured
Rename max_cpu_default   to max_cpu_mhz_allowed
Rename constants related to max_cpu_mhz feature

Reason: Improve readability

Test plan:
  Bootstrap
  Verify max_cpu_mhz_allowed is set
  Set max_cpu_mhz_configured from CLI
  Set max_cpu_mhz_configured from GUI

Signed-off-by: Iago Estrela <IagoFilipe.EstrelaBarros@windriver.com>
Change-Id: I49a4a304f6e5c20f3ce2c0f26b1ce54a807967b5
This commit is contained in:
Iago Estrela 2022-05-27 14:26:52 -03:00 committed by Iago Filipe
parent f9d0338178
commit 37abe7a7d5
13 changed files with 73 additions and 73 deletions

View File

@ -36,7 +36,7 @@ def _print_ihost_show(ihost, columns=None, output_format=None):
'tboot', 'vim_progress_status', 'software_load',
'install_state', 'install_state_info', 'inv_state',
'clock_synchronization', 'device_image_update',
'reboot_needed', 'max_cpu_frequency', 'max_cpu_default']
'reboot_needed', 'max_cpu_mhz_configured', 'max_cpu_mhz_allowed']
optional_fields = ['vsc_controllers', 'ttys_dcd']
if ihost.subfunctions != ihost.personality:
fields.append('subfunctions')
@ -692,13 +692,13 @@ def do_host_device_image_update_abort(cc, args):
@utils.arg('hostnameorid',
metavar='<hostnameorid>',
help="Name or ID of host")
@utils.arg('max_cpu_frequency',
metavar='<max_cpu_frequency>',
@utils.arg('max_cpu_mhz_configured',
metavar='<max_cpu_mhz_configured>',
help="Max CPU frequency MHz")
def do_host_cpu_max_frequency_modify(cc, args):
"""Modify host cpu max frequency."""
attributes = ['max_cpu_frequency=%s' % args.max_cpu_frequency]
attributes = ['max_cpu_mhz_configured=%s' % args.max_cpu_mhz_configured]
patch = utils.args_array_to_patch("replace", attributes)
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)

View File

@ -288,7 +288,7 @@ class AgentManager(service.PeriodicService):
else:
LOG.debug("ttys_dcd is not configured")
def _max_cpu_frequency_configurable(self):
def _is_max_cpu_mhz_configurable(self):
fail_result = "System does not support"
output = utils.execute('/usr/bin/cpupower', 'info', run_as_root=True)
@ -299,7 +299,7 @@ class AgentManager(service.PeriodicService):
return constants.CONFIGURABLE
return constants.NOT_CONFIGURABLE
def _max_cpu_frequency_default(self):
def _get_max_cpu_mhz_allowed(self):
output = utils.execute(
"lscpu | grep 'CPU max MHz' | awk '{ print $4 }' | cut -d ',' -f 1",
shell=True)
@ -573,10 +573,10 @@ class AgentManager(service.PeriodicService):
"""
if os.path.exists(FIRST_BOOT_FLAG):
max_cpu_freq_dict = {
constants.IHOST_MAX_CPU_CONFIG:
self._max_cpu_frequency_configurable(),
constants.IHOST_MAX_CPU_DEFAULT:
self._max_cpu_frequency_default()}
constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE:
self._is_max_cpu_mhz_configurable(),
constants.IHOST_MAX_CPU_MHZ_ALLOWED:
self._get_max_cpu_mhz_allowed()}
msg_dict.update({constants.HOST_ACTION_STATE:
constants.HAS_REINSTALLED,
'max_cpu_dict': max_cpu_freq_dict})

View File

@ -550,10 +550,10 @@ class Host(base.APIBase):
install_state_info = wtypes.text
"Represent install state extra information if there is any"
max_cpu_frequency = wtypes.text
max_cpu_mhz_configured = wtypes.text
"Represent the CPU max frequency"
max_cpu_default = wtypes.text
max_cpu_mhz_allowed = wtypes.text
"Represent the default CPU max frequency"
iscsi_initiator_name = wtypes.text
@ -594,7 +594,7 @@ class Host(base.APIBase):
'iscsi_initiator_name',
'device_image_update', 'reboot_needed',
'inv_state', 'clock_synchronization',
'max_cpu_frequency', 'max_cpu_default']
'max_cpu_mhz_configured', 'max_cpu_mhz_allowed']
fields = minimum_fields if not expand else None
uhost = Host.from_rpc_object(rpc_ihost, fields)
@ -2081,15 +2081,15 @@ class HostController(rest.RestController):
'bm_username': None,
'bm_password': None})
if 'max_cpu_frequency' in delta:
self._check_max_cpu_frequency(hostupdate)
max_cpu_frequency = hostupdate.ihost_patch.get('max_cpu_frequency')
ihost_obj['max_cpu_frequency'] = max_cpu_frequency
if 'max_cpu_mhz_configured' in delta:
self._check_max_cpu_mhz_configured(hostupdate)
max_cpu_mhz_configured = hostupdate.ihost_patch.get('max_cpu_mhz_configured')
ihost_obj['max_cpu_mhz_configured'] = max_cpu_mhz_configured
pecan.request.dbapi.ihost_update(
ihost_obj['uuid'],
{'max_cpu_frequency': max_cpu_frequency})
{'max_cpu_mhz_configured': max_cpu_mhz_configured})
if not hostupdate.configure_required:
pecan.request.rpcapi.update_host_max_cpu_frequency(
pecan.request.rpcapi.update_host_max_cpu_mhz_configured(
pecan.request.context, ihost_obj)
if hostupdate.ihost_val_prenotify:
@ -2882,18 +2882,18 @@ class HostController(rest.RestController):
"operation can proceed")
% (personality, load.software_version))
def _check_max_cpu_frequency(self, host):
def _check_max_cpu_mhz_configured(self, host):
# Max CPU frequency requested by the user and the maximum frequency
# allowed by the CPU.
max_cpu_frequency = str(host.ihost_patch.get('max_cpu_frequency', ''))
max_cpu_default = host.ihost_orig.get('max_cpu_default', 0)
max_cpu_mhz_configured = str(host.ihost_patch.get('max_cpu_mhz_configured', ''))
max_cpu_mhz_allowed = host.ihost_orig.get('max_cpu_mhz_allowed', 0)
if (constants.WORKER in host.ihost_orig[constants.SUBFUNCTIONS] and
host.ihost_orig.get('capabilities').get(constants.IHOST_MAX_CPU_CONFIG) ==
constants.CONFIGURABLE and max_cpu_default):
max_cpu_default = int(max_cpu_default)
host.ihost_orig.get('capabilities').get(constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE) ==
constants.CONFIGURABLE and max_cpu_mhz_allowed):
max_cpu_mhz_allowed = int(max_cpu_mhz_allowed)
# The service parameter is used to constrain the max_cpu_frequency
# The service parameter is used to constrain the max_cpu_mhz_configured
# into a range defined as a percentage of the max frequency allowed
# by the CPU and the max CPU frequency allowed itself.
max_cpu_percentage = pecan.request.dbapi.service_parameter_get_one(
@ -2901,23 +2901,23 @@ class HostController(rest.RestController):
section=constants.SERVICE_PARAM_SECTION_PLATFORM_CONFIG,
name=constants.SERVICE_PARAM_NAME_PLATFORM_MAX_CPU_PERCENTAGE
).value
max_cpu_floor = (int(max_cpu_percentage) * max_cpu_default) // 100
max_cpu_floor = (int(max_cpu_percentage) * max_cpu_mhz_allowed) // 100
# Restore the max_cpu_frequency to default if user set max_cpu_frequency
# to max_cpu_default.
if max_cpu_frequency == constants.IHOST_MAX_CPU_DEFAULT:
host.ihost_patch['max_cpu_frequency'] = max_cpu_default
# Restore the max_cpu_mhz_configured to default if user set max_cpu_mhz_configured
# to max_cpu_mhz_allowed.
if max_cpu_mhz_configured == constants.IHOST_MAX_CPU_MHZ_ALLOWED:
host.ihost_patch['max_cpu_mhz_configured'] = max_cpu_mhz_allowed
return
if not max_cpu_frequency.lstrip('-+').isdigit():
if not max_cpu_mhz_configured.lstrip('-+').isdigit():
raise wsme.exc.ClientSideError(
_("Max CPU frequency %s must be an integer.")
% (max_cpu_frequency))
% (max_cpu_mhz_configured))
if not (max_cpu_floor <= int(max_cpu_frequency) <= max_cpu_default):
if not (max_cpu_floor <= int(max_cpu_mhz_configured) <= max_cpu_mhz_allowed):
raise wsme.exc.ClientSideError(
_("Max CPU Frequency must be between (%d, %d).")
% (max_cpu_floor, max_cpu_default))
% (max_cpu_floor, max_cpu_mhz_allowed))
else:
raise wsme.exc.ClientSideError(
_("Host does not support configuration of Max CPU Frequency."))

View File

@ -199,8 +199,8 @@ PATCH_DEFAULT_TIMEOUT_IN_SECS = 6
# ihost field attributes
IHOST_STOR_FUNCTION = 'stor_function'
IHOST_MAX_CPU_CONFIG = 'max_cpu_config'
IHOST_MAX_CPU_DEFAULT = 'max_cpu_default'
IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE = 'is_max_cpu_configurable'
IHOST_MAX_CPU_MHZ_ALLOWED = 'max_cpu_mhz_allowed'
# ihost config_status field values
CONFIG_STATUS_OUT_OF_DATE = "Config out-of-date"

View File

@ -5380,11 +5380,11 @@ class ConductorManager(service.PeriodicService):
if max_cpu_dict:
ihost.capabilities.update({
constants.IHOST_MAX_CPU_CONFIG:
max_cpu_dict.get(constants.IHOST_MAX_CPU_CONFIG)})
ihost.max_cpu_default = max_cpu_dict.get('max_cpu_default')
constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE:
max_cpu_dict.get(constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE)})
ihost.max_cpu_mhz_allowed = max_cpu_dict.get('max_cpu_mhz_allowed')
val.update({'capabilities': ihost.capabilities,
constants.IHOST_MAX_CPU_DEFAULT: ihost.max_cpu_default})
constants.IHOST_max_cpu_mhz_allowed: ihost.max_cpu_mhz_allowed})
if val:
ihost = self.dbapi.ihost_update(ihost_uuid, val)
@ -13294,7 +13294,7 @@ class ConductorManager(service.PeriodicService):
LOG.error(msg)
raise exception.SysinvException(_(msg))
def update_host_max_cpu_frequency(self, context, host):
def update_host_max_cpu_mhz_configured(self, context, host):
personalities = [constants.WORKER]
config_uuid = self._config_update_hosts(context,

View File

@ -2300,13 +2300,13 @@ class ConductorAPI(sysinv.openstack.common.rpc.proxy.RpcProxy):
issuers_list=issuers_list,
secret_list=secret_list))
def update_host_max_cpu_frequency(self, context, host):
"""Synchronously, execute runtime manifests to update host max_cpu_frequency.
def update_host_max_cpu_mhz_configured(self, context, host):
"""Synchronously, execute runtime manifests to update host max_cpu_mhz_configured.
:param context: request context.
:param ihost: the host to update the max_cpu_frequency.
:param ihost: the host to update the max_cpu_mhz_configured.
"""
return self.call(context,
self.make_msg('update_host_max_cpu_frequency',
self.make_msg('update_host_max_cpu_mhz_configured',
host=host))

View File

@ -12,8 +12,8 @@ def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
host_table = Table('i_host', meta, autoload=True)
host_table.create_column(Column('max_cpu_frequency', String(64)))
host_table.create_column(Column('max_cpu_default', String(64)))
host_table.create_column(Column('max_cpu_mhz_configured', String(64)))
host_table.create_column(Column('max_cpu_mhz_allowed', String(64)))
def downgrade(migrate_engine):

View File

@ -239,8 +239,8 @@ class ihost(Base):
device_image_update = Column(String(64))
reboot_needed = Column(Boolean, nullable=False, default=False)
max_cpu_frequency = Column(String(64)) # in MHz
max_cpu_default = Column(String(64)) # in MHz
max_cpu_mhz_configured = Column(String(64)) # in MHz
max_cpu_mhz_allowed = Column(String(64)) # in MHz
forisystemid = Column(Integer,
ForeignKey('i_system.id', ondelete='CASCADE'))

View File

@ -100,8 +100,8 @@ class Host(base.SysinvObject):
'iscsi_initiator_name': utils.str_or_none,
'device_image_update': utils.str_or_none,
'reboot_needed': utils.bool_or_none,
'max_cpu_frequency': utils.str_or_none,
'max_cpu_default': utils.str_or_none
'max_cpu_mhz_configured': utils.str_or_none,
'max_cpu_mhz_allowed': utils.str_or_none
}
_foreign_fields = {

View File

@ -572,8 +572,8 @@ class PlatformPuppet(base.BasePuppet):
reserved_vswitch_cores,
'platform::compute::params::reserved_platform_cores':
reserved_platform_cores,
'platform::compute::params::max_cpu_frequency':
host.max_cpu_frequency,
'platform::compute::params::max_cpu_mhz_configured':
host.max_cpu_mhz_configured,
'platform::compute::grub::params::n_cpus': n_cpus,
'platform::compute::grub::params::cpu_options': cpu_options,
'platform::compute::grub::params::bios_cstate': True

View File

@ -22,7 +22,7 @@ class FakeConductorAPI(object):
def __init__(self, isystem=None):
self.create_host_filesystems = mock.MagicMock()
self.update_host_max_cpu_frequency = mock.MagicMock()
self.update_host_max_cpu_mhz_configured = mock.MagicMock()
self.is_virtual_system_config_result = False
self.isystem = isystem

View File

@ -46,7 +46,7 @@ class FakeConductorAPI(object):
self.kube_upgrade_kubelet = mock.MagicMock()
self.create_barbican_secret = mock.MagicMock()
self.mtc_action_apps_semantic_checks = mock.MagicMock()
self.update_host_max_cpu_frequency = mock.MagicMock()
self.update_host_max_cpu_mhz_configured = mock.MagicMock()
def create_ihost(self, context, values):
# Create the host in the DB as the code under test expects this
@ -3453,33 +3453,33 @@ class TestHostModifyCPUMaxFrequency(TestHost):
super(TestHostModifyCPUMaxFrequency, self).tearDown()
self.dbapi.service_parameter_get_one = self.real_service_parameter_get_one
def test_host_max_cpu_frequency_not_configurable(self):
def test_host_max_cpu_mhz_configured_not_configurable(self):
worker = self._create_worker(
max_cpu_frequency=None,
max_cpu_mhz_configured=None,
invprovision=constants.PROVISIONED,
administrative=constants.ADMIN_UNLOCKED,
operational=constants.OPERATIONAL_ENABLED,
availability=constants.AVAILABILITY_ONLINE,
capabilities={constants.IHOST_MAX_CPU_CONFIG:
capabilities={constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE:
constants.NOT_CONFIGURABLE})
self.assertRaises(
webtest.app.AppError,
self._patch_host,
worker.get('hostname'),
[{'path': '/max_cpu_frequency',
[{'path': '/max_cpu_mhz_configured',
'value': '283487',
'op': 'replace'}],
'sysinv-test')
def test_host_max_cpu_frequency_configurable_bad_values(self):
def test_host_max_cpu_mhz_configured_configurable_bad_values(self):
worker = self._create_worker(
max_cpu_frequency=None,
max_cpu_mhz_configured=None,
invprovision=constants.PROVISIONED,
administrative=constants.ADMIN_UNLOCKED,
operational=constants.OPERATIONAL_ENABLED,
availability=constants.AVAILABILITY_ONLINE,
capabilities={constants.IHOST_MAX_CPU_CONFIG:
capabilities={constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE:
constants.CONFIGURABLE})
for bad_value in ['AAAAA', '1A1A1A1', '-1', '0']:
@ -3487,28 +3487,28 @@ class TestHostModifyCPUMaxFrequency(TestHost):
webtest.app.AppError,
self._patch_host,
worker.get('hostname'),
[{'path': '/max_cpu_frequency',
[{'path': '/max_cpu_mhz_configured',
'value': bad_value,
'op': 'replace'}],
'sysinv-test')
def test_host_max_cpu_frequency_default(self):
max_cpu_default = 1000000
def test_host_max_cpu_mhz_configured_default(self):
max_cpu_mhz_allowed = 1000000
worker = self._create_worker(
max_cpu_frequency=None,
max_cpu_default=max_cpu_default,
max_cpu_mhz_configured=None,
max_cpu_mhz_allowed=max_cpu_mhz_allowed,
invprovision=constants.PROVISIONED,
administrative=constants.ADMIN_UNLOCKED,
operational=constants.OPERATIONAL_ENABLED,
availability=constants.AVAILABILITY_ONLINE,
capabilities={constants.IHOST_MAX_CPU_CONFIG:
capabilities={constants.IHOST_IS_MAX_CPU_MHZ_CONFIGURABLE:
constants.CONFIGURABLE})
response = self._patch_host(
worker.get('hostname'),
[{'path': '/max_cpu_frequency',
'value': 'max_cpu_default',
[{'path': '/max_cpu_mhz_configured',
'value': 'max_cpu_mhz_allowed',
'op': 'replace'}],
'sysinv-test')

View File

@ -165,8 +165,8 @@ def get_test_ihost(**kw):
'iscsi_initiator_name': kw.get('iscsi_initiator_name', None),
'inv_state': kw.get('inv_state', 'inventoried'),
'clock_synchronization': kw.get('clock_synchronization', constants.NTP),
'max_cpu_frequency': kw.get('max_cpu_frequency', ''),
'max_cpu_default': kw.get('max_cpu_default', '')
'max_cpu_mhz_configured': kw.get('max_cpu_mhz_configured', ''),
'max_cpu_mhz_allowed': kw.get('max_cpu_mhz_allowed', '')
}
return inv