Blame SOURCES/sos-bz1751578-ovn-plugins-containerized.patch

7711bd
From cc6374914a47eb3777c5b8306506df43522a31e0 Mon Sep 17 00:00:00 2001
7711bd
From: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Date: Thu, 18 Jul 2019 14:08:27 +0200
7711bd
Subject: [PATCH 1/4] [ovn_central] add additional show commands
7711bd
7711bd
This patch is adding 'show' commands for both OVN
7711bd
NorthBound and SouthBound databases.
7711bd
7711bd
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
7711bd
---
7711bd
 sos/plugins/ovn_central.py | 2 ++
7711bd
 1 file changed, 2 insertions(+)
7711bd
7711bd
diff --git a/sos/plugins/ovn_central.py b/sos/plugins/ovn_central.py
7711bd
index e0585687..2d252625 100644
7711bd
--- a/sos/plugins/ovn_central.py
7711bd
+++ b/sos/plugins/ovn_central.py
7711bd
@@ -57,6 +57,8 @@ class OVNCentral(Plugin):
7711bd
 
7711bd
         # Some user-friendly versions of DB output
7711bd
         cmds = [
7711bd
+            'ovn-nbctl show',
7711bd
+            'ovn-sbctl show',
7711bd
             'ovn-sbctl lflow-list',
7711bd
             'ovn-nbctl get-ssl',
7711bd
             'ovn-nbctl get-connection',
7711bd
-- 
7711bd
2.21.0
7711bd
7711bd
7711bd
From 5fd4e850ad9a6636d0fb206954e8ab016584974d Mon Sep 17 00:00:00 2001
7711bd
From: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Date: Wed, 11 Sep 2019 16:19:15 +0100
7711bd
Subject: [PATCH 2/4] [ovn_host] fix Open_vSwitch table name
7711bd
7711bd
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
7711bd
---
7711bd
 sos/plugins/ovn_host.py | 2 +-
7711bd
 1 file changed, 1 insertion(+), 1 deletion(-)
7711bd
7711bd
diff --git a/sos/plugins/ovn_host.py b/sos/plugins/ovn_host.py
7711bd
index 54251627..ba35d87e 100644
7711bd
--- a/sos/plugins/ovn_host.py
7711bd
+++ b/sos/plugins/ovn_host.py
7711bd
@@ -35,7 +35,7 @@ class OVNHost(Plugin):
7711bd
         self.add_cmd_output([
7711bd
             'ovs-ofctl -O OpenFlow13 dump-flows br-int',
7711bd
             'ovs-vsctl list-br',
7711bd
-            'ovs-vsctl list OpenVswitch',
7711bd
+            'ovs-vsctl list Open_vSwitch',
7711bd
         ])
7711bd
 
7711bd
         self.add_journal(units="ovn-controller")
7711bd
-- 
7711bd
2.21.0
7711bd
7711bd
7711bd
From 3c842046e9c4c5b371566347f51e5e242daf4f8d Mon Sep 17 00:00:00 2001
7711bd
From: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Date: Tue, 23 Jul 2019 12:44:07 +0200
7711bd
Subject: [PATCH 3/4] [ovn_central] Add support to containerized setups
7711bd
7711bd
This patch is adding support in ovn_central plugin to containerized
7711bd
setups.
7711bd
7711bd
Now it's detecting if the OVN central services are running in
7711bd
container and execute the relevant commands inside it. The support
7711bd
covers both podman and docker runtimes.
7711bd
7711bd
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
7711bd
---
7711bd
 sos/plugins/ovn_central.py | 94 ++++++++++++++++++++++++++++----------
7711bd
 1 file changed, 69 insertions(+), 25 deletions(-)
7711bd
7711bd
diff --git a/sos/plugins/ovn_central.py b/sos/plugins/ovn_central.py
7711bd
index 2d252625..a9fcdf33 100644
7711bd
--- a/sos/plugins/ovn_central.py
7711bd
+++ b/sos/plugins/ovn_central.py
7711bd
@@ -19,30 +19,64 @@ class OVNCentral(Plugin):
7711bd
     """
7711bd
     plugin_name = "ovn_central"
7711bd
     profiles = ('network', 'virt')
7711bd
-
7711bd
-    def add_database_output(self, filename, cmds, ovn_cmd, skip=[]):
7711bd
+    _container_runtime = None
7711bd
+    _container_name = None
7711bd
+
7711bd
+    def get_tables_from_schema(self, filename, skip=[]):
7711bd
+        if self._container_name:
7711bd
+            cmd = "%s exec %s cat %s" % (
7711bd
+                self._container_runtime, self._container_name, filename)
7711bd
+            res = self.get_command_output(cmd)
7711bd
+            if res['status'] != 0:
7711bd
+                self._log_error("Could not retrieve DB schema file from "
7711bd
+                                "container %s" % self._container_name)
7711bd
+                return
7711bd
+            try:
7711bd
+                db = json.loads(res['output'])
7711bd
+            except Exception:
7711bd
+                self._log_error("Cannot parse JSON file %s" % filename)
7711bd
+                return
7711bd
+        else:
7711bd
+            try:
7711bd
+                with open(filename, 'r') as f:
7711bd
+                    try:
7711bd
+                        db = json.load(f)
7711bd
+                    except Exception:
7711bd
+                        self._log_error(
7711bd
+                            "Cannot parse JSON file %s" % filename)
7711bd
+                        return
7711bd
+            except IOError as ex:
7711bd
+                self._log_error(
7711bd
+                    "Could not open DB schema file %s: %s" % (filename, ex))
7711bd
+                return
7711bd
         try:
7711bd
-            with open(filename, 'r') as f:
7711bd
-                try:
7711bd
-                    db = json.load(f)
7711bd
-                except Exception:
7711bd
-                    # If json can't be parsed, then exit early
7711bd
-                    self._log_error("Cannot parse JSON file %s" % filename)
7711bd
-                    return
7711bd
-                try:
7711bd
-                    for table in six.iterkeys(db['tables']):
7711bd
-                        if table not in skip:
7711bd
-                            cmds.append('%s list %s' % (ovn_cmd, table))
7711bd
-                except AttributeError:
7711bd
-                    self._log_error("DB schema %s has no 'tables' key" %
7711bd
-                                    filename)
7711bd
-                    return
7711bd
-        except IOError as ex:
7711bd
-            self._log_error("Could not open DB schema file %s: %s" % (filename,
7711bd
-                                                                      ex))
7711bd
-            return
7711bd
+            return [table for table in six.iterkeys(
7711bd
+                db['tables']) if table not in skip]
7711bd
+        except AttributeError:
7711bd
+            self._log_error("DB schema %s has no 'tables' key" % filename)
7711bd
+
7711bd
+    def add_database_output(self, tables, cmds, ovn_cmd):
7711bd
+        for table in tables:
7711bd
+            cmds.append('%s list %s' % (ovn_cmd, table))
7711bd
+
7711bd
+    def running_in_container(self):
7711bd
+        for runtime in ["podman", "docker"]:
7711bd
+            container_status = self.get_command_output(runtime + " ps")
7711bd
+            if container_status['status'] == 0:
7711bd
+                for line in container_status['output'].splitlines():
7711bd
+                    if "ovn-dbs-bundle" in line:
7711bd
+                        self._container_name = line.split()[-1]
7711bd
+                        self._container_runtime = runtime
7711bd
+                        return True
7711bd
+        return False
7711bd
+
7711bd
+    def check_enabled(self):
7711bd
+        return (self.running_in_container() or
7711bd
+                super(OVNCentral, self).check_enabled())
7711bd
 
7711bd
     def setup(self):
7711bd
+        containerized = self.running_in_container()
7711bd
+
7711bd
         ovs_rundir = os.environ.get('OVS_RUNDIR')
7711bd
         for pidfile in ['ovnnb_db.pid', 'ovnsb_db.pid', 'ovn-northd.pid']:
7711bd
             self.add_copy_spec([
7711bd
@@ -68,10 +102,20 @@ class OVNCentral(Plugin):
7711bd
 
7711bd
         schema_dir = '/usr/share/openvswitch'
7711bd
 
7711bd
-        self.add_database_output(os.path.join(schema_dir, 'ovn-nb.ovsschema'),
7711bd
-                                 cmds, 'ovn-nbctl')
7711bd
-        self.add_database_output(os.path.join(schema_dir, 'ovn-sb.ovsschema'),
7711bd
-                                 cmds, 'ovn-sbctl', ['Logical_Flow'])
7711bd
+        nb_tables = self.get_tables_from_schema(os.path.join(
7711bd
+            schema_dir, 'ovn-nb.ovsschema'))
7711bd
+        sb_tables = self.get_tables_from_schema(os.path.join(
7711bd
+            schema_dir, 'ovn-sb.ovsschema'), ['Logical_Flow'])
7711bd
+
7711bd
+        self.add_database_output(nb_tables, cmds, 'ovn-nbctl')
7711bd
+        self.add_database_output(sb_tables, cmds, 'ovn-sbctl')
7711bd
+
7711bd
+        # If OVN is containerized, we need to run the above commands inside
7711bd
+        # the container.
7711bd
+        if containerized:
7711bd
+            cmds = ['%s exec %s %s' % (self._container_runtime,
7711bd
+                                       self._container_name,
7711bd
+                                       cmd) for cmd in cmds]
7711bd
 
7711bd
         self.add_cmd_output(cmds)
7711bd
 
7711bd
-- 
7711bd
2.21.0
7711bd
7711bd
7711bd
From a895bf4096f1dbd71c9dbd4defb47783f4ef9840 Mon Sep 17 00:00:00 2001
7711bd
From: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Date: Thu, 25 Jul 2019 11:42:16 +0200
7711bd
Subject: [PATCH 4/4] [ovn_host] Add support for containerized setups
7711bd
7711bd
Prior to this patch, ovn_host was disabled on containerized
7711bd
setups due to the fact that ovn-controller package is not
7711bd
installed in the host.
7711bd
7711bd
This patch fixes it by checking if the ovn-controller process
7711bd
is running.
7711bd
7711bd
Resolves: #1767
7711bd
7711bd
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
7711bd
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
7711bd
---
7711bd
 sos/plugins/ovn_host.py | 21 ++++++++++++++-------
7711bd
 1 file changed, 14 insertions(+), 7 deletions(-)
7711bd
7711bd
diff --git a/sos/plugins/ovn_host.py b/sos/plugins/ovn_host.py
7711bd
index ba35d87e..5225f010 100644
7711bd
--- a/sos/plugins/ovn_host.py
7711bd
+++ b/sos/plugins/ovn_host.py
7711bd
@@ -12,6 +12,15 @@ import os
7711bd
 from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin
7711bd
 
7711bd
 
7711bd
+pidfile = 'ovn-controller.pid'
7711bd
+pid_paths = [
7711bd
+        '/var/lib/openvswitch/ovn',
7711bd
+        '/usr/local/var/run/openvswitch',
7711bd
+        '/var/run/openvswitch',
7711bd
+        '/run/openvswitch'
7711bd
+]
7711bd
+
7711bd
+
7711bd
 class OVNHost(Plugin):
7711bd
     """ OVN Controller
7711bd
     """
7711bd
@@ -19,13 +28,6 @@ class OVNHost(Plugin):
7711bd
     profiles = ('network', 'virt')
7711bd
 
7711bd
     def setup(self):
7711bd
-        pidfile = 'ovn-controller.pid'
7711bd
-        pid_paths = [
7711bd
-                '/var/lib/openvswitch/ovn',
7711bd
-                '/usr/local/var/run/openvswitch',
7711bd
-                '/var/run/openvswitch',
7711bd
-                '/run/openvswitch'
7711bd
-        ]
7711bd
         if os.environ.get('OVS_RUNDIR'):
7711bd
             pid_paths.append(os.environ.get('OVS_RUNDIR'))
7711bd
         self.add_copy_spec([os.path.join(pp, pidfile) for pp in pid_paths])
7711bd
@@ -40,6 +42,11 @@ class OVNHost(Plugin):
7711bd
 
7711bd
         self.add_journal(units="ovn-controller")
7711bd
 
7711bd
+    def check_enabled(self):
7711bd
+        return (any([os.path.isfile(
7711bd
+            os.path.join(pp, pidfile)) for pp in pid_paths]) or
7711bd
+            super(OVNHost, self).check_enabled())
7711bd
+
7711bd
 
7711bd
 class RedHatOVNHost(OVNHost, RedHatPlugin):
7711bd
 
7711bd
-- 
7711bd
2.21.0
7711bd