From 7cb7070df4d73f5e6cc21c54e91a66b4b7c12269 Mon Sep 17 00:00:00 2001 From: Ken Fujimoto Date: Fri, 8 Nov 2024 06:44:39 +0000 Subject: [PATCH] Add exclusive processing to get_vnfd in v2 API When using an external NFVO, if VNF instances with the same vnfd_id are instantiated at the same time, one of the VNF instances will fail to create the CSAR cache directory and will have a "ROLLED_BACK" status. This patch fixes the get_vnfd method so that it cannot be executed on the same vnfd_id at the same time. Closes-Bug: #2088124 Change-Id: I15dab7796b356376f39c9a46410f7edb9d2d8242 --- tacker/sol_refactored/common/coordinate.py | 5 +++-- tacker/sol_refactored/nfvo/nfvo_client.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tacker/sol_refactored/common/coordinate.py b/tacker/sol_refactored/common/coordinate.py index 83d527ba7..9d6b80b26 100644 --- a/tacker/sol_refactored/common/coordinate.py +++ b/tacker/sol_refactored/common/coordinate.py @@ -69,7 +69,7 @@ def lock_vnf_instance(inst_arg, delay=False): return operation_lock -def lock_resources(res_arg, delay=False): +def lock_resources(res_arg, blocking=False): def operation_lock(func): @functools.wraps(func) @@ -84,7 +84,8 @@ def lock_resources(res_arg, delay=False): res_id = res_arg.format(**call_args) lock = coord.get_lock(res_id) - blocking = False if not delay else 10 + # NOTE: blocking can be integer and it means timeout period. + # if blocking is True, wait until lock is released. # NOTE: 'with lock' is not used since it can't handle # lock failed exception well. if not lock.acquire(blocking=blocking): diff --git a/tacker/sol_refactored/nfvo/nfvo_client.py b/tacker/sol_refactored/nfvo/nfvo_client.py index 1017d4bc5..14764c72f 100644 --- a/tacker/sol_refactored/nfvo/nfvo_client.py +++ b/tacker/sol_refactored/nfvo/nfvo_client.py @@ -22,6 +22,7 @@ import zipfile from oslo_log import log as logging from tacker.sol_refactored.common import config +from tacker.sol_refactored.common import coordinate from tacker.sol_refactored.common import fm_alarm_utils as alarm_utils from tacker.sol_refactored.common import fm_subscription_utils as fm_utils from tacker.sol_refactored.common import http_client @@ -124,6 +125,7 @@ class NfvoClient(object): LOG.debug("grant response: %s", grant_res.to_dict()) return grant_res + @coordinate.lock_resources('{vnfd_id}', blocking=True) def get_vnfd(self, context, vnfd_id, all_contents=False): if self.is_local: return self.nfvo.get_vnfd(context, vnfd_id)