Skip to content

Commit

Permalink
Implement get_volume_stats for GlusterFS driver
Browse files Browse the repository at this point in the history
Implement get_volume_stats(), so that the GlusterFS driver
will work correctly with the scheduler.

Fixes bug: 1164038

Change-Id: Ib4db8bad897212227b39704e2e6cb5f07f2bb70e
  • Loading branch information
eharney committed Apr 5, 2013
1 parent 7997148 commit d59094f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
17 changes: 9 additions & 8 deletions cinder/tests/test_glusterfs.py
Expand Up @@ -255,10 +255,11 @@ def test_get_available_capacity_with_df(self):
mox = self._mox
drv = self._driver

df_total_size = 2620544
df_avail = 1490560
df_head = 'Filesystem 1K-blocks Used Available Use% Mounted on\n'
df_data = 'glusterfs-host:/export 2620544 996864 %d 41%% /mnt' % \
df_avail
df_data = 'glusterfs-host:/export %d 996864 %d 41%% /mnt' % \
(df_total_size, df_avail)
df_output = df_head + df_data

setattr(glusterfs.FLAGS, 'glusterfs_disk_util', 'df')
Expand All @@ -274,7 +275,7 @@ def test_get_available_capacity_with_df(self):

mox.ReplayAll()

self.assertEquals(df_avail,
self.assertEquals((df_avail, df_total_size),
drv._get_available_capacity(
self.TEST_EXPORT1))

Expand Down Expand Up @@ -319,7 +320,7 @@ def test_get_available_capacity_with_du(self):

mox.ReplayAll()

self.assertEquals(df_total_size - du_used,
self.assertEquals((df_total_size - du_used, df_total_size),
drv._get_available_capacity(
self.TEST_EXPORT1))

Expand Down Expand Up @@ -450,9 +451,9 @@ def test_find_share(self):

mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_EXPORT1).\
AndReturn(2 * self.ONE_GB_IN_BYTES)
AndReturn((2 * self.ONE_GB_IN_BYTES, 5 * self.ONE_GB_IN_BYTES))
drv._get_available_capacity(self.TEST_EXPORT2).\
AndReturn(3 * self.ONE_GB_IN_BYTES)
AndReturn((3 * self.ONE_GB_IN_BYTES, 10 * self.ONE_GB_IN_BYTES))

mox.ReplayAll()

Expand All @@ -471,9 +472,9 @@ def test_find_share_should_throw_error_if_there_is_no_enough_place(self):

mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_EXPORT1).\
AndReturn(0)
AndReturn((0, 5 * self.ONE_GB_IN_BYTES))
drv._get_available_capacity(self.TEST_EXPORT2).\
AndReturn(0)
AndReturn((0, 10 * self.ONE_GB_IN_BYTES))

mox.ReplayAll()

Expand Down
40 changes: 37 additions & 3 deletions cinder/volume/drivers/glusterfs.py
Expand Up @@ -200,7 +200,7 @@ def _find_share(self, volume_size_for):
greatest_share = None

for glusterfs_share in self._mounted_shares:
capacity = self._get_available_capacity(glusterfs_share)
capacity = self._get_available_capacity(glusterfs_share)[0]
if capacity > greatest_size:
greatest_share = glusterfs_share
greatest_size = capacity
Expand Down Expand Up @@ -229,17 +229,17 @@ def _get_available_capacity(self, glusterfs_share):

available = 0

size = int(out.split()[1])
if self.configuration.glusterfs_disk_util == 'df':
available = int(out.split()[3])
else:
size = int(out.split()[1])
out, _ = self._execute('du', '-sb', '--apparent-size',
'--exclude', '*snapshot*', mount_point,
run_as_root=True)
used = int(out.split()[0])
available = size - used

return available
return available, size

def _mount_glusterfs(self, glusterfs_share, mount_path, ensure=False):
"""Mount GlusterFS share to mount path."""
Expand All @@ -254,3 +254,37 @@ def _mount_glusterfs(self, glusterfs_share, mount_path, ensure=False):
LOG.warn(_("%s is already mounted"), glusterfs_share)
else:
raise

def get_volume_stats(self, refresh=False):
"""Get volume stats.
If 'refresh' is True, update the stats first."""
if refresh or not self._stats:
self._update_volume_stats()

return self._stats

def _update_volume_stats(self):
"""Retrieve stats info from volume group."""

data = {}
backend_name = self.configuration.safe_get('volume_backend_name')
data['volume_backend_name'] = backend_name or 'GlusterFS'
data['vendor_name'] = 'Open Source'
data['driver_version'] = '1.0'
data['storage_protocol'] = 'glusterfs'

self._ensure_shares_mounted()

global_capacity = 0
global_free = 0
for nfs_share in self._mounted_shares:
free, capacity = self._get_available_capacity(nfs_share)
global_capacity += capacity
global_free += free

data['total_capacity_gb'] = global_capacity / 1024.0 ** 3
data['free_capacity_gb'] = global_free / 1024.0 ** 3
data['reserved_percentage'] = 0
data['QoS_support'] = False
self._stats = data

0 comments on commit d59094f

Please sign in to comment.