Delegate tearDown logic to addCleanup method
tearDown doesn't work if setUp is failed, for ex. https://bugs.launchpad.net/searchlight/+bug/1557287 https://bugs.launchpad.net/horizon/+bug/1405553 Change-Id: I4e02dfbd6dc902d50dd47f8441919aa5e29b3101 Closed-Bug: #1405553
This commit is contained in:
parent
63be880cc2
commit
c3da75ab5a
@ -107,6 +107,9 @@ class BaseTestCase(testtools.TestCase):
|
||||
else:
|
||||
self.vdisplay.xvfb_cmd.extend(args)
|
||||
self.vdisplay.start()
|
||||
|
||||
self.addCleanup(self.vdisplay.stop)
|
||||
|
||||
# Increase the default Python socket timeout from nothing
|
||||
# to something that will cope with slow webdriver startup times.
|
||||
# This *just* affects the communication between this test process
|
||||
@ -123,6 +126,9 @@ class BaseTestCase(testtools.TestCase):
|
||||
self.driver.implicitly_wait(self.CONFIG.selenium.implicit_wait)
|
||||
self.driver.set_page_load_timeout(
|
||||
self.CONFIG.selenium.page_timeout)
|
||||
|
||||
self.addCleanup(self.driver.quit)
|
||||
|
||||
self.addOnException(self._attach_page_source)
|
||||
self.addOnException(self._attach_screenshot)
|
||||
self.addOnException(self._attach_browser_log)
|
||||
@ -214,13 +220,6 @@ class BaseTestCase(testtools.TestCase):
|
||||
html_elem = self.driver.find_element_by_tag_name("html")
|
||||
return html_elem.get_attribute("innerHTML").encode("utf-8")
|
||||
|
||||
def tearDown(self):
|
||||
if os.environ.get('INTEGRATION_TESTS', False):
|
||||
self.driver.quit()
|
||||
if hasattr(self, 'vdisplay'):
|
||||
self.vdisplay.stop()
|
||||
super(BaseTestCase, self).tearDown()
|
||||
|
||||
|
||||
class TestCase(BaseTestCase, AssertsMixin):
|
||||
|
||||
@ -241,13 +240,12 @@ class TestCase(BaseTestCase, AssertsMixin):
|
||||
self.assertFalse(
|
||||
self.home_pg.find_message_and_dismiss(messages.ERROR))
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
def cleanup():
|
||||
if self.home_pg.is_logged_in:
|
||||
self.home_pg.go_to_home_page()
|
||||
self.home_pg.log_out()
|
||||
finally:
|
||||
super(TestCase, self).tearDown()
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
|
||||
class AdminTestCase(TestCase, AssertsMixin):
|
||||
|
@ -34,6 +34,13 @@ class TestDownloadRCFile(helpers.AdminTestCase):
|
||||
'OS_TENANT_NAME': tenant_name,
|
||||
'OS_TENANT_ID': tenant_id}
|
||||
|
||||
def cleanup():
|
||||
temporary_files = listdir(self._directory)
|
||||
if len(temporary_files):
|
||||
remove(join(self._directory, temporary_files[0]))
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
def test_download_rc_v2_file(self):
|
||||
"""This is a basic scenario test:
|
||||
Steps:
|
||||
@ -70,9 +77,3 @@ class TestDownloadRCFile(helpers.AdminTestCase):
|
||||
cred_dict = api_access_page.get_credentials_from_file(
|
||||
3, self._directory, self._openrc_template)
|
||||
self.assertEqual(cred_dict, self.actual_dict)
|
||||
|
||||
def tearDown(self):
|
||||
super(TestDownloadRCFile, self).tearDown()
|
||||
temporary_files = listdir(self._directory)
|
||||
if len(temporary_files):
|
||||
remove(join(self._directory, temporary_files[0]))
|
||||
|
@ -48,6 +48,13 @@ class TestModifyProject(helpers.AdminTestCase):
|
||||
self.assertTrue(
|
||||
self.projects_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
|
||||
def cleanup():
|
||||
if not self.projects_page.is_the_current_page():
|
||||
self.home_pg.go_to_identity_projectspage()
|
||||
self.projects_page.delete_project(PROJECT_NAME)
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
def test_add_member(self):
|
||||
admin_name = self.CONFIG.identity.admin_username
|
||||
regular_role_name = self.CONFIG.identity.default_keystone_role
|
||||
@ -65,9 +72,3 @@ class TestModifyProject(helpers.AdminTestCase):
|
||||
admin_name, PROJECT_NAME)
|
||||
self.assertEqual(roles2add, user_roles,
|
||||
"The requested roles haven't been set for the user!")
|
||||
|
||||
def tearDown(self):
|
||||
if not self.projects_page.is_the_current_page():
|
||||
self.home_pg.go_to_identity_projectspage()
|
||||
self.projects_page.delete_project(PROJECT_NAME)
|
||||
super(TestModifyProject, self).tearDown()
|
||||
|
@ -31,6 +31,14 @@ class TestStacks(helpers.AdminTestCase):
|
||||
go_to_compute_accessandsecurity_keypairspage()
|
||||
self.assertTrue(keypair_page.is_keypair_present(self.KEYPAIR_NAME))
|
||||
|
||||
def cleanup():
|
||||
keypair_page = self.home_pg.\
|
||||
go_to_compute_accessandsecurity_keypairspage()
|
||||
keypair_page.delete_keypairs(self.KEYPAIR_NAME)
|
||||
keypair_page.find_message_and_dismiss(messages.SUCCESS)
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
@decorators.skip_because(bugs=['1584057'])
|
||||
@decorators.services_required("heat")
|
||||
def test_create_delete_stack(self):
|
||||
@ -62,10 +70,3 @@ class TestStacks(helpers.AdminTestCase):
|
||||
self.assertFalse(
|
||||
stacks_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(stacks_page.is_stack_deleted(self.STACKS_NAME))
|
||||
|
||||
def tearDown(self):
|
||||
keypair_page = self.home_pg.\
|
||||
go_to_compute_accessandsecurity_keypairspage()
|
||||
keypair_page.delete_keypairs(self.KEYPAIR_NAME)
|
||||
keypair_page.find_message_and_dismiss(messages.SUCCESS)
|
||||
super(TestStacks, self).tearDown()
|
||||
|
@ -33,6 +33,16 @@ class TestVolumeSnapshotsBasic(helpers.TestCase):
|
||||
self.assertTrue(volumes_page.is_volume_status(self.VOLUME_NAME,
|
||||
'Available'))
|
||||
|
||||
def cleanup():
|
||||
volumes_snapshot_page = \
|
||||
self.home_pg.go_to_compute_volumes_volumesnapshotspage()
|
||||
volumes_page = volumes_snapshot_page.switch_to_volumes_tab()
|
||||
volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
volumes_page.find_message_and_dismiss(messages.SUCCESS)
|
||||
self.assertTrue(volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
def test_create_edit_delete_volume_snapshot(self):
|
||||
"""Test checks create/delete volume snapshot action
|
||||
Steps:
|
||||
@ -158,16 +168,6 @@ class TestVolumeSnapshotsBasic(helpers.TestCase):
|
||||
for name in snapshot_names:
|
||||
volumes_snapshot_page.is_volume_snapshot_deleted(name)
|
||||
|
||||
def tearDown(self):
|
||||
"""Clean up: delete volume"""
|
||||
volumes_snapshot_page = \
|
||||
self.home_pg.go_to_compute_volumes_volumesnapshotspage()
|
||||
volumes_page = volumes_snapshot_page.switch_to_volumes_tab()
|
||||
volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
volumes_page.find_message_and_dismiss(messages.SUCCESS)
|
||||
self.assertTrue(volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
super(TestVolumeSnapshotsBasic, self).tearDown()
|
||||
|
||||
|
||||
class TestVolumeSnapshotsAdmin(helpers.AdminTestCase,
|
||||
TestVolumeSnapshotsBasic):
|
||||
@ -208,6 +208,19 @@ class TestVolumeSnapshotsAdvanced(helpers.TestCase):
|
||||
self.assertTrue(volumes_page.is_volume_status(self.VOLUME_NAME,
|
||||
'Available'))
|
||||
|
||||
def cleanup():
|
||||
volumes_snapshot_page = \
|
||||
self.home_pg.go_to_compute_volumes_volumesnapshotspage()
|
||||
volumes_page = volumes_snapshot_page.switch_to_volumes_tab()
|
||||
volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
self.assertTrue(
|
||||
volumes_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
self.assertFalse(
|
||||
volumes_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
def test_create_volume_from_snapshot(self):
|
||||
"""Test checks possibility to create volume from snapshot
|
||||
Steps:
|
||||
@ -248,15 +261,3 @@ class TestVolumeSnapshotsAdvanced(helpers.TestCase):
|
||||
volumes_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
self.assertFalse(volumes_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(volumes_page.is_volume_deleted(new_volume))
|
||||
|
||||
def tearDown(self):
|
||||
"""Clean up: delete volume"""
|
||||
volumes_snapshot_page = \
|
||||
self.home_pg.go_to_compute_volumes_volumesnapshotspage()
|
||||
volumes_page = volumes_snapshot_page.switch_to_volumes_tab()
|
||||
volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
self.assertTrue(
|
||||
volumes_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
self.assertFalse(volumes_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
super(TestVolumeSnapshotsAdvanced, self).tearDown()
|
||||
|
@ -239,6 +239,17 @@ class TestVolumesActions(helpers.TestCase):
|
||||
self.assertTrue(self.volumes_page.is_volume_status(self.VOLUME_NAME,
|
||||
'Available'))
|
||||
|
||||
def cleanup():
|
||||
self.volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
self.assertTrue(
|
||||
self.volumes_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
self.assertFalse(
|
||||
self.volumes_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(
|
||||
self.volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
def test_volume_extend(self):
|
||||
"""This test case checks extend volume functionality:
|
||||
Steps:
|
||||
@ -322,12 +333,3 @@ class TestVolumesActions(helpers.TestCase):
|
||||
instances_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(instances_page.is_instance_deleted(self.INSTANCE_NAME))
|
||||
self.volumes_page = self.home_pg.go_to_compute_volumes_volumespage()
|
||||
|
||||
def tearDown(self):
|
||||
self.volumes_page.delete_volume(self.VOLUME_NAME)
|
||||
self.assertTrue(
|
||||
self.volumes_page.find_message_and_dismiss(messages.SUCCESS))
|
||||
self.assertFalse(
|
||||
self.volumes_page.find_message_and_dismiss(messages.ERROR))
|
||||
self.assertTrue(self.volumes_page.is_volume_deleted(self.VOLUME_NAME))
|
||||
super(TestVolumesActions, self).tearDown()
|
||||
|
Loading…
Reference in New Issue
Block a user