Blame SOURCES/sos-bz1744553-ovn-plugins-containerized-env.patch

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