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

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