]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu-gather: Allow overwriting model name
authorTim Wiederhake <twiederh@redhat.com>
Tue, 15 Dec 2020 16:24:50 +0000 (17:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Dec 2020 22:19:41 +0000 (23:19 +0100)
Some hardware, e.g. exotic platforms or pre-production hardware, may
report wrong or random data for the cpu model name. As the name of
the created files is derived from that name, this may lead to issues.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/cputestdata/cpu-gather.py

index 1b02df6ec7d646480767b6a65d8e4a1aff2f9fa4..4e8c72e4f41e497fda1ab9c67160c9ddc3ea233b 100755 (executable)
@@ -1,20 +1,33 @@
 #!/usr/bin/env python3
 
+import argparse
 import os
 import subprocess
 
 
-def gather_name():
+def gather_name(args):
+    if args.name:
+        return args.name
+
     with open("/proc/cpuinfo", "rt") as f:
         for line in f.readlines():
             if line.startswith("model name"):
                 return line.split(":", 2)[1].strip()
 
-    exit("Error: '/proc/cpuinfo' does not contain a model name.")
+    exit("Error: '/proc/cpuinfo' does not contain a model name.\n"
+         "Use '--model' to set a model name.")
 
 
 def main():
-    name = gather_name()
+    parser = argparse.ArgumentParser(description="Gather cpu test data")
+    parser.add_argument(
+        "--name",
+        help="CPU model name. "
+        "If unset, model name is read from '/proc/cpuinfo'.")
+
+    args = parser.parse_args()
+
+    name = gather_name(args)
     print("model name\t: {}".format(name))
 
     print(end="", flush=True)