[libvirt] [PATCH v2 2/2] test: qemuhotplugtest mock virFileMakePath

Christian Ehrhardt christian.ehrhardt at canonical.com
Thu Jan 16 08:28:56 UTC 2020


In certain build environments (e.g. Debian and Ubuntu) $HOME is set
to a non existing path intentionally. That breaks and crashes
qemuhotplugtest by failing the init in virHostdevManagerGetDefault.

Avoid that issue by mocking the virFileMakePath behavior if it is
passed a path that matches $HOME and doesn't exists. That fixes
qemuhotplugtest in Debian/Ubuntu builds of v6.0.0.

Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
---
 tests/qemuhotplugmock.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c
index 43a9d79051..06a28742d4 100644
--- a/tests/qemuhotplugmock.c
+++ b/tests/qemuhotplugmock.c
@@ -18,6 +18,7 @@
 
 #include <config.h>
 
+#include "virmock.h"
 #include "qemu/qemu_hotplug.h"
 #include "conf/domain_conf.h"
 
@@ -31,3 +32,19 @@ qemuDomainGetUnplugTimeout(virDomainObjPtr vm G_GNUC_UNUSED)
         return 200;
     return 100;
 }
+
+VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
+                       const char *, path)
+{
+    const char *home;
+
+    VIR_MOCK_REAL_INIT(virFileMakePath);
+
+    /* ignore non-existing homes (e.g. in build environments) */
+    home = getenv("HOME");
+    if (strstr(path, home)) {
+        if (!g_file_test (home, G_FILE_TEST_EXISTS))
+            return 0;
+    }
+    return real_virFileMakePath(path);
+}
-- 
2.25.0





More information about the libvir-list mailing list