Blame 0048-report-python-fix-getVersion_fromOSRELEASE.patch

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