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:
parent
8d4bd979d5
commit
a44befb061
@ -18,9 +18,9 @@ import copy
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from osc_lib import exceptions
|
from keystoneauth1.exceptions import base as keystoneauth_exception
|
||||||
|
|
||||||
from monascaclient import client
|
from monascaclient import client
|
||||||
|
from osc_lib import exceptions
|
||||||
|
|
||||||
from monasca_agent.common import keystone
|
from monasca_agent.common import keystone
|
||||||
|
|
||||||
@ -136,17 +136,20 @@ class MonascaAPI(object):
|
|||||||
self._post(tenant_group[tenant], tenant)
|
self._post(tenant_group[tenant], tenant)
|
||||||
|
|
||||||
def _get_mon_client(self):
|
def _get_mon_client(self):
|
||||||
k = keystone.Keystone(self._config)
|
try:
|
||||||
endpoint = k.get_monasca_url()
|
k = keystone.Keystone(self._config)
|
||||||
session = k.get_session()
|
endpoint = k.get_monasca_url()
|
||||||
c = client.Client(
|
session = k.get_session()
|
||||||
api_version=self._api_version,
|
c = client.Client(
|
||||||
endpoint=endpoint,
|
api_version=self._api_version,
|
||||||
session=session,
|
endpoint=endpoint,
|
||||||
timeout=self.write_timeout,
|
session=session,
|
||||||
**keystone.get_args(self._config)
|
timeout=self.write_timeout,
|
||||||
)
|
**keystone.get_args(self._config)
|
||||||
return c
|
)
|
||||||
|
return c
|
||||||
|
except keystoneauth_exception.ClientException as ex:
|
||||||
|
log.error('Failed to initialize Monasca client. {}'.format(ex))
|
||||||
|
|
||||||
def _send_message(self, **kwargs):
|
def _send_message(self, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user