]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use cached values for stats on query failures for vmem drivers
authorRyan Lucio <rlucio@vmem.com>
Thu, 19 Mar 2015 10:17:17 +0000 (03:17 -0700)
committerRyan Lucio <rlucio@vmem.com>
Mon, 23 Mar 2015 23:20:38 +0000 (16:20 -0700)
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

cinder/tests/test_v6000_fcp.py
cinder/tests/test_v6000_iscsi.py
cinder/volume/drivers/violin/v6000_fcp.py
cinder/volume/drivers/violin/v6000_iscsi.py

index f0448be99364b0a1584cc0c3104085a89e360422..a1d66cc8e240035c0f9727eb51cce0934c839c4b 100644 (file)
@@ -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,
index 9dddb040b2f7aca009f3198b3349de3caaaefb01..458a938d89f42e4385df76026ef2cd4d7c06086e 100644 (file)
@@ -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"
index ce82a184da94d740cb17755060c6922615525a96..a06235e9179654c9f55026baccd2eb7ac23c637d 100644 (file)
@@ -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__
index 31c7f8392df7d5d685ab745db17bb88730f37707..836bceb9c077b9c5ff679937bfea62f5545aadc4 100644 (file)
@@ -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__