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

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