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

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