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
This commit is contained in:
Thomas Goirand 2015-04-20 10:26:31 +02:00 committed by Stuart McLaren
parent 825c4a5df2
commit 1686d6aa53

View File

@ -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'