Better errors for execute() failures
Exceptions raised due to processutils.execute() failing now include stdout and stderr. Change-Id: Id5d1b5bc51d377f9f3c338cd7303ea800f76e5cd
This commit is contained in:
@@ -159,10 +159,11 @@ class ImageWriteError(RESTError):
|
|||||||
|
|
||||||
message = 'Error writing image to device.'
|
message = 'Error writing image to device.'
|
||||||
|
|
||||||
def __init__(self, exit_code, device):
|
def __init__(self, device, exit_code, stdout, stderr):
|
||||||
super(ImageWriteError, self).__init__()
|
super(ImageWriteError, self).__init__()
|
||||||
self.details = 'Writing image to device {0} failed with exit code {1}.'
|
self.details = ('Writing image to device {0} failed with exit code '
|
||||||
self.details = self.details.format(device, exit_code)
|
'{1}. stdout: {2}. stderr: {3}')
|
||||||
|
self.details = self.details.format(device, exit_code, stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
class ConfigDriveTooLargeError(RESTError):
|
class ConfigDriveTooLargeError(RESTError):
|
||||||
@@ -183,10 +184,10 @@ class ConfigDriveWriteError(RESTError):
|
|||||||
|
|
||||||
message = 'Error writing configdrive to device.'
|
message = 'Error writing configdrive to device.'
|
||||||
|
|
||||||
def __init__(self, exit_code, device):
|
def __init__(self, device, exit_code, stdout, stderr):
|
||||||
details = 'Writing configdrive to device {0} failed with exit code ' \
|
details = ('Writing configdrive to device {0} failed with exit code '
|
||||||
'{1}.'
|
'{1}. stdout: {2}. stderr: {3}.')
|
||||||
details = details.format(device, exit_code)
|
details = details.format(device, exit_code, stdout, stderr)
|
||||||
super(ConfigDriveWriteError, self).__init__(details)
|
super(ConfigDriveWriteError, self).__init__(details)
|
||||||
self.details = details
|
self.details = details
|
||||||
|
|
||||||
@@ -196,10 +197,11 @@ class SystemRebootError(RESTError):
|
|||||||
|
|
||||||
message = 'Error rebooting system.'
|
message = 'Error rebooting system.'
|
||||||
|
|
||||||
def __init__(self, exit_code):
|
def __init__(self, exit_code, stdout, stderr):
|
||||||
super(SystemRebootError, self).__init__()
|
super(SystemRebootError, self).__init__()
|
||||||
self.details = 'Reboot script failed with exit code {0}.'
|
self.details = ('Reboot script failed with exit code {0}. stdout: '
|
||||||
self.details = self.details.format(exit_code)
|
'{1}. stderr: {2}.')
|
||||||
|
self.details = self.details.format(exit_code, stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
class BlockDeviceEraseError(RESTError):
|
class BlockDeviceEraseError(RESTError):
|
||||||
|
@@ -54,7 +54,7 @@ def _write_image(image_info, device):
|
|||||||
try:
|
try:
|
||||||
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
||||||
except processutils.ProcessExecutionError as e:
|
except processutils.ProcessExecutionError as e:
|
||||||
raise errors.ImageWriteError(e.exit_code, device)
|
raise errors.ImageWriteError(device, e.exit_code, e.stdout, e.stderr)
|
||||||
totaltime = time.time() - starttime
|
totaltime = time.time() - starttime
|
||||||
LOG.info('Image {0} written to device {1} in {2} seconds'.format(
|
LOG.info('Image {0} written to device {1} in {2} seconds'.format(
|
||||||
image, device, totaltime))
|
image, device, totaltime))
|
||||||
@@ -88,7 +88,10 @@ def _write_configdrive_to_partition(configdrive, device):
|
|||||||
try:
|
try:
|
||||||
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
||||||
except processutils.ProcessExecutionError as e:
|
except processutils.ProcessExecutionError as e:
|
||||||
raise errors.ConfigDriveWriteError(e.exit_code, device)
|
raise errors.ConfigDriveWriteError(device,
|
||||||
|
e.exit_code,
|
||||||
|
e.stdout,
|
||||||
|
e.stderr)
|
||||||
|
|
||||||
totaltime = time.time() - starttime
|
totaltime = time.time() - starttime
|
||||||
LOG.info('configdrive copied from {0} to {1} in {2} seconds'.format(
|
LOG.info('configdrive copied from {0} to {1} in {2} seconds'.format(
|
||||||
@@ -209,4 +212,4 @@ class StandbyExtension(base.BaseAgentExtension):
|
|||||||
try:
|
try:
|
||||||
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
||||||
except processutils.ProcessExecutionError as e:
|
except processutils.ProcessExecutionError as e:
|
||||||
raise errors.SystemRebootError(e.exit_code)
|
raise errors.SystemRebootError(e.exit_code, e.stdout, e.stderr)
|
||||||
|
Reference in New Issue
Block a user