summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-12-12 04:54:03 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2017-12-12 05:09:08 +0100
commit9a74aa7683d34e6954eb5d0bd54253935c975c59 (patch)
tree07fb8f29eea4254c431cc6db7f7cc54fb3a1581c
parentdf6ee9b1222ebd81fa22ce3499e536abe7bcb05e (diff)
Mock time.sleep() to decrease test duration
It also returns None when getting floating ips after deleting them. It now runs 40 tests in 0.084s. Change-Id: If4b1032ab9890fd291d99beb57166ead8729d822 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/tests/unit/utils/test_openstack_clean.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py
index d85bd2ba9..afd9120a8 100644
--- a/functest/tests/unit/utils/test_openstack_clean.py
+++ b/functest/tests/unit/utils/test_openstack_clean.py
@@ -73,8 +73,9 @@ class OSCleanTesting(unittest.TestCase):
"-----------------"
"---------")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances(self, mock_logger_debug):
+ def test_remove_instances(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list):
openstack_clean.remove_instances(self.client, self.update_list)
@@ -83,16 +84,19 @@ class OSCleanTesting(unittest.TestCase):
"instance and will "
"NOT be deleted.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_missing_instances(self, mock_logger_debug):
+ def test_remove_instances_missing_instances(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=[]):
openstack_clean.remove_instances(self.client, self.update_list)
mock_logger_debug.assert_any_call("Removing Nova instances...")
mock_logger_debug.assert_any_call("No instances found.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_delete_success(self, mock_logger_debug):
+ def test_remove_instances_delete_success(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -105,8 +109,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_pending_delete_success(self, mock_logger_debug):
+ def test_remove_instances_pending_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.deleted_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -118,8 +124,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ...").assert_not_called()
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_other_delete_success(self, mock_logger_debug):
+ def test_remove_instances_other_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.other_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -132,10 +140,11 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.error')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_instances_delete_failed(self, mock_logger_debug,
- mock_logger_error):
+ mock_logger_error, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -276,7 +285,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_floatingips_delete_success(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_floating_ips',
- return_value=self.floatingips_list), \
+ side_effect=[self.floatingips_list, None]), \
mock.patch('functest.utils.openstack_clean.os_utils'
'.delete_floating_ip', return_value=True):
openstack_clean.remove_floatingips(self.client, self.remove_list)
@@ -306,12 +315,13 @@ class OSCleanTesting(unittest.TestCase):
RegexMatch("Removing floating "
"IP \s*\S+ ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \
@@ -331,12 +341,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_missing_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list', return_value=None), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -354,12 +365,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_delete_success(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
@@ -385,6 +397,7 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.remove_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.error')
@@ -392,7 +405,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_networks_delete_failed(self, mock_logger_debug,
mock_logger_error,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \