Blame SOURCES/0141-report-python-fix-getVersion_fromOSRELEASE.patch

4b6aa8
From c25b7bd7a28a093284d7ffe41db3ede51542439c Mon Sep 17 00:00:00 2001
4b6aa8
From: Jakub Filak <jfilak@redhat.com>
4b6aa8
Date: Wed, 4 Mar 2015 11:38:45 +0100
4b6aa8
Subject: [PATCH] report-python: fix getVersion_fromOSRELEASE
4b6aa8
4b6aa8
Related to rhbz#1198551
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
---
4b6aa8
 src/report-python/__init__.py |  5 +++-
4b6aa8
 tests/osinfo.at               | 24 +++++++--------
4b6aa8
 tests/report_python.at        | 68 +++++++++++++++++++++++++++++++++++++++++++
4b6aa8
 3 files changed, 84 insertions(+), 13 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py
4b6aa8
index b0ba497..e2716a5 100644
4b6aa8
--- a/src/report-python/__init__.py
4b6aa8
+++ b/src/report-python/__init__.py
4b6aa8
@@ -33,7 +33,7 @@ SYSTEM_RELEASE_PATHS = ["/etc/system-release","/etc/redhat-release"]
4b6aa8
 SYSTEM_RELEASE_DEPS = ["system-release", "redhat-release"]
4b6aa8
 SYSTEM_OS_RELEASE_FILE = "/etc/os-release"
4b6aa8
 OS_RELEASE_PRODUCT_FIELDS = ["REDHAT_BUGZILLA_PRODUCT", "REDHAT_SUPPORT_PRODUCT", "NAME"]
4b6aa8
-OS_RELEASE_VERSION_FIELDS = ["REDHAT_BUGZILLA_VERSION", "REDHAT_SUPPORT_VERSION", "NAME"]
4b6aa8
+OS_RELEASE_VERSION_FIELDS = ["REDHAT_BUGZILLA_PRODUCT_VERSION", "REDHAT_SUPPORT_PRODUCT_VERSION", "VERSION_ID"]
4b6aa8
 
4b6aa8
 _hardcoded_default_product = ""
4b6aa8
 _hardcoded_default_version = ""
4b6aa8
@@ -72,6 +72,9 @@ def parse_os_release_lines(osreleaselines):
4b6aa8
     osrel = {}
4b6aa8
 
4b6aa8
     for line in osreleaselines:
4b6aa8
+        if line.endswith("\n"):
4b6aa8
+            line = line[:-1]
4b6aa8
+
4b6aa8
         kvp = line.split('=')
4b6aa8
         if len(kvp) < 2:
4b6aa8
             continue
4b6aa8
diff --git a/tests/osinfo.at b/tests/osinfo.at
4b6aa8
index 868a9a2..6ece180 100644
4b6aa8
--- a/tests/osinfo.at
4b6aa8
+++ b/tests/osinfo.at
4b6aa8
@@ -408,18 +408,18 @@ report = __import__("report-python", globals(), locals(), [], -1)
4b6aa8
 sys.modules["report"] = report
4b6aa8
 
4b6aa8
 lines = [
4b6aa8
-    'NAME=fedora',
4b6aa8
-    'VERSION="20 (Heisenbug)"',
4b6aa8
-    'ID=fedora',
4b6aa8
-    'VERSION_ID=20',
4b6aa8
-    'PRETTY_NAME="Fedora 20 (Heisenbug)"',
4b6aa8
-    'ANSI_COLOR="0;34"',
4b6aa8
-    'CPE_NAME="cpe:/o:fedoraproject:fedora:20"',
4b6aa8
-    'HOME_URL="https://fedoraproject.org/"',
4b6aa8
-    'BUG_REPORT_URL="https://bugzilla.redhat.com/"',
4b6aa8
-    'REDHAT_BUGZILLA_PRODUCT="Fedora"',
4b6aa8
-    'REDHAT_BUGZILLA_PRODUCT_VERSION=20',
4b6aa8
-    'REDHAT_SUPPORT_PRODUCT="Fedora"',
4b6aa8
+    'NAME=fedora\n',
4b6aa8
+    'VERSION="20 (Heisenbug)"\n',
4b6aa8
+    'ID=fedora\n',
4b6aa8
+    'VERSION_ID=20\n',
4b6aa8
+    'PRETTY_NAME="Fedora 20 (Heisenbug)"\n',
4b6aa8
+    'ANSI_COLOR="0;34"\n',
4b6aa8
+    'CPE_NAME="cpe:/o:fedoraproject:fedora:20"\n',
4b6aa8
+    'HOME_URL="https://fedoraproject.org/"\n',
4b6aa8
+    'BUG_REPORT_URL="https://bugzilla.redhat.com/"\n',
4b6aa8
+    'REDHAT_BUGZILLA_PRODUCT="Fedora"\n',
4b6aa8
+    'REDHAT_BUGZILLA_PRODUCT_VERSION=20\n',
4b6aa8
+    'REDHAT_SUPPORT_PRODUCT="Fedora"\n',
4b6aa8
     'REDHAT_SUPPORT_PRODUCT_VERSION=20',
4b6aa8
 ]
