Move network_undisrupt_controller_main_vip to tearDown

The faults test test_network_disruptor_main_vip runs a method to undo
the disruptive action that it executes.
That method is called at the end of the test. If something fails before,
the "undisruption" is not called.
This patch moves network_undisrupt_controller_main_vip to the tearDown
method, which guarantees it would be executed, regardless of passing or
failing.

Change-Id: I05183de74d12a00bc57efd8a3bce10525a3efd0b
This commit is contained in:
Eduardo Olivares 2023-11-15 12:04:14 +01:00
parent 87cd444254
commit 11a625d215
1 changed files with 31 additions and 23 deletions

View File

@ -161,6 +161,36 @@ class DisruptTripleoNodesTest(testtools.TestCase):
disruptive_action: a function that runs some
disruptive scenario on a overcloud"""
vms_detailed_info = None
undisrupt_network_at_teardown = False
def tearDown(self):
super(DisruptTripleoNodesTest, self).tearDown()
# this loop is run after test_z99_reboot_controller_galera_main_vip
for i, vm in enumerate(self.vms_detailed_info or []):
if vm is None or vm.get('id') is None:
# server_name pattern comes from multi_ip_test_stack.yaml
server_name = "group_of_vms_%d" % i
try:
server = nova_osp.find_server(unique=True,
name=server_name)
except tobiko.ObjectNotFound:
LOG.debug(f"Server {server_name} not found. "
"Perhaps it was never created.")
continue
vm_id = server.id
else:
vm_id = vm['id']
try:
nova_osp.delete_server(vm_id)
except nova_osp.ServerNotFoundError:
LOG.debug(f"Server {vm_id} not found. "
"Perhaps it was already deleted.")
# this is run after test_network_disruptor_main_vip
if self.undisrupt_network_at_teardown:
self.undisrupt_network_at_teardown = False
cloud_disruptions.network_undisrupt_controller_main_vip()
def test_0vercloud_health_check(self):
OvercloudHealthCheck.run_before(skip_mac_table_size_test=False)
@ -204,28 +234,6 @@ class DisruptTripleoNodesTest(testtools.TestCase):
# nova.start_all_instances()
# OvercloudHealthCheck.run_after(passive_checks_only=True)
def tearDown(self):
super(DisruptTripleoNodesTest, self).tearDown()
for i, vm in enumerate(self.vms_detailed_info or []):
if vm is None or vm.get('id') is None:
# server_name pattern comes from multi_ip_test_stack.yaml
server_name = "group_of_vms_%d" % i
try:
server = nova_osp.find_server(unique=True,
name=server_name)
except tobiko.ObjectNotFound:
LOG.debug(f"Server {server_name} not found. "
"Perhaps it was never created.")
continue
vm_id = server.id
else:
vm_id = vm['id']
try:
nova_osp.delete_server(vm_id)
except nova_osp.ServerNotFoundError:
LOG.debug(f"Server {vm_id} not found. "
"Perhaps it was already deleted.")
@nova.skip_background_vm_ping_checks_when_nondvr
@testtools.skipIf(has_external_lb, SKIP_MESSAGE_EXTLB)
def test_z99_reboot_controller_galera_main_vip(self):
@ -277,9 +285,9 @@ class DisruptTripleoNodesTest(testtools.TestCase):
@testtools.skipIf(has_external_lb, SKIP_MESSAGE_EXTLB)
def test_network_disruptor_main_vip(self):
OvercloudHealthCheck.run_before()
self.undisrupt_network_at_teardown = True
cloud_disruptions.network_disrupt_controller_main_vip()
OvercloudHealthCheck.run_after()
cloud_disruptions.network_undisrupt_controller_main_vip()
# @pacemaker.skip_if_fencing_not_deployed
# def test_network_disruptor_non_main_vip(self):