Merge "Populate more specific load import error messages"

This commit is contained in:
Zuul
2022-07-06 13:45:10 +00:00
committed by Gerrit Code Review

View File

@@ -269,19 +269,17 @@ class LoadController(rest.RestController):
os.path.basename(file_item.filename))
if source_file is None:
LOG.error("Failed to upload load file %s, invalid file object"
% staging_file)
return None
raise wsme.exc.ClientSideError(_("Failed to upload load file %s,\
invalid file object" % staging_file))
if hasattr(source_file, 'fileno'):
# Only proceed if there is space available for copying
file_size = os.fstat(source_file.fileno()).st_size
avail_space = psutil.disk_usage('/scratch').free
if (avail_space < file_size):
LOG.error("Failed to upload load file %s, not enough space on /scratch"
raise wsme.exc.ClientSideError(_("Failed to upload load file %s, not enough space on /scratch"
" partition: %d bytes available "
% (staging_file, avail_space))
return None
% (staging_file, avail_space)))
# Large iso file, allocate the required space
subprocess.check_call(["/usr/bin/fallocate", # pylint: disable=not-callable
@@ -291,16 +289,14 @@ class LoadController(rest.RestController):
shutil.copyfileobj(source_file, destination_file)
except subprocess.CalledProcessError as e:
LOG.error("Failed to upload load file %s, /usr/bin/fallocate error: %s"
% (staging_file, e.output))
if os.path.isfile(staging_file):
os.remove(staging_file)
return None
raise wsme.exc.ClientSideError(_("Failed to upload load file %s, /usr/bin/fallocate error: %s"
% (staging_file, e.output)))
except Exception:
if os.path.isfile(staging_file):
os.remove(staging_file)
LOG.exception("Failed to upload load file %s" % file_item.filename)
return None
raise wsme.exc.ClientSideError(_("Failed to upload load file %s" % file_item.filename))
return staging_file
@@ -322,8 +318,6 @@ class LoadController(rest.RestController):
LOG.info("Load import request received.")
system_controller_import_active = False
# Only import loads on controller-0. This is required because the load
# is only installed locally and we will be booting controller-1 from
# this load during the upgrade.
@@ -332,6 +326,7 @@ class LoadController(rest.RestController):
" %s is active.")
% constants.CONTROLLER_0_HOSTNAME)
system_controller_import_active = False
req_content = dict()
load_files = dict()
is_multiform_req = True
@@ -356,6 +351,7 @@ class LoadController(rest.RestController):
self._check_existing_loads(active_import=system_controller_import_active)
try:
for file in constants.IMPORT_LOAD_FILES:
if file not in req_content:
raise wsme.exc.ClientSideError(_("Missing required file for %s")
@@ -375,10 +371,12 @@ class LoadController(rest.RestController):
file_location = self._upload_file(file_item)
if file_location:
load_files.update({file: file_location})
else:
raise wsme.exc.ClientSideError(_("Failed to save file %s to disk."
except subprocess.CalledProcessError as ex:
raise wsme.exc.ClientSideError(str(ex))
except Exception as ex:
raise wsme.exc.ClientSideError(_("Failed to save file %s to disk. Error: %s"
" Please check sysinv logs for"
" details." % file_item.filename))
" details." % (file_item.filename, str(ex))))
LOG.info("Load files: %s saved to disk." % load_files)