]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes an get_volume_stats reporting issue
authorWalter A. Boring IV <walter.boring@hp.com>
Thu, 9 May 2013 21:15:13 +0000 (14:15 -0700)
committerGerrit Code Review <review@openstack.org>
Mon, 13 May 2013 20:59:21 +0000 (20:59 +0000)
This patch fixes a bug introduced in the last get_volume_stats
patch that caused the method to fail.  I Also added another set
of unit tests to catch any future issues related to get_volume_stats.

Fixes Bug: #1178418

Change-Id: I0dd2e0113ff822d3e717ab3d6da6b9d1b914a995

cinder/tests/test_hp3par.py
cinder/volume/drivers/san/hp/hp_3par_common.py

index c4965caa64db00832dd8cddeb3bacdcb6df5b23d..86519290063657ea3ea0ebce1cfef7f8ba7c2ac2 100644 (file)
@@ -206,6 +206,39 @@ class FakeHP3ParClient(object):
         volume = self.getVolume(name)
         self.volumes.remove(volume)
 
+    def createCPG(self, name, optional=None):
+        cpg = {'SAGrowth': {'LDLayout': {'diskPatterns': [{'diskType': 2}]},
+                            'incrementMiB': 8192},
+               'SAUsage': {'rawTotalMiB': 24576,
+                           'rawUsedMiB': 768,
+                           'totalMiB': 8192,
+                           'usedMiB': 256},
+               'SDGrowth': {'LDLayout': {'RAIDType': 4,
+                            'diskPatterns': [{'diskType': 2}]},
+                            'incrementMiB': 32768},
+               'SDUsage': {'rawTotalMiB': 49152,
+                           'rawUsedMiB': 1023,
+                           'totalMiB': 36864,
+                           'usedMiB': 768},
+               'UsrUsage': {'rawTotalMiB': 57344,
+                            'rawUsedMiB': 43349,
+                            'totalMiB': 43008,
+                            'usedMiB': 32512},
+               'additionalStates': [],
+               'degradedStates': [],
+               'domain': HP3PAR_DOMAIN,
+               'failedStates': [],
+               'id': 1,
+               'name': name,
+               'numFPVVs': 2,
+               'numTPVVs': 0,
+               'state': 1,
+               'uuid': '29c214aa-62b9-41c8-b198-000000000000'}
+
+        new_cpg = cpg.copy()
+        new_cpg.update(optional)
+        self.cpgs.append(new_cpg)
+
     def getCPGs(self):
         return self.cpgs
 
@@ -219,6 +252,10 @@ class FakeHP3ParClient(object):
                'desc': "CPG '%s' was not found" % name}
         raise hpexceptions.HTTPNotFound(msg)
 
+    def deleteCPG(self, name):
+        cpg = self.getCPG(name)
+        self.cpgs.remove(cpg)
+
     def createVLUN(self, volumeName, lun, hostname=None,
                    portPos=None, noVcn=None,
                    overrideLowerPriority=None):
@@ -515,6 +552,22 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase):
         self.assertEquals(stats['total_capacity_gb'], 'infinite')
         self.assertEquals(stats['free_capacity_gb'], 'infinite')
 
+        #modify the CPG to have a limit
+        old_cpg = self.driver.client.getCPG(HP3PAR_CPG)
+        options = {'SDGrowth': {'limitMiB': 8192}}
+        self.driver.client.deleteCPG(HP3PAR_CPG)
+        self.driver.client.createCPG(HP3PAR_CPG, options)
+
+        const = 0.0009765625
+        stats = self.driver.get_volume_stats(True)
+        self.assertEquals(stats['storage_protocol'], 'FC')
+        total_capacity_gb = 8192 * const
+        self.assertEquals(stats['total_capacity_gb'], total_capacity_gb)
+        free_capacity_gb = int((8192 - old_cpg['UsrUsage']['usedMiB']) * const)
+        self.assertEquals(stats['free_capacity_gb'], free_capacity_gb)
+        self.driver.client.deleteCPG(HP3PAR_CPG)
+        self.driver.client.createCPG(HP3PAR_CPG, {})
+
     def test_create_host(self):
         self.flags(lock_path=self.tempdir)
 
@@ -723,6 +776,22 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase):
         self.assertEquals(stats['total_capacity_gb'], 'infinite')
         self.assertEquals(stats['free_capacity_gb'], 'infinite')
 
+        #modify the CPG to have a limit
+        old_cpg = self.driver.client.getCPG(HP3PAR_CPG)
+        options = {'SDGrowth': {'limitMiB': 8192}}
+        self.driver.client.deleteCPG(HP3PAR_CPG)
+        self.driver.client.createCPG(HP3PAR_CPG, options)
+
+        const = 0.0009765625
+        stats = self.driver.get_volume_stats(True)
+        self.assertEquals(stats['storage_protocol'], 'iSCSI')
+        total_capacity_gb = 8192 * const
+        self.assertEquals(stats['total_capacity_gb'], total_capacity_gb)
+        free_capacity_gb = int((8192 - old_cpg['UsrUsage']['usedMiB']) * const)
+        self.assertEquals(stats['free_capacity_gb'], free_capacity_gb)
+        self.driver.client.deleteCPG(HP3PAR_CPG)
+        self.driver.client.createCPG(HP3PAR_CPG, {})
+
     def test_create_host(self):
         self.flags(lock_path=self.tempdir)
 
index bed8cc39d4442d0e533e3dcda5326b44f1e64c8e..519b43665b9ddd5e624ea4944baf1abb922d3c5c 100644 (file)
@@ -412,15 +412,14 @@ exit
         return ports
 
     def get_volume_stats(self, refresh, client):
-        # const to convert MiB to GB
-        const = 0.0009765625
-
         if refresh:
             self._update_volume_stats(client)
 
         return self.stats
 
     def _update_volume_stats(self, client):
+        # const to convert MiB to GB
+        const = 0.0009765625
 
         # storage_protocol and volume_backend_name are
         # set in the child classes