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

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