-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[microovn] Added new plugin support for MicroOVN.
Signed-off-by: Alan Baghumian <alan.baghumian@canonical.com>
- Loading branch information
Showing
1 changed file
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Copyright (C) 2018 Mark Michelson <mmichels@redhat.com> | ||
# Copyright (C) 2024 Alan Baghumian <alan.baghumian@canonical.com> | ||
|
||
# This file is part of the sos project: https://github.com/sosreport/sos | ||
# | ||
# This is based on code from ovn_central.py plugin | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# version 2 of the GNU General Public License. | ||
# | ||
# See the LICENSE file in the source distribution for further information. | ||
|
||
import json | ||
import os | ||
from sos.report.plugins import Plugin, UbuntuPlugin | ||
|
||
class MicroOVN(Plugin, UbuntuPlugin): | ||
|
||
short_desc = 'MicroOVN Snap' | ||
plugin_name = "microovn" | ||
profiles = ('network', 'virt') | ||
|
||
packages = ('microovn', ) | ||
commands = ('microovn', 'microovn.ovn-appctl', 'microovn.ovn-nbctl', 'microovn.ovn-sbctl', 'microovn.ovn-trace', 'microovn.ovs-appctl', 'microovn.ovs-dpctl', 'microovn.ovs-ofctl', 'microovn.ovs-vsctl', 'microovn.ovsdb-client', 'microovn.ovsdb-tool',) | ||
services = ('snap.microovn.central', 'snap.microovn.daemon', 'snap.microovn.ovn-ovsdb-server-nb', 'snap.microovn.refresh-expiring-certs', 'snap.microovn.switch', 'snap.microovn.chassis', 'snap.microovn.ovn-northd', 'snap.microovn.ovn-ovsdb-server-sb', 'snap.microovn.refresh-expiring-certs.timer',) | ||
|
||
ovn_nbdb_sock_path = '/var/snap/microovn/common/run/ovn/ovnnb_db.ctl' | ||
ovn_sbdb_sock_path = '/var/snap/microovn/common/run/ovn/ovnsb_db.ctl' | ||
ovn_sock_path = '/var/snap/microovn/common/run/ovn' | ||
ovn_controller_sock_regex = 'ovn-controller.*.ctl' | ||
ovn_northd_sock_regex = 'ovn-northd.*.ctl' | ||
|
||
def _find_sock(self, path, regex_name): | ||
return os.path.join(path, regex_name) | ||
|
||
def get_tables_from_schema(self, filename, skip=None): | ||
""" Get tables from schema """ | ||
try: | ||
fname = self.path_join(filename) | ||
with open(fname, 'r', encoding='UTF-8') as file: | ||
try: | ||
db_schema = json.load(file) | ||
except Exception: # pylint: disable=broad-except | ||
self._log_error(f"Cannot parse JSON file {filename}") | ||
return None | ||
except IOError as ex: | ||
self._log_error( | ||
f"Could not open DB schema file {filename}: {ex}") | ||
return None | ||
|
||
try: | ||
return [table for table in dict.keys( | ||
db_schema['tables']) if table not in skip] | ||
except AttributeError: | ||
self._log_error(f"DB schema {filename} has no 'tables' key") | ||
return None | ||
|
||
def add_database_output(self, tables, cmds, ovn_cmd): | ||
""" Collect OVN database output """ | ||
if not tables: | ||
return | ||
for table in tables: | ||
cmds.append(f'{ovn_cmd} list {table}') | ||
|
||
def setup(self): | ||
# check if env is a clustered or non-clustered one | ||
for pidfile in ['ovnnb_db.pid', 'ovnsb_db.pid', 'ovn-northd.pid', 'ovn-controller.pid']: | ||
self.add_copy_spec([ | ||
self.path_join('/var/snap/microovn/common/run/ovn', pidfile), | ||
]) | ||
|
||
ovn_controller_sock_path = self._find_sock( | ||
self.ovn_sock_path, self.ovn_controller_sock_regex) | ||
|
||
northd_sock_path = self._find_sock(self.ovn_sock_path, | ||
self.ovn_northd_sock_regex) | ||
|
||
# ovsdb nb/sb cluster status commands | ||
cstat = "cluster/status" | ||
self.add_cmd_output([ | ||
f"microovn.ovs-appctl -t {self.ovn_nbdb_sock_path} {cstat} OVN_Northbound", | ||
f"microovn.ovs-appctl -t {self.ovn_sbdb_sock_path} {cstat} OVN_Southbound", | ||
f"microovn.ovn-appctl -t {northd_sock_path} status", | ||
f"microovn.ovn-appctl -t {ovn_controller_sock_path} connection-status", | ||
], foreground=True, timeout=30 | ||
) | ||
|
||
# Some user-friendly versions of DB output | ||
nbctl_cmds = [ | ||
'microovn.ovn-nbctl --no-leader-only show', | ||
'microovn.ovn-nbctl --no-leader-only get-ssl', | ||
'microovn.ovn-nbctl --no-leader-only get-connection', | ||
] | ||
|
||
sbctl_cmds = [ | ||
'microovn.ovn-sbctl --no-leader-only show', | ||
'microovn.ovn-sbctl --no-leader-only lflow-list', | ||
'microovn.ovn-sbctl --no-leader-only get-ssl', | ||
'microovn.ovn-sbctl --no-leader-only get-connection', | ||
] | ||
|
||
# Database Output | ||
nb_tables = self.get_tables_from_schema(self.path_join( | ||
'/snap/microovn/current/share/ovn', 'ovn-nb.ovsschema')) | ||
self.add_database_output(nb_tables, nbctl_cmds, | ||
'microovn.ovn-nbctl --no-leader-only') | ||
cmds = nbctl_cmds | ||
|
||
sb_tables = self.get_tables_from_schema(self.path_join( | ||
'/snap/microovn/current/share/ovn', 'ovn-sb.ovsschema'), ['Logical_Flow']) | ||
self.add_database_output(sb_tables, sbctl_cmds, | ||
'microovn.ovn-sbctl --no-leader-only') | ||
cmds += sbctl_cmds | ||
|
||
# If OVN is containerized, we need to run the above commands inside | ||
# the container. Removing duplicates (in case there are) to avoid | ||
# failing on collecting output to file on container running commands | ||
cmds = list(set(cmds)) | ||
self.add_cmd_output( | ||
cmds, foreground=True | ||
) | ||
|
||
for dbfile in ["ovnnb_db.db", "ovnsb_db.db"]: | ||
for path in [ | ||
"/var/snap/microovn/common/data/central/db", | ||
]: | ||
dbfilepath = self.path_join(path, dbfile) | ||
if os.path.exists(dbfilepath): | ||
self.add_copy_spec(dbfilepath) | ||
self.add_cmd_output( | ||
f"ls -lan {dbfilepath}", foreground=True) | ||
|
||
self.add_journal(units="ovn-northd") | ||
|