]> xenbits.xensource.com Git - xtf.git/commitdiff
runner: Collect the host virt capabilities
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 9 Jan 2024 11:09:07 +0000 (11:09 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 9 Jan 2024 11:59:00 +0000 (11:59 +0000)
Use the test environment and variation to calculate a set of required virt
capabilities.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
xtf-runner

index 138f3b1cfeb98757dd9d91ecb66dcdda1c9bbe2f..41431312324ada92d1821945a455430e08db524c 100755 (executable)
@@ -61,6 +61,17 @@ all_environments       = pv_environments | hvm_environments
 class RunnerError(Exception):
     """ Errors relating to xtf-runner itself """
 
+
+def env_to_virt_caps(env):
+    """ Identify which virt cap(s) are needed for an environment """
+    if env in hvm_environments:
+        return {"hvm"}
+    caps = {"pv"}
+    if env == "pv32pae":
+        caps |= {"pv32"}
+    return caps
+
+
 class TestInstance(object):
     """ Object representing a single test. """
 
@@ -75,6 +86,9 @@ class TestInstance(object):
             raise RunnerError("Test '{0}' has variations, but none specified"
                               .format(self.name))
 
+        self.req_caps = env_to_virt_caps(self.env)
+        self.req_caps |= {"hap", "shadow"} & set((self.variation, ))
+
     def vm_name(self):
         """ Return the VM name as `xl` expects it. """
         return repr(self)
@@ -259,6 +273,29 @@ def get_all_test_info():
     return _all_test_info
 
 
+# Cached virt caps
+_virt_caps = set()
+
+def get_virt_caps():
+    """ Query Xen for the virt capabilities of the host """
+    global _virt_caps
+
+    if not _virt_caps: # Cache on first request
+
+        # Filter down to caps we're happy for tests to use
+        caps = {"pv", "hvm", "hap", "shadow"}
+        caps &= set(check_output(["xl", "info", "virt_caps"]).split())
+
+        # Synthesize a pv32 virt cap by looking at xen_caps
+        if ("pv" in caps and
+            "xen-3.0-x86_32p" in check_output(["xl", "info", "xen_caps"])):
+            caps |= {"pv32"}
+
+        _virt_caps = caps
+
+    return _virt_caps
+
+
 def tests_from_selection(cats, envs, tests):
     """Given a selection of possible categories, environment and tests, return
     all tests within the provided parameters.