]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu-cpuid: Remove xmltodict usage in parseCPU
authorTim Wiederhake <twiederh@redhat.com>
Mon, 4 Jan 2021 11:30:13 +0000 (12:30 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 7 Jan 2021 17:10:44 +0000 (18:10 +0100)
'xmltodict' is a Python module that is not installed by default.
Replace it, so the dependencies of cpu-gather.py do not change
when both scripts are merged.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
tests/cputestdata/cpu-cpuid.py

index 2db0552b12c8912c1b2d0b140ab95f40e3f0ef4d..ebf8cdee7e9fef4953f3edcf5d8b8346cc7fd61d 100755 (executable)
@@ -4,7 +4,6 @@ import argparse
 import os
 import sys
 import json
-import xmltodict
 import xml.etree.ElementTree
 
 
@@ -105,31 +104,19 @@ def parseQemu(path, features):
 
 
 def parseCPUData(path):
-    cpuData = {}
-    with open(path, "rb") as f:
-        data = xmltodict.parse(f)
-
-    for leaf in data["cpudata"]["cpuid"]:
-        feature = {"type": "cpuid"}
-        feature["eax_in"] = int(leaf["@eax_in"], 0)
-        feature["ecx_in"] = int(leaf["@ecx_in"], 0)
-        for reg in ["eax", "ebx", "ecx", "edx"]:
-            feature[reg] = int(leaf["@" + reg], 0)
+    cpuData = dict()
+    for f in xml.etree.ElementTree.parse(path).getroot():
+        if f.tag == "cpuid":
+            reg_list = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
+        elif f.tag == "msr":
+            reg_list = ["index", "eax", "edx"]
+        else:
+            continue
 
+        feature = {"type": f.tag}
+        for reg in reg_list:
+            feature[reg] = int(f.attrib.get(reg, "0"), 0)
         addFeature(cpuData, feature)
-
-    if "msr" in data["cpudata"]:
-        if not isinstance(data["cpudata"]["msr"], list):
-            data["cpudata"]["msr"] = [data["cpudata"]["msr"]]
-
-        for msr in data["cpudata"]["msr"]:
-            feature = {"type": "msr"}
-            feature["index"] = int(msr["@index"], 0)
-            feature["edx"] = int(msr["@edx"], 0)
-            feature["eax"] = int(msr["@eax"], 0)
-
-            addFeature(cpuData, feature)
-
     return cpuData