Merge "[Verify] Fixing tokens expiration issue when deleting Tempest resources"
This commit is contained in:
commit
dda2a81116
@ -291,9 +291,14 @@ class TempestResourcesContext(object):
|
|||||||
_write_config(self.conf_path, self.conf)
|
_write_config(self.conf_path, self.conf)
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||||
self._cleanup_roles()
|
# Tempest tests may take more than 1 hour and we should remove all
|
||||||
self._cleanup_resource("image", self._created_images)
|
# cached clients sessions to avoid tokens expiration when deleting
|
||||||
self._cleanup_resource("flavor", self._created_flavors)
|
# Tempest resources.
|
||||||
|
self.clients.clear()
|
||||||
|
|
||||||
|
self._cleanup_tempest_roles()
|
||||||
|
self._cleanup_images()
|
||||||
|
self._cleanup_flavors()
|
||||||
if "neutron" in self.available_services:
|
if "neutron" in self.available_services:
|
||||||
self._cleanup_network_resources()
|
self._cleanup_network_resources()
|
||||||
|
|
||||||
@ -366,19 +371,25 @@ class TempestResourcesContext(object):
|
|||||||
|
|
||||||
return net
|
return net
|
||||||
|
|
||||||
def _cleanup_roles(self):
|
def _cleanup_tempest_roles(self):
|
||||||
|
keystoneclient = self.clients.keystone()
|
||||||
for role in self._created_roles:
|
for role in self._created_roles:
|
||||||
LOG.debug("Deleting role '%s'" % role.name)
|
LOG.debug("Deleting role '%s'" % role.name)
|
||||||
role.delete()
|
keystoneclient.roles.delete(role.id)
|
||||||
|
|
||||||
def _cleanup_resource(self, resource_type, created_resources):
|
def _cleanup_images(self):
|
||||||
for res in created_resources:
|
glanceclient = self.clients.glance()
|
||||||
LOG.debug("Deleting %s '%s'" % (resource_type, res.name))
|
for image in self._created_images:
|
||||||
if res.id == self.conf.get("compute", "%s_ref" % resource_type):
|
LOG.debug("Deleting image '%s'" % image.name)
|
||||||
self.conf.set("compute", "%s_ref" % resource_type, "")
|
glanceclient.images.delete(image.id)
|
||||||
else:
|
self._remove_opt_value_from_config(image.id)
|
||||||
self.conf.set("compute", "%s_ref_alt" % resource_type, "")
|
|
||||||
res.delete()
|
def _cleanup_flavors(self):
|
||||||
|
novaclient = self.clients.nova()
|
||||||
|
for flavor in self._created_flavors:
|
||||||
|
LOG.debug("Deleting flavor '%s'" % flavor.name)
|
||||||
|
novaclient.flavors.delete(flavor.id)
|
||||||
|
self._remove_opt_value_from_config(flavor.id)
|
||||||
|
|
||||||
def _cleanup_network_resources(self):
|
def _cleanup_network_resources(self):
|
||||||
neutron_wrapper = network.NeutronWrapper(self.clients, task=None)
|
neutron_wrapper = network.NeutronWrapper(self.clients, task=None)
|
||||||
|
@ -425,21 +425,37 @@ class TempestResourcesContextTestCase(test.TestCase):
|
|||||||
self.assertEqual("id1", network.id)
|
self.assertEqual("id1", network.id)
|
||||||
self.assertEqual("id1", self.context._created_networks[0].id)
|
self.assertEqual("id1", self.context._created_networks[0].id)
|
||||||
|
|
||||||
def test__cleanup_roles(self):
|
def test__cleanup_tempest_roles(self):
|
||||||
self.context._created_roles = [mock.MagicMock(), mock.MagicMock()]
|
self.context._created_roles = [fakes.FakeRole(), fakes.FakeRole()]
|
||||||
|
|
||||||
self.context._cleanup_roles()
|
self.context._cleanup_tempest_roles()
|
||||||
for role in self.context._created_roles:
|
client = self.context.clients.keystone()
|
||||||
self.assertEqual(role.delete.call_count, 1)
|
self.assertEqual(client.roles.delete.call_count, 2)
|
||||||
|
|
||||||
|
def test__cleanup_images(self):
|
||||||
|
self.context._created_images = [fakes.FakeImage(id="id1"),
|
||||||
|
fakes.FakeImage(id="id2")]
|
||||||
|
|
||||||
|
self.context.conf.set("compute", "image_ref", "id1")
|
||||||
|
self.context.conf.set("compute", "image_ref_alt", "id2")
|
||||||
|
|
||||||
|
self.context._cleanup_images()
|
||||||
|
client = self.context.clients.glance()
|
||||||
|
self.assertEqual(client.images.delete.call_count, 2)
|
||||||
|
|
||||||
|
self.assertEqual("", self.context.conf.get("compute", "image_ref"))
|
||||||
|
self.assertEqual("", self.context.conf.get("compute", "image_ref_alt"))
|
||||||
|
|
||||||
|
def test__cleanup_flavors(self):
|
||||||
|
self.context._created_flavors = [fakes.FakeFlavor(id="id1"),
|
||||||
|
fakes.FakeFlavor(id="id2")]
|
||||||
|
|
||||||
def test__cleanup_resource(self):
|
|
||||||
created_flavors = [mock.MagicMock(id="id1"), mock.MagicMock(id="id2")]
|
|
||||||
self.context.conf.set("compute", "flavor_ref", "id1")
|
self.context.conf.set("compute", "flavor_ref", "id1")
|
||||||
self.context.conf.set("compute", "flavor_ref_alt", "id2")
|
self.context.conf.set("compute", "flavor_ref_alt", "id2")
|
||||||
|
|
||||||
self.context._cleanup_resource("flavor", created_flavors)
|
self.context._cleanup_flavors()
|
||||||
for flavor in self.context._created_flavors:
|
client = self.context.clients.nova()
|
||||||
self.assertEqual(flavor.delete.call_count, 1)
|
self.assertEqual(client.flavors.delete.call_count, 2)
|
||||||
|
|
||||||
self.assertEqual("", self.context.conf.get("compute", "flavor_ref"))
|
self.assertEqual("", self.context.conf.get("compute", "flavor_ref"))
|
||||||
self.assertEqual("", self.context.conf.get("compute",
|
self.assertEqual("", self.context.conf.get("compute",
|
||||||
|
Loading…
Reference in New Issue
Block a user