Using ProcessExecutionError in shell instead of Runtime, and functionalizing old flags conversion in nova

This commit is contained in:
Joshua Harlow 2012-03-07 14:00:46 -08:00
parent ad3130d629
commit 37ee46b404
3 changed files with 26 additions and 15 deletions

View File

@ -739,20 +739,23 @@ class NovaConfConfigurator(object):
cleaned_lines.append(cleaned_line)
return cleaned_lines
def _convert_extra_flags(self, extra_flags):
converted_flags = list()
for f in extra_flags:
cleaned_opt = f.lstrip("-")
if len(cleaned_opt) == 0:
continue
if cleaned_opt.find("=") == -1:
cleaned_opt += "=%s" % (True)
converted_flags.append(cleaned_opt)
return converted_flags
def _get_content(self, nova_conf):
generated_content = nova_conf.generate()
extra_flags = self._get_extra('extra_flags')
if extra_flags:
LOG.warning("EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS!")
converted_flags = list()
for f in extra_flags:
cleaned_opt = f.lstrip("-")
if len(cleaned_opt) == 0:
continue
if cleaned_opt.find("=") == -1:
cleaned_opt += "=%s" % (True)
converted_flags.append(cleaned_opt)
extra_flags = converted_flags
extra_flags = self._convert_extra_flags(extra_flags)
extra_opts = self._get_extra('extra_opts')
if extra_flags or extra_opts:
new_contents = list()

View File

@ -76,17 +76,24 @@ class ConfigException(StackException):
class ProcessExecutionError(IOError):
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
def __init__(self, stdout=None, stderr=None,
exit_code=None, cmd=None,
description=None):
self.exit_code = exit_code
self.stderr = stderr
self.stdout = stdout
self.cmd = cmd
self.description = description
if description is None:
description = ('Unexpected error while running command.')
if exit_code is None:
exit_code = '-'
if self.cmd is None:
self.cmd = '-'
if self.description is None:
self.description = 'Unexpected error while running command.'
if self.exit_code is None:
self.exit_code = '-'
if self.stderr is None:
self.stderr = '-'
if self.stdout is None:
self.stdout = '-'
message = ('%(description)s\nCommand: %(cmd)s\n'
'Exit code: %(exit_code)s\nStdout: %(stdout)r\n'
'Stderr: %(stderr)r' % locals())

View File

@ -143,7 +143,8 @@ def execute(*cmd, **kwargs):
else:
result = obj.communicate()
except OSError as e:
raise RuntimeError('Could not run %s: %s' % (execute_cmd, e))
error_description = "%s: [%s, %s]" % (e.message, e.errno, e.strerror)
raise excp.ProcessExecutionError(description=error_description, cmd=str_cmd)
if (stdin_fh != subprocess.PIPE
and obj.stdin and close_stdin):
obj.stdin.close()