Cleanup bgpvpn envtries at the end of test
At the moment bgpvpns are removed when all tests finished in class
resource_cleanup. The patch adds addCleanup() at the places
where bgpvpn entries are created to let them cleanned after single
test finished.
Also add cleanup for some API tests that were completely missing.
Related-Prod: PRODX-12050
Change-Id: I94229f2d6cc3331a61a57e5d03231fa8640857b6
(cherry picked from commit de5a63800ff3486be77f4399660d13668c0efccc)
(cherry picked from commit 63807a43771fe3a8f19089037a663ce6f852c43b)
diff --git a/neutron_tempest_plugin/bgpvpn/api/test_bgpvpn.py b/neutron_tempest_plugin/bgpvpn/api/test_bgpvpn.py
index f3a7b11..2045b57 100644
--- a/neutron_tempest_plugin/bgpvpn/api/test_bgpvpn.py
+++ b/neutron_tempest_plugin/bgpvpn/api/test_bgpvpn.py
@@ -257,6 +257,7 @@
self.assertRaises(exceptions.BadRequest,
self.bgpvpn_admin_client.update_bgpvpn,
bgpvpn['bgpvpn']['id'], **updatedata)
+ self.delete_bgpvpn(self.bgpvpn_admin_client, bgpvpn['bgpvpn'])
@decorators.attr(type=['negative'])
@decorators.idempotent_id('f049ce21-d239-47c0-b13f-fb57a2a558ce')
@@ -279,6 +280,7 @@
self.bgpvpn_client.create_network_association,
uuidutils.generate_uuid(),
network['network']['id'])
+ self.delete_bgpvpn(self.bgpvpn_admin_client, bgpvpn['bgpvpn'])
@decorators.attr(type=['negative'])
@decorators.idempotent_id('078b2660-4adb-4c4c-abf0-b77bf0bface5')
@@ -306,6 +308,7 @@
self.bgpvpn_client.delete_network_association,
uuidutils.generate_uuid(),
association['network_association']['id'])
+ self.delete_bgpvpn(self.bgpvpn_admin_client, bgpvpn['bgpvpn'])
@decorators.idempotent_id('de8d94b0-0239-4a48-9574-c3a4a4f7cacb')
def test_associate_disassociate_router(self):
diff --git a/neutron_tempest_plugin/bgpvpn/base.py b/neutron_tempest_plugin/bgpvpn/base.py
index b436a5d..46c2c78 100644
--- a/neutron_tempest_plugin/bgpvpn/base.py
+++ b/neutron_tempest_plugin/bgpvpn/base.py
@@ -17,6 +17,7 @@
from tempest.common import utils
from tempest import config
from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
from neutron_tempest_plugin.bgpvpn.services import bgpvpn_client
@@ -34,12 +35,6 @@
bgpvpn_alt_client = None
@classmethod
- def resource_cleanup(cls):
- for bgpvpn in cls.bgpvpns:
- cls.bgpvpn_admin_client.delete_bgpvpn(bgpvpn['id'])
- super(BaseBgpvpnTest, cls).resource_cleanup()
-
- @classmethod
def resource_setup(cls):
cls.route_distinguishers = []
cls.bgpvpns = []
@@ -87,9 +82,9 @@
body = client.create_bgpvpn(**kwargs)
bgpvpn = body['bgpvpn']
- self.bgpvpns.append(bgpvpn)
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.bgpvpn_admin_client.delete_bgpvpn, bgpvpn['id'])
return bgpvpn
def delete_bgpvpn(self, client, bgpvpn):
client.delete_bgpvpn(bgpvpn['id'])
- self.bgpvpns.remove(bgpvpn)
diff --git a/neutron_tempest_plugin/bgpvpn/scenario/test_bgpvpn_basic.py b/neutron_tempest_plugin/bgpvpn/scenario/test_bgpvpn_basic.py
index 14b0572..382519a 100644
--- a/neutron_tempest_plugin/bgpvpn/scenario/test_bgpvpn_basic.py
+++ b/neutron_tempest_plugin/bgpvpn/scenario/test_bgpvpn_basic.py
@@ -1227,6 +1227,9 @@
self.bgpvpn_admin_client, tenant_id=self.bgpvpn_client.tenant_id,
name=name, route_targets=rts, export_targets=export_rts,
import_targets=import_rts)
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.bgpvpn_admin_client.delete_bgpvpn,
+ self.bgpvpn['id'])
return self.bgpvpn
def _update_l3_bgpvpn(self, rts=None, import_rts=None, export_rts=None,