From dbbf891fd2043b5c1ec367b89b2bec13b500ee38 Mon Sep 17 00:00:00 2001 From: dharmendra Date: Wed, 30 Mar 2016 10:02:08 +0530 Subject: [PATCH] Remove premature vnf delete from db Hold the vnf in "PENDING_DELETE" state until underlying heat-stack deletion is complete. Closes-bug: #1554663 Change-Id: I5c52a9fc55950355f9122cc907f41cb8b9217a5c --- tacker/tests/constants.py | 1 + tacker/tests/functional/base.py | 15 +++++++++++++++ tacker/tests/functional/vnfm/test_tosca_vnf.py | 7 +++---- .../vnfm/test_tosca_vnf_multiple_vdu.py | 7 +++---- tacker/tests/functional/vnfm/test_vnf.py | 7 +++---- .../tests/functional/vnfm/test_vnf_monitoring.py | 9 ++++----- .../functional/vnfm/test_vnf_multiple_vdu.py | 7 +++---- tacker/tests/functional/vnfm/test_vnfm_param.py | 5 ++++- tacker/vm/plugin.py | 1 - 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/tacker/tests/constants.py b/tacker/tests/constants.py index 317a3f0f5..3e14a3a88 100644 --- a/tacker/tests/constants.py +++ b/tacker/tests/constants.py @@ -1,4 +1,5 @@ VNF_CIRROS_CREATE_TIMEOUT = 300 +VNF_CIRROS_DELETE_TIMEOUT = 300 VNF_CIRROS_DEAD_TIMEOUT = 250 ACTIVE_SLEEP_TIME = 3 DEAD_SLEEP_TIME = 1 diff --git a/tacker/tests/functional/base.py b/tacker/tests/functional/base.py index e83b9841c..417f190cc 100644 --- a/tacker/tests/functional/base.py +++ b/tacker/tests/functional/base.py @@ -17,6 +17,7 @@ import time from oslo_config import cfg from tempest_lib.tests import base +from tacker.common.exceptions import TackerException from tacker.tests import constants from tacker import version @@ -85,6 +86,20 @@ class BaseTackerTest(base.TestCase): return cls.wait_until_vnf_status(vnf_id, 'ACTIVE', timeout, sleep_interval) + @classmethod + def wait_until_vnf_delete(cls, vnf_id, timeout): + start_time = int(time.time()) + while True: + try: + vnf_result = cls.client.show_vnf(vnf_id) + time.sleep(1) + except Exception: + return + status = vnf_result['vnf']['status'] + if (status != 'PENDING_DELETE') or (( + int(time.time()) - start_time) > timeout): + raise TackerException(_("Failed with status: %s"), status) + @classmethod def wait_until_vnf_dead(cls, vnf_id, timeout, sleep_interval): return cls.wait_until_vnf_status(vnf_id, 'DEAD', timeout, diff --git a/tacker/tests/functional/vnfm/test_tosca_vnf.py b/tacker/tests/functional/vnfm/test_tosca_vnf.py index d95531e45..dd028670f 100644 --- a/tacker/tests/functional/vnfm/test_tosca_vnf.py +++ b/tacker/tests/functional/vnfm/test_tosca_vnf.py @@ -57,7 +57,6 @@ class VnfTestToscaCreate(base.BaseTackerTest): assert False, "vnf Delete failed" # Delete vnfd_instance - try: - self.client.delete_vnfd(vnfd_id) - except Exception: - assert False, "vnfd Delete failed" + self.addCleanup(self.client.delete_vnfd, vnfd_id) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) diff --git a/tacker/tests/functional/vnfm/test_tosca_vnf_multiple_vdu.py b/tacker/tests/functional/vnfm/test_tosca_vnf_multiple_vdu.py index e439fcb51..afcfd3ae2 100644 --- a/tacker/tests/functional/vnfm/test_tosca_vnf_multiple_vdu.py +++ b/tacker/tests/functional/vnfm/test_tosca_vnf_multiple_vdu.py @@ -76,7 +76,6 @@ class VnfTestToscaMultipleVDU(base.BaseTackerTest): assert False, "vnf Delete of test_vnf_with_multiple_vdus failed" # Delete vnfd_instance - try: - self.client.delete_vnfd(vnfd_id) - except Exception: - assert False, "vnfd Delete of sample-vnfd-multiple-vdus failed" + self.addCleanup(self.client.delete_vnfd, vnfd_id) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) diff --git a/tacker/tests/functional/vnfm/test_vnf.py b/tacker/tests/functional/vnfm/test_vnf.py index 1ba7289ab..a54b5ae1a 100644 --- a/tacker/tests/functional/vnfm/test_vnf.py +++ b/tacker/tests/functional/vnfm/test_vnf.py @@ -58,10 +58,9 @@ class VnfTestCreate(base.BaseTackerTest): assert False, "vnf Delete failed" # Delete vnfd_instance - try: - self.client.delete_vnfd(vnfd_id) - except Exception: - assert False, "vnfd Delete failed" + self.addCleanup(self.client.delete_vnfd, vnfd_id) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) def test_create_delete_vnf_with_default_vim(self): self._test_create_delete_vnf( diff --git a/tacker/tests/functional/vnfm/test_vnf_monitoring.py b/tacker/tests/functional/vnfm/test_vnf_monitoring.py index b0759f2a2..d13a6aec9 100644 --- a/tacker/tests/functional/vnfm/test_vnf_monitoring.py +++ b/tacker/tests/functional/vnfm/test_vnf_monitoring.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from tacker.tests import constants from tacker.tests.functional import base from tacker.tests.utils import read_file @@ -45,11 +46,9 @@ class VnfTestPingMonitor(base.BaseTackerTest): vnf_id) # Delete vnfd_instance - try: - self.client.delete_vnfd(vnfd_id) - except Exception: - assert False, ("Failed to delete vnfd %s after the monitor test" % - vnfd_id) + self.addCleanup(self.client.delete_vnfd, vnfd_id) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) def test_create_delete_vnf_monitoring(self): self._test_vnf_with_monitoring( diff --git a/tacker/tests/functional/vnfm/test_vnf_multiple_vdu.py b/tacker/tests/functional/vnfm/test_vnf_multiple_vdu.py index 72edf9041..8614ea2bc 100644 --- a/tacker/tests/functional/vnfm/test_vnf_multiple_vdu.py +++ b/tacker/tests/functional/vnfm/test_vnf_multiple_vdu.py @@ -67,7 +67,6 @@ class VnfTestMultipleVDU(base.BaseTackerTest): assert False, "vnf Delete of test_vnf_with_multiple_vdus failed" # Delete vnfd_instance - try: - self.client.delete_vnfd(vnfd_id) - except Exception: - assert False, "vnfd Delete of sample-vnfd-multiple-vdus failed" + self.addCleanup(self.client.delete_vnfd, vnfd_id) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) diff --git a/tacker/tests/functional/vnfm/test_vnfm_param.py b/tacker/tests/functional/vnfm/test_vnfm_param.py index 8da6b9e02..a65268392 100644 --- a/tacker/tests/functional/vnfm/test_vnfm_param.py +++ b/tacker/tests/functional/vnfm/test_vnfm_param.py @@ -97,4 +97,7 @@ class VnfmTestParam(base.BaseTackerTest): 'test_vnf_with_parameters', 'sample_cirros_vnf_values.yaml') self._test_vnf_delete(vnf_instance) - self._test_vnfd_delete(vnfd_instance) + vnf_id = vnf_instance['vnf']['id'] + self.addCleanup(self.client.delete_vnfd, vnfd_instance['vnfd']['id']) + self.addCleanup(self.wait_until_vnf_delete, vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) diff --git a/tacker/vm/plugin.py b/tacker/vm/plugin.py index dc0424a4d..ef60a01d5 100644 --- a/tacker/vm/plugin.py +++ b/tacker/vm/plugin.py @@ -380,7 +380,6 @@ class VNFMPlugin(vm_db.VNFMPluginDb, VNFMMgmtMixin): self.mgmt_delete_post(context, device_dict) self._delete_device_post(context, device_id, e) - self._delete_device_post(context, device_id, None) self.spawn_n(self._delete_device_wait, context, device_dict, vim_auth) def create_vnf(self, context, vnf):