aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/core/singlevm.py18
-rw-r--r--functest/core/tenantnetwork.py21
-rw-r--r--functest/opnfv_tests/openstack/cinder/cinder_test.py13
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py3
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py6
-rw-r--r--functest/opnfv_tests/openstack/vmtp/vmtp.py3
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py7
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py14
-rw-r--r--functest/tests/unit/openstack/vping/test_vping_ssh.py14
9 files changed, 64 insertions, 35 deletions
diff --git a/functest/core/singlevm.py b/functest/core/singlevm.py
index 23f453722..ad79a8e14 100644
--- a/functest/core/singlevm.py
+++ b/functest/core/singlevm.py
@@ -186,8 +186,10 @@ class VmReady1(tenantnetwork.TenantNetwork1):
assert self.orig_cloud
assert self.cloud
super(VmReady1, self).clean()
- self.cloud.delete_image(self.image.id)
- self.orig_cloud.delete_flavor(self.flavor.id)
+ if self.image:
+ self.cloud.delete_image(self.image.id)
+ if self.flavor:
+ self.orig_cloud.delete_flavor(self.flavor.id)
except Exception: # pylint: disable=broad-except
self.__logger.exception("Cannot clean all ressources")
@@ -368,10 +370,14 @@ class SingleVm1(VmReady1):
try:
assert self.orig_cloud
assert self.cloud
- self.cloud.delete_floating_ip(self.fip.id)
- self.cloud.delete_server(self.sshvm, wait=True)
- self.cloud.delete_security_group(self.sec.id)
- self.cloud.delete_keypair(self.keypair.name)
+ if self.fip:
+ self.cloud.delete_floating_ip(self.fip.id)
+ if self.sshvm:
+ self.cloud.delete_server(self.sshvm, wait=True)
+ if self.sec:
+ self.cloud.delete_security_group(self.sec.id)
+ if self.keypair:
+ self.cloud.delete_keypair(self.keypair.name)
super(SingleVm1, self).clean()
except Exception: # pylint: disable=broad-except
self.__logger.exception("Cannot clean all ressources")
diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py
index da4ff7482..05c14c2d4 100644
--- a/functest/core/tenantnetwork.py
+++ b/functest/core/tenantnetwork.py
@@ -93,10 +93,10 @@ class NewProject(object):
"""Remove projects/users"""
try:
assert self.orig_cloud
- assert self.user.id
- assert self.project.id
- self.orig_cloud.delete_user(self.user.id)
- self.orig_cloud.delete_project(self.project.id)
+ if self.user:
+ self.orig_cloud.delete_user(self.user.id)
+ if self.project:
+ self.orig_cloud.delete_project(self.project.id)
if self.role:
self.orig_cloud.delete_role(self.role.id)
except Exception: # pylint: disable=broad-except
@@ -210,10 +210,15 @@ class TenantNetwork1(testcase.TestCase):
def clean(self):
try:
assert self.cloud
- self.cloud.remove_router_interface(self.router, self.subnet.id)
- self.cloud.delete_router(self.router.id)
- self.cloud.delete_subnet(self.subnet.id)
- self.cloud.delete_network(self.network.id)
+ if self.router:
+ if self.subnet:
+ self.cloud.remove_router_interface(
+ self.router, self.subnet.id)
+ self.cloud.delete_router(self.router.id)
+ if self.subnet:
+ self.cloud.delete_subnet(self.subnet.id)
+ if self.network:
+ self.cloud.delete_network(self.network.id)
except Exception: # pylint: disable=broad-except
self.__logger.exception("cannot clean all ressources")
diff --git a/functest/opnfv_tests/openstack/cinder/cinder_test.py b/functest/opnfv_tests/openstack/cinder/cinder_test.py
index 7d4b4358b..5354291e6 100644
--- a/functest/opnfv_tests/openstack/cinder/cinder_test.py
+++ b/functest/opnfv_tests/openstack/cinder/cinder_test.py
@@ -111,9 +111,12 @@ class CinderCheck(singlevm.SingleVm2):
def clean(self):
assert self.cloud
- self.cloud.delete_server(
- self.vm2, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
- self.cloud.delete_floating_ip(self.fip2.id)
- self.cloud.delete_volume(self.volume.id)
+ if self.vm2:
+ self.cloud.delete_server(
+ self.vm2, wait=True,
+ timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
+ if self.fip2:
+ self.cloud.delete_floating_ip(self.fip2.id)
+ if self.volume:
+ self.cloud.delete_volume(self.volume.id)
super(CinderCheck, self).clean()
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index 49379e991..2cdb03cb3 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -479,7 +479,8 @@ class RallyBase(singlevm.VmReady1):
def clean(self):
"""Cleanup of OpenStack resources. Should be called on completion."""
super(RallyBase, self).clean()
- self.orig_cloud.delete_flavor(self.flavor_alt.id)
+ if self.flavor_alt:
+ self.orig_cloud.delete_flavor(self.flavor_alt.id)
def is_successful(self):
"""The overall result of the test."""
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 168e28907..40954de2c 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -308,5 +308,7 @@ class TempestCommon(singlevm.VmReady1):
Cleanup all OpenStack objects. Should be called on completion.
"""
super(TempestCommon, self).clean()
- self.cloud.delete_image(self.image_alt)
- self.orig_cloud.delete_flavor(self.flavor_alt.id)
+ if self.image_alt:
+ self.cloud.delete_image(self.image_alt)
+ if self.flavor_alt:
+ self.orig_cloud.delete_flavor(self.flavor_alt.id)
diff --git a/functest/opnfv_tests/openstack/vmtp/vmtp.py b/functest/opnfv_tests/openstack/vmtp/vmtp.py
index 52d1d6d75..326a4f383 100644
--- a/functest/opnfv_tests/openstack/vmtp/vmtp.py
+++ b/functest/opnfv_tests/openstack/vmtp/vmtp.py
@@ -146,7 +146,8 @@ class Vmtp(singlevm.VmReady1):
assert self.cloud
os.remove(self.privkey_filename)
os.remove(self.pubkey_filename)
- self.cloud.delete_image(self.image)
+ if self.image:
+ self.cloud.delete_image(self.image)
self.cloud.delete_network("pns-internal-net_{}".format(self.guid))
self.cloud.delete_network("pns-internal-net2_{}".format(self.guid))
except Exception: # pylint: disable=broad-except
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 1fd2d975f..643f4f6de 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -51,7 +51,8 @@ class VPingSSH(singlevm.SingleVm2):
def clean(self):
assert self.cloud
- self.cloud.delete_server(
- self.vm2, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
+ if self.vm2:
+ self.cloud.delete_server(
+ self.vm2, wait=True,
+ timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
super(VPingSSH, self).clean()
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index 3b0a1a9e1..421ea6a2c 100644
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -122,10 +122,12 @@ class VPingUserdata(singlevm.VmReady2):
def clean(self):
assert self.cloud
- self.cloud.delete_server(
- self.vm1, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
- self.cloud.delete_server(
- self.vm2, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
+ if self.vm1:
+ self.cloud.delete_server(
+ self.vm1, wait=True,
+ timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
+ if self.vm2:
+ self.cloud.delete_server(
+ self.vm2, wait=True,
+ timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
super(VPingUserdata, self).clean()
diff --git a/functest/tests/unit/openstack/vping/test_vping_ssh.py b/functest/tests/unit/openstack/vping/test_vping_ssh.py
index 589668efc..3595638ec 100644
--- a/functest/tests/unit/openstack/vping/test_vping_ssh.py
+++ b/functest/tests/unit/openstack/vping/test_vping_ssh.py
@@ -92,6 +92,7 @@ class VpingSSHTesting(unittest.TestCase):
self.vping.clean()
def test_clean_exc2(self):
+ self.vping.vm2 = munch.Munch(id='vm2')
mdelete_server = self.vping.cloud.delete_server
mdelete_server.side_effect = shade.OpenStackCloudException(None)
with self.assertRaises(shade.OpenStackCloudException):
@@ -100,7 +101,7 @@ class VpingSSHTesting(unittest.TestCase):
@mock.patch('functest.core.singlevm.SingleVm2.clean',
side_effect=Exception)
def test_clean_exc3(self, *args):
- self.vping.vm2 = munch.Munch()
+ self.vping.vm2 = munch.Munch(id='vm2')
with self.assertRaises(Exception):
self.vping.clean()
self.vping.cloud.delete_server.assert_called_once_with(
@@ -109,8 +110,15 @@ class VpingSSHTesting(unittest.TestCase):
args[0].assert_called_once_with()
@mock.patch('functest.core.singlevm.SingleVm2.clean')
- def test_clean(self, *args):
- self.vping.vm2 = munch.Munch()
+ def test_clean1(self, *args):
+ self.vping.vm2 = None
+ self.vping.clean()
+ self.vping.cloud.delete_server.assert_not_called()
+ args[0].assert_called_once_with()
+
+ @mock.patch('functest.core.singlevm.SingleVm2.clean')
+ def test_clean2(self, *args):
+ self.vping.vm2 = munch.Munch(id='vm2')
self.vping.clean()
self.vping.cloud.delete_server.assert_called_once_with(
self.vping.vm2, wait=True,