diff options
author | 2020-02-24 14:13:03 +0000 | |
---|---|---|
committer | 2020-02-26 15:25:50 +0000 | |
commit | e7f6914ca5397987eddc6788a6e378c51b12ce52 (patch) | |
tree | 1c4a1015afa1030ee3e75fdf78c282a2ce994433 /components/pm-subscription-handler/pmsh_service/mod/subscription.py | |
parent | de549f5f1bb3e0a6f94e9755ae0800b469114113 (diff) |
Handle AAI Update and Delete events for PMSH
Change-Id: I7f84e4429011bbaea4de23077ce23629b897fd7d
Issue-ID: DCAEGEN2-1846
Signed-off-by: emartin <ephraim.martin@est.tech>
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/subscription.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/mod/subscription.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/subscription.py b/components/pm-subscription-handler/pmsh_service/mod/subscription.py index 031609aa..7a0b88c1 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/subscription.py +++ b/components/pm-subscription-handler/pmsh_service/mod/subscription.py @@ -143,12 +143,19 @@ class Subscription: db.session.commit() def delete_subscription(self): - """ Deletes a subscription from the database """ - SubscriptionModel.query.filter( - SubscriptionModel.subscription_name == self.subscriptionName). \ - delete(synchronize_session='evaluate') - - db.session.commit() + """ Deletes a subscription and all its association from the database. A network function + that is only associated with the subscription being removed will also be deleted.""" + subscription = SubscriptionModel.query.filter( + SubscriptionModel.subscription_name == self.subscriptionName).one_or_none() + if subscription: + for nf_relationship in subscription.nfs: + other_nf_relationship = NfSubRelationalModel.query.filter( + NfSubRelationalModel.subscription_name != self.subscriptionName, + NfSubRelationalModel.nf_name == nf_relationship.nf_name).one_or_none() + if not other_nf_relationship: + db.session.delete(nf_relationship.nf) + db.session.delete(subscription) + db.session.commit() @retry(wait=wait_exponential(multiplier=1, min=30, max=120), stop=stop_after_attempt(3), retry=retry_if_exception_type(Exception)) |