diff options
author | efiacor <fiachra.corcoran@est.tech> | 2020-06-22 18:51:43 +0100 |
---|---|---|
committer | efiacor <fiachra.corcoran@est.tech> | 2020-07-06 09:07:37 +0100 |
commit | 0464347539f931847ab578ff935994aef0102352 (patch) | |
tree | 601971765ec6b363b6755984e437c02bea3c83ec | |
parent | b80449b81a2deb3b6e2510a655de02f9375ef636 (diff) |
[PMSH] Add enable_tls boolean flag to config1.1.0
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: I19f71b690f743980eaa149c9b2c76fecb98a0120
Issue-ID: DCAEGEN2-2146
19 files changed, 155 insertions, 190 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/__init__.py index efc61aae..4c86ccda 100644 --- a/components/pm-subscription-handler/pmsh_service/mod/__init__.py +++ b/components/pm-subscription-handler/pmsh_service/mod/__init__.py @@ -42,8 +42,11 @@ def _get_app(): def launch_api_server(app_config): connex_app = _get_app() connex_app.add_api('api/pmsh_swagger.yml') - connex_app.run(port=os.environ.get('PMSH_API_PORT', '8443'), - ssl_context=(app_config.cert_path, app_config.key_path)) + if app_config.enable_tls: + connex_app.run(port=os.environ.get('PMSH_API_PORT', '8443'), + ssl_context=app_config.cert_params) + else: + connex_app.run(port=os.environ.get('PMSH_API_PORT', '8443')) def create_app(): diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py index 2b92df41..bd052741 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py @@ -61,15 +61,14 @@ def _get_all_aai_nf_data(app_conf, **kwargs): nf_data = None try: session = requests.Session() - aai_endpoint = f'{_get_aai_service_url()}{"/aai/v16/query"}' + aai_endpoint = f'{_get_aai_service_url()}{"/aai/v19/query"}' logger.info('Fetching XNFs from AAI.') headers = {'accept': 'application/json', 'content-type': 'application/json', 'x-fromappid': 'dcae-pmsh', 'x-transactionid': kwargs['request_id'], 'InvocationID': kwargs['invocation_id'], - 'RequestID': kwargs['request_id'] - } + 'RequestID': kwargs['request_id']} json_data = """ {'start': ['network/pnfs', @@ -79,14 +78,16 @@ def _get_all_aai_nf_data(app_conf, **kwargs): response = session.put(aai_endpoint, headers=headers, auth=HTTPBasicAuth(app_conf.aaf_creds.get('aaf_id'), app_conf.aaf_creds.get('aaf_pass')), - data=json_data, params=params, verify=False) + data=json_data, params=params, + verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), + cert=(app_conf.cert_params if app_conf.enable_tls else None)) response.raise_for_status() if response.ok: nf_data = json.loads(response.text) logger.info('Successfully fetched XNFs from AAI') logger.debug(f'XNFs from AAI: {nf_data}') except Exception as e: - logger.error(f'Failed to get XNFs from AAI: {e}') + logger.error(f'Failed to get XNFs from AAI: {e}', exc_info=True) return nf_data @@ -98,14 +99,13 @@ def _get_aai_service_url(): str: the AAI k8s service URL. Raises: - KeyError: if AAI env vars not found. + KeyError: if AAI env var not found. """ try: - aai_service = environ['AAI_SERVICE_HOST'] aai_ssl_port = environ['AAI_SERVICE_PORT'] - return f'https://{aai_service}:{aai_ssl_port}' + return f'https://aai:{aai_ssl_port}' except KeyError as e: - logger.error(f'Failed to get AAI env vars: {e}') + logger.error(f'Failed to get AAI env var: {e}', exc_info=True) raise @@ -134,6 +134,6 @@ def _filter_nf_data(nf_data, nf_filter): nf_name=nf['properties'].get(name_identifier), orchestration_status=orchestration_status)) except KeyError as e: - logger.error(f'Failed to parse AAI data: {e}') + logger.error(f'Failed to parse AAI data: {e}', exc_info=True) raise return nf_set diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py index b3957bc5..f1e8cf27 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py @@ -19,8 +19,6 @@ import json from enum import Enum -from requests import HTTPError - from mod import logger from mod.network_function import NetworkFunction @@ -46,26 +44,26 @@ def process_aai_events(mr_sub, mr_pub, app, app_conf): app_conf (AppConfig): the application configuration. """ app.app_context().push() + logger.info('Polling MR for XNF AAI events.') try: - aai_events = mr_sub.get_from_topic('AAI-EVENT') - if len(aai_events) != 0: - for entry in aai_events: + aai_events = mr_sub.get_from_topic('dcae_pmsh_aai_event') + if aai_events is not None and len(aai_events) != 0: + aai_events = [json.loads(e) for e in aai_events] + xnf_events = [e for e in aai_events if e['event-header']['entity-type'] == ( + XNFType.PNF.value or XNFType.VNF.value)] + for entry in xnf_events: logger.debug(f'AAI-EVENT entry: {entry}') - entry = json.loads(entry) - event_header = entry['event-header'] - aai_xnf = entry['entity'] - action = event_header['action'] - entity_type = event_header['entity-type'] - xnf_name = aai_xnf['pnf-name'] if entity_type == XNFType.PNF.value else aai_xnf[ - 'vnf-name'] - new_status = aai_xnf['orchestration-status'] + aai_entity = entry['entity'] + action = entry['event-header']['action'] + entity_type = entry['event-header']['entity-type'] + xnf_name = aai_entity['pnf-name'] if entity_type == XNFType.PNF.value \ + else aai_entity['vnf-name'] + new_status = aai_entity['orchestration-status'] if app_conf.nf_filter.is_nf_in_filter(xnf_name, new_status): _process_event(action, new_status, xnf_name, mr_pub, app_conf) - except HTTPError as e: - logger.debug(f'Failed to fetch AAI-EVENT messages from MR {e}') except Exception as e: - logger.debug(f'Exception trying to process AAI events {e}') + logger.error(f'Failed to process AAI event: {e}', exc_info=True) def _process_event(action, new_status, xnf_name, mr_pub, app_conf): diff --git a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py index 01cb8dc3..3d02375d 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py @@ -39,11 +39,14 @@ class ExitHandler: logger.debug(f'ExitHandler was called with signal number: {sig_num}.') current_sub = self.subscription_handler.current_sub if current_sub and current_sub.administrativeState == AdministrativeState.UNLOCKED.value: - for thread in self.periodic_tasks: - logger.debug(f'Cancelling periodic task with thread name: {thread.name}.') - thread.cancel() - current_sub.administrativeState = AdministrativeState.LOCKED.value - current_sub.process_subscription(current_sub.get_network_functions(), - self.subscription_handler.mr_pub, - self.subscription_handler.app_conf) + try: + for thread in self.periodic_tasks: + logger.debug(f'Cancelling periodic task with thread name: {thread.name}.') + thread.cancel() + current_sub.administrativeState = AdministrativeState.LOCKED.value + current_sub.process_subscription(current_sub.get_network_functions(), + self.subscription_handler.mr_pub, + self.subscription_handler.app_conf) + except Exception as e: + logger.error(f'Failed to shut down PMSH application: {e}', exc_info=True) ExitHandler.shutdown_signal_received = True diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py index 354d6b8d..50eb122b 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py +++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py @@ -67,6 +67,8 @@ class AppConfig(metaclass=ThreadSafeSingleton): raise self.aaf_creds = {'aaf_id': conf['config'].get('aaf_identity'), 'aaf_pass': conf['config'].get('aaf_password')} + self.enable_tls = conf['config'].get('enable_tls') + self.ca_cert_path = conf['config'].get('ca_cert_path') self.cert_path = conf['config'].get('cert_path') self.key_path = conf['config'].get('key_path') self.streams_subscribes = conf['config'].get('streams_subscribes') @@ -77,7 +79,7 @@ class AppConfig(metaclass=ThreadSafeSingleton): self.nf_filter = NetworkFunctionFilter(**self.subscription.nfFilter) @mdc_handler - @retry(wait=wait_fixed(2), stop=stop_after_attempt(5), retry=retry_if_exception_type(Exception)) + @retry(wait=wait_fixed(5), stop=stop_after_attempt(5), retry=retry_if_exception_type(Exception)) def _get_pmsh_config(self, **kwargs): """ Retrieves PMSH's configuration from Config binding service. If a non-2xx response is received, it retries after 2 seconds for 5 times before raising an exception. @@ -94,7 +96,7 @@ class AppConfig(metaclass=ThreadSafeSingleton): logger.info(f'Successfully fetched PMSH config from CBS: {config}') return config except Exception as err: - logger.error(f'Failed to get config from CBS: {err}') + logger.error(f'Failed to get config from CBS: {err}', exc_info=True) raise Exception def refresh_config(self): @@ -106,14 +108,16 @@ class AppConfig(metaclass=ThreadSafeSingleton): """ try: app_conf = self._get_pmsh_config() - except Exception: - logger.debug("Failed to refresh AppConfig data") - raise - self.subscription.administrativeState = \ - app_conf['policy']['subscription']['administrativeState'] - self.nf_filter.nf_names = app_conf['policy']['subscription']['nfFilter']['nfNames'] - self.nf_filter.nf_sw_version = app_conf['policy']['subscription']['nfFilter']['swVersions'] - logger.info("AppConfig data has been refreshed") + if "INVALID JSON" in app_conf.values(): + raise ValueError('Failed to refresh AppConfig: INVALID JSON') + self.subscription.administrativeState = app_conf['policy']['subscription'][ + 'administrativeState'] + self.nf_filter.nf_names = app_conf['policy']['subscription']['nfFilter']['nfNames'] + self.nf_filter.nf_sw_version = app_conf['policy']['subscription']['nfFilter'][ + 'swVersions'] + logger.info("AppConfig data has been refreshed") + except ValueError or Exception as e: + logger.error(e) def get_mr_sub(self, sub_name): """ @@ -129,9 +133,10 @@ class AppConfig(metaclass=ThreadSafeSingleton): KeyError: if the sub_name is not found. """ try: - return _MrSub(sub_name, self.aaf_creds, **self.streams_subscribes[sub_name]) + return _MrSub(sub_name, self.aaf_creds, self.ca_cert_path, + self.enable_tls, self.cert_params, **self.streams_subscribes[sub_name]) except KeyError as e: - logger.debug(e) + logger.error(f'Failed to get MrSub {sub_name}: {e}', exc_info=True) raise def get_mr_pub(self, pub_name): @@ -148,9 +153,10 @@ class AppConfig(metaclass=ThreadSafeSingleton): KeyError: if the sub_name is not found. """ try: - return _MrPub(pub_name, self.aaf_creds, **self.streams_publishes[pub_name]) + return _MrPub(pub_name, self.aaf_creds, self.ca_cert_path, + self.enable_tls, self.cert_params, **self.streams_publishes[pub_name]) except KeyError as e: - logger.debug(e) + logger.error(f'Failed to get MrPub {pub_name}: {e}', exc_info=True) raise @property @@ -159,29 +165,35 @@ class AppConfig(metaclass=ThreadSafeSingleton): Returns the tls artifact paths. Returns: - cert_path, key_path: the path to tls cert and key. + cert_path, key_path (tuple): the path to tls cert and key. """ return self.cert_path, self.key_path class _DmaapMrClient: - def __init__(self, aaf_creds, **kwargs): + def __init__(self, aaf_creds, ca_cert_path, enable_tls, cert_params, **kwargs): """ A DMaaP Message Router utility class. Sub classes should be invoked via the AppConfig.get_mr_{pub|sub} only. Args: - aaf_creds: a dict of aaf secure credentials. + aaf_creds (dict): a dict of aaf secure credentials. + ca_cert_path (str): path to the ca certificate. + enable_tls (bool): TLS if True, else False + cert_params (tuple): client side (cert, key) tuple. **kwargs: a dict of streams_{subscribes|publishes} data. """ self.topic_url = kwargs.get('dmaap_info').get('topic_url') self.aaf_id = aaf_creds.get('aaf_id') self.aaf_pass = aaf_creds.get('aaf_pass') + self.ca_cert_path = ca_cert_path + self.enable_tls = enable_tls + self.cert_params = cert_params class _MrPub(_DmaapMrClient): - def __init__(self, pub_name, aaf_creds, **kwargs): + def __init__(self, pub_name, aaf_creds, ca_cert_path, enable_tls, cert_params, **kwargs): self.pub_name = pub_name - super().__init__(aaf_creds, **kwargs) + super().__init__(aaf_creds, ca_cert_path, enable_tls, cert_params, **kwargs) @mdc_handler def publish_to_topic(self, event_json, **kwargs): @@ -189,7 +201,7 @@ class _MrPub(_DmaapMrClient): Publish the event to the DMaaP Message Router topic. Args: - event_json: the json data to be published. + event_json (dict): the json data to be published. Raises: Exception: if post request fails. @@ -200,36 +212,34 @@ class _MrPub(_DmaapMrClient): 'InvocationID': kwargs['invocation_id'], 'RequestID': kwargs['request_id'] } - logger.info(f'Attempting to publish event to {self.topic_url}') + logger.info(f'Publishing event to {self.topic_url}') response = session.post(self.topic_url, headers=headers, auth=HTTPBasicAuth(self.aaf_id, self.aaf_pass), json=event_json, - verify=False) + verify=(self.ca_cert_path if self.enable_tls else False)) response.raise_for_status() except Exception as e: - logger.error(f'Failed to publish message to MR topic: {e}') - raise + raise e def publish_subscription_event_data(self, subscription, xnf_name, app_conf): """ Update the Subscription dict with xnf and policy name then publish to DMaaP MR topic. Args: - subscription: the `Subscription` <Subscription> object. - xnf_name: the xnf to include in the event. + subscription (Subscription): the `Subscription` <Subscription> object. + xnf_name (str): the xnf to include in the event. app_conf (AppConfig): the application configuration. """ try: subscription_event = subscription.prepare_subscription_event(xnf_name, app_conf) self.publish_to_topic(subscription_event) except Exception as e: - logger.debug(f'pmsh_utils.publish_subscription_event_data : {e}') - raise + logger.error(f'Failed to publish to topic {self.topic_url}: {e}', exc_info=True) class _MrSub(_DmaapMrClient): - def __init__(self, sub_name, aaf_creds, **kwargs): + def __init__(self, sub_name, aaf_creds, ca_cert_path, enable_tls, cert_params, **kwargs): self.sub_name = sub_name - super().__init__(aaf_creds, **kwargs) + super().__init__(aaf_creds, ca_cert_path, enable_tls, cert_params, **kwargs) @mdc_handler def get_from_topic(self, consumer_id, consumer_group='dcae_pmsh_cg', timeout=1000, **kwargs): @@ -237,10 +247,10 @@ class _MrSub(_DmaapMrClient): Returns the json data from the MrTopic. Args: - consumer_id: Within your subscribers group, a name that uniquely + consumer_id (str): Within your subscribers group, a name that uniquely identifies your subscribers process. - consumer_group: A name that uniquely identifies your subscribers. - timeout: The request timeout value in mSec. + consumer_group (str): A name that uniquely identifies your subscribers. + timeout (int): The request timeout value in mSec. Returns: list[str]: the json response from DMaaP Message Router topic. @@ -250,11 +260,14 @@ class _MrSub(_DmaapMrClient): headers = {'accept': 'application/json', 'content-type': 'application/json', 'InvocationID': kwargs['invocation_id'], 'RequestID': kwargs['request_id']} - logger.debug(f'Fetching messages from MR topic: {self.topic_url}') + logger.info(f'Fetching messages from MR topic: {self.topic_url}') response = session.get(f'{self.topic_url}/{consumer_group}/{consumer_id}' f'?timeout={timeout}', auth=HTTPBasicAuth(self.aaf_id, self.aaf_pass), headers=headers, - verify=False) + 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() diff --git a/components/pm-subscription-handler/pmsh_service/mod/policy_response_handler.py b/components/pm-subscription-handler/pmsh_service/mod/policy_response_handler.py index 8a993828..73a5e7e8 100644 --- a/components/pm-subscription-handler/pmsh_service/mod/policy_response_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/policy_response_handler.py @@ -47,9 +47,9 @@ class PolicyResponseHandler: """ self.app.app_context().push() administrative_state = self.app_conf.subscription.administrativeState - logger.info('Polling MR started for XNF activation/deactivation policy response events.') + logger.info('Polling MR for XNF activation/deactivation policy response events.') try: - response_data = self.mr_sub.get_from_topic('policy_response_consumer') + response_data = self.mr_sub.get_from_topic('dcae_pmsh_policy_cl_input') for data in response_data: data = json.loads(data) if data['status']['subscriptionName'] \ @@ -59,7 +59,7 @@ class PolicyResponseHandler: self._handle_response(self.app_conf.subscription.subscriptionName, administrative_state, nf_name, response_message) except Exception as err: - logger.error(f'Error trying to poll policy response topic on MR: {err}') + logger.error(f'Error trying to poll policy response topic on MR: {err}', exc_info=True) @staticmethod def _handle_response(subscription_name, administrative_state, nf_name, response_message): diff --git a/components/pm-subscription-handler/pmsh_service/mod/subscription.py b/components/pm-subscription-handler/pmsh_service/mod/subscription.py index b623cbdf..dbcd7a5e 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/subscription.py +++ b/components/pm-subscription-handler/pmsh_service/mod/subscription.py @@ -66,13 +66,17 @@ class Subscription: Returns: dict: the Subscription event to be published. """ - clean_sub = {k: v for k, v in self.__dict__.items() if k != 'nfFilter'} - sub_event = {'nfName': xnf_name, 'policyName': app_conf.operational_policy_name, - 'changeType': 'DELETE' - if self.administrativeState == AdministrativeState.LOCKED.value - else 'CREATE', 'closedLoopControlName': app_conf.control_loop_name, - 'subscription': clean_sub} - return sub_event + try: + clean_sub = {k: v for k, v in self.__dict__.items() if k != 'nfFilter'} + sub_event = {'nfName': xnf_name, 'policyName': app_conf.operational_policy_name, + 'changeType': 'DELETE' + if self.administrativeState == AdministrativeState.LOCKED.value + else 'CREATE', 'closedLoopControlName': app_conf.control_loop_name, + 'subscription': clean_sub} + return sub_event + except Exception as e: + logger.error(f'Failed to prep Sub event for xNF {xnf_name}: {e}', exc_info=True) + raise def create(self): """ Creates a subscription database entry @@ -94,7 +98,8 @@ class Subscription: f' returning this subscription..') return existing_subscription except Exception as e: - logger.debug(f'Failed to create subscription {self.subscriptionName} in the DB: {e}') + logger.error(f'Failed to create subscription {self.subscriptionName} in the DB: {e}', + exc_info=True) def add_network_function_to_subscription(self, nf): """ Associates a network function to a Subscription @@ -120,8 +125,8 @@ class Subscription: db.session.add(current_sub) db.session.commit() except Exception as e: - logger.debug(f'Failed to add nf {nf.nf_name} to subscription ' - f'{current_sub.subscription_name}: {e}') + logger.error(f'Failed to add nf {nf.nf_name} to subscription ' + f'{current_sub.subscription_name}: {e}', exc_info=True) logger.debug(f'Subscription {current_sub.subscription_name} now contains these XNFs:' f'{Subscription.get_nf_names_per_sub(current_sub.subscription_name)}') @@ -175,7 +180,8 @@ class Subscription: db.session.commit() except Exception as e: - logger.debug(f'Failed to update status of subscription: {self.subscriptionName}: {e}') + logger.error(f'Failed to update status of subscription: {self.subscriptionName}: {e}', + exc_info=True) def delete_subscription(self): """ Deletes a subscription and all its association from the database. A network function @@ -193,8 +199,8 @@ class Subscription: db.session.delete(subscription) db.session.commit() except Exception as e: - logger.debug(f'Failed to delete subscription: {self.subscriptionName} ' - f'and it\'s relations from the DB: {e}') + logger.error(f'Failed to delete subscription: {self.subscriptionName} ' + f'and it\'s relations from the DB: {e}', exc_info=True) def process_subscription(self, nfs, mr_pub, app_conf): action = 'Deactivate' @@ -211,7 +217,8 @@ class Subscription: mr_pub.publish_subscription_event_data(self, nf.nf_name, app_conf) logger.debug(f'Publishing Event to {action} ' f'Sub: {self.subscriptionName} for the nf: {nf.nf_name}') - self.add_network_function_to_subscription(nf) + if action == 'Activate': + self.add_network_function_to_subscription(nf) self.update_sub_nf_status(self.subscriptionName, sub_nf_state, nf.nf_name) except Exception as err: raise Exception(f'Error publishing activation event to MR: {err}') @@ -242,8 +249,8 @@ class Subscription: update({NfSubRelationalModel.nf_sub_status: status}, synchronize_session='evaluate') db.session.commit() except Exception as e: - logger.debug(f'Failed to update status of nf: {nf_name} for subscription: ' - f'{subscription_name}: {e}') + logger.error(f'Failed to update status of nf: {nf_name} for subscription: ' + f'{subscription_name}: {e}', exc_info=True) def _get_nf_models(self): nf_sub_relationships = NfSubRelationalModel.query.filter( diff --git a/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py b/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py index 112f994b..74b6ac88 100644 --- a/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py @@ -57,4 +57,5 @@ class SubscriptionHandler: self.aai_event_thread.cancel() except Exception as err: - logger.error(f'Error occurred during the activation/deactivation process {err}') + logger.error(f'Error occurred during the activation/deactivation process {err}', + exc_info=True) diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py index 143b5c8c..b3c906d0 100755 --- a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py +++ b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py @@ -29,13 +29,17 @@ from mod.subscription_handler import SubscriptionHandler def main(): try: - app = create_app() - app.app_context().push() - db.create_all(app=app) - app_conf = AppConfig() - policy_mr_pub = app_conf.get_mr_pub('policy_pm_publisher') - policy_mr_sub = app_conf.get_mr_sub('policy_pm_subscriber') - mr_aai_event_sub = app_conf.get_mr_sub('aai_subscriber') + try: + app = create_app() + app.app_context().push() + db.create_all(app=app) + app_conf = AppConfig() + policy_mr_pub = app_conf.get_mr_pub('policy_pm_publisher') + policy_mr_sub = app_conf.get_mr_sub('policy_pm_subscriber') + aai_event_mr_sub = app_conf.get_mr_sub('aai_subscriber') + except Exception as e: + logger.error(f'Failed to get config and create application: {e}', exc_info=True) + sys.exit(e) subscription_in_db = Subscription.get(app_conf.subscription.subscriptionName) administrative_state = subscription_in_db.status if subscription_in_db \ else AdministrativeState.LOCKED.value @@ -43,13 +47,13 @@ def main(): app_conf_thread = PeriodicTask(10, app_conf.refresh_config) app_conf_thread.start() aai_event_thread = PeriodicTask(10, process_aai_events, - args=(mr_aai_event_sub, policy_mr_pub, app, app_conf)) + args=(aai_event_mr_sub, policy_mr_pub, app, app_conf)) subscription_handler = SubscriptionHandler(administrative_state, policy_mr_pub, app, app_conf, aai_event_thread) policy_response_handler = PolicyResponseHandler(policy_mr_sub, app_conf, app) subscription_handler_thread = PeriodicTask(30, subscription_handler.execute) - policy_response_handler_thread = PeriodicTask(5, policy_response_handler.poll_policy_topic) + policy_response_handler_thread = PeriodicTask(10, policy_response_handler.poll_policy_topic) subscription_handler_thread.start() policy_response_handler_thread.start() periodic_tasks = [app_conf_thread, aai_event_thread, subscription_handler_thread, @@ -60,7 +64,7 @@ def main(): launch_api_server(app_conf) except Exception as e: - logger.error(f'Failed to initialise PMSH: {e}') + logger.error(f'Failed to initialise PMSH: {e}', exc_info=True) sys.exit(e) diff --git a/components/pm-subscription-handler/setup.py b/components/pm-subscription-handler/setup.py index c8170b70..04df305b 100644 --- a/components/pm-subscription-handler/setup.py +++ b/components/pm-subscription-handler/setup.py @@ -36,7 +36,7 @@ setup( "Flask==1.1.1", "swagger-ui-bundle==0.0.6", "psycopg2-binary==2.8.4", - "onap_dcae_cbs_docker_client==2.1.0", + "onap_dcae_cbs_docker_client==2.1.1", "onappylog==1.0.9", "ruamel.yaml==0.16.10"] ) diff --git a/components/pm-subscription-handler/tests/data/cbs_data_1.json b/components/pm-subscription-handler/tests/data/cbs_data_1.json index 8dc225dc..75253c88 100644 --- a/components/pm-subscription-handler/tests/data/cbs_data_1.json +++ b/components/pm-subscription-handler/tests/data/cbs_data_1.json @@ -64,13 +64,15 @@ "operational_policy_name": "pmsh-operational-policy", "aaf_password":"demo123456!", "aaf_identity":"dcae@dcae.onap.org", - "cert_path":"/opt/app/pm-mapper/etc/certs/cert.pem", - "key_path":"/opt/app/pm-mapper/etc/certs/key.pem", + "cert_path":"/opt/app/pmsh/etc/certs/cert.pem", + "key_path":"/opt/app/pmsh/etc/certs/key.pem", + "ca_cert_path":"/opt/app/pmsh/etc/certs/cacert.pem", + "enable_tls":"true", "streams_subscribes":{ "aai_subscriber":{ "type":"message_router", "dmaap_info":{ - "topic_url":"https://node:30226/events/AAI_EVENT", + "topic_url":"https://message-router:3905/events/AAI_EVENT", "client_role":"org.onap.dcae.aaiSub", "location":"san-francisco", "client_id":"1575976809466" @@ -79,7 +81,7 @@ "policy_pm_subscriber":{ "type":"message_router", "dmaap_info":{ - "topic_url":"https://node:30226/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", + "topic_url":"https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", "client_role":"org.onap.dcae.pmSubscriber", "location":"san-francisco", "client_id":"1575876809456" @@ -90,7 +92,7 @@ "policy_pm_publisher":{ "type":"message_router", "dmaap_info":{ - "topic_url":"https://node:30226/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", + "topic_url":"https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", "client_role":"org.onap.dcae.pmPublisher", "location":"san-francisco", "client_id":"1475976809466" @@ -99,7 +101,7 @@ "other_publisher":{ "type":"message_router", "dmaap_info":{ - "topic_url":"https://node:30226/events/org.onap.dmaap.mr.SOME_OTHER_TOPIC", + "topic_url":"https://message-router:3905/events/org.onap.dmaap.mr.SOME_OTHER_TOPIC", "client_role":"org.onap.dcae.pmControlPub", "location":"san-francisco", "client_id":"1875976809466" diff --git a/components/pm-subscription-handler/tests/data/cbs_data_2.json b/components/pm-subscription-handler/tests/data/cbs_data_2.json deleted file mode 100755 index c223ddea..00000000 --- a/components/pm-subscription-handler/tests/data/cbs_data_2.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "config":{}, - "policy": { - "subscription": { - "subscriptionName": "someExtraPM-AllKista-gNB-R2B", - "administrativeState": "UNLOCKED", - "fileBasedGP": 15, - "fileLocation": "c:\/\/PM", - "nfFilter": { - "swVersions": [ - "A21", - "B" - ], - "nfNames": [ - "ABC", - "DEF", - "foo.*" - ] - }, - "measurementGroups": [ - { - "measurementGroup": { - "measurementTypes": [ - { - "measurementType": "countera" - }, - { - "measurementType": "counterb" - } - ], - "managedObjectDNsBasic": [ - { - "DN": "dna" - }, - { - "DN": "dnb" - } - ] - } - }, - { - "measurementGroup": { - "measurementTypes": [ - { - "measurementType": "counterc" - }, - { - "measurementType": "counterd" - } - ], - "managedObjectDNsBasic": [ - { - "DN": "dnc" - }, - { - "DN": "dnd" - } - ] - } - } - ] - } -} - - - -}
\ No newline at end of file diff --git a/components/pm-subscription-handler/tests/data/mr_aai_events.json b/components/pm-subscription-handler/tests/data/mr_aai_events.json index 202d1339..156a8e8d 100755 --- a/components/pm-subscription-handler/tests/data/mr_aai_events.json +++ b/components/pm-subscription-handler/tests/data/mr_aai_events.json @@ -2,5 +2,8 @@ "mr_response": [
"{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"pnf\",\"top-entity-type\":\"pnf\",\"entity-link\":\"/aai/v16/network/pnfs/pnf/pnf_newly_discovered\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"UPDATE\",\"sequence-number\":\"0\",\"id\":\"db09e090-196e-4f84-9645-e449b1cd3640\",\"source-name\":\"dcae-curl\",\"version\":\"v16\",\"timestamp\":\"20200203-15:14:08:807\"},\"entity\":{\"ipaddress-v4-oam\":\"10.10.10.37\",\"nf-role\":\"gNB\",\"equip-type\":\"val8\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"service-instance\",\"relationship-data\":[{\"relationship-value\":\"Demonstration\",\"relationship-key\":\"customer.global-customer-id\"},{\"relationship-value\":\"vCPE\",\"relationship-key\":\"service-subscription.service-type\"},{\"relationship-value\":\"2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-key\":\"service-instance.service-instance-id\"}],\"related-link\":\"/aai/v16/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-label\":\"org.onap.relationships.inventory.ComposedOf\",\"related-to-property\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":\"Svc6_1\"}]}]},\"equip-vendor\":\"Ericsson\",\"serial-number\":\"6061ZW3\",\"ipaddress-v6-oam\":\"2001:0db8:0:0:0:0:1428:57ab\",\"equip-model\":\"val6\",\"in-maint\":false,\"resource-version\":\"1578668956804\",\"sw-version\":\"val7\",\"pnf-id\":\"eabcfaf7-b7f3-45fb-94e7-e6112fb3e8b8\",\"pnf-name\":\"pnf_newly_discovered\",\"orchestration-status\":\"Active\"}}",
"{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"pnf\",\"top-entity-type\":\"pnf\",\"entity-link\":\"/aai/v16/network/pnfs/pnf/pnf_newly_discovered\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"UPDATE\",\"sequence-number\":\"0\",\"id\":\"db09e090-196e-4f84-9645-e449b1cd3640\",\"source-name\":\"dcae-curl\",\"version\":\"v16\",\"timestamp\":\"20200203-15:14:08:807\"},\"entity\":{\"orchestration-status\":\"Active\",\"ipaddress-v4-oam\":\"10.10.10.37\",\"nf-role\":\"gNB\",\"equip-type\":\"val8\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"service-instance\",\"relationship-data\":[{\"relationship-value\":\"Demonstration\",\"relationship-key\":\"customer.global-customer-id\"},{\"relationship-value\":\"vCPE\",\"relationship-key\":\"service-subscription.service-type\"},{\"relationship-value\":\"2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-key\":\"service-instance.service-instance-id\"}],\"related-link\":\"/aai/v16/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-label\":\"org.onap.relationships.inventory.ComposedOf\",\"related-to-property\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":\"Svc6_1\"}]}]},\"equip-vendor\":\"Ericsson\",\"serial-number\":\"6061ZW3\",\"ipaddress-v6-oam\":\"2001:0db8:0:0:0:0:1428:57ab\",\"equip-model\":\"val6\",\"in-maint\":false,\"resource-version\":\"1578668956804\",\"sw-version\":\"val7\",\"pnf-id\":\"eabcfaf7-b7f3-45fb-94e7-e6112fb3e8b8\",\"pnf-name\":\"pnf_already_active\",\"orchestration-status\":\"Active\"}}",
- "{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"pnf\",\"top-entity-type\":\"pnf\",\"entity-link\":\"/aai/v16/network/pnfs/pnf/pnf_newly_discovered\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"DELETE\",\"sequence-number\":\"0\",\"id\":\"db09e090-196e-4f84-9645-e449b1cd3640\",\"source-name\":\"dcae-curl\",\"version\":\"v16\",\"timestamp\":\"20200203-15:14:08:807\"},\"entity\":{\"ipaddress-v4-oam\":\"10.10.10.37\",\"nf-role\":\"gNB\",\"equip-type\":\"val8\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"service-instance\",\"relationship-data\":[{\"relationship-value\":\"Demonstration\",\"relationship-key\":\"customer.global-customer-id\"},{\"relationship-value\":\"vCPE\",\"relationship-key\":\"service-subscription.service-type\"},{\"relationship-value\":\"2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-key\":\"service-instance.service-instance-id\"}],\"related-link\":\"/aai/v16/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-label\":\"org.onap.relationships.inventory.ComposedOf\",\"related-to-property\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":\"Svc6_1\"}]}]},\"equip-vendor\":\"Ericsson\",\"serial-number\":\"6061ZW3\",\"ipaddress-v6-oam\":\"2001:0db8:0:0:0:0:1428:57ab\",\"equip-model\":\"val6\",\"in-maint\":false,\"resource-version\":\"1578668956804\",\"sw-version\":\"val7\",\"pnf-id\":\"eabcfaf7-b7f3-45fb-94e7-e6112fb3e8b8\",\"pnf-name\":\"pnf_to_be_deleted\",\"orchestration-status\":\"Active\"}}"]
+ "{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"pnf\",\"top-entity-type\":\"pnf\",\"entity-link\":\"/aai/v16/network/pnfs/pnf/pnf_newly_discovered\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"DELETE\",\"sequence-number\":\"0\",\"id\":\"db09e090-196e-4f84-9645-e449b1cd3640\",\"source-name\":\"dcae-curl\",\"version\":\"v16\",\"timestamp\":\"20200203-15:14:08:807\"},\"entity\":{\"ipaddress-v4-oam\":\"10.10.10.37\",\"nf-role\":\"gNB\",\"equip-type\":\"val8\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"service-instance\",\"relationship-data\":[{\"relationship-value\":\"Demonstration\",\"relationship-key\":\"customer.global-customer-id\"},{\"relationship-value\":\"vCPE\",\"relationship-key\":\"service-subscription.service-type\"},{\"relationship-value\":\"2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-key\":\"service-instance.service-instance-id\"}],\"related-link\":\"/aai/v16/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/2c03b2a8-e31a-4749-9e99-3089ab441400\",\"relationship-label\":\"org.onap.relationships.inventory.ComposedOf\",\"related-to-property\":[{\"property-key\":\"service-instance.service-instance-name\",\"property-value\":\"Svc6_1\"}]}]},\"equip-vendor\":\"Ericsson\",\"serial-number\":\"6061ZW3\",\"ipaddress-v6-oam\":\"2001:0db8:0:0:0:0:1428:57ab\",\"equip-model\":\"val6\",\"in-maint\":false,\"resource-version\":\"1578668956804\",\"sw-version\":\"val7\",\"pnf-id\":\"eabcfaf7-b7f3-45fb-94e7-e6112fb3e8b8\",\"pnf-name\":\"pnf_to_be_deleted\",\"orchestration-status\":\"Active\"}}",
+ "{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"model-ver\",\"top-entity-type\":\"model\",\"entity-link\":\"/aai/v19/service-design-and-creation/models/model/60cd7bbf-0a6b-43ce-a5af-07cbf168ecdc/model-vers/model-ver/5485c7ac-825f-414d-aba4-e24147107d0b\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"UPDATE\",\"sequence-number\":\"0\",\"id\":\"e16cb0f9-3617-4a14-9c81-f7ee4cdf9df7\",\"source-name\":\"UNKNOWN\",\"version\":\"v19\",\"timestamp\":\"20200701-12:06:12:135\"},\"entity\":{\"model-type\":\"service\",\"model-vers\":{\"model-ver\":[{\"model-version-id\":\"5485c7ac-825f-414d-aba4-e24147107d0b\",\"resource-version\":\"1593605171956\",\"model-description\":\"catalog service description\",\"model-name\":\"Demo_pNF_WCcM9Z2VNE3eGfLIKulP\",\"model-elements\":{\"model-element\":[{\"relationship-list\":{\"relationship\":[{\"related-to\":\"model-ver\",\"relationship-data\":[{\"relationship-value\":\"82194af1-3c2c-485a-8f44-420e22a9eaa4\",\"relationship-key\":\"model.model-invariant-id\"},{\"relationship-value\":\"46b92144-923a-4d20-b85a-3cbd847668a9\",\"relationship-key\":\"model-ver.model-version-id\"}],\"related-link\":\"/aai/v19/service-design-and-creation/models/model/82194af1-3c2c-485a-8f44-420e22a9eaa4/model-vers/model-ver/46b92144-923a-4d20-b85a-3cbd847668a9\",\"relationship-label\":\"org.onap.relationships.inventory.IsA\",\"related-to-property\":[{\"property-key\":\"model-ver.model-name\",\"property-value\":\"service-instance\"}]}]},\"resource-version\":\"1593605012006\",\"model-elements\":{\"model-element\":[{\"relationship-list\":{\"relationship\":[{\"related-to\":\"model-ver\",\"relationship-data\":[{\"relationship-value\":\"c8fb1064-f38a-4a13-90a6-ec60289879ac\",\"relationship-key\":\"model.model-invariant-id\"},{\"relationship-value\":\"94c051c3-4484-425e-a107-6914816321a6\",\"relationship-key\":\"model-ver.model-version-id\"}],\"related-link\":\"/aai/v19/service-design-and-creation/models/model/c8fb1064-f38a-4a13-90a6-ec60289879ac/model-vers/model-ver/94c051c3-4484-425e-a107-6914816321a6\",\"relationship-label\":\"org.onap.relationships.inventory.IsA\",\"related-to-property\":[{\"property-key\":\"model-ver.model-name\",\"property-value\":\"pNF 77be3d89-b735\"}]}]},\"resource-version\":\"1593605012006\",\"new-data-del-flag\":\"T\",\"cardinality\":\"unbounded\",\"model-element-uuid\":\"44712769-981d-4970-9ea5-4c99b86f838e\"}]},\"new-data-del-flag\":\"T\",\"cardinality\":\"unbounded\",\"model-element-uuid\":\"4a601305-9e09-4152-98ad-b8c466d57813\"}]},\"model-version\":\"1.0\",\"distribution-status\":\"DISTRIBUTION_COMPLETE_OK\"}]},\"model-invariant-id\":\"60cd7bbf-0a6b-43ce-a5af-07cbf168ecdc\"}}",
+ "{\"cambria.partition\":\"AAI\",\"event-header\":{\"severity\":\"NORMAL\",\"entity-type\":\"customer\",\"top-entity-type\":\"customer\",\"entity-link\":\"/aai/v19/business/customers/customer/ETE_Customer_5638d7b4-a02d-4cc4-801e-77ee837d2855\",\"event-type\":\"AAI-EVENT\",\"domain\":\"dev\",\"action\":\"CREATE\",\"sequence-number\":\"0\",\"id\":\"ef390383-3d08-4268-a013-d11c14efd716\",\"source-name\":\"robot-ete\",\"version\":\"v19\",\"timestamp\":\"20200701-12:06:50:388\"},\"entity\":{\"global-customer-id\":\"ETE_Customer_5638d7b4-a02d-4cc4-801e-77ee837d2855\",\"subscriber-type\":\"INFRA\",\"resource-version\":\"1593605210258\",\"subscriber-name\":\"ETE_Customer_5638d7b4-a02d-4cc4-801e-77ee837d2855\",\"service-subscriptions\":{\"service-subscription\":[{\"relationship-list\":{\"relationship\":[{\"related-to\":\"tenant\",\"relationship-data\":[{\"relationship-value\":\"CloudOwner\",\"relationship-key\":\"cloud-region.cloud-owner\"},{\"relationship-value\":\"RegionForPNF\",\"relationship-key\":\"cloud-region.cloud-region-id\"},{\"relationship-value\":\"dummy_tenant_id_for_pnf\",\"relationship-key\":\"tenant.tenant-id\"}],\"related-link\":\"/aai/v19/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionForPNF/tenants/tenant/dummy_tenant_id_for_pnf\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"related-to-property\":[{\"property-key\":\"tenant.tenant-name\",\"property-value\":\"dummy_tenant_for_pnf\"}]}]},\"resource-version\":\"1593605210258\",\"service-type\":\"pNF\"}]}}}"
+ ]
}
diff --git a/components/pm-subscription-handler/tests/log_config.yaml b/components/pm-subscription-handler/tests/log_config.yaml index 56620708..1c3abd8b 100755 --- a/components/pm-subscription-handler/tests/log_config.yaml +++ b/components/pm-subscription-handler/tests/log_config.yaml @@ -4,7 +4,7 @@ disable_existing_loggers: true loggers: onap_logger: - level: INFO + level: DEBUG handlers: [stdout_handler] propagate: false handlers: diff --git a/components/pm-subscription-handler/tests/test_aai_service.py b/components/pm-subscription-handler/tests/test_aai_service.py index 9f370096..4b7be153 100644 --- a/components/pm-subscription-handler/tests/test_aai_service.py +++ b/components/pm-subscription-handler/tests/test_aai_service.py @@ -37,7 +37,6 @@ class AaiClientTestCase(TestCase): def setUp(self, mock_get_db_url, mock_update_config, mock_get_pmsh_config): mock_get_db_url.return_value = 'sqlite://' self.env = EnvironmentVarGuard() - self.env.set('AAI_SERVICE_HOST', '1.2.3.4') self.env.set('AAI_SERVICE_PORT', '8443') self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml')) with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data: @@ -67,14 +66,14 @@ class AaiClientTestCase(TestCase): @responses.activate def test_aai_client_get_all_aai_xnf_data_not_found(self): responses.add(responses.PUT, - 'https://1.2.3.4:8443/aai/v16/query?format=simple&nodesOnly=true', + 'https://1.2.3.4:8443/aai/v19/query?format=simple&nodesOnly=true', json={'error': 'not found'}, status=404) self.assertIsNone(aai_client._get_all_aai_nf_data(self.app_conf)) @responses.activate def test_aai_client_get_all_aai_xnf_data_success(self): responses.add(responses.PUT, - 'https://1.2.3.4:8443/aai/v16/query?format=simple&nodesOnly=true', + 'https://aai:8443/aai/v19/query?format=simple&nodesOnly=true', json={'dummy_data': 'blah_blah'}, status=200) self.assertIsNotNone(aai_client._get_all_aai_nf_data(self.app_conf)) @@ -84,4 +83,4 @@ class AaiClientTestCase(TestCase): aai_client._get_aai_service_url() def test_aai_client_get_aai_service_url_success(self): - self.assertEqual('https://1.2.3.4:8443', aai_client._get_aai_service_url()) + self.assertEqual('https://aai:8443', aai_client._get_aai_service_url()) diff --git a/components/pm-subscription-handler/tests/test_controller.py b/components/pm-subscription-handler/tests/test_controller.py index 57230429..d324a07d 100755 --- a/components/pm-subscription-handler/tests/test_controller.py +++ b/components/pm-subscription-handler/tests/test_controller.py @@ -42,7 +42,6 @@ class ControllerTestCase(unittest.TestCase): mock_session.return_value.status_code = 200 mock_session.return_value.text = self.aai_response_data self.env = EnvironmentVarGuard() - self.env.set('AAI_SERVICE_HOST', '1.2.3.4') self.env.set('AAI_SERVICE_PORT', '8443') self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml')) with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data: diff --git a/components/pm-subscription-handler/tests/test_pmsh_utils.py b/components/pm-subscription-handler/tests/test_pmsh_utils.py index 1ea27a7c..6e5585f5 100644 --- a/components/pm-subscription-handler/tests/test_pmsh_utils.py +++ b/components/pm-subscription-handler/tests/test_pmsh_utils.py @@ -78,8 +78,8 @@ class PmshUtilsTestCase(TestCase): def test_utils_get_cert_data(self, mock_get_pmsh_config): mock_get_pmsh_config.return_value = self.cbs_data self.app_conf = AppConfig() - self.assertTrue(self.app_conf.cert_params, ('/opt/app/pm-mapper/etc/certs/cert.pem', - '/opt/app/pm-mapper/etc/certs/key.pem')) + self.assertEqual(self.app_conf.cert_params, ('/opt/app/pmsh/etc/certs/cert.pem', + '/opt/app/pmsh/etc/certs/key.pem')) @patch('mod.pmsh_utils.AppConfig._get_pmsh_config') @patch.object(Session, 'post') @@ -98,7 +98,7 @@ class PmshUtilsTestCase(TestCase): mock_get_pmsh_config.return_value = self.cbs_data self.app_conf = AppConfig() responses.add(responses.POST, - 'https://node:30226/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS', + 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS', json={'error': 'Client Error'}, status=400) mr_policy_pub = self.app_conf.get_mr_pub('policy_pm_publisher') with self.assertRaises(Exception): @@ -121,7 +121,7 @@ class PmshUtilsTestCase(TestCase): self.app_conf = AppConfig() policy_mr_sub = self.app_conf.get_mr_sub('policy_pm_subscriber') responses.add(responses.GET, - 'https://node:30226/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/' + 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/' 'dcae_pmsh_cg/1?timeout=1000', json={"dummy_val": "43c4ee19-6b8d-4279-a80f-c507850aae47"}, status=200) mr_topic_data = policy_mr_sub.get_from_topic(1) @@ -134,7 +134,7 @@ class PmshUtilsTestCase(TestCase): self.app_conf = AppConfig() policy_mr_sub = self.app_conf.get_mr_sub('policy_pm_subscriber') responses.add(responses.GET, - 'https://node:30226/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/' + 'https://message-router:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/' 'dcae_pmsh_cg/1?timeout=1000', json={"dummy_val": "43c4ee19-6b8d-4279-a80f-c507850aae47"}, status=400) with self.assertRaises(Exception): @@ -163,7 +163,7 @@ class PmshUtilsTestCase(TestCase): self.app_conf.refresh_config() mock_logger.assert_called_with('AppConfig data has been refreshed') - @patch('mod.logger.debug') + @patch('mod.logger.error') @patch('mod.pmsh_utils.get_all') def test_refresh_config_fail(self, mock_cbs_client_get_all, mock_logger): mock_cbs_client_get_all.return_value = self.cbs_data @@ -171,4 +171,4 @@ class PmshUtilsTestCase(TestCase): mock_cbs_client_get_all.side_effect = Exception with self.assertRaises(RetryError): self.app_conf.refresh_config() - mock_logger.assert_called_with('Failed to refresh AppConfig data') + mock_logger.assert_called_with('Failed to get config from CBS: ', exc_info=True) diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py index 1543afe8..74593a42 100755 --- a/components/pm-subscription-handler/tests/test_subscription.py +++ b/components/pm-subscription-handler/tests/test_subscription.py @@ -46,7 +46,6 @@ class SubscriptionTest(TestCase): mock_session.return_value.status_code = 200 mock_session.return_value.text = self.aai_response_data self.env = EnvironmentVarGuard() - self.env.set('AAI_SERVICE_HOST', '1.2.3.4') self.env.set('AAI_SERVICE_PORT', '8443') self.env.set('LOGGER_CONFIG', os.path.join(os.path.dirname(__file__), 'log_config.yaml')) with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data: diff --git a/components/pm-subscription-handler/tests/test_subscription_handler.py b/components/pm-subscription-handler/tests/test_subscription_handler.py index a277da66..65a7c2c0 100644 --- a/components/pm-subscription-handler/tests/test_subscription_handler.py +++ b/components/pm-subscription-handler/tests/test_subscription_handler.py @@ -95,4 +95,5 @@ class SubscriptionHandlerTest(TestCase): self.mock_app, self.app_conf, self.mock_aai_event_thread) sub_handler.execute() - mock_logger.assert_called_with('Error occurred during the activation/deactivation process ') + mock_logger.assert_called_with('Error occurred during the activation/deactivation process ', + exc_info=True) |