Commit a5397327 by Stéphane Graber

python3: Don't fail in list_containers on ValueError

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 378a5729
...@@ -386,10 +386,16 @@ def list_containers(active=True, defined=True, ...@@ -386,10 +386,16 @@ def list_containers(active=True, defined=True,
if config_path: if config_path:
if not os.path.exists(config_path): if not os.path.exists(config_path):
return tuple() return tuple()
entries = _lxc.list_containers(active=active, defined=defined, try:
config_path=config_path) entries = _lxc.list_containers(active=active, defined=defined,
config_path=config_path)
except ValueError:
return tuple()
else: 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: if as_object:
return tuple([Container(name, config_path) for name in entries]) return tuple([Container(name, config_path) for name in entries])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment