summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-09-28 22:28:23 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-09-28 22:28:23 +0000
commitb2d53a8952ee5a3977ee75b25a4aacde81acc34e (patch)
tree1ead9f47122d6dae7790ff453c1cb25e6aee4a9e /nova
parent8e9a2ac7fe19ca8319b27b4cf779b255926033a0 (diff)
Use test.TestCase provided self.mox and self.stubs
Since these test cases subclass test.TestCase, it's unnecessary to create a new self._mox when self.mox already exists. Also, self.stubs already exists. Finally, it's unnecessary to call VerifyAll() since test.TestCase does that as well. Change-Id: Ib5a176d9d3448f3eb86d13ca6199d1ea557480d0
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_netapp_nfs.py37
-rw-r--r--nova/tests/test_nfs.py103
2 files changed, 34 insertions, 106 deletions
diff --git a/nova/tests/test_netapp_nfs.py b/nova/tests/test_netapp_nfs.py
index 2a0b4ffde..49a93728d 100644
--- a/nova/tests/test_netapp_nfs.py
+++ b/nova/tests/test_netapp_nfs.py
@@ -72,13 +72,10 @@ class NetappNfsDriverTestCase(test.TestCase):
def setUp(self):
self._driver = netapp_nfs.NetAppNFSDriver()
- self._mox = mox.Mox()
-
- def tearDown(self):
- self._mox.UnsetStubs()
+ super(NetappNfsDriverTestCase, self).setUp()
def test_check_for_setup_error(self):
- mox = self._mox
+ mox = self.mox
drv = self._driver
required_flags = [
'netapp_wsdl_url',
@@ -102,14 +99,12 @@ class NetappNfsDriverTestCase(test.TestCase):
drv.check_for_setup_error()
- mox.VerifyAll()
-
# restore initial FLAGS
for flag in required_flags:
delattr(netapp.FLAGS, flag)
def test_do_setup(self):
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, 'check_for_setup_error')
@@ -122,11 +117,9 @@ class NetappNfsDriverTestCase(test.TestCase):
drv.do_setup(IsA(context.RequestContext))
- mox.VerifyAll()
-
def test_create_snapshot(self):
"""Test snapshot can be created and deleted"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_clone_volume')
@@ -135,12 +128,10 @@ class NetappNfsDriverTestCase(test.TestCase):
drv.create_snapshot(FakeSnapshot())
- mox.VerifyAll()
-
def test_create_volume_from_snapshot(self):
"""Tests volume creation from snapshot"""
drv = self._driver
- mox = self._mox
+ mox = self.mox
volume = FakeVolume(1)
snapshot = FakeSnapshot(2)
@@ -164,11 +155,9 @@ class NetappNfsDriverTestCase(test.TestCase):
self.assertEquals(loc, expected_result)
- mox.VerifyAll()
-
def _prepare_delete_snapshot_mock(self, snapshot_exists):
drv = self._driver
- mox = self._mox
+ mox = self.mox
mox.StubOutWithMock(drv, '_get_provider_location')
mox.StubOutWithMock(drv, '_volume_not_present')
@@ -191,23 +180,19 @@ class NetappNfsDriverTestCase(test.TestCase):
def test_delete_existing_snapshot(self):
drv = self._driver
- mox = self._prepare_delete_snapshot_mock(True)
+ self._prepare_delete_snapshot_mock(True)
drv.delete_snapshot(FakeSnapshot())
- mox.VerifyAll()
-
def test_delete_missing_snapshot(self):
drv = self._driver
- mox = self._prepare_delete_snapshot_mock(False)
+ self._prepare_delete_snapshot_mock(False)
drv.delete_snapshot(FakeSnapshot())
- mox.VerifyAll()
-
def _prepare_clone_mock(self, status):
drv = self._driver
- mox = self._mox
+ mox = self.mox
volume = FakeVolume()
setattr(volume, 'provider_location', '127.0.0.1:/nfs')
@@ -242,8 +227,6 @@ class NetappNfsDriverTestCase(test.TestCase):
drv._clone_volume(volume_name, clone_name, volume_id)
- mox.VerifyAll()
-
def test_failed_clone_volume(self):
drv = self._driver
mox = self._prepare_clone_mock('failed')
@@ -257,5 +240,3 @@ class NetappNfsDriverTestCase(test.TestCase):
self.assertRaises(exception.NovaException,
drv._clone_volume,
volume_name, clone_name, volume_id)
-
- mox.VerifyAll()
diff --git a/nova/tests/test_nfs.py b/nova/tests/test_nfs.py
index 4c97f128a..ddfee2fd1 100644
--- a/nova/tests/test_nfs.py
+++ b/nova/tests/test_nfs.py
@@ -58,12 +58,7 @@ class NfsDriverTestCase(test.TestCase):
def setUp(self):
self._driver = nfs.NfsDriver()
- self._mox = mox_lib.Mox()
- self.stubs = stubout.StubOutForTesting()
-
- def tearDown(self):
- self._mox.UnsetStubs()
- self.stubs.UnsetAll()
+ super(NfsDriverTestCase, self).setUp()
def stub_out_not_replaying(self, obj, attr_name):
attr_to_replace = getattr(obj, attr_name)
@@ -72,7 +67,7 @@ class NfsDriverTestCase(test.TestCase):
def test_path_exists_should_return_true(self):
"""_path_exists should return True if stat returns 0"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_execute')
@@ -82,11 +77,9 @@ class NfsDriverTestCase(test.TestCase):
self.assertTrue(drv._path_exists(self.TEST_FILE_NAME))
- mox.VerifyAll()
-
def test_path_exists_should_return_false(self):
"""_path_exists should return True if stat doesn't return 0"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_execute')
@@ -98,8 +91,6 @@ class NfsDriverTestCase(test.TestCase):
self.assertFalse(drv._path_exists(self.TEST_FILE_NAME))
- mox.VerifyAll()
-
def test_local_path(self):
"""local_path common use case"""
nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE
@@ -115,7 +106,7 @@ class NfsDriverTestCase(test.TestCase):
def test_mount_nfs_should_mount_correctly(self):
"""_mount_nfs common case usage"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
@@ -129,12 +120,10 @@ class NfsDriverTestCase(test.TestCase):
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
- mox.VerifyAll()
-
def test_mount_nfs_should_suppress_already_mounted_error(self):
"""_mount_nfs should suppress already mounted error if ensure=True
"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
@@ -150,12 +139,10 @@ class NfsDriverTestCase(test.TestCase):
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, ensure=True)
- mox.VerifyAll()
-
def test_mount_nfs_should_reraise_already_mounted_error(self):
"""_mount_nfs should not suppress already mounted error if ensure=False
"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
@@ -172,11 +159,9 @@ class NfsDriverTestCase(test.TestCase):
self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT,
ensure=False)
- mox.VerifyAll()
-
def test_mount_nfs_should_create_mountpoint_if_not_yet(self):
"""_mount_nfs should create mountpoint if it doesn't exist"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
@@ -190,11 +175,9 @@ class NfsDriverTestCase(test.TestCase):
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
- mox.VerifyAll()
-
def test_mount_nfs_should_not_create_mountpoint_if_already(self):
"""_mount_nfs should not create mountpoint if it already exists"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
@@ -207,8 +190,6 @@ class NfsDriverTestCase(test.TestCase):
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
- mox.VerifyAll()
-
def test_get_hash_str(self):
"""_get_hash_str should calculation correct value"""
drv = self._driver
@@ -227,7 +208,7 @@ class NfsDriverTestCase(test.TestCase):
def test_get_available_capacity_with_df(self):
"""_get_available_capacity should calculate correct value"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
df_avail = 1490560
@@ -250,13 +231,11 @@ class NfsDriverTestCase(test.TestCase):
self.assertEquals(df_avail,
drv._get_available_capacity(self.TEST_NFS_EXPORT1))
- mox.VerifyAll()
-
delattr(nfs.FLAGS, 'nfs_disk_util')
def test_get_available_capacity_with_du(self):
"""_get_available_capacity should calculate correct value"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
setattr(nfs.FLAGS, 'nfs_disk_util', 'du')
@@ -291,12 +270,10 @@ class NfsDriverTestCase(test.TestCase):
self.assertEquals(df_total_size - du_used,
drv._get_available_capacity(self.TEST_NFS_EXPORT1))
- mox.VerifyAll()
-
delattr(nfs.FLAGS, 'nfs_disk_util')
def test_load_shares_config(self):
- mox = self._mox
+ mox = self.mox
drv = self._driver
nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
@@ -313,11 +290,9 @@ class NfsDriverTestCase(test.TestCase):
self.assertEqual([self.TEST_NFS_EXPORT1], shares)
- mox.VerifyAll()
-
def test_ensure_share_mounted(self):
"""_ensure_share_mounted simple use case"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_get_mount_point_for_share')
@@ -331,11 +306,9 @@ class NfsDriverTestCase(test.TestCase):
drv._ensure_share_mounted(self.TEST_NFS_EXPORT1)
- mox.VerifyAll()
-
def test_ensure_shares_mounted_should_save_mounting_successfully(self):
"""_ensure_shares_mounted should save share if mounted with success"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_load_shares_config')
@@ -350,11 +323,9 @@ class NfsDriverTestCase(test.TestCase):
self.assertEqual(1, len(drv._mounted_shares))
self.assertEqual(self.TEST_NFS_EXPORT1, drv._mounted_shares[0])
- mox.VerifyAll()
-
def test_ensure_shares_mounted_should_not_save_mounting_with_error(self):
"""_ensure_shares_mounted should not save share if failed to mount"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
mox.StubOutWithMock(drv, '_load_shares_config')
@@ -368,8 +339,6 @@ class NfsDriverTestCase(test.TestCase):
self.assertEqual(0, len(drv._mounted_shares))
- mox.VerifyAll()
-
def test_setup_should_throw_error_if_shares_config_not_configured(self):
"""do_setup should throw error if shares config is not configured """
drv = self._driver
@@ -381,7 +350,7 @@ class NfsDriverTestCase(test.TestCase):
def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self):
"""do_setup should throw error if nfs client is not installed """
- mox = self._mox
+ mox = self.mox
drv = self._driver
nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
@@ -397,8 +366,6 @@ class NfsDriverTestCase(test.TestCase):
self.assertRaises(exception.NfsException,
drv.do_setup, IsA(context.RequestContext))
- mox.VerifyAll()
-
def test_find_share_should_throw_error_if_there_is_no_mounted_shares(self):
"""_find_share should throw error if there is no mounted shares"""
drv = self._driver
@@ -410,7 +377,7 @@ class NfsDriverTestCase(test.TestCase):
def test_find_share(self):
"""_find_share simple use case"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
drv._mounted_shares = [self.TEST_NFS_EXPORT1, self.TEST_NFS_EXPORT2]
@@ -426,11 +393,9 @@ class NfsDriverTestCase(test.TestCase):
self.assertEqual(self.TEST_NFS_EXPORT2,
drv._find_share(self.TEST_SIZE_IN_GB))
- mox.VerifyAll()
-
def test_find_share_should_throw_error_if_there_is_no_enough_place(self):
"""_find_share should throw error if there is no share to host vol"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
drv._mounted_shares = [self.TEST_NFS_EXPORT1, self.TEST_NFS_EXPORT2]
@@ -446,8 +411,6 @@ class NfsDriverTestCase(test.TestCase):
self.assertRaises(exception.NfsNoSuitableShareFound, drv._find_share,
self.TEST_SIZE_IN_GB)
- mox.VerifyAll()
-
def _simple_volume(self):
volume = DumbVolume()
volume['provider_location'] = '127.0.0.1:/mnt'
@@ -457,7 +420,7 @@ class NfsDriverTestCase(test.TestCase):
return volume
def test_create_sparsed_volume(self):
- mox = self._mox
+ mox = self.mox
drv = self._driver
volume = self._simple_volume()
@@ -473,12 +436,10 @@ class NfsDriverTestCase(test.TestCase):
drv._do_create_volume(volume)
- mox.VerifyAll()
-
delattr(nfs.FLAGS, 'nfs_sparsed_volumes')
def test_create_nonsparsed_volume(self):
- mox = self._mox
+ mox = self.mox
drv = self._driver
volume = self._simple_volume()
@@ -494,13 +455,11 @@ class NfsDriverTestCase(test.TestCase):
drv._do_create_volume(volume)
- mox.VerifyAll()
-
delattr(nfs.FLAGS, 'nfs_sparsed_volumes')
def test_create_volume_should_ensure_nfs_mounted(self):
"""create_volume should ensure shares provided in config are mounted"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(nfs, 'LOG')
@@ -516,11 +475,9 @@ class NfsDriverTestCase(test.TestCase):
volume['size'] = self.TEST_SIZE_IN_GB
drv.create_volume(volume)
- mox.VerifyAll()
-
def test_create_volume_should_return_provider_location(self):
"""create_volume should return provider_location with found share """
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(nfs, 'LOG')
@@ -537,11 +494,9 @@ class NfsDriverTestCase(test.TestCase):
result = drv.create_volume(volume)
self.assertEqual(self.TEST_NFS_EXPORT1, result['provider_location'])
- mox.VerifyAll()
-
def test_delete_volume(self):
"""delete_volume simple test case"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
@@ -563,11 +518,9 @@ class NfsDriverTestCase(test.TestCase):
drv.delete_volume(volume)
- mox.VerifyAll()
-
def test_delete_should_ensure_share_mounted(self):
"""delete_volume should ensure that corresponding share is mounted"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(drv, '_execute')
@@ -583,11 +536,9 @@ class NfsDriverTestCase(test.TestCase):
drv.delete_volume(volume)
- mox.VerifyAll()
-
def test_delete_should_not_delete_if_provider_location_not_provided(self):
"""delete_volume shouldn't try to delete if provider_location missed"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
@@ -602,11 +553,9 @@ class NfsDriverTestCase(test.TestCase):
drv.delete_volume(volume)
- mox.VerifyAll()
-
def test_delete_should_not_delete_if_there_is_no_file(self):
"""delete_volume should not try to delete if file missed"""
- mox = self._mox
+ mox = self.mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
@@ -626,5 +575,3 @@ class NfsDriverTestCase(test.TestCase):
mox.ReplayAll()
drv.delete_volume(volume)
-
- mox.VerifyAll()