Fixes new sanity_check tests deleting too many resources.
Because tests are run out of order, this will not always be re-produced, but inevitably this bug will happen. Right now, the test test_delete_multiple_images in TestSuiteImage will delete all the images in tearDownClass -- including the cls.image_id which is used by many other tests. If the TestSuiteImage tests run before tests in another suite that rely on cls.image_id, they will fail. This same scenario can also happen with the recent addition of filter component tests. These tests delete the resources created by the test at the end of the test. But eventually, when these tests fail, that code will not run, causing many other tests to fail, making debugging very hard as well. This patch adds addCleanup at the beginning of these tests so that deletion always works and prevents the cls.image_id from being deleted. Change-Id: If199d560870a138d250bfba332da90e557693a03
This commit is contained in:
parent
a73cb4b7bb
commit
fc34a1aaf5
|
@ -424,22 +424,19 @@ class ImageTestCase(PackageBase):
|
|||
glance_endpoint = cls.service_catalog.url_for(service_type='image')
|
||||
cls.glance = gclient.Client('1', endpoint=glance_endpoint,
|
||||
session=cls.keystone_client.session)
|
||||
cls.images = []
|
||||
cls.image_title = 'New Image ' + str(time.time())
|
||||
cls.image = cls.upload_image(cls.image_title)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(ImageTestCase, cls).tearDownClass()
|
||||
for image in cls.images:
|
||||
cls.glance.images.delete(image.id)
|
||||
cls.glance.images.delete(cls.image.id)
|
||||
|
||||
@classmethod
|
||||
def upload_image(cls, title):
|
||||
try:
|
||||
property = {'murano_image_info': json.dumps({'title': title,
|
||||
'type': 'linux'})}
|
||||
|
||||
image = cls.glance.images.create(name='TestImage',
|
||||
disk_format='qcow2',
|
||||
size=0,
|
||||
|
@ -448,7 +445,6 @@ class ImageTestCase(PackageBase):
|
|||
except Exception:
|
||||
logger.error("Unable to create or update image in Glance")
|
||||
raise
|
||||
cls.images.append(image)
|
||||
return image
|
||||
|
||||
def select_and_click_element(self, element):
|
||||
|
|
|
@ -26,6 +26,7 @@ from selenium.webdriver.common import by
|
|||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support import ui
|
||||
|
||||
from muranoclient.common import exceptions as muranoclient_exc
|
||||
from muranodashboard.tests.functional import base
|
||||
from muranodashboard.tests.functional.config import config as cfg
|
||||
from muranodashboard.tests.functional import consts as c
|
||||
|
@ -569,6 +570,7 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
metadata, **manifest_kwargs)
|
||||
apps_by_name.append(app_name)
|
||||
packages.append(pkg_id)
|
||||
self.addCleanup(self.murano_client.packages.delete, pkg_id)
|
||||
|
||||
self.navigate_to('Applications')
|
||||
self.go_to_submenu('Environments')
|
||||
|
@ -585,9 +587,6 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
self.check_element_not_on_page(by.By.XPATH,
|
||||
c.Component.format(app_name))
|
||||
|
||||
for pkg_id in packages:
|
||||
self.murano_client.packages.delete(pkg_id)
|
||||
|
||||
def test_filter_component_by_description(self):
|
||||
"""Test filtering components by description.
|
||||
|
||||
|
@ -616,6 +615,7 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
metadata, **manifest_kwargs)
|
||||
apps_by_description[app_name] = description
|
||||
packages.append(pkg_id)
|
||||
self.addCleanup(self.murano_client.packages.delete, pkg_id)
|
||||
|
||||
self.navigate_to('Applications')
|
||||
self.go_to_submenu('Environments')
|
||||
|
@ -634,9 +634,6 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
self.check_element_not_on_page(
|
||||
by.By.XPATH, c.Component.format(app_description))
|
||||
|
||||
for pkg_id in packages:
|
||||
self.murano_client.packages.delete(pkg_id)
|
||||
|
||||
def test_filter_component_by_tag(self):
|
||||
"""Test filtering components by tag.
|
||||
|
||||
|
@ -699,6 +696,7 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
metadata)
|
||||
apps_by_name.append(app_name)
|
||||
packages.append(pkg_id)
|
||||
self.addCleanup(self.murano_client.packages.delete, pkg_id)
|
||||
|
||||
self.navigate_to('Applications')
|
||||
self.go_to_submenu('Environments')
|
||||
|
@ -712,9 +710,6 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
|
|||
self.check_element_on_page(by.By.XPATH,
|
||||
c.Component.format(app_name))
|
||||
|
||||
for pkg_id in packages:
|
||||
self.murano_client.packages.delete(pkg_id)
|
||||
|
||||
def test_deploy_env_from_table_view(self):
|
||||
"""Test that deploy environment works from the table view.
|
||||
|
||||
|
@ -847,12 +842,19 @@ class TestSuiteImage(base.ImageTestCase):
|
|||
a. Check that the current image was deleted.
|
||||
8. Check that ``self.image_title`` was also deleted.
|
||||
"""
|
||||
def _try_delete_image(image_id):
|
||||
try:
|
||||
self.glance.images.delete(image_id)
|
||||
except muranoclient_exc.HTTPNotFound:
|
||||
pass
|
||||
|
||||
default_image_title = self.image_title
|
||||
image_titles = []
|
||||
for i in range(3):
|
||||
image_title = self.gen_random_resource_name('image')
|
||||
image_titles.append(image_title)
|
||||
self.upload_image(image_title)
|
||||
image = self.upload_image(image_title)
|
||||
self.addCleanup(_try_delete_image, image.id)
|
||||
|
||||
self.navigate_to('Manage')
|
||||
self.go_to_submenu('Images')
|
||||
|
@ -863,7 +865,6 @@ class TestSuiteImage(base.ImageTestCase):
|
|||
by.By.XPATH, c.DeleteImageMeta.format(image_title)).click()
|
||||
with self.wait_for_page_reload():
|
||||
self.driver.find_element_by_xpath(c.ConfirmDeletion).click()
|
||||
self.wait_for_alert_message()
|
||||
self.check_element_not_on_page(
|
||||
by.By.XPATH, c.TestImage.format(image_title))
|
||||
self.check_element_on_page(
|
||||
|
@ -874,17 +875,18 @@ class TestSuiteImage(base.ImageTestCase):
|
|||
for i in range(3):
|
||||
image_title = self.gen_random_resource_name('image')
|
||||
image_titles.append(image_title)
|
||||
self.upload_image(image_title)
|
||||
image = self.upload_image(image_title)
|
||||
self.addCleanup(_try_delete_image, image.id)
|
||||
|
||||
self.go_to_submenu('Images')
|
||||
|
||||
# Check the topmost checkbox, then delete all images at the same time.
|
||||
self.go_to_submenu('Images')
|
||||
self.wait_element_is_clickable(by.By.CSS_SELECTOR,
|
||||
'label[for="ui-id-1"]').click()
|
||||
self.wait_element_is_clickable(by.By.ID,
|
||||
'marked_images__action_delete').click()
|
||||
with self.wait_for_page_reload():
|
||||
self.driver.find_element_by_xpath(c.ConfirmDeletion).click()
|
||||
self.wait_for_alert_message()
|
||||
|
||||
for image_title in image_titles:
|
||||
self.check_element_not_on_page(
|
||||
|
|
Loading…
Reference in New Issue