From 1ac9847eb66a074b5413264c788152f7c3ffc28d Mon Sep 17 00:00:00 2001 From: egernug Date: Mon, 22 Feb 2021 11:35:35 +0000 Subject: [PMSH] Update filter User can edit/update the nfFilter to include/exclude selected NFs Changelog and version update Issue-ID: DCAEGEN2-2531 Signed-off-by: egernug Change-Id: I61388775a711687525b12087e9b533bee1c6b039 --- .../pmsh_service/mod/policy_response_handler.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'components/pm-subscription-handler/pmsh_service/mod/policy_response_handler.py') 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 09c97047..ec331791 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 @@ -1,5 +1,5 @@ # ============LICENSE_START=================================================== -# Copyright (C) 2020 Nordix Foundation. +# Copyright (C) 2020-2021 Nordix Foundation. # ============================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -31,6 +31,10 @@ policy_response_handle_functions = { 'success': Subscription.update_sub_nf_status, 'failed': Subscription.update_sub_nf_status }, + AdministrativeState.FILTERING.value: { + 'success': NetworkFunction.delete, + 'failed': Subscription.update_sub_nf_status + }, AdministrativeState.LOCKING.value: { 'success': NetworkFunction.delete, 'failed': Subscription.update_sub_nf_status @@ -38,6 +42,19 @@ policy_response_handle_functions = { } +def _set_sub_nf_status(administrative_state, response_message): + """ + + Args: + administrative_state (str): The administrative state of the subscription + response_message (str): The message in the response regarding the state (success|failed) + + Returns: + str: sub_nf_status + """ + return subscription_nf_states[administrative_state][response_message].value; + + class PolicyResponseHandler: def __init__(self, mr_sub, app_conf, app): self.mr_sub = mr_sub @@ -60,13 +77,14 @@ class PolicyResponseHandler: == self.app_conf.subscription.subscriptionName: nf_name = data['status']['nfName'] response_message = data['status']['message'] + change_type = data['status']['changeType'] self._handle_response(self.app_conf.subscription.subscriptionName, - administrative_state, nf_name, response_message) + administrative_state, nf_name, response_message, change_type) except Exception as 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): + def _handle_response(subscription_name, administrative_state, nf_name, response_message, change_type): """ Handles the response from Policy, updating the DB @@ -79,9 +97,14 @@ class PolicyResponseHandler: logger.info(f'Response from MR: Sub: {subscription_name} for ' f'NF: {nf_name} received, updating the DB') try: + if administrative_state == AdministrativeState.UNLOCKED.value and change_type == "DELETED": + administrative_state = AdministrativeState.FILTERING.value sub_nf_status = subscription_nf_states[administrative_state][response_message].value policy_response_handle_functions[administrative_state][response_message]( - subscription_name=subscription_name, status=sub_nf_status, nf_name=nf_name) + subscription_name=subscription_name, status=sub_nf_status, nf_name=nf_name) except Exception as err: logger.error(f'Error changing nf_sub status in the DB: {err}') raise + + + -- cgit 1.2.3-korg