Improve error handling in method that creates Monasca client

Add error handler that prevent crash of forwarded
when agent is not able to connect to keystone

Story: 2007674
Task: 39781
Change-Id: If6366e5b94f9cbe3f21ce9dbeb26d28e3a36ae88
This commit is contained in:
Adrian Czarnecki 2020-04-28 13:46:40 -07:00
parent 8d4bd979d5
commit a44befb061

View File

@ -18,9 +18,9 @@ import copy
import json
import logging
from osc_lib import exceptions
from keystoneauth1.exceptions import base as keystoneauth_exception
from monascaclient import client
from osc_lib import exceptions
from monasca_agent.common import keystone
@ -136,6 +136,7 @@ class MonascaAPI(object):
self._post(tenant_group[tenant], tenant)
def _get_mon_client(self):
try:
k = keystone.Keystone(self._config)
endpoint = k.get_monasca_url()
session = k.get_session()
@ -147,6 +148,8 @@ class MonascaAPI(object):
**keystone.get_args(self._config)
)
return c
except keystoneauth_exception.ClientException as ex:
log.error('Failed to initialize Monasca client. {}'.format(ex))
def _send_message(self, **kwargs):
try: