]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add stats reporting to Nexenta Driver
authorJohn Griffith <john.griffith@solidfire.com>
Fri, 12 Apr 2013 17:11:38 +0000 (11:11 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Fri, 3 May 2013 21:32:17 +0000 (15:32 -0600)
Nexenta driver was never updated to report stats.
This change doesn't include support for backend_name assignment
via configs, there's some other work that will need to be
done to enable that.

Fixes bug: 1166607

Change-Id: Id9cfff24df8815a67e42393aa18fd41ac1b9e6b3
(cherry picked from commit 781055bc1f30cebe08848130f3a40764f7f1bb4f)

cinder/tests/test_nexenta.py
cinder/volume/drivers/nexenta/volume.py

index e430809c0a4f8f85262733b593e312a2f17bbd00..aadefc1ffbcf09727f1b6341de36de7eddf99ec4 100644 (file)
@@ -23,7 +23,7 @@ import base64
 import urllib2
 
 import cinder.flags
-import cinder.test
+from cinder import test
 from cinder.volume.drivers import nexenta
 from cinder.volume.drivers.nexenta import jsonrpc
 from cinder.volume.drivers.nexenta import volume
@@ -31,7 +31,7 @@ from cinder.volume.drivers.nexenta import volume
 FLAGS = cinder.flags.FLAGS
 
 
-class TestNexentaDriver(cinder.test.TestCase):
+class TestNexentaDriver(test.TestCase):
     TEST_VOLUME_NAME = 'volume1'
     TEST_VOLUME_NAME2 = 'volume2'
     TEST_SNAPSHOT_NAME = 'snapshot1'
@@ -197,8 +197,25 @@ class TestNexentaDriver(cinder.test.TestCase):
         self.mox.ReplayAll()
         self.drv.remove_export({}, self.TEST_VOLUME_REF)
 
+    def test_get_volume_stats(self):
+        stats = {'size': '5368709120G',
+                 'used': '5368709120G',
+                 'available': '5368709120G',
+                 'health': 'ONLINE'}
+        self.nms_mock.volume.get_child_props(
+            FLAGS.nexenta_volume,
+            'health|size|used|available').AndReturn(stats)
+        self.mox.ReplayAll()
+        stats = self.drv.get_volume_stats(True)
+        self.assertEquals(stats['storage_protocol'], 'iSCSI')
+        self.assertEquals(stats['volume_backend_name'], 'NexentaDriver')
+        self.assertEquals(stats['total_capacity_gb'], 5368709120.0)
+        self.assertEquals(stats['free_capacity_gb'], 5368709120.0)
+        self.assertEquals(stats['reserved_percentage'], 0)
+        self.assertEquals(stats['QoS_support'], False)
+
 
-class TestNexentaJSONRPC(cinder.test.TestCase):
+class TestNexentaJSONRPC(test.TestCase):
     URL = 'http://example.com/'
     URL_S = 'https://example.com/'
     USER = 'user'
index 2b752314f48e0f3831ddd234b86042da954388a0..f657a0c7ccf3e9b7b4f96625ce795059c422a0b5 100644 (file)
@@ -31,6 +31,7 @@ from cinder.volume import driver
 from cinder.volume.drivers import nexenta
 from cinder.volume.drivers.nexenta import jsonrpc
 
+VERSION = '1.0'
 LOG = logging.getLogger(__name__)
 FLAGS = flags.FLAGS
 
@@ -293,3 +294,57 @@ class NexentaDriver(driver.ISCSIDriver):  # pylint: disable=R0921
     def create_cloned_volume(self, volume, src_vref):
         """Creates a clone of the specified volume."""
         raise NotImplementedError()
+
+    def get_volume_stats(self, refresh=False):
+        """Get volume status.
+
+        If 'refresh' is True, run update the stats first."""
+        if refresh:
+            self._update_volume_status()
+
+        return self._stats
+
+    def _update_volume_status(self):
+        """Retrieve status info for Nexenta device."""
+
+        # NOTE(jdg): Aimon Bustardo was kind enough to point out the
+        # info he had regarding Nexenta Capabilities, ideally it would
+        # be great if somebody from Nexenta looked this over at some point
+
+        KB = 1024
+        MB = KB ** 2
+
+        LOG.debug(_("Updating volume status"))
+        data = {}
+        data["volume_backend_name"] = self.__class__.__name__
+        data["vendor_name"] = 'Nexenta'
+        data["driver_version"] = VERSION
+        data["storage_protocol"] = 'iSCSI'
+
+        stats = self.nms.volume.get_child_props(FLAGS.nexenta_volume,
+                                                'health|size|used|available')
+        total_unit = stats['size'][-1]
+        total_amount = float(stats['size'][:-1])
+        free_unit = stats['available'][-1]
+        free_amount = float(stats['available'][:-1])
+
+        if total_unit == "T":
+                total_amount = total_amount * KB
+        elif total_unit == "M":
+                total_amount = total_amount / KB
+        elif total_unit == "B":
+                total_amount = total_amount / MB
+
+        if free_unit == "T":
+                free_amount = free_amount * KB
+        elif free_unit == "M":
+                free_amount = free_amount / KB
+        elif free_unit == "B":
+                free_amount = free_amount / MB
+
+        data['total_capacity_gb'] = total_amount
+        data['free_capacity_gb'] = free_amount
+
+        data['reserved_percentage'] = 0
+        data['QoS_support'] = False
+        self._stats = data