IBP: improve exception handling in fuel-agent
This patch resolves the issue with exception's message carrying and adds very high level try/except clause to fuel-agent entrypoint. Closes-Bug: #1422448 Change-Id: Ie0d326b3b5db4ce05e688a63b817971b4fd77080
This commit is contained in:
parent
bb88701347
commit
dcbd01e55a
@ -16,6 +16,7 @@ import json
|
||||
import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
||||
from fuel_agent import manager as manager
|
||||
from fuel_agent.openstack.common import log
|
||||
@ -31,6 +32,10 @@ opts = [
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(opts)
|
||||
CONF(sys.argv[1:], project='fuel-agent',
|
||||
version=version.version_info.release_string())
|
||||
log.setup('fuel-agent')
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def provision():
|
||||
@ -53,18 +58,29 @@ def bootloader():
|
||||
main(['do_parsing', 'do_bootloader'])
|
||||
|
||||
|
||||
def print_err(line):
|
||||
sys.stderr.write(six.text_type(line))
|
||||
sys.stderr.write('\n')
|
||||
|
||||
|
||||
def handle_exception(exc):
|
||||
LOG.exception(exc)
|
||||
print_err('Unexpected error')
|
||||
print_err(exc)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def main(actions=None):
|
||||
CONF(sys.argv[1:], project='fuel-agent',
|
||||
version=version.version_info.release_string())
|
||||
log.setup('fuel-agent')
|
||||
try:
|
||||
with open(CONF.provision_data_file) as f:
|
||||
data = json.load(f)
|
||||
|
||||
with open(CONF.provision_data_file) as f:
|
||||
data = json.load(f)
|
||||
|
||||
mgr = manager.Manager(data)
|
||||
if actions:
|
||||
for action in actions:
|
||||
getattr(mgr, action)()
|
||||
mgr = manager.Manager(data)
|
||||
if actions:
|
||||
for action in actions:
|
||||
getattr(mgr, action)()
|
||||
except Exception as exc:
|
||||
handle_exception(exc)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -15,6 +15,9 @@
|
||||
import jsonschema
|
||||
|
||||
from fuel_agent import errors
|
||||
from fuel_agent.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
KS_SPACES_SCHEMA = {
|
||||
@ -128,6 +131,7 @@ def validate(scheme):
|
||||
jsonschema.validate(scheme, KS_SPACES_SCHEMA,
|
||||
format_checker=checker)
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
raise errors.WrongPartitionSchemeError(str(exc))
|
||||
|
||||
# scheme is not valid if the number of disks is 0
|
||||
|
@ -12,15 +12,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from fuel_agent.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BaseError(Exception):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BaseException, self).__init__(*args, **kwargs)
|
||||
LOG.error(self.message)
|
||||
def __init__(self, message, *args, **kwargs):
|
||||
self.message = message
|
||||
super(BaseError, self).__init__(message, *args, **kwargs)
|
||||
|
||||
|
||||
class WrongPartitionSchemeError(BaseError):
|
||||
@ -103,7 +99,7 @@ class TemplateWriteError(BaseError):
|
||||
pass
|
||||
|
||||
|
||||
class ProcessExecutionError(Exception):
|
||||
class ProcessExecutionError(BaseError):
|
||||
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
|
||||
description=None):
|
||||
self.exit_code = exit_code
|
||||
|
@ -61,7 +61,8 @@ def mddisplay(names=None):
|
||||
output = utils.execute('mdadm', '--detail', mdname,
|
||||
check_exit_code=[0])[0]
|
||||
md.update(mddetail_parse(output))
|
||||
except errors.ProcessExecutionError:
|
||||
except errors.ProcessExecutionError as exc:
|
||||
LOG.debug(exc)
|
||||
continue
|
||||
finally:
|
||||
mds.append(md)
|
||||
|
Loading…
Reference in New Issue
Block a user