From a539732721c45939ab79c01abd19298e4e5c74ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Thu, 16 Jan 2014 13:37:32 -0500 Subject: [PATCH] python3: Don't fail in list_containers on ValueError MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Acked-by: Serge E. Hallyn --- 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 0ca3e54c5..c274a12a1 100644 --- a/src/python-lxc/lxc/__init__.py +++ b/src/python-lxc/lxc/__init__.py @@ -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]) -- 2.47.2