diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2019-11-21 15:35:44 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-04-07 16:43:35 -0400 |
commit | b6e0117660d816e162a9b8a4df1b79b9ca3982c9 (patch) | |
tree | 11b41541c762f2b84f03168b6692ca70b7dee388 | |
parent | f6e87578edbfa5251d9369e95dc9efc1a2306178 (diff) | |
download | sos-b6e0117660d816e162a9b8a4df1b79b9ca3982c9.tar.gz |
[ovn_central] Use new ContainerRuntime methods
Updates `ovn_central` to use the new ContainerRuntime methods exposed to
the `Plugin` class.
Rather than manually checking for runtimes, and then manually building
the exec commands, the plugin now relies on the `Plugin` methods for
discovering containers and formatting commands to be run in a container,
if applicable.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/plugins/ovn_central.py | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/sos/plugins/ovn_central.py b/sos/plugins/ovn_central.py index 7be274f7..3c564788 100644 --- a/sos/plugins/ovn_central.py +++ b/sos/plugins/ovn_central.py @@ -19,14 +19,12 @@ class OVNCentral(Plugin): """ plugin_name = "ovn_central" profiles = ('network', 'virt') - _container_runtime = None - _container_name = None def get_tables_from_schema(self, filename, skip=[]): if self._container_name: - cmd = "%s exec %s cat %s" % ( - self._container_runtime, self._container_name, filename) - res = self.exec_cmd(cmd, foreground=True) + cmd = "cat %s" % filename + res = self.exec_cmd(cmd, timeout=None, foreground=True, + container=self._container_name) if res['status'] != 0: self._log_error("Could not retrieve DB schema file from " "container %s" % self._container_name) @@ -61,23 +59,12 @@ class OVNCentral(Plugin): for table in tables: cmds.append('%s list %s' % (ovn_cmd, table)) - def running_in_container(self): - for runtime in ["podman", "docker"]: - container_status = self.exec_cmd(runtime + " ps") - if container_status['status'] == 0: - for line in container_status['output'].splitlines(): - if "ovn-dbs-bundle" in line: - self._container_name = line.split()[-1] - self._container_runtime = runtime - return True - return False - def check_enabled(self): - return (self.running_in_container() or + return (self.container_exists('ovs-dbs-bundle.*') or super(OVNCentral, self).check_enabled()) def setup(self): - containerized = self.running_in_container() + self._container_name = self.get_container_by_name('ovs-dbs-bundle.*') ovs_rundir = os.environ.get('OVS_RUNDIR') for pidfile in ['ovnnb_db.pid', 'ovnsb_db.pid', 'ovn-northd.pid']: @@ -113,10 +100,9 @@ class OVNCentral(Plugin): # If OVN is containerized, we need to run the above commands inside # the container. - if containerized: - cmds = ['%s exec %s %s' % (self._container_runtime, - self._container_name, - cmd) for cmd in cmds] + cmds = [ + self.fmt_container_cmd(self._container_name, cmd) for cmd in cmds + ] self.add_cmd_output(cmds, foreground=True) |