From 20c2be3e7912e9c58392e11934c8114b63e73670 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Thu, 9 May 2013 14:15:13 -0700 Subject: [PATCH] Fixes an get_volume_stats reporting issue 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 | 69 +++++++++++++++++++ .../volume/drivers/san/hp/hp_3par_common.py | 5 +- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_hp3par.py b/cinder/tests/test_hp3par.py index c4965caa6..865192900 100644 --- a/cinder/tests/test_hp3par.py +++ b/cinder/tests/test_hp3par.py @@ -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) diff --git a/cinder/volume/drivers/san/hp/hp_3par_common.py b/cinder/volume/drivers/san/hp/hp_3par_common.py index bed8cc39d..519b43665 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_common.py +++ b/cinder/volume/drivers/san/hp/hp_3par_common.py @@ -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 -- 2.45.2