Log errors with raised exceptions
Fix return codes not raising errors. Log errors before raising exception. Add traceback for DeploymentErrors. Complements Iba8c7e63b52acc41964ff099efc7fa181185bad7 and I82144af35f5f9cd57ef794cc58c33b0ab15b02b2 Change-Id: Iad9de7fab0ee740bd20f8facd49f36e6f18d2fb1 Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
This commit is contained in:
parent
88462e4b2c
commit
0e1a99ebaf
@ -13,6 +13,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
"""Exception definitions"""
|
"""Exception definitions"""
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +37,9 @@ class NotFound(Exception):
|
|||||||
|
|
||||||
class DeploymentError(RuntimeError):
|
class DeploymentError(RuntimeError):
|
||||||
"""Deployment failed"""
|
"""Deployment failed"""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
traceback.format_exception(*sys.exc_info())
|
||||||
|
super(RuntimeError, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PlanEnvWorkflowError(RuntimeError):
|
class PlanEnvWorkflowError(RuntimeError):
|
||||||
|
@ -25,7 +25,6 @@ import six
|
|||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
import traceback
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from cliff import command
|
from cliff import command
|
||||||
@ -114,8 +113,9 @@ class Deploy(command.Command):
|
|||||||
filter=remove_output_dir)
|
filter=remove_output_dir)
|
||||||
tf.close()
|
tf.close()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.log.error("Unable to create artifact tarball, %s"
|
msg = _("Unable to create artifact tarball, %s") % ex.message
|
||||||
% ex.message)
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
return tar_filename
|
return tar_filename
|
||||||
|
|
||||||
def _create_working_dirs(self):
|
def _create_working_dirs(self):
|
||||||
@ -317,9 +317,11 @@ class Deploy(command.Command):
|
|||||||
uid = pwd.getpwnam(parsed_args.heat_user).pw_uid
|
uid = pwd.getpwnam(parsed_args.heat_user).pw_uid
|
||||||
gid = pwd.getpwnam(parsed_args.heat_user).pw_gid
|
gid = pwd.getpwnam(parsed_args.heat_user).pw_gid
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.DeploymentError(
|
msg = _(
|
||||||
"Please create a %s user account before "
|
"Please create a %s user account before "
|
||||||
"proceeding." % parsed_args.heat_user)
|
"proceeding.") % parsed_args.heat_user
|
||||||
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
os.setgid(gid)
|
os.setgid(gid)
|
||||||
os.setuid(uid)
|
os.setuid(uid)
|
||||||
self.heat_launch.heat_db_sync()
|
self.heat_launch.heat_db_sync()
|
||||||
@ -361,7 +363,9 @@ class Deploy(command.Command):
|
|||||||
parsed_args.roles_file, '--output-dir', self.tht_render]
|
parsed_args.roles_file, '--output-dir', self.tht_render]
|
||||||
if utils.run_command_and_log(self.log, args, cwd=self.tht_render) != 0:
|
if utils.run_command_and_log(self.log, args, cwd=self.tht_render) != 0:
|
||||||
# TODO(aschultz): improve error messaging
|
# TODO(aschultz): improve error messaging
|
||||||
raise exceptions.DeploymentError("Problems generating templates.")
|
msg = _("Problems generating templates.")
|
||||||
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
|
|
||||||
self.log.info("Deploying templates in the directory {0}".format(
|
self.log.info("Deploying templates in the directory {0}".format(
|
||||||
os.path.abspath(self.tht_render)))
|
os.path.abspath(self.tht_render)))
|
||||||
@ -698,9 +702,10 @@ class Deploy(command.Command):
|
|||||||
|
|
||||||
def _standalone_deploy(self, parsed_args):
|
def _standalone_deploy(self, parsed_args):
|
||||||
if not parsed_args.local_ip:
|
if not parsed_args.local_ip:
|
||||||
self.log.error('Please set --local-ip to the correct '
|
msg = _('Please set --local-ip to the correct '
|
||||||
'ipaddress/cidr for this machine.')
|
'ipaddress/cidr for this machine.')
|
||||||
return
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
|
|
||||||
if not os.environ.get('HEAT_API_PORT'):
|
if not os.environ.get('HEAT_API_PORT'):
|
||||||
os.environ['HEAT_API_PORT'] = parsed_args.heat_api_port
|
os.environ['HEAT_API_PORT'] = parsed_args.heat_api_port
|
||||||
@ -709,7 +714,9 @@ class Deploy(command.Command):
|
|||||||
# processes below. Only the heat deploy/os-collect-config forked
|
# processes below. Only the heat deploy/os-collect-config forked
|
||||||
# process runs as root.
|
# process runs as root.
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
raise exceptions.DeploymentError("Please run as root.")
|
msg = _("Please run as root.")
|
||||||
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
|
|
||||||
# prepare working spaces
|
# prepare working spaces
|
||||||
self.output_dir = os.path.abspath(parsed_args.output_dir)
|
self.output_dir = os.path.abspath(parsed_args.output_dir)
|
||||||
@ -732,7 +739,9 @@ class Deploy(command.Command):
|
|||||||
status, msg = event_utils.poll_for_events(
|
status, msg = event_utils.poll_for_events(
|
||||||
orchestration_client, stack_id, nested_depth=6)
|
orchestration_client, stack_id, nested_depth=6)
|
||||||
if status != "CREATE_COMPLETE":
|
if status != "CREATE_COMPLETE":
|
||||||
raise Exception("Stack create failed; %s" % msg)
|
message = _("Stack create failed; %s") % msg
|
||||||
|
self.log.error(message)
|
||||||
|
raise exceptions.DeploymentError(message)
|
||||||
|
|
||||||
# download the ansible playbooks and execute them.
|
# download the ansible playbooks and execute them.
|
||||||
ansible_dir = \
|
ansible_dir = \
|
||||||
@ -747,8 +756,7 @@ class Deploy(command.Command):
|
|||||||
rc = self._launch_ansible_deploy(ansible_dir)
|
rc = self._launch_ansible_deploy(ansible_dir)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error("Exception: %s" % e)
|
self.log.error("Exception: %s" % e)
|
||||||
self.log.error(traceback.format_exception(*sys.exc_info()))
|
raise exceptions.DeploymentError(e.message)
|
||||||
raise
|
|
||||||
finally:
|
finally:
|
||||||
self._kill_heat(parsed_args)
|
self._kill_heat(parsed_args)
|
||||||
tar_filename = self._create_install_artifact()
|
tar_filename = self._create_install_artifact()
|
||||||
@ -761,6 +769,7 @@ class Deploy(command.Command):
|
|||||||
self.log.error(DEPLOY_FAILURE_MESSAGE.format(
|
self.log.error(DEPLOY_FAILURE_MESSAGE.format(
|
||||||
self.heat_launch.install_tmp
|
self.heat_launch.install_tmp
|
||||||
))
|
))
|
||||||
|
raise exceptions.DeploymentError('Deployment failed.')
|
||||||
else:
|
else:
|
||||||
self.log.warning(DEPLOY_COMPLETION_MESSAGE.format(
|
self.log.warning(DEPLOY_COMPLETION_MESSAGE.format(
|
||||||
'~/undercloud-passwords.conf',
|
'~/undercloud-passwords.conf',
|
||||||
@ -773,7 +782,10 @@ class Deploy(command.Command):
|
|||||||
|
|
||||||
if parsed_args.standalone:
|
if parsed_args.standalone:
|
||||||
if self._standalone_deploy(parsed_args) != 0:
|
if self._standalone_deploy(parsed_args) != 0:
|
||||||
raise exceptions.DeploymentError('Deployment failed.')
|
msg = _('Deployment failed.')
|
||||||
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
else:
|
else:
|
||||||
raise exceptions.DeploymentError('Non-standalone is currently not '
|
msg = _('Non-standalone is currently not supported')
|
||||||
'supported')
|
self.log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
|
@ -28,6 +28,7 @@ from cryptography import x509
|
|||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
|
|
||||||
|
from osc_lib.i18n import _
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from tripleo_common.image import kolla_builder
|
from tripleo_common.image import kolla_builder
|
||||||
|
|
||||||
@ -523,7 +524,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=False,
|
|||||||
if 'network_config' not in net_config_json:
|
if 'network_config' not in net_config_json:
|
||||||
msg = ('Unsupported data format in net_config_override '
|
msg = ('Unsupported data format in net_config_override '
|
||||||
'file %s: %s' % (data_file, net_config_str))
|
'file %s: %s' % (data_file, net_config_str))
|
||||||
LOG(msg)
|
LOG.error(msg)
|
||||||
raise exceptions.DeploymentError(msg)
|
raise exceptions.DeploymentError(msg)
|
||||||
|
|
||||||
env_data['UndercloudNetConfigOverride'] = net_config_json
|
env_data['UndercloudNetConfigOverride'] = net_config_json
|
||||||
@ -594,8 +595,10 @@ def _get_public_tls_resource_registry_overwrites(enable_tls_yaml_path):
|
|||||||
try:
|
try:
|
||||||
return enable_tls_dict['resource_registry']
|
return enable_tls_dict['resource_registry']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise RuntimeError('%s is malformed and is missing the resource '
|
msg = _('%s is malformed and is missing the resource '
|
||||||
'registry.' % enable_tls_yaml_path)
|
'registry.') % enable_tls_yaml_path
|
||||||
|
LOG.error(msg)
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
|
||||||
def _container_images_config(conf, deploy_args, env_data):
|
def _container_images_config(conf, deploy_args, env_data):
|
||||||
|
@ -312,6 +312,7 @@ def _validate_no_overlap(subnet_props):
|
|||||||
(subnet_props.inspection_iprange.split(',')[0],
|
(subnet_props.inspection_iprange.split(',')[0],
|
||||||
subnet_props.inspection_iprange.split(',')[1],
|
subnet_props.inspection_iprange.split(',')[1],
|
||||||
subnet_props.dhcp_start, subnet_props.dhcp_end))
|
subnet_props.dhcp_start, subnet_props.dhcp_end))
|
||||||
|
LOG.error(message)
|
||||||
raise FailedValidation(message)
|
raise FailedValidation(message)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user