Skip to content

Commit

Permalink
More performance improvements
Browse files Browse the repository at this point in the history
 * Fix mysql plugin is_runnable()
 * Move Openstack install info to custom class
 * Defer config load to a property
  • Loading branch information
dosaboy committed Oct 22, 2024
1 parent 7d54d4a commit 84ce6e6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 34 deletions.
2 changes: 1 addition & 1 deletion hotsos/core/plugins/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def is_runnable(cls):
@return: True or False
"""
return MySQLInstallInfo().apt.core is not None
return len(MySQLInstallInfo().apt.core) > 0


class MySQLConfig(host_helpers.IniConfigBase):
Expand Down
40 changes: 30 additions & 10 deletions hotsos/core/plugins/openstack/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
APTPackageHelper,
DockerImageHelper,
DPKGVersion,
InstallInfoBase,
PebbleHelper,
SystemdHelper,
SSLCertificate,
Expand All @@ -37,6 +38,32 @@ class OSTProjectHelpers:
octavia: OctaviaBase


@dataclass
class OpenStackInstallInfo(InstallInfoBase):
"""
OpenStack installation information.
"""
project_catalog: OSTProjectCatalog = None

def __post_init__(self):
service_exprs = self.project_catalog.service_exprs
core_pkgs = self.project_catalog.packages_core_exprs
other_pkgs = self.project_catalog.packages_dep_exprs

self.apt = APTPackageHelper(core_pkgs=core_pkgs,
other_pkgs=other_pkgs)
self.docker = DockerImageHelper(core_pkgs=core_pkgs,
other_pkgs=other_pkgs)
self.pebble = PebbleHelper(service_exprs=service_exprs)
self.systemd = SystemdHelper(service_exprs=service_exprs)

def mixin(self, _self):
_self.apt = self.apt
_self.docker = self.docker
_self.pebble = self.pebble
_self.systemd = self.systemd


class OpenstackBase():
"""
Base class for Openstack checks.
Expand All @@ -49,16 +76,9 @@ def __init__(self, *args, **kwargs):
self.project_helpers = OSTProjectHelpers(NovaBase(), NeutronBase(),
OctaviaBase())
self.project_catalog = OSTProjectCatalog()

service_exprs = self.project_catalog.service_exprs
self.pebble = PebbleHelper(service_exprs=service_exprs)
self.systemd = SystemdHelper(service_exprs=service_exprs)

core_pkgs = self.project_catalog.packages_core_exprs
other_pkgs = self.project_catalog.packages_dep_exprs
self.apt = APTPackageHelper(core_pkgs=core_pkgs, other_pkgs=other_pkgs)
self.docker = DockerImageHelper(core_pkgs=core_pkgs,
other_pkgs=other_pkgs)
# Keep pylint happy
self.apt = self.pebble = self.docker = self.systemd = None
OpenStackInstallInfo(project_catalog=self.project_catalog).mixin(self)

@cached_property
def apt_source_path(self):
Expand Down
8 changes: 5 additions & 3 deletions hotsos/core/plugins/openstack/neutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

class NeutronBase(OSTServiceBase):
""" Base class for Neutron checks. """
def __init__(self, *args, **kwargs):
super().__init__('neutron', *args, **kwargs)
self.neutron_ovs_config = self.project.config['openvswitch-agent']
PROJECT_NAME = 'neutron'

@cached_property
def neutron_ovs_config(self):
return self.project.config['openvswitch-agent']

@cached_property
def bind_interfaces(self):
Expand Down
8 changes: 5 additions & 3 deletions hotsos/core/plugins/openstack/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class NovaQemuProcessIdentifierARM(NovaQemuProcessIdentifierBase):

class NovaBase(OSTServiceBase):
""" Base class for Nova checks. """
def __init__(self, *args, **kwargs):
super().__init__('nova', *args, **kwargs)
self.nova_config = self.project.config['main']
PROJECT_NAME = 'nova'

@cached_property
def nova_config(self):
return self.project.config['main']

def get_instances(self, identifiers):
"""
Expand Down
3 changes: 1 addition & 2 deletions hotsos/core/plugins/openstack/octavia.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

class OctaviaBase(OSTServiceBase):
""" Base class for Octavia checks. """
def __init__(self, *args, **kwargs):
super().__init__('octavia', *args, **kwargs)
PROJECT_NAME = 'octavia'

@property
def bind_interfaces(self):
Expand Down
42 changes: 27 additions & 15 deletions hotsos/core/plugins/openstack/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def __init__(self, params: OSTProjectParameters):
apache or if a package runs components using services whose name
don't match the name of the project.
"""
self.params = params
self.name = params.name

self.apt_params = OSTProjectAptHelperParams([self.PY_CLIENT_PREFIX.
Expand All @@ -392,17 +393,6 @@ def __init__(self, params: OSTProjectParameters):
for c in params.apt_core_alt:
self.apt_params.deps.append(self.PY_CLIENT_PREFIX.format(c))

self.config = {}
if params.config:
for label, path in params.config.items():
path = os.path.join(
HotSOSConfig.data_root,
"etc",
params.name,
path
)
self.config[label] = OpenstackConfig(path)

self.systemd_params = OSTProjectSystemdHelperParams(
params.systemd_extra_services,
params.systemd_masked_services,
Expand All @@ -415,6 +405,23 @@ def __init__(self, params: OSTProjectParameters):
[]
)

@cached_property
def config(self):
config = {}
if not self.params.config:
return config

for label, path in self.params.config.items():
path = os.path.join(
HotSOSConfig.data_root,
"etc",
self.params.name,
path
)
config[label] = OpenstackConfig(path)

return config

@cached_property
def installed(self):
""" Return True if the openstack service is installed. """
Expand Down Expand Up @@ -624,10 +631,15 @@ def packages_dep_exprs(self):

class OSTServiceBase():
""" Representation of an Openstack service. """
def __init__(self, name, *args, **kwargs):
super().__init__(*args, **kwargs)
self.nethelp = host_helpers.HostNetworkingHelper()
self.project = OSTProjectCatalog()[name]
PROJECT_NAME = None

@cached_property
def nethelp(self):
return host_helpers.HostNetworkingHelper()

@cached_property
def project(self):
return OSTProjectCatalog()[self.PROJECT_NAME]

@cached_property
def installed(self):
Expand Down

0 comments on commit 84ce6e6

Please sign in to comment.