Using ProcessExecutionError in shell instead of Runtime, and functionalizing old flags conversion in nova
This commit is contained in:
parent
ad3130d629
commit
37ee46b404
@ -739,20 +739,23 @@ class NovaConfConfigurator(object):
|
|||||||
cleaned_lines.append(cleaned_line)
|
cleaned_lines.append(cleaned_line)
|
||||||
return cleaned_lines
|
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):
|
def _get_content(self, nova_conf):
|
||||||
generated_content = nova_conf.generate()
|
generated_content = nova_conf.generate()
|
||||||
extra_flags = self._get_extra('extra_flags')
|
extra_flags = self._get_extra('extra_flags')
|
||||||
if extra_flags:
|
if extra_flags:
|
||||||
LOG.warning("EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS!")
|
LOG.warning("EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS!")
|
||||||
converted_flags = list()
|
extra_flags = self._convert_extra_flags(extra_flags)
|
||||||
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_opts = self._get_extra('extra_opts')
|
extra_opts = self._get_extra('extra_opts')
|
||||||
if extra_flags or extra_opts:
|
if extra_flags or extra_opts:
|
||||||
new_contents = list()
|
new_contents = list()
|
||||||
|
@ -76,17 +76,24 @@ class ConfigException(StackException):
|
|||||||
|
|
||||||
|
|
||||||
class ProcessExecutionError(IOError):
|
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):
|
description=None):
|
||||||
self.exit_code = exit_code
|
self.exit_code = exit_code
|
||||||
self.stderr = stderr
|
self.stderr = stderr
|
||||||
self.stdout = stdout
|
self.stdout = stdout
|
||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
self.description = description
|
self.description = description
|
||||||
if description is None:
|
if self.cmd is None:
|
||||||
description = ('Unexpected error while running command.')
|
self.cmd = '-'
|
||||||
if exit_code is None:
|
if self.description is None:
|
||||||
exit_code = '-'
|
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'
|
message = ('%(description)s\nCommand: %(cmd)s\n'
|
||||||
'Exit code: %(exit_code)s\nStdout: %(stdout)r\n'
|
'Exit code: %(exit_code)s\nStdout: %(stdout)r\n'
|
||||||
'Stderr: %(stderr)r' % locals())
|
'Stderr: %(stderr)r' % locals())
|
||||||
|
@ -143,7 +143,8 @@ def execute(*cmd, **kwargs):
|
|||||||
else:
|
else:
|
||||||
result = obj.communicate()
|
result = obj.communicate()
|
||||||
except OSError as e:
|
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
|
if (stdin_fh != subprocess.PIPE
|
||||||
and obj.stdin and close_stdin):
|
and obj.stdin and close_stdin):
|
||||||
obj.stdin.close()
|
obj.stdin.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user