Commit c4aefeaf authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Update and enrich error messages in image register

Parse ivalid property file and guide users to correct it
Guide users to pass valid container:path parameters

Refs:#3769
parent 9553da85
......@@ -358,6 +358,22 @@ class plankton(object):
'* get a list of image ids: /image list',
'* details of image: /flavor info <image id>']
remote_image_file = [
'Suggested usage:',
' /image register <image container>:<uploaded image file path>',
'To set "image" as image container and "my_dir/img.diskdump" as',
'the remote image file path, try one of the following:',
'- <image container>:<remote path>',
' e.g. image:/my_dir/img.diskdump',
'- <remote path> -C <image container>',
' e.g. /my_dir/img.diskdump -C image',
'To check if the image file is accessible to current user:',
' /file list <image container>',
'If the file is located under a different user id "us3r1d"',
' use the --fileowner=us3r1d argument e.g.:',
' /image register "my" image:my_dir/img.diskdump --fileowner=us3r1d',
'Note: The form pithos://<userid>/<container>/<path> is deprecated']
@classmethod
def connection(this, foo):
return generic._connection(foo, 'image.url')
......@@ -386,7 +402,7 @@ class plankton(object):
def _raise(self, *args, **kwargs):
key = kwargs.get('key', None)
try:
foo(self, *args, **kwargs)
return foo(self, *args, **kwargs)
except ClientError as ce:
ce_msg = ('%s' % ce).lower()
if ce.status == 404 or (
......@@ -396,6 +412,20 @@ class plankton(object):
raise
return _raise
@classmethod
def image_file(this, foo):
def _raise(self, name, container_path):
try:
return foo(self, name, container_path)
except ClientError as ce:
if ce.status in (400,):
raiseCLIError(
ce,
'Nonexistent location for %s' % container_path,
importance=2, details=this.remote_image_file)
raise
return _raise
class pithos(object):
container_howto = [
......
......@@ -319,6 +319,7 @@ class image_register(_init_image):
return container, path
@errors.generic.all
@errors.plankton.image_file
@errors.plankton.connection
def _run(self, name, container_path):
container, path = self._get_container_path(container_path)
......@@ -351,9 +352,24 @@ class image_register(_init_image):
#load properties
properties = dict()
if self['property_file']:
for k, v in _load_image_props(self['property_file']).items():
properties[k.lower()] = v
pfile = self['property_file']
if pfile:
try:
for k, v in _load_image_props(pfile).items():
properties[k.lower()] = v
except Exception as e:
raiseCLIError(
e, 'Format error in property file %s' % pfile,
details=[
'Expected content format:',
' {',
' "key1": "value1",',
' "key2": "value2",',
' ...',
' }',
'',
'Parser:'
])
for k, v in self['properties'].items():
properties[k.lower()] = v
......@@ -368,7 +384,7 @@ class image_register(_init_image):
property_file_location='%s:%s' % (container, prop_path),
headers=prop_headers))
else:
print('Property file location is %s:%s with version %s' % (
print('Property file uploaded as %s:%s (version %s)' % (
container, prop_path, prop_headers['x-object-version']))
def main(self, name, container___path):
......
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