[lxc-devel] [PATCH] python3: Don't fail in list_containers on ValueError

Serge Hallyn serge.hallyn at ubuntu.com
Thu Jan 16 19:06:12 UTC 2014


Quoting Stéphane Graber (stgraber at ubuntu.com):
> ValueError typically means that the user doesn't have permissions to
> access the directory. Raising an exception there isn't consistent with
> other error behaviour of list_containers which simple returns an empty
> tuple.
> 
> So simply catch the exception and ignore it. An error message is already
> printed by LXC itself anyway.
> 
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/python-lxc/lxc/__init__.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py
> index fa74297..43fb07d 100644
> --- a/src/python-lxc/lxc/__init__.py
> +++ b/src/python-lxc/lxc/__init__.py
> @@ -398,10 +398,16 @@ def list_containers(active=True, defined=True,
>      if config_path:
>          if not os.path.exists(config_path):
>              return tuple()
> -        entries = _lxc.list_containers(active=active, defined=defined,
> -                                       config_path=config_path)
> +        try:
> +            entries = _lxc.list_containers(active=active, defined=defined,
> +                                           config_path=config_path)
> +        except ValueError:
> +            return tuple()
>      else:
> -        entries = _lxc.list_containers(active=active, defined=defined)
> +        try:
> +            entries = _lxc.list_containers(active=active, defined=defined)
> +        except ValueError:
> +            return tuple()
>  
>      if as_object:
>          return tuple([Container(name, config_path) for name in entries])
> -- 
> 1.8.5.2
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list