Blame SOURCES/0308-plugins-a-a-g-machine-id-use-dmidecode-command.patch

868a66
From 685bf3a4a05e02f628c19f23a60107b98b52d199 Mon Sep 17 00:00:00 2001
868a66
From: Martin Kutlak <mkutlak@redhat.com>
868a66
Date: Wed, 18 Apr 2018 17:12:17 +0200
868a66
Subject: [PATCH] plugins: a-a-g-machine-id use dmidecode command
868a66
868a66
python-dmidecode is broken on aarch64 [1] and the issue won't be fixed.
868a66
Recommendation is to use regular dmidecode command instead.
868a66
868a66
Related to BZ#1566707
868a66
868a66
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1509938
868a66
868a66
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
868a66
---
868a66
 src/plugins/abrt-action-generate-machine-id | 40 ++++++++-------------
868a66
 1 file changed, 15 insertions(+), 25 deletions(-)
868a66
868a66
diff --git a/src/plugins/abrt-action-generate-machine-id b/src/plugins/abrt-action-generate-machine-id
868a66
index 6f43258c..f843d773 100644
868a66
--- a/src/plugins/abrt-action-generate-machine-id
868a66
+++ b/src/plugins/abrt-action-generate-machine-id
868a66
@@ -20,8 +20,10 @@
868a66
 """This module provides algorithms for generating Machine IDs.
868a66
 """
868a66
 
868a66
+import os
868a66
 import sys
868a66
 from argparse import ArgumentParser
868a66
+from subprocess import check_output
868a66
 import logging
868a66
 
868a66
 import hashlib
868a66
@@ -35,38 +37,26 @@ def generate_machine_id_dmidecode():
868a66
 
868a66
     """
868a66
 
868a66
-    try:
868a66
-        import dmidecode
868a66
-    except ImportError as ex:
868a66
-        raise RuntimeError("Could not import dmidecode module: {0}"
868a66
-                .format(str(ex)))
868a66
-
868a66
-    dmixml = dmidecode.dmidecodeXML()
868a66
-    # Fetch all DMI data into a libxml2.xmlDoc object
868a66
-    dmixml.SetResultType(dmidecode.DMIXML_DOC)
868a66
-    xmldoc = dmixml.QuerySection('all')
868a66
+    if not os.path.isfile("/usr/sbin/dmidecode"):
868a66
+        raise RuntimeError("Could not find dmidecode. It might not be available for this " \
868a66
+                           "architecture.")
868a66
 
868a66
-    # Do some XPath queries on the XML document
868a66
-    dmixp = xmldoc.xpathNewContext()
868a66
-
868a66
-    # What to look for - XPath expressions
868a66
-    keys = ['/dmidecode/SystemInfo/Manufacturer',
868a66
-            '/dmidecode/SystemInfo/ProductName',
868a66
-            '/dmidecode/SystemInfo/SerialNumber',
868a66
-            '/dmidecode/SystemInfo/SystemUUID']
868a66
+    # What to look for
868a66
+    keys = ['system-manufacturer',
868a66
+            'system-product-name',
868a66
+            'system-serial-number',
868a66
+            'system-uuid']
868a66
 
868a66
     # Create a sha256 of ^ for machine_id
868a66
     machine_id = hashlib.sha256()
868a66
 
868a66
-    # Run xpath expressions
868a66
+    # Run dmidecode command
868a66
     for k in keys:
868a66
-        data = dmixp.xpathEval(k)
868a66
-        for d in data:
868a66
-            # Update the hash as we find the fields we are looking for
868a66
-            machine_id.update(d.get_content())
868a66
+        data = check_output(["dmidecode", "-s", k]).strip()
868a66
+
868a66
+        # Update the hash as we find the fields we are looking for
868a66
+        machine_id.update(data)
868a66
 
868a66
-    del dmixp
868a66
-    del xmldoc
868a66
     # Create sha256 digest
868a66
     return machine_id.hexdigest()
868a66
 
868a66
-- 
868a66
2.17.1
868a66