]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test_driver: Introduce testDomainObjCheckTaint
authorLuke Yue <lukedyue@gmail.com>
Mon, 12 Jul 2021 11:32:16 +0000 (19:32 +0800)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 3 Aug 2021 12:22:10 +0000 (14:22 +0200)
In order to test the virDomainGetMessages for test driver, we need to
check some taints or deprecations, so introduce testDomainObjCheckTaint
for checking taints.

As we introduced testDomainObjCheckTaint for test driver, the `dominfo`
command in virshtest will now print tainting messages, so add them for
test.

Signed-off-by: Luke Yue <lukedyue@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/test/test_driver.c
tests/virshtest.c

index 950e62ab3f96d2947f86b63e56d57e6d1bffdc96..16d70d9025b8b1c3389abd0c16b1d7e8ad21c7c3 100644 (file)
@@ -746,6 +746,81 @@ static char *testBuildFilename(const char *relativeTo,
     return g_strdup_printf("%s/%s", basename, filename);
 }
 
+static void
+testDomainObjCheckCPUTaint(virDomainObj *obj)
+{
+    switch (obj->def->cpu->mode) {
+    case VIR_CPU_MODE_CUSTOM:
+        if (obj->def->cpu->model)
+            if (STREQ(obj->def->cpu->model, "Deprecated-Test")) {
+                virDomainObjTaint(obj, VIR_DOMAIN_TAINT_DEPRECATED_CONFIG);
+                virDomainObjDeprecation(obj, "CPU model Deprecated-Test");
+            }
+
+        break;
+    default:
+        break;
+    }
+}
+
+static void
+testDomainObjCheckDiskTaint(virDomainObj *obj,
+                            virDomainDiskDef *disk)
+{
+    if (disk->rawio == VIR_TRISTATE_BOOL_YES)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES);
+
+    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
+        virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK &&
+        disk->src->path)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH);
+}
+
+static void
+testDomainObjCheckHostdevTaint(virDomainObj *obj,
+                               virDomainHostdevDef *hostdev)
+{
+    if (!virHostdevIsSCSIDevice(hostdev))
+        return;
+
+    if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES);
+}
+
+static void
+testDomainObjCheckNetTaint(virDomainObj *obj,
+                           virDomainNetDef *net)
+{
+    /* script is only useful for NET_TYPE_ETHERNET (qemu) and
+     * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for
+     * any interface type. In any case, it's adding user sauce into
+     * the soup, so it should taint the domain.
+     */
+    if (net->script != NULL)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS);
+}
+
+static void
+testDomainObjCheckTaint(virDomainObj *obj)
+{
+    size_t i;
+
+    for (i = 0; i < obj->def->ndisks; i++)
+        testDomainObjCheckDiskTaint(obj, obj->def->disks[i]);
+
+    for (i = 0; i < obj->def->nhostdevs; i++)
+        testDomainObjCheckHostdevTaint(obj, obj->def->hostdevs[i]);
+
+    for (i = 0; i < obj->def->nnets; i++)
+        testDomainObjCheckNetTaint(obj, obj->def->nets[i]);
+
+    if (obj->def->cpu)
+        testDomainObjCheckCPUTaint(obj);
+
+    if (obj->def->os.dtb)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB);
+}
+
 static xmlNodePtr
 testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
 {
@@ -968,6 +1043,8 @@ testParseDomains(testDriver *privconn,
         }
         virDomainObjSetState(obj, nsdata->runstate, 0);
 
+        testDomainObjCheckTaint(obj);
+
         virDomainObjEndAPI(&obj);
     }
 
index fe0c420958812f2c889153408170c87251612271..0419552b38f1d3de1b2e136e66c4971f3b959f1a 100644 (file)
@@ -22,6 +22,7 @@ main(void)
 
 # define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493"
 # define SECURITY_LABEL "libvirt-test (enforcing)"
+# define MESSAGES "tainted: network configuration using opaque shell scripts"
 
 static const char *dominfo_fc4 = "\
 Id:             2\n\
@@ -38,6 +39,7 @@ Managed save:   no\n\
 Security model: testSecurity\n\
 Security DOI:   \n\
 Security label: " SECURITY_LABEL "\n\
+Messages:       " MESSAGES "\n\
 \n";
 static const char *domuuid_fc4 = DOM_UUID "\n\n";
 static const char *domid_fc4 = "2\n\n";