Fix HPE3PAR not returning cached stats
All Cinder drivers must honor this: stats = driver.get_volume_stats(refresh=True) cached_stats = driver.get_volume_stats(refresh=False) assert stats == cached_stats But HPE 3PAR drivers don't. If you try to get cached stats values you'll get an empty dictionary instead. This is caused by the get_volume_stats method calling the _login method which in turn calls _init_common, which returns a new HPE3PARCommon instance on each call, so it won't have any cached values. Closes-Bug: #1813930 Change-Id: I011e7142db5d54882fd2cd9c07276ac71a07b4b7
This commit is contained in:
parent
45f967ef9a
commit
1ae7ebb98b
@ -7632,6 +7632,32 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver):
|
||||
expected +
|
||||
self.standard_logout)
|
||||
|
||||
def test_get_volume_stats5(self):
|
||||
# Testing get_volume_stats(refresh=False) for cached values
|
||||
config = self.setup_configuration()
|
||||
self.setup_driver(config=config)
|
||||
with mock.patch.object(self.driver, '_login') as login_mock, \
|
||||
mock.patch.object(self.driver, '_logout') as logout_mock:
|
||||
stats_mock = login_mock.return_value.get_volume_stats
|
||||
|
||||
stats = self.driver.get_volume_stats(True)
|
||||
|
||||
self.assertEqual(stats_mock.return_value, stats)
|
||||
login_mock.assert_called_once_with()
|
||||
stats_mock.assert_called_once_with(True, FILTER_FUNCTION,
|
||||
GOODNESS_FUNCTION)
|
||||
logout_mock.assert_called_once_with(login_mock.return_value)
|
||||
|
||||
login_mock.reset_mock()
|
||||
stats_mock.reset_mock()
|
||||
logout_mock.reset_mock()
|
||||
|
||||
cached_stats = self.driver.get_volume_stats(False)
|
||||
self.assertEqual(stats, cached_stats)
|
||||
login_mock.assert_not_called()
|
||||
stats_mock.assert_not_called()
|
||||
logout_mock.assert_not_called()
|
||||
|
||||
def test_create_host_with_unmanage_fc_and_manage_iscsi_hosts(self):
|
||||
# setup_mock_client drive with default configuration
|
||||
# and return the mock HTTP 3PAR client
|
||||
|
@ -115,6 +115,14 @@ class HPE3PARDriverBase(driver.ManageableVD,
|
||||
|
||||
@utils.trace
|
||||
def get_volume_stats(self, refresh=False):
|
||||
# NOTE(geguileo): We don't need to login to the backed if we are not
|
||||
# going to refresh the stats, furthermore if we login, then we'll
|
||||
# return an empty dict, because the _login method calls calls
|
||||
# _init_common which returns a new HPE3PARCommon instance each time,
|
||||
# so it won't have any cached values.
|
||||
if not refresh:
|
||||
return self._stats
|
||||
|
||||
common = self._login()
|
||||
try:
|
||||
self._stats = common.get_volume_stats(
|
||||
|
Loading…
Reference in New Issue
Block a user