diff --git a/vitrage/api/controllers/v1/alarm.py b/vitrage/api/controllers/v1/alarm.py index 2f258ed04..fa3c770b6 100755 --- a/vitrage/api/controllers/v1/alarm.py +++ b/vitrage/api/controllers/v1/alarm.py @@ -18,7 +18,6 @@ import pecan from oslo_log import log -from oslo_utils import encodeutils from oslo_utils.strutils import bool_from_string from osprofiler import profiler from pecan.core import abort @@ -33,6 +32,7 @@ from vitrage.common.constants import VertexProperties as Vprops LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("alarm controller", info={}, hide_args=False, trace_private=False) class AlarmsController(RootRestController): @@ -54,10 +54,9 @@ class AlarmsController(RootRestController): try: return self._get_alarms(vitrage_id, all_tenants) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to get alarms.') - abort(404, to_unicode) + abort(404, 'Failed to get alarms.') @staticmethod def _get_alarms(vitrage_id=None, all_tenants=False): @@ -71,10 +70,9 @@ class AlarmsController(RootRestController): alarms_list = json.loads(alarms_json)['alarms'] return alarms_list - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to open file.') - abort(404, to_unicode) + abort(404, 'Failed to get alarms') @pecan.expose('json') def get(self, vitrage_id): @@ -87,10 +85,9 @@ class AlarmsController(RootRestController): try: return self._show_alarm(vitrage_id) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to load JSON.') - abort(404, to_unicode) + abort(404, "Failed to show alarm.") @staticmethod def _show_alarm(vitrage_id): @@ -103,7 +100,6 @@ class AlarmsController(RootRestController): alarms_list = json.loads(alarm_json) return alarms_list - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to load JSON.') - abort(404, to_unicode) + abort(404, 'Failed to show alarm.') diff --git a/vitrage/api/controllers/v1/count.py b/vitrage/api/controllers/v1/count.py index 5f95f5c41..9f74dba2f 100755 --- a/vitrage/api/controllers/v1/count.py +++ b/vitrage/api/controllers/v1/count.py @@ -14,7 +14,6 @@ import json import pecan from oslo_log import log -from oslo_utils import encodeutils from oslo_utils.strutils import bool_from_string from pecan.core import abort @@ -25,6 +24,7 @@ from vitrage.api.policy import enforce LOG = log.getLogger(__name__) +# noinspection PyBroadException class CountsController(RootRestController): @pecan.expose('json') @@ -50,7 +50,6 @@ class CountsController(RootRestController): return json.loads(alarm_counts_json) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('failed to get alarm count.') - abort(404, to_unicode) + abort(404, 'Failed to get alarm count.') diff --git a/vitrage/api/controllers/v1/event.py b/vitrage/api/controllers/v1/event.py index 055cac55d..42f5c1541 100644 --- a/vitrage/api/controllers/v1/event.py +++ b/vitrage/api/controllers/v1/event.py @@ -15,7 +15,6 @@ import pecan from oslo_log import log -from oslo_utils import encodeutils from osprofiler import profiler from pecan.core import abort @@ -26,6 +25,7 @@ from vitrage.api.policy import enforce LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("event controller", info={}, hide_args=False, trace_private=False) class EventController(RootRestController): @@ -51,7 +51,6 @@ class EventController(RootRestController): event_time=event_time, event_type=event_type, details=details) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) - LOG.exception('Failed to post an event %s', to_unicode) - abort(404, to_unicode) + except Exception: + LOG.exception('Failed to post an event') + abort(404, 'Failed to post event') diff --git a/vitrage/api/controllers/v1/rca.py b/vitrage/api/controllers/v1/rca.py index efe192de4..1a528e8bc 100644 --- a/vitrage/api/controllers/v1/rca.py +++ b/vitrage/api/controllers/v1/rca.py @@ -17,7 +17,6 @@ import json import pecan from oslo_log import log -from oslo_utils import encodeutils from oslo_utils.strutils import bool_from_string from osprofiler import profiler from pecan.core import abort @@ -28,6 +27,7 @@ from vitrage.api.policy import enforce LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("rca controller", info={}, hide_args=False, trace_private=False) class RCAController(RootRestController): @@ -59,7 +59,6 @@ class RCAController(RootRestController): graph = json.loads(graph_data) return graph - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to get RCA.') - abort(404, to_unicode) + abort(404, 'Failed to get RCA') diff --git a/vitrage/api/controllers/v1/resource.py b/vitrage/api/controllers/v1/resource.py index 0a1fff5ba..87110b219 100644 --- a/vitrage/api/controllers/v1/resource.py +++ b/vitrage/api/controllers/v1/resource.py @@ -13,7 +13,6 @@ import json import pecan from oslo_log import log -from oslo_utils import encodeutils from oslo_utils.strutils import bool_from_string from osprofiler import profiler from pecan.core import abort @@ -25,6 +24,7 @@ from vitrage.api.policy import enforce LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("resource controller", info={}, hide_args=False, trace_private=False) class ResourcesController(RootRestController): @@ -46,10 +46,9 @@ class ResourcesController(RootRestController): try: return self._get_resources(resource_type, all_tenants) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to list resources.') - abort(404, to_unicode) + abort(404, 'Failed to list resources.') @staticmethod def _get_resources(resource_type=None, all_tenants=False): @@ -64,10 +63,9 @@ class ResourcesController(RootRestController): LOG.info(resources_json) resources = json.loads(resources_json)['resources'] return resources - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to get resources.') - abort(404, to_unicode) + abort(404, 'Failed to list resources.') @pecan.expose('json') def get(self, vitrage_id): @@ -94,8 +92,7 @@ class ResourcesController(RootRestController): LOG.debug('resource found = %s', resource) return json.loads(resource) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('failed to show resource with vitrage_id(%s).', vitrage_id) - abort(404, to_unicode) + abort(404, 'Failed to show resource.') diff --git a/vitrage/api/controllers/v1/template.py b/vitrage/api/controllers/v1/template.py index db2e899ae..0ad94fb42 100644 --- a/vitrage/api/controllers/v1/template.py +++ b/vitrage/api/controllers/v1/template.py @@ -15,7 +15,6 @@ import json import pecan from oslo_log import log -from oslo_utils import encodeutils from osprofiler import profiler from pecan.core import abort @@ -27,6 +26,7 @@ from vitrage.common.exception import VitrageError LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("template controller", info={}, hide_args=False, trace_private=False) class TemplateController(RootRestController): @@ -42,10 +42,9 @@ class TemplateController(RootRestController): {}) try: return self._get_templates() - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('failed to get template list.') - abort(404, to_unicode) + abort(404, 'Failed to get template list') @pecan.expose('json') def get(self, template_uuid): @@ -59,11 +58,10 @@ class TemplateController(RootRestController): try: return self._show_template(template_uuid) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to show template %s.', template_uuid) - abort(404, to_unicode) + abort(404, 'Failed to show template.') @pecan.expose('json') def delete(self, **kwargs): @@ -76,9 +74,9 @@ class TemplateController(RootRestController): {}) try: return self._delete(uuid) - except Exception as e: + except Exception: LOG.exception('Failed to delete template.') - abort(404, str(e)) + abort(404, 'Failed to delete template.') @pecan.expose('json') def put(self, **kwargs): @@ -93,9 +91,9 @@ class TemplateController(RootRestController): try: return self._add(templates, template_type) - except Exception as e: + except Exception: LOG.exception('Failed to add template.') - abort(404, str(e)) + abort(404, 'Failed to add template.') @pecan.expose('json') def post(self, **kwargs): @@ -112,10 +110,9 @@ class TemplateController(RootRestController): try: return self._validate(templates, template_type) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to validate template(s).') - abort(404, to_unicode) + abort(404, 'Failed to validate template.') @classmethod def _get_templates(cls): @@ -124,10 +121,9 @@ class TemplateController(RootRestController): templates = [t for t in templates if t.status != TStatus.DELETED] templates.sort(key=lambda template: template.created_at) return [cls._db_template_to_dict(t) for t in templates] - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to get template list.') - abort(404, to_unicode) + abort(404, 'Failed to get template list.') @staticmethod def _show_template(uuid): @@ -136,10 +132,9 @@ class TemplateController(RootRestController): if not templates: raise VitrageError("Template %s not found", uuid) return templates[0].file_content - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to show template with uuid: %s ', uuid) - abort(404, to_unicode) + abort(404, 'Failed to show template.') @staticmethod def _validate(templates, template_type): @@ -150,10 +145,9 @@ class TemplateController(RootRestController): template_type=template_type) try: return json.loads(result_json) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('Failed to open template file(s).') - abort(404, to_unicode) + abort(404, 'Failed to validate template file.') @classmethod def _add(cls, templates, template_type): @@ -164,9 +158,9 @@ class TemplateController(RootRestController): templates=templates, template_type=template_type) return results - except Exception as e: + except Exception: LOG.exception('Failed to add template file.') - abort(404, str(e)) + abort(404, 'Failed to add template file.') @staticmethod def _db_template_to_dict(template): @@ -187,6 +181,6 @@ class TemplateController(RootRestController): 'delete_template', uuids=uuid) return results - except Exception as e: + except Exception: LOG.exception('Failed to delete template.') - abort(404, str(e)) + abort(404, 'Failed to delete template.') diff --git a/vitrage/api/controllers/v1/topology.py b/vitrage/api/controllers/v1/topology.py index 705ef28c3..cacaae36a 100644 --- a/vitrage/api/controllers/v1/topology.py +++ b/vitrage/api/controllers/v1/topology.py @@ -16,7 +16,6 @@ import json from oslo_log import log -from oslo_utils import encodeutils from oslo_utils.strutils import bool_from_string from osprofiler import profiler import pecan @@ -33,6 +32,7 @@ from vitrage.datasources.transformer_base import CLUSTER_ID LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("topology controller", info={}, hide_args=False, trace_private=False) class TopologyController(RootRestController): @@ -89,10 +89,9 @@ class TopologyController(RootRestController): break return RootRestController.as_tree(graph, node_id) - except Exception as e: - to_unicode = encodeutils.exception_to_unicode(e) + except Exception: LOG.exception('failed to get topology.') - abort(404, to_unicode) + abort(404, 'Failed to get topology.') @staticmethod def _check_input_para(graph_type, depth, query, root, all_tenants): diff --git a/vitrage/api/controllers/v1/webhook.py b/vitrage/api/controllers/v1/webhook.py index 48c66ab64..6f1bcc9c5 100644 --- a/vitrage/api/controllers/v1/webhook.py +++ b/vitrage/api/controllers/v1/webhook.py @@ -25,6 +25,7 @@ from vitrage.common.constants import TenantProps LOG = log.getLogger(__name__) +# noinspection PyBroadException @profiler.trace_cls("webhook controller", info={}, hide_args=False, trace_private=False) class WebhookController(RootRestController): @@ -45,9 +46,9 @@ class WebhookController(RootRestController): try: return self._get_all(all_tenants) - except Exception as e: + except Exception: LOG.exception('Failed to list webhooks.') - abort(404, str(e)) + abort(404, 'Failed to list webhooks.') @staticmethod def _get_all(all_tenants): @@ -67,9 +68,9 @@ class WebhookController(RootRestController): try: return self._get(id) - except Exception as e: - LOG.exception('Failed to get webhooks.') - abort(404, str(e)) + except Exception: + LOG.exception('Failed to get webhook.') + abort(404, 'Failed to get webhook.') @staticmethod def _get(id): @@ -90,9 +91,9 @@ class WebhookController(RootRestController): pecan.request.enforcer, {}) try: return self._post(**kwargs) - except Exception as e: + except Exception: LOG.exception('Failed to add webhooks.') - abort(400, str(e)) + abort(400, 'Failed to add webhooks.') @staticmethod def _post(**kwargs): @@ -124,9 +125,9 @@ class WebhookController(RootRestController): try: return self._delete_registration(id) - except Exception as e: + except Exception: LOG.exception('Failed to delete webhook "%s"', id) - abort(404, str(e)) + abort(404, 'Failed to delete webhook.') @staticmethod def _delete_registration(id):