Blame SOURCES/sos-bz1442078-container-test-oci.patch

b939f5
From 471d8e86c3c174f7b075c306542c732f30893281 Mon Sep 17 00:00:00 2001
b939f5
From: "Bryn M. Reeves" <bmr@redhat.com>
b939f5
Date: Wed, 3 May 2017 16:39:25 +0100
b939f5
Subject: [PATCH 1/3] [reporting] imrove readability of Six string workaround
b939f5
b939f5
Improve the readability of the changes to work around Six issue
b939f5
emphasise the fact that the buffer contains line oriented data,
b939f5
and introduce a helper function to test whether the string needs
b939f5
the workaround to be applied or not: this shortens the list
b939f5
comprehension which would otherwise overflow a single line due
b939f5
to the longer buffer variable name.
b939f5
b939f5
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
b939f5
---
b939f5
 sos/reporting.py | 25 ++++++++++++++++++-------
b939f5
 1 file changed, 18 insertions(+), 7 deletions(-)
b939f5
b939f5
diff --git a/sos/reporting.py b/sos/reporting.py
b939f5
index 0bb7d29..a4941ad 100644
b939f5
--- a/sos/reporting.py
b939f5
+++ b/sos/reporting.py
b939f5
@@ -118,6 +118,17 @@ class Note(Leaf):
b939f5
         self.data = content
b939f5
 
b939f5
 
b939f5
+def ends_bs(string):
b939f5
+    """ Return True if 'string' ends with a backslash, and False otherwise.
b939f5
+
b939f5
+        Define this as a named function for no other reason than that pep8
b939f5
+        now forbids binding of a lambda expression to a name:
b939f5
+
b939f5
+        'E731 do not assign a lambda expression, use a def'
b939f5
+    """
b939f5
+    return string.endswith('\\')
b939f5
+
b939f5
+
b939f5
 class PlainTextReport(object):
b939f5
     """Will generate a plain text report from a top_level Report object"""
b939f5
 
b939f5
@@ -134,16 +145,16 @@ class PlainTextReport(object):
b939f5
         (Note, NOTE,         "-  notes:"),
b939f5
     )
b939f5
 
b939f5
-    buf = []
b939f5
+    line_buf = []
b939f5
 
b939f5
     def __init__(self, report_node):
b939f5
         self.report_node = report_node
b939f5
 
b939f5
     def unicode(self):
b939f5
-        self.buf = buf = []
b939f5
+        self.line_buf = line_buf = []
b939f5
         for section_name, section_contents in sorted(iteritems(
b939f5
                 self.report_node.data)):
b939f5
-            buf.append(section_name + "\n" + self.DIVIDER)
b939f5
+            line_buf.append(section_name + "\n" + self.DIVIDER)
b939f5
             for type_, format_, header in self.subsections:
b939f5
                 self.process_subsection(section_contents, type_.ADDS_TO,
b939f5
                                         header, format_)
b939f5
@@ -151,10 +162,10 @@ class PlainTextReport(object):
b939f5
         # Workaround python.six mishandling of strings ending in '/' by
b939f5
         # adding a single space following any '\' at end-of-line.
b939f5
         # See Six issue #60.
b939f5
-        buf = [(val + " ") if val.endswith('\\') else val for val in buf]
b939f5
+        line_buf = [line + " " if ends_bs(line) else line for line in line_buf]
b939f5
 
b939f5
         output = u'\n'.join(map(lambda i: (i if isinstance(i, six.text_type)
b939f5
-                                           else six.u(i)), buf))
b939f5
+                                           else six.u(i)), line_buf))
b939f5
         if six.PY3:
b939f5
             return output
b939f5
         else:
b939f5
@@ -162,8 +173,8 @@ class PlainTextReport(object):
b939f5
 
b939f5
     def process_subsection(self, section, key, header, format_):
b939f5
         if key in section:
b939f5
-            self.buf.append(header)
b939f5
+            self.line_buf.append(header)
b939f5
             for item in section.get(key):
b939f5
-                self.buf.append(format_ % item)
b939f5
+                self.line_buf.append(format_ % item)
b939f5
 
b939f5
 # vim: set et ts=4 sw=4 :