4b6aa8
 
4b6aa8
diff --git a/tests/report_python.at b/tests/report_python.at
4b6aa8
index 5569b1f..a05498c 100644
4b6aa8
--- a/tests/report_python.at
4b6aa8
+++ b/tests/report_python.at
4b6aa8
@@ -2,6 +2,74 @@
4b6aa8
 
4b6aa8
 AT_BANNER([report_python])
4b6aa8
 
4b6aa8
+## ------------------------- ##
4b6aa8
+## arbitrary_etc_os_releases ##
4b6aa8
+## ------------------------- ##
4b6aa8
+
4b6aa8
+AT_PYTESTFUN([arbitrary_etc_os_releases],
4b6aa8
+[[import sys
4b6aa8
+import tempfile
4b6aa8
+import os
4b6aa8
+
4b6aa8
+sys.path.insert(0, "../../../src/report-python")
4b6aa8
+sys.path.insert(0, "../../../src/report-python/.libs")
4b6aa8
+
4b6aa8
+report = __import__("report-python", globals(), locals(), [], -1)
4b6aa8
+sys.modules["report"] = report
4b6aa8
+
4b6aa8
+
4b6aa8
+PRODUCT_TEST_CASES = [
4b6aa8
+    ("REDHAT_BUGZILLA_PRODUCT", "bugzilla-product"),
4b6aa8
+    ("REDHAT_SUPPORT_PRODUCT", "support-product"),
4b6aa8
+    ("NAME", "os-name")
4b6aa8
+]
4b6aa8
+
4b6aa8
+VERSION_TEST_CASES = [
4b6aa8
+    ("REDHAT_BUGZILLA_PRODUCT_VERSION", "bugzilla-product-version"),
4b6aa8
+    ("REDHAT_SUPPORT_PRODUCT_VERSION", "support-product-version"),
4b6aa8
+    ("VERSION_ID", "os-version-id")
4b6aa8
+]
4b6aa8
+
4b6aa8
+def run_test(fields, getter, expected):
4b6aa8
+    retval = True
4b6aa8
+
4b6aa8
+    osrelf = tempfile.NamedTemporaryFile(delete=False)
4b6aa8
+    osrelf.write("ID=\"field-id\"\n")
4b6aa8
+
4b6aa8
+    for (field, value) in fields:
4b6aa8
+        osrelf.write("%s=%s\n" %(field, value))
4b6aa8
+
4b6aa8
+    osrelf.write("PRETTY_NAME=\"field-pretty-name\"\n")
4b6aa8
+    osrelf.close()
4b6aa8
+
4b6aa8
+    result = getter(file_path=osrelf.name)
4b6aa8
+    if result != expected:
4b6aa8
+        print("expected: '%s'" % (expected))
4b6aa8
+        print("result  : '%s'" % (result))
4b6aa8
+        retval = False
4b6aa8
+
4b6aa8
+    os.remove(osrelf.name)
4b6aa8
+    return retval
4b6aa8
+
4b6aa8
+
4b6aa8
+def verify_information_type(test_cases, stuffing, getter):
4b6aa8
+    retval = 0
4b6aa8
+    for i in xrange(0, len(test_cases)):
4b6aa8
+        for j in xrange(len(test_cases), i, -1):
4b6aa8
+            if not run_test(stuffing + test_cases[i:j], getter, test_cases[i][1]):
4b6aa8
+                print("field   : '%s'" % (test_cases[i][0]))
4b6aa8
+                retval += 1
4b6aa8
+
4b6aa8
+
4b6aa8
+def main():
4b6aa8
+    verify_information_type(PRODUCT_TEST_CASES, VERSION_TEST_CASES, report.getProduct_fromOSRELEASE)
4b6aa8
+    verify_information_type(VERSION_TEST_CASES, PRODUCT_TEST_CASES, report.getVersion_fromOSRELEASE)
4b6aa8
+
4b6aa8
+
4b6aa8
+if __name__ == "__main__":
4b6aa8
+    sys.exit(main())
4b6aa8
+]])
4b6aa8
+
4b6aa8
 ## ----------------------- ##
4b6aa8
 ## get_from_etc_os_release ##
4b6aa8
 ## ----------------------- ##
4b6aa8
-- 
4b6aa8
2.4.3
4b6aa8