From b3026c1d43e4604bc3569194b3af62640beb4f3e Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Mon, 31 Oct 2016 13:20:12 -0400 Subject: [PATCH] RBD: improve readability in over provisioning tests This change doesn't effect behaviour, but makes the tests more readable as the stats fields are now of the correct type. Change-Id: If0d8fd16c75eb206f3889244ce19eb04b7b783ef --- cinder/tests/unit/volume/drivers/test_rbd.py | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/test_rbd.py b/cinder/tests/unit/volume/drivers/test_rbd.py index 31d89d8545d..d6150491764 100644 --- a/cinder/tests/unit/volume/drivers/test_rbd.py +++ b/cinder/tests/unit/volume/drivers/test_rbd.py @@ -133,6 +133,14 @@ CEPH_MON_DUMP = """dumped monmap epoch 1 """ +def mock_driver_configuration(value): + if value == 'max_over_subscription_ratio': + return 1.0 + if value == 'reserved_percentage': + return 0 + return 'RBD' + + @ddt.ddt class RBDTestCase(test.TestCase): @@ -811,8 +819,9 @@ class RBDTestCase(test.TestCase): '"bytes_used":1546440971,"max_avail":28987613184,"objects":412}},' '{"name":"volumes","id":3,"stats":{"kb_used":0,"bytes_used":0,' '"max_avail":28987613184,"objects":0}}]}\n', '') - self.driver.configuration.safe_get = mock.Mock() - self.driver.configuration.safe_get.return_value = 'RBD' + + self.mock_object(self.driver.configuration, 'safe_get', + mock_driver_configuration) expected = dict( volume_backend_name='RBD', @@ -821,10 +830,10 @@ class RBDTestCase(test.TestCase): storage_protocol='ceph', total_capacity_gb=28.44, free_capacity_gb=27.0, - reserved_percentage='RBD', + reserved_percentage=0, thin_provisioning_support=True, provisioned_capacity_gb=0.0, - max_over_subscription_ratio='RBD', + max_over_subscription_ratio=1.0, multiattach=False) actual = self.driver.get_volume_stats(True) @@ -841,8 +850,8 @@ class RBDTestCase(test.TestCase): client.cluster.mon_command = mock.Mock() client.cluster.mon_command.return_value = (22, '', '') - self.driver.configuration.safe_get = mock.Mock() - self.driver.configuration.safe_get.return_value = 'RBD' + self.mock_object(self.driver.configuration, 'safe_get', + mock_driver_configuration) expected = dict(volume_backend_name='RBD', vendor_name='Open Source', @@ -850,10 +859,10 @@ class RBDTestCase(test.TestCase): storage_protocol='ceph', total_capacity_gb='unknown', free_capacity_gb='unknown', - reserved_percentage='RBD', + reserved_percentage=0, multiattach=False, provisioned_capacity_gb=0.0, - max_over_subscription_ratio='RBD', + max_over_subscription_ratio=1.0, thin_provisioning_support=True) actual = self.driver.get_volume_stats(True)