]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix ability to add custom volume_backend_name
authorWalter A. Boring IV <walter.boring@hp.com>
Fri, 3 May 2013 21:36:12 +0000 (14:36 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Mon, 6 May 2013 17:51:15 +0000 (10:51 -0700)
This patch fixes the ability to set the volume_backend_name
for each driver.   The original bug was filed against LeftHand
and 3PAR, but several drivers exhibited a fixed backend name.

Fixes: bug #1175222
       bug #1172286

Change-Id: I4197f99bebd6ca8e4969795ae6edb537bc066c90

13 files changed:
cinder/tests/test_hp3par.py
cinder/tests/test_rbd.py
cinder/volume/drivers/coraid.py
cinder/volume/drivers/emc/emc_smis_iscsi.py
cinder/volume/drivers/huawei/huawei_iscsi.py
cinder/volume/drivers/nexenta/volume.py
cinder/volume/drivers/rbd.py
cinder/volume/drivers/san/hp/hp_3par_common.py
cinder/volume/drivers/san/hp/hp_3par_fc.py
cinder/volume/drivers/san/hp/hp_3par_iscsi.py
cinder/volume/drivers/scality.py
cinder/volume/drivers/sheepdog.py
cinder/volume/drivers/xenapi/sm.py

index c6d0c57a7890a3cdf029864fb0b068020f351dc6..f73fbba333d14d9fd806db1f9a12a43369987a11 100644 (file)
@@ -492,9 +492,15 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase):
 
     def test_get_volume_stats(self):
         self.flags(lock_path=self.tempdir)
+
+        def fake_safe_get(*args):
+            return "HP3PARFCDriver"
+
+        self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get)
         stats = self.driver.get_volume_stats(True)
         self.assertEquals(stats['storage_protocol'], 'FC')
-        self.assertEquals(stats['volume_backend_name'], 'HP3PARFCDriver')
+        self.assertEquals(stats['total_capacity_gb'], 'infinite')
+        self.assertEquals(stats['free_capacity_gb'], 'infinite')
 
 
 class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase):
@@ -628,6 +634,12 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase):
 
     def test_get_volume_stats(self):
         self.flags(lock_path=self.tempdir)
+
+        def fake_safe_get(*args):
+            return "HP3PARFCDriver"
+
+        self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get)
         stats = self.driver.get_volume_stats(True)
         self.assertEquals(stats['storage_protocol'], 'iSCSI')
-        self.assertEquals(stats['volume_backend_name'], 'HP3PARISCSIDriver')
+        self.assertEquals(stats['total_capacity_gb'], 'infinite')
+        self.assertEquals(stats['free_capacity_gb'], 'infinite')
index 8db5445559b9a92ef879b69eae1ace8463a1dfb6..54b6ffffa463c90742146c3f277b9c66c97e8cd6 100644 (file)
@@ -153,7 +153,12 @@ class RBDTestCase(test.TestCase):
     def test_update_volume_stats(self):
         def fake_stats(*args):
             return RADOS_DF_OUT, ''
+
+        def fake_safe_get(*args):
+            return "RBD"
+
         self.stubs.Set(self.driver, '_execute', fake_stats)
+        self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get)
         expected = dict(
             volume_backend_name='RBD',
             vendor_name='Open Source',
@@ -168,7 +173,12 @@ class RBDTestCase(test.TestCase):
     def test_update_volume_stats_error(self):
         def fake_exc(*args):
             raise exception.ProcessExecutionError()
+
+        def fake_safe_get(*args):
+            return "RBD"
+
         self.stubs.Set(self.driver, '_execute', fake_exc)
+        self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get)
         expected = dict(
             volume_backend_name='RBD',
             vendor_name='Open Source',
index ca7d674f8e629da6e9b1f42be207737ebbb9c8ae..0c251304bc241bc9d9bff22f39cc9e58ccd00dd2 100644 (file)
@@ -392,13 +392,15 @@ class CoraidDriver(driver.VolumeDriver):
 
     def get_volume_stats(self, refresh=False):
         """Return Volume Stats."""
-        return {'driver_version': '1.0',
+        data = {'driver_version': '1.0',
                 'free_capacity_gb': 'unknown',
                 'reserved_percentage': 0,
                 'storage_protocol': 'aoe',
                 'total_capacity_gb': 'unknown',
-                'vendor_name': 'Coraid',
-                'volume_backend_name': 'EtherCloud ESM'}
+                'vendor_name': 'Coraid'}
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        data['volume_backend_name'] = backend_name or 'EtherCloud ESM'
+        return data
 
     def local_path(self, volume):
         pass
index d9c58a29a515d1a21dbdfbab7276a4d469dd1b8c..25308c53a30fae25f6c5690544dbb2e16a85e375 100644 (file)
@@ -240,6 +240,7 @@ class EMCSMISISCSIDriver(driver.ISCSIDriver):
         """Retrieve status info from volume group."""
         LOG.debug(_("Updating volume status"))
         data = self.common.update_volume_status()
-        data['volume_backend_name'] = 'EMCSMISISCSIDriver'
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        data['volume_backend_name'] = backend_name or 'EMCSMISISCSIDriver'
         data['storage_protocol'] = 'iSCSI'
         self._stats = data
index 6eb4a957cee6186e47253ebc22461bfc94ee78be..8b8ae632019204b4cf85d800a59306a1f814b581 100644 (file)
@@ -1501,7 +1501,8 @@ class HuaweiISCSIDriver(driver.ISCSIDriver):
 
         LOG.debug(_("Updating volume status"))
         data = {}
-        data['volume_backend_name'] = 'HuaweiISCSIDriver'
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        data["volume_backend_name"] = backend_name or 'HuaweiISCSIDriver'
         data['vendor_name'] = 'Huawei'
         data['driver_version'] = '1.0'
         data['storage_protocol'] = 'iSCSI'
index f657a0c7ccf3e9b7b4f96625ce795059c422a0b5..94b73fd3aa51246718e6e967f3cfd43096cd6191 100644 (file)
@@ -316,7 +316,10 @@ class NexentaDriver(driver.ISCSIDriver):  # pylint: disable=R0921
 
         LOG.debug(_("Updating volume status"))
         data = {}
-        data["volume_backend_name"] = self.__class__.__name__
+        backend_name = self.__class__.__name__
+        if self.configuration:
+            backend_name = self.configuration.safe_get('volume_backend_name')
+        data["volume_backend_name"] = backend_name or self.__class__.__name__
         data["vendor_name"] = 'Nexenta'
         data["driver_version"] = VERSION
         data["storage_protocol"] = 'iSCSI'
index c9016bf8bf3546216190e9ff6e6b5dc7b2334040..6a8f5c044204c65297c9f9fd5c1ad843b2c2779a 100644 (file)
@@ -54,14 +54,7 @@ class RBDDriver(driver.VolumeDriver):
     def __init__(self, *args, **kwargs):
         super(RBDDriver, self).__init__(*args, **kwargs)
         self.configuration.append_config_values(rbd_opts)
-        self._stats = dict(
-            volume_backend_name='RBD',
-            vendor_name='Open Source',
-            driver_version=VERSION,
-            storage_protocol='ceph',
-            total_capacity_gb='unknown',
-            free_capacity_gb='unknown',
-            reserved_percentage=0)
+        self._stats = {}
 
     def check_for_setup_error(self):
         """Returns an error if prerequisites aren't met"""
@@ -73,9 +66,15 @@ class RBDDriver(driver.VolumeDriver):
             raise exception.VolumeBackendAPIException(data=exception_message)
 
     def _update_volume_stats(self):
-        stats = dict(
-            total_capacity_gb='unknown',
-            free_capacity_gb='unknown')
+        stats = {'vendor_name': 'Open Source',
+                 'driver_version': VERSION,
+                 'storage_protocol': 'ceph',
+                 'total_capacity_gb': 'unknown',
+                 'free_capacity_gb': 'unknown',
+                 'reserved_percentage': 0}
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        stats['volume_backend_name'] = backend_name or 'RBD'
+
         try:
             stdout, _err = self._execute('rados', 'df', '--format', 'json')
             new_stats = json.loads(stdout)
@@ -86,7 +85,7 @@ class RBDDriver(driver.VolumeDriver):
         except exception.ProcessExecutionError:
             # just log and return unknown capacities
             LOG.exception(_('error refreshing volume stats'))
-        self._stats.update(stats)
+        self._stats = stats
 
     def get_volume_stats(self, refresh=False):
         """Return the current state of the volume service. If 'refresh' is
index 31bbb7db7c98b1895384773e5d15d86831c6de4e..bed8cc39d4442d0e533e3dcda5326b44f1e64c8e 100644 (file)
@@ -95,13 +95,7 @@ hp3par_opts = [
 
 class HP3PARCommon():
 
-    stats = {'driver_version': '1.0',
-             'free_capacity_gb': 'unknown',
-             'reserved_percentage': 0,
-             'storage_protocol': None,
-             'total_capacity_gb': 'unknown',
-             'vendor_name': 'Hewlett-Packard',
-             'volume_backend_name': None}
+    stats = {}
 
     # Valid values for volume type extra specs
     # The first value in the list is the default value
@@ -422,26 +416,42 @@ exit
         const = 0.0009765625
 
         if refresh:
-            try:
-                cpg = client.getCPG(self.config.hp3par_cpg)
-                if 'limitMiB' not in cpg['SDGrowth']:
-                    total_capacity = 'infinite'
-                    free_capacity = 'infinite'
-                else:
-                    total_capacity = int(cpg['SDGrowth']['limitMiB'] * const)
-                    free_capacity = int((cpg['SDGrowth']['limitMiB'] -
-                                        cpg['UsrUsage']['usedMiB']) * const)
-
-                self.stats['total_capacity_gb'] = total_capacity
-                self.stats['free_capacity_gb'] = free_capacity
-            except hpexceptions.HTTPNotFound:
-                err = (_("CPG (%s) doesn't exist on array")
-                       % self.config.hp3par_cpg)
-                LOG.error(err)
-                raise exception.InvalidInput(reason=err)
+            self._update_volume_stats(client)
 
         return self.stats
 
+    def _update_volume_stats(self, client):
+
+        # storage_protocol and volume_backend_name are
+        # set in the child classes
+        stats = {'driver_version': '1.0',
+                 'free_capacity_gb': 'unknown',
+                 'reserved_percentage': 0,
+                 'storage_protocol': None,
+                 'total_capacity_gb': 'unknown',
+                 'vendor_name': 'Hewlett-Packard',
+                 'volume_backend_name': None}
+
+        try:
+            cpg = client.getCPG(self.config.hp3par_cpg)
+            if 'limitMiB' not in cpg['SDGrowth']:
+                total_capacity = 'infinite'
+                free_capacity = 'infinite'
+            else:
+                total_capacity = int(cpg['SDGrowth']['limitMiB'] * const)
+                free_capacity = int((cpg['SDGrowth']['limitMiB'] -
+                                    cpg['UsrUsage']['usedMiB']) * const)
+
+            stats['total_capacity_gb'] = total_capacity
+            stats['free_capacity_gb'] = free_capacity
+        except hpexceptions.HTTPNotFound:
+            err = (_("CPG (%s) doesn't exist on array")
+                   % self.config.hp3par_cpg)
+            LOG.error(err)
+            raise exception.InvalidInput(reason=err)
+
+        self.stats = stats
+
     def create_vlun(self, volume, host, client):
         """
         In order to export a volume on a 3PAR box, we have to
index 6eb6a3527714de8c11e17ae11244960d71cf94f6..d5af46d3e59acac0a453214e39e24a00e7b20466 100644 (file)
@@ -76,7 +76,8 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver):
     def get_volume_stats(self, refresh):
         stats = self.common.get_volume_stats(refresh, self.client)
         stats['storage_protocol'] = 'FC'
-        stats['volume_backend_name'] = 'HP3PARFCDriver'
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        stats['volume_backend_name'] = backend_name or self.__class__.__name__
         return stats
 
     def do_setup(self, context):
index b740a2f57d9428c63436446430c8812e584da072..fca9c20066f6aed89c9a5727dd56536cd454910e 100644 (file)
@@ -75,7 +75,8 @@ class HP3PARISCSIDriver(cinder.volume.driver.ISCSIDriver):
     def get_volume_stats(self, refresh):
         stats = self.common.get_volume_stats(refresh, self.client)
         stats['storage_protocol'] = 'iSCSI'
-        stats['volume_backend_name'] = 'HP3PARISCSIDriver'
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        stats['volume_backend_name'] = backend_name or self.__class__.__name__
         return stats
 
     def do_setup(self, context):
index 31a41909fff7a0b48185876a250376f0c117a894..b59fe26be42c032e5df9eacdb2222fcabd66b09c 100644 (file)
@@ -223,7 +223,6 @@ class ScalityDriver(driver.VolumeDriver):
         If 'refresh' is True, run the update first.
         """
         stats = {
-            'volume_backend_name': 'Scality_SOFS',
             'vendor_name': 'Scality',
             'driver_version': '1.0',
             'storage_protocol': 'scality',
@@ -231,6 +230,8 @@ class ScalityDriver(driver.VolumeDriver):
             'free_capacity_gb': 'infinite',
             'reserved_percentage': 0,
         }
+        backend_name = self.configuration.safe_get('volume_backend_name')
+        stats['volume_backend_name'] = backend_name or 'Scality_SOFS'
         return stats
 
     def copy_image_to_volume(self, context, volume, image_service, image_id):
index d1916c7ad5baa8ae743c2ab8e311957dcf2ef753..a539ce1815791fe8ddb21fa0b3270eb84a6c54da 100644 (file)
@@ -33,16 +33,8 @@ class SheepdogDriver(driver.VolumeDriver):
 
     def __init__(self, *args, **kwargs):
         super(SheepdogDriver, self).__init__(*args, **kwargs)
-        self._stats = dict(
-            volume_backend_name='sheepdog',
-            vendor_name='Open Source',
-            dirver_version='1.0',
-            storage_protocol='sheepdog',
-            total_capacity_gb='unknown',
-            free_capacity_gb='unknown',
-            reserved_percentage=0,
-            QoS_support=False)
         self.stats_pattern = re.compile(r'[\w\s%]*Total\s(\d+)\s(\d+)*')
+        self._stats = {}
 
     def check_for_setup_error(self):
         """Returns an error if prerequisites aren't met"""
@@ -118,6 +110,19 @@ class SheepdogDriver(driver.VolumeDriver):
 
     def _update_volume_stats(self):
         stats = {}
+
+        backend_name = "sheepdog"
+        if self.configuration:
+            backend_name = self.configuration.safe_get('volume_backend_name')
+        stats["volume_backend_name"] = backend_name or 'sheepdog'
+        stats['vendor_name'] = 'Open Source'
+        stats['dirver_version'] = '1.0'
+        stats['storage_protocol'] = 'sheepdog'
+        stats['total_capacity_gb'] = 'unknown'
+        stats['free_capacity_gb'] = 'unknown'
+        stats['reserved_percentage'] = 0
+        stats['QoS_support'] = False
+
         try:
             stdout, _err = self._execute('collie', 'node', 'info', '-r')
             m = self.stats_pattern.match(stdout)
@@ -127,7 +132,8 @@ class SheepdogDriver(driver.VolumeDriver):
             stats['free_capacity_gb'] = (total - used) / (1024 ** 3)
         except exception.ProcessExecutionError:
             LOG.exception(_('error refreshing volume stats'))
-        self._stats.update(stats)
+
+        self._stats = stats
 
     def get_volume_stats(self, refresh=False):
         if refresh:
index cc93af09628ad06f05540dfb7fe2b1f1b791ad12..c1b64e2c9cf605aae8aec9bb02be1d0056f5c68f 100644 (file)
@@ -245,14 +245,17 @@ class XenAPINFSDriver(driver.VolumeDriver):
 
     def get_volume_stats(self, refresh=False):
         if refresh or not self._stats:
-            self._stats = dict(
-                volume_backend_name='XenAPINFS',
-                vendor_name='Open Source',
-                driver_version='1.0',
-                storage_protocol='xensm',
-                total_capacity_gb='unknown',
-                free_capacity_gb='unknown',
-                reserved_percentage=0)
+            data = {}
+
+            backend_name = self.configuration.safe_get('volume_backend_name')
+            data["volume_backend_name"] = backend_name or 'XenAPINFS',
+            data['vendor_name'] = 'Open Source',
+            data['driver_version'] = '1.0'
+            data['storage_protocol'] = 'xensm'
+            data['total_capacity_gb'] = 'unknown'
+            data['free_capacity_gb'] = 'unknown'
+            data['reserved_percentage'] = 0
+            self._stats = data
 
         return self._stats