]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
python3: Don't fail in list_containers on ValueError
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 16 Jan 2014 18:37:32 +0000 (13:37 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 16 Jan 2014 20:44:45 +0000 (15:44 -0500)
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@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/python-lxc/lxc/__init__.py

index 0ca3e54c52c79dd87d19e798abbc0605f903a4dc..c274a12a12e9c4bd95657d414bae9e3b7043bb9b 100644 (file)
@@ -386,10 +386,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])