from cinder.volume.drivers import vzstorage
+_orig_path_exists = os.path.exists
+
+
class VZStorageTestCase(test.TestCase):
_FAKE_SHARE = "10.0.0.1,10.0.0.2:/cluster123:123123"
self._vz_driver._execute = mock.Mock()
self._vz_driver.base = self._FAKE_MNT_BASE
+ def _path_exists(self, path):
+ if path.startswith(self._FAKE_VZ_CONFIG.vzstorage_shares_config):
+ return True
+ return _orig_path_exists(path)
+
+ def _path_dont_exists(self, path):
+ if path.startswith('/fake'):
+ return False
+ return _orig_path_exists(path)
+
@mock.patch('os.path.exists')
def test_setup_ok(self, mock_exists):
- mock_exists.return_value = True
+ mock_exists.side_effect = self._path_exists
self._vz_driver.do_setup(mock.sentinel.context)
@mock.patch('os.path.exists')
def test_setup_missing_shares_conf(self, mock_exists):
- mock_exists.return_value = False
+ mock_exists.side_effect = self._path_dont_exists
self.assertRaises(exception.VzStorageException,
self._vz_driver.do_setup,
mock.sentinel.context)
@mock.patch('os.path.exists')
def test_setup_invalid_usage_ratio(self, mock_exists):
- mock_exists.return_value = True
+ mock_exists.side_effect = self._path_exists
self._vz_driver.configuration.vzstorage_used_ratio = 1.2
self.assertRaises(exception.VzStorageException,
self._vz_driver.do_setup,
@mock.patch('os.path.exists')
def test_setup_invalid_usage_ratio2(self, mock_exists):
- mock_exists.return_value = True
+ mock_exists.side_effect = self._path_exists
self._vz_driver.configuration.vzstorage_used_ratio = 0
self.assertRaises(exception.VzStorageException,
self._vz_driver.do_setup,
@mock.patch('os.path.exists')
def test_setup_invalid_mount_point_base(self, mock_exists):
- mock_exists.return_value = True
+ mock_exists.side_effect = self._path_exists
conf = copy.copy(self._FAKE_VZ_CONFIG)
conf.vzstorage_mount_point_base = './tmp'
vz_driver = vzstorage.VZStorageDriver(configuration=conf)
@mock.patch('os.path.exists')
def test_setup_no_vzstorage(self, mock_exists):
- mock_exists.return_value = True
+ mock_exists.side_effect = self._path_exists
exc = OSError()
exc.errno = errno.ENOENT
self._vz_driver._execute.side_effect = exc
drv = self._vz_driver
cap_info = (100 * units.Gi, 40 * units.Gi, 60 * units.Gi)
with mock.patch.object(drv, '_get_capacity_info',
- return_value = cap_info):
+ return_value=cap_info):
ret = drv._is_share_eligible(self._FAKE_SHARE, 50)
self.assertFalse(ret)
drv = self._vz_driver
cap_info = (100 * units.Gi, 40 * units.Gi, 60 * units.Gi)
with mock.patch.object(drv, '_get_capacity_info',
- return_value = cap_info):
+ return_value=cap_info):
ret = drv._is_share_eligible(self._FAKE_SHARE, 30)
self.assertTrue(ret)