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

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