From: Ryan Lucio Date: Thu, 19 Mar 2015 10:17:17 +0000 (-0700) Subject: Use cached values for stats on query failures for vmem drivers X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=479b4c0dd3496f739e05082df0f2c675b34b7d0c;p=openstack-build%2Fcinder-build.git Use cached values for stats on query failures for vmem drivers This change allows vmem drivers to return previously cached values for free_capacity_gb and total_capacity_gb if the queries to the backend for those stats succeed but do not contain the data. This can happen when the mgmt plane is under heavy load. Change-Id: I218a54897361d739c04963b4c36d93620be01fb3 Closes-Bug: 1433990 --- diff --git a/cinder/tests/test_v6000_fcp.py b/cinder/tests/test_v6000_fcp.py index f0448be99..a1d66cc8e 100644 --- a/cinder/tests/test_v6000_fcp.py +++ b/cinder/tests/test_v6000_fcp.py @@ -547,6 +547,29 @@ class V6000FCPDriverTestCase(test.TestCase): self.driver.stats['volume_backend_name']) self.assertEqual(vendor_name, self.driver.stats['vendor_name']) + def test_update_stats_fails_data_query_but_has_cached_stats(self): + """Stats query to backend fails, but cached stats are available. """ + backend_name = self.conf.volume_backend_name + vendor_name = "Violin Memory, Inc." + bn0 = '/cluster/state/master_id' + response1 = {bn0: '1'} + response2 = {} + + # fake cached stats, from a previous stats query + self.driver.stats = {'free_capacity_gb': 50, 'total_capacity_gb': 100} + + conf = { + 'basic.get_node_values.side_effect': [response1, response2], + } + self.driver.common.vip = self.setup_mock_vshare(m_conf=conf) + + self.assertIsNone(self.driver._update_stats()) + self.assertEqual(100, self.driver.stats['total_capacity_gb']) + self.assertEqual(50, self.driver.stats['free_capacity_gb']) + self.assertEqual(backend_name, + self.driver.stats['volume_backend_name']) + self.assertEqual(vendor_name, self.driver.stats['vendor_name']) + def test_get_active_fc_targets(self): bn0 = '/vshare/state/global/*' response0 = {'/vshare/state/global/1': 1, diff --git a/cinder/tests/test_v6000_iscsi.py b/cinder/tests/test_v6000_iscsi.py index 9dddb040b..458a938d8 100644 --- a/cinder/tests/test_v6000_iscsi.py +++ b/cinder/tests/test_v6000_iscsi.py @@ -590,6 +590,29 @@ class V6000ISCSIDriverTestCase(test.TestCase): self.driver.stats['volume_backend_name']) self.assertEqual(vendor_name, self.driver.stats['vendor_name']) + def test_update_stats_fails_data_query_but_has_cached_stats(self): + """Stats query to backend fails, but cached stats are available. """ + backend_name = self.conf.volume_backend_name + vendor_name = "Violin Memory, Inc." + bn0 = '/cluster/state/master_id' + response1 = {bn0: '1'} + response2 = {} + + # fake cached stats, from a previous stats query + self.driver.stats = {'free_capacity_gb': 50, 'total_capacity_gb': 100} + + conf = { + 'basic.get_node_values.side_effect': [response1, response2], + } + self.driver.common.vip = self.setup_mock_vshare(m_conf=conf) + + self.assertIsNone(self.driver._update_stats()) + self.assertEqual(100, self.driver.stats['total_capacity_gb']) + self.assertEqual(50, self.driver.stats['free_capacity_gb']) + self.assertEqual(backend_name, + self.driver.stats['volume_backend_name']) + self.assertEqual(vendor_name, self.driver.stats['vendor_name']) + def testGetShortName_LongName(self): long_name = "abcdefghijklmnopqrstuvwxyz1234567890" short_name = "abcdefghijklmnopqrstuvwxyz123456" diff --git a/cinder/volume/drivers/violin/v6000_fcp.py b/cinder/volume/drivers/violin/v6000_fcp.py index ce82a184d..a06235e91 100644 --- a/cinder/volume/drivers/violin/v6000_fcp.py +++ b/cinder/volume/drivers/violin/v6000_fcp.py @@ -440,11 +440,15 @@ class V6000FCDriver(driver.FibreChannelDriver): total_gb = resp[bn1] / units.Gi else: LOG.warn(_LW("Failed to receive update for total_gb stat!")) + if 'total_capacity_gb' in self.stats: + total_gb = self.stats['total_capacity_gb'] if bn2 in resp: free_gb = resp[bn2] / units.Gi else: LOG.warn(_LW("Failed to receive update for free_gb stat!")) + if 'free_capacity_gb' in self.stats: + free_gb = self.stats['free_capacity_gb'] backend_name = self.configuration.volume_backend_name data['volume_backend_name'] = backend_name or self.__class__.__name__ diff --git a/cinder/volume/drivers/violin/v6000_iscsi.py b/cinder/volume/drivers/violin/v6000_iscsi.py index 31c7f8392..836bceb9c 100644 --- a/cinder/volume/drivers/violin/v6000_iscsi.py +++ b/cinder/volume/drivers/violin/v6000_iscsi.py @@ -469,11 +469,15 @@ class V6000ISCSIDriver(driver.ISCSIDriver): total_gb = resp[bn1] / units.Gi else: LOG.warn(_LW("Failed to receive update for total_gb stat!")) + if 'total_capacity_gb' in self.stats: + total_gb = self.stats['total_capacity_gb'] if bn2 in resp: free_gb = resp[bn2] / units.Gi else: LOG.warn(_LW("Failed to receive update for free_gb stat!")) + if 'free_capacity_gb' in self.stats: + free_gb = self.stats['free_capacity_gb'] backend_name = self.configuration.volume_backend_name data['volume_backend_name'] = backend_name or self.__class__.__name__