Merge "Fix HPE3PAR not returning cached stats"

This commit is contained in:
Zuul 2019-02-15 02:18:10 +00:00 committed by Gerrit Code Review
commit 2d79dafcb3
2 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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(