From d79b2a2589ffb21e80e29eb909a021d4f1700374 Mon Sep 17 00:00:00 2001 From: Dmitry Guryanov Date: Wed, 10 Jun 2015 23:01:55 +0300 Subject: [PATCH] smbfs: fix invalid check for smbfs_used_ratio correctness The check allowed to specify values greater than 1 because of a error in condition. So I've fixed the condition and updated unit test, so it would catch the bug. Closes-Bug: #1469249 Change-Id: I34f4128a8a80ae57be5c0af90308d2d517022d8e --- cinder/tests/unit/test_smbfs.py | 5 +++++ cinder/volume/drivers/smbfs.py | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/test_smbfs.py b/cinder/tests/unit/test_smbfs.py index 05cf1f2a7..028e91352 100644 --- a/cinder/tests/unit/test_smbfs.py +++ b/cinder/tests/unit/test_smbfs.py @@ -132,6 +132,11 @@ class SmbFsTestCase(test.TestCase): fake_config.smbfs_used_ratio = -1 self._test_setup(config=fake_config) + def test_setup_invalid_used_ratio2(self): + fake_config = copy.copy(self._FAKE_SMBFS_CONFIG) + fake_config.smbfs_used_ratio = 1.1 + self._test_setup(config=fake_config) + def _test_create_volume(self, volume_exists=False, volume_format=None): fake_method = mock.MagicMock() self._smbfs_driver.configuration = copy.copy(self._FAKE_SMBFS_CONFIG) diff --git a/cinder/volume/drivers/smbfs.py b/cinder/volume/drivers/smbfs.py index e3321f0c3..fa6b3bfcd 100644 --- a/cinder/volume/drivers/smbfs.py +++ b/cinder/volume/drivers/smbfs.py @@ -156,8 +156,7 @@ class SmbfsDriver(remotefs_drv.RemoteFSSnapDriver): LOG.error(msg) raise exception.SmbfsException(msg) - if ((not self.configuration.smbfs_used_ratio > 0) and - (self.configuration.smbfs_used_ratio <= 1)): + if not 0 < self.configuration.smbfs_used_ratio <= 1: msg = _("SMBFS config 'smbfs_used_ratio' invalid. Must be > 0 " "and <= 1.0: %s") % self.configuration.smbfs_used_ratio LOG.error(msg) -- 2.45.2