From 1686d6aa535562ae2ea6e04b6dfd59b86c998c8a Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Mon, 20 Apr 2015 10:26:31 +0200 Subject: [PATCH] Do not crash on homedir mkdir Glanceclient is trying to create ~/.glanceclient, and crashes if it can't do that. In some environment (for example, when building the package under Jenkins), writing on $HOME is simply not allowed, and Glanceclient can simply ignore it. This patch allows the mkdir() to fail, which fixes the issue. Closes-Bug: #1446096 Change-Id: Ib3591fb4e54ccd2fe63a1a4815551ac10ef5b961 --- glanceclient/shell.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index f212323d..6ffd53d1 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -556,7 +556,15 @@ class OpenStackImagesShell(object): def _cache_schemas(self, options, home_dir='~/.glanceclient'): homedir = expanduser(home_dir) if not os.path.exists(homedir): - os.makedirs(homedir) + try: + os.makedirs(homedir) + except OSError as e: + # This avoids glanceclient to crash if it can't write to + # ~/.glanceclient, which may happen on some env (for me, + # it happens in Jenkins, as Glanceclient can't write to + # /var/lib/jenkins). + msg = '%s' % e + print(encodeutils.safe_decode(msg), file=sys.stderr) resources = ['image', 'metadefs/namespace', 'metadefs/resource_type'] schema_file_paths = [homedir + os.sep + x + '_schema.json'