[libvirt PATCH] tests: Mock virGetUserRuntimeDirectory() for qemuhotplug

Daniel P. Berrangé berrange at redhat.com
Fri May 1 13:09:10 UTC 2020


On Fri, May 01, 2020 at 02:30:16PM +0200, Andrea Bolognani wrote:
> Not mocking this function results in files being created in the
> user's home directory when running the test and in the build
> failing altogether inside a constrained environment such as the
> one used by pbuilder:

What's pbuilder ? I wonder if we can make it so that in our
containers $HOME points to a non-writable directory such that
we can see this failure (and others) in our GitLab CI ?

> 
>   Could not initialize HostdevManager - operation failed: Failed
>   to create state dir '/nonexistent/.cache/libvirt/hostdevmgr'
> 
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
>  tests/qemuhotplugmock.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c
> index d2324913cf..27c81670a3 100644
> --- a/tests/qemuhotplugmock.c
> +++ b/tests/qemuhotplugmock.c
> @@ -27,6 +27,7 @@
>  
>  static int (*real_virGetDeviceID)(const char *path, int *maj, int *min);
>  static bool (*real_virFileExists)(const char *path);
> +static char *(*real_virGetUserRuntimeDirectory)(void);
>  
>  static void
>  init_syms(void)
> @@ -36,6 +37,7 @@ init_syms(void)
>  
>      VIR_MOCK_REAL_INIT(virGetDeviceID);
>      VIR_MOCK_REAL_INIT(virFileExists);
> +    VIR_MOCK_REAL_INIT(virGetUserRuntimeDirectory);
>  }
>  
>  unsigned long long
> @@ -106,3 +108,10 @@ void
>  qemuProcessKillManagedPRDaemon(virDomainObjPtr vm G_GNUC_UNUSED)
>  {
>  }
> +
> +char *
> +virGetUserRuntimeDirectory(void)
> +{
> +    return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"),
> +                            "user-runtime-directory", NULL);
> +}
> -- 
> 2.25.4
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list