b939f5
-- 
b939f5
2.7.4
b939f5
b939f5
b939f5
From a81243cdd3f0e7db152251caeb478c19cd801277 Mon Sep 17 00:00:00 2001
b939f5
From: "Bryn M. Reeves" <bmr@redhat.com>
b939f5
Date: Wed, 3 May 2017 16:42:10 +0100
b939f5
Subject: [PATCH 2/3] [plugins] work around Six string problems in HTML reports
b939f5
b939f5
A workaround for Six string encoding problems involving strings
b939f5
that end in '\' characters was introduced for plain text reports
b939f5
in commit 3d23564: a similar fix is also needed for HTML reports,
b939f5
since the same string encoding problem can occur there too:
b939f5
b939f5
> /usr/lib/python2.7/site-packages/six.py(647)u()
b939f5
-> return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
b939f5
(Pdb) bt
b939f5
  /usr/sbin/sosreport(25)<module>()
b939f5
-> main(sys.argv[1:])
b939f5
  /usr/lib/python2.7/site-packages/sos/sosreport.py(1632)main()
b939f5
-> sos.execute()
b939f5
  /usr/lib/python2.7/site-packages/sos/sosreport.py(1606)execute()
b939f5
-> self.html_report()
b939f5
  /usr/lib/python2.7/site-packages/sos/sosreport.py(1373)html_report()
b939f5
-> self._html_report()
b939f5
  /usr/lib/python2.7/site-packages/sos/sosreport.py(1434)_html_report()
b939f5
-> self.handle_exception()
b939f5
  /usr/lib/python2.7/site-packages/sos/sosreport.py(1432)_html_report()
b939f5
-> html = plug.report()
b939f5
  /usr/lib/python2.7/site-packages/sos/plugins/__init__.py(930)report()
b939f5
-> + "/" + _to_u(cmd['file'])
b939f5
  /usr/lib/python2.7/site-packages/sos/plugins/__init__.py(44)_to_u()
b939f5
-> s = six.u(s)
b939f5
> /usr/lib/python2.7/site-packages/six.py(647)u()
b939f5
-> return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
b939f5
b939f5
Avoid this by applying the same workaround ('\$' -> '\ $') in the
b939f5
existing Plugin _to_u() helper function.
b939f5
b939f5
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
b939f5
---
b939f5
 sos/plugins/__init__.py | 5 +++++
b939f5
 1 file changed, 5 insertions(+)
b939f5
b939f5
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
b939f5
index 49da6f2..cd34d19 100644
b939f5
--- a/sos/plugins/__init__.py
b939f5
+++ b/sos/plugins/__init__.py
b939f5
@@ -36,6 +36,11 @@ from six.moves import zip, filter
b939f5
 
b939f5
 def _to_u(s):
b939f5
     if not isinstance(s, six.text_type):
b939f5
+        # Workaround python.six mishandling of strings ending in '\' by
b939f5
+        # adding a single space following any '\' at end-of-line.
b939f5
+        # See Six issue #60.
b939f5
+        if s.endswith('\\'):
b939f5
+            s += " "
b939f5
         s = six.u(s)
b939f5
     return s
b939f5
 
b939f5
-- 
b939f5
2.7.4
b939f5
b939f5
b939f5
From 5e3ae1cf78cbd7dd122ed229add39e89aefdc21e Mon Sep 17 00:00:00 2001
b939f5
From: "Bryn M. Reeves" <bmr@redhat.com>
b939f5
Date: Wed, 3 May 2017 16:47:04 +0100
b939f5
Subject: [PATCH 3/3] [policies/redhat] accept 'oci' as a valid container type
b939f5
b939f5
Currently the Red Hat container policy accepts 'container=docker'
b939f5
as a valid indication that we are running in a container and to
b939f5
enable sysroot and host sysroot checks.
b939f5
b939f5
More recent Red Hat container infrastructure has change to setting
b939f5
'container=oci', so recognise this value as well.
b939f5
b939f5
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
b939f5
---
b939f5
 sos/policies/redhat.py | 2 +-
b939f5
 1 file changed, 1 insertion(+), 1 deletion(-)
b939f5
b939f5
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
b939f5
index a1565c6..a6e3712 100644
b939f5
--- a/sos/policies/redhat.py
b939f5
+++ b/sos/policies/redhat.py
b939f5
@@ -84,7 +84,7 @@ class RedHatPolicy(LinuxPolicy):
b939f5
         specific initialisation based on ENV_HOST_SYSROOT.
b939f5
         """
b939f5
         if ENV_CONTAINER in os.environ:
b939f5
-            if os.environ[ENV_CONTAINER] == 'docker':
b939f5
+            if os.environ[ENV_CONTAINER] in ['docker', 'oci']:
b939f5
                 self._in_container = True
b939f5
         if ENV_HOST_SYSROOT in os.environ:
b939f5
             self._host_sysroot = os.environ[ENV_HOST_SYSROOT]
b939f5
-- 
b939f5
2.7.4
b939f5