Skip to content

Commit

Permalink
Extend Sunbeam support to cover sosreport plugin (#1000)
Browse files Browse the repository at this point in the history
* also adds k8s snap to kubernetes plugin deps since
   sunbeam now uses Canonical K8s

Resolves: #999
  • Loading branch information
dosaboy authored Jan 11, 2025
1 parent ce19719 commit 0bae62c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
64 changes: 60 additions & 4 deletions hotsos/core/host_helpers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dataclasses import dataclass, field, fields
from functools import cached_property

import yaml
from hotsos.core.config import HotSOSConfig
from hotsos.core.host_helpers.common import (
CmdOutput,
Expand Down Expand Up @@ -75,6 +76,7 @@ class FileCmdBase(CmdBase):
"""
path: str
json_decode: bool = False
yaml_decode: bool = False
singleline: bool = False
decode_error_handling: str = None

Expand All @@ -88,6 +90,7 @@ class BinCmdBase(CmdBase):
""" State used to execute a binary command. """
cmd: str
json_decode: bool = False
yaml_decode: bool = False
singleline: bool = False
cmd_extras: list = field(default_factory=lambda: [])

Expand Down Expand Up @@ -128,6 +131,9 @@ def __call__(self, *args, skip_json_decode=False, **kwargs):
if self.json_decode and not skip_json_decode:
return CmdOutput(json.loads(output))

if self.yaml_decode:
return CmdOutput(yaml.safe_load(output))

if self.singleline:
return CmdOutput(output.strip())

Expand Down Expand Up @@ -164,6 +170,9 @@ def __call__(self, *args, skip_load_contents=False, **kwargs):
if self.json_decode:
with open(self.path, encoding='utf-8') as fd:
output = json.load(fd)
elif self.yaml_decode:
with open(self.path, encoding='utf-8') as fd:
output = yaml.safe_.load(fd)
else:
output = []
ln = 0
Expand Down Expand Up @@ -338,12 +347,14 @@ def __call__(self, *args, **kwargs):

class OVSOFCtlBinCmd(BinCmd):
""" Implementation of ovs-ofctl binary command. """
BIN_CMD = 'ovs-ofctl'

def __call__(self, *args, **kwargs):
"""
First try without specifying protocol version. If error is raised
try with different versions until we get a result.
"""
self.cmd = f"ovs-ofctl {self.cmd}"
self.cmd = f"{self.BIN_CMD} {self.cmd}"
try:
return super().__call__(*args, **kwargs)
except CLIExecError:
Expand All @@ -358,7 +369,7 @@ def __call__(self, *args, **kwargs):
log.debug("%s: trying again with protocol version %s",
self.__class__.__name__, ver)
self.reset()
self.cmd = f"ovs-ofctl -O {ver} {self.cmd}"
self.cmd = f"{self.BIN_CMD} -O {ver} {self.cmd}"
try:
return super().__call__(*args, **kwargs)
except CLIExecError:
Expand All @@ -368,6 +379,12 @@ def __call__(self, *args, **kwargs):
return CmdOutput([])


class SunbeamOVSOFCtlBinCmd(OVSOFCtlBinCmd):
""" Implementation of Sunbeam openstack-hypervisor.ovs-ofctl binary
command. """
BIN_CMD = 'openstack-hypervisor.ovs-ofctl'


class OVSOFCtlFileCmd(FileCmd):
""" Implementation of ovs-ofctl file-based command. """
def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -774,35 +791,66 @@ def command_catalog(self):
'ip_netns_exec_{namespace}_ip_-d_address_show')],
'ovn_nbctl_show':
[BinCmd('ovn-nbctl --no-leader-only show'),
BinCmd('openstack-hypervisor.'
'ovn-nbctl --no-leader-only show'),
FileCmd('sos_commands/ovn_central/'
'ovn-nbctl_--no-leader-only_show'),
FileCmd('sos_commands/ovn_central/'
'openstack-hypervisor.'
'ovn-nbctl_--no-leader-only_show'),
# sosreport < 4.5
FileCmd('sos_commands/ovn_central/ovn-nbctl_show')],
'ovn_sbctl_show':
[BinCmd('ovn-sbctl --no-leader-only show'),
BinCmd('openstack-hypervisor.'
'ovn-sbctl --no-leader-only show'),
FileCmd('sos_commands/ovn_central/'
'ovn-sbctl_--no-leader-only_show'),
FileCmd('sos_commands/ovn_central/'
'openstack-hypervisor.'
'ovn-sbctl_--no-leader-only_show'),
# sosreport < 4.5
FileCmd('sos_commands/ovn_central/ovn-sbctl_show')],
'ovs_vsctl_get':
[BinCmd('ovs-vsctl get {table} {record} {column}',
singleline=True),
BinCmd('openstack-hypervisor.'
'ovs-vsctl get {table} {record} {column}',
singleline=True),
FileCmd('sos_commands/openvswitch/ovs-vsctl_-t_5_get_'
'{table}_{record}_{column}', singleline=True),
FileCmd('sos_commands/openvswitch/openstack-hypervisor.'
'ovs-vsctl_-t_5_get_'
'{table}_{record}_{column}', singleline=True)],
'ovs_vsctl_list':
[BinCmd('ovs-vsctl list {table}'),
BinCmd('openstack-hypervisor.ovs-vsctl list {table}'),
FileCmd('sos_commands/openvswitch/'
'ovs-vsctl_-t_5_list_{table}'),
FileCmd('sos_commands/openvswitch/'
'ovs-vsctl_-t_5_list_{table}')],
'openstack-hypervisor.ovs-vsctl_-t_5_list_{table}')],
'ovs_vsctl_list_br':
[BinCmd('ovs-vsctl list-br'),
FileCmd('sos_commands/openvswitch/ovs-vsctl_-t_5_list-br')],
BinCmd('openstack-hypervisor.ovs-vsctl list-br'),
FileCmd('sos_commands/openvswitch/ovs-vsctl_-t_5_list-br'),
FileCmd('sos_commands/openvswitch/openstack-hypervisor.'
'ovs-vsctl_-t_5_list-br')],
'ovs_appctl':
[OVSAppCtlBinCmd('ovs-appctl {command} {flags} {args}'),
OVSAppCtlBinCmd('openstack-hypervisor.'
'ovs-appctl {command} {flags} {args}'),
OVSAppCtlFileCmd('sos_commands/openvswitch/ovs-appctl_'
'{command}{flags}{args}'),
OVSAppCtlFileCmd('sos_commands/openvswitch/'
'openstack-hypervisor.ovs-appctl_'
'{command}{flags}{args}')],
'ovs_ofctl':
[OVSOFCtlBinCmd('{command} {args}'),
SunbeamOVSOFCtlBinCmd('{command} {args}'),
OVSOFCtlFileCmd('sos_commands/openvswitch/'
'ovs-ofctl{ofversion}_{command}_{args}'),
OVSOFCtlFileCmd('sos_commands/openvswitch/'
'openstack-hypervisor.'
'ovs-ofctl{ofversion}_{command}_{args}')],
'pacemaker_crm_status':
[BinCmd('crm status'),
Expand Down Expand Up @@ -830,6 +878,14 @@ def command_catalog(self):
'rabbitmqctl_report':
[BinCmd('rabbitmqctl report'),
FileCmd('sos_commands/rabbitmq/rabbitmqctl_report')],
'sunbeam_cluster_list':
[BinCmd('sunbeam cluster list'),
FileCmd('sos_commands/sunbeam/sunbeam_cluster_list')],
'sunbeam_cluster_list_yaml_decoded':
[BinCmd('sunbeam cluster list --format yaml'),
FileCmd('sos_commands/sunbeam/'
'sunbeam_cluster_list_--format_yaml',
yaml_decode=True)],
'snap_list_all':
[BinCmd('snap list --all'),
FileCmd('sos_commands/snap/snap_list_--all'),
Expand Down
3 changes: 2 additions & 1 deletion hotsos/core/plugins/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
r'kubelet',
r'kubeadm',
r'kubefed',
r'microk8s'
r'microk8s',
r'k8s',
]
# Packages that are used in a K8s deployment
K8S_PACKAGE_DEPS = [r'charm[\S]+',
Expand Down
11 changes: 10 additions & 1 deletion hotsos/core/plugins/openvswitch/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
APTPackageHelper,
InstallInfoBase,
PebbleHelper,
SnapPackageHelper,
SystemdHelper,
)
from hotsos.core.plugins.openstack.openstack import OST_SUNBEAM_SNAP_NAMES
from hotsos.core.ycheck.events import EventCallbackBase, EventHandlerBase
from hotsos.core.ycheck.common import GlobalSearcherAutoRegisterBase
from hotsos.core.utils import sorted_dict
Expand Down Expand Up @@ -55,6 +57,9 @@ class OpenvSwitchInstallInfo(InstallInfoBase):
systemd: SystemdHelper = field(default_factory=lambda:
SystemdHelper(
service_exprs=OVS_SERVICES_EXPRS))
snaps: SnapPackageHelper = field(default_factory=lambda:
SnapPackageHelper(
core_snaps=OST_SUNBEAM_SNAP_NAMES))


class OpenvSwitchChecks(plugintools.PluginPartBase):
Expand All @@ -74,7 +79,11 @@ def is_runnable(cls):
@return: True or False
"""
# require at least one core package to be installed to run this plugin.
return len(OpenvSwitchInstallInfo().apt.core) > 0
if len(OpenvSwitchInstallInfo().apt.core) > 0:
return True

# This is to account for OpenStack Sunbeam
return len(OpenvSwitchInstallInfo().snaps.core) > 0


class OpenvSwitchEventCallbackBase(EventCallbackBase):
Expand Down

0 comments on commit 0bae62c

Please sign in to comment.