diff options
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py')
-rw-r--r-- | components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py b/components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py index 9c282ab7..295fc379 100644 --- a/components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py +++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_config.py @@ -1,5 +1,5 @@ # ============LICENSE_START=================================================== -# Copyright (C) 2021 Nordix Foundation. +# Copyright (C) 2021-2022 Nordix Foundation. # ============================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,8 +28,7 @@ from onap_dcae_cbs_docker_client.client import get_all from requests.auth import HTTPBasicAuth from tenacity import wait_fixed, stop_after_attempt, retry, retry_if_exception_type -from mod import logger -from mod.pmsh_utils import mdc_handler +from mod import logger, mdc_handler @unique @@ -67,8 +66,6 @@ class AppConfig(metaclass=MetaSingleton): self.aaf_pass = app_config['config'].get('aaf_password') self.streams_publishes = app_config['config'].get('streams_publishes') self.streams_subscribes = app_config['config'].get('streams_subscribes') - # TODO: aaf_creds variable should be removed on code cleanup - self.aaf_creds = {'aaf_id': self.aaf_id, 'aaf_pass': self.aaf_pass} @staticmethod def get_instance(): @@ -94,7 +91,7 @@ class AppConfig(metaclass=MetaSingleton): return config except Exception as e: logger.error(f'Failed to get config from CBS: {e}', exc_info=True) - raise ValueError(e) + raise ValueError(e) from e @mdc_handler def publish_to_topic(self, mr_topic, event_json, **kwargs): @@ -104,22 +101,16 @@ class AppConfig(metaclass=MetaSingleton): Args: mr_topic (enum) : Message Router topic to publish. event_json (dict): the json data to be published. - - Raises: - Exception: if post request fails. """ - try: - session = requests.Session() - topic_url = self.streams_publishes[mr_topic].get('dmaap_info').get('topic_url') - headers = {'content-type': 'application/json', 'x-transactionid': kwargs['request_id'], - 'InvocationID': kwargs['invocation_id'], 'RequestID': kwargs['request_id']} - logger.info(f'Publishing event to MR topic: {topic_url}') - response = session.post(topic_url, headers=headers, - auth=HTTPBasicAuth(self.aaf_id, self.aaf_pass), json=event_json, - verify=(self.ca_cert_path if self.enable_tls else False)) - response.raise_for_status() - except Exception as e: - raise e + session = requests.Session() + topic_url = self.streams_publishes[mr_topic].get('dmaap_info').get('topic_url') + headers = {'content-type': 'application/json', 'x-transactionid': kwargs['request_id'], + 'InvocationID': kwargs['invocation_id'], 'RequestID': kwargs['request_id']} + logger.info(f'Publishing event to MR topic: {topic_url}') + response = session.post(topic_url, headers=headers, + auth=HTTPBasicAuth(self.aaf_id, self.aaf_pass), json=event_json, + verify=(self.ca_cert_path if self.enable_tls else False)) + response.raise_for_status() @mdc_handler def get_from_topic(self, mr_topic, consumer_id, consumer_group='dcae_pmsh_cg', timeout=5000, @@ -149,7 +140,6 @@ class AppConfig(metaclass=MetaSingleton): verify=(self.ca_cert_path if self.enable_tls else False)) if response.status_code == 503: logger.error(f'MR Service is unavailable at present: {response.content}') - pass response.raise_for_status() if response.ok: return response.json() |