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
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'
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'
from cinder.volume.drivers import nexenta
from cinder.volume.drivers.nexenta import jsonrpc
+VERSION = '1.0'
LOG = logging.getLogger(__name__)
FLAGS = flags.FLAGS
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