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

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