Merge "Add option for QEMU Gluster libgfapi support"

This commit is contained in:
Jenkins 2013-08-13 11:51:02 +00:00 committed by Gerrit Code Review
commit 7b77052037
3 changed files with 51 additions and 5 deletions

View File

@ -2124,6 +2124,10 @@
# Base dir where Scality SOFS shall be mounted (string value)
#scality_sofs_mount_point=$state_path/scality
# Protocols listed here will be accessed directly from QEMU.
# Currently supported protocols: [gluster] (list value)
#qemu_allowed_storage_drivers=
#
# Options defined in nova.virt.powervm.driver

View File

@ -494,6 +494,32 @@ class LibvirtVolumeTestCase(test.TestCase):
export_string, export_mnt_base)]
self.assertEqual(self.executes, expected_commands)
def test_libvirt_glusterfs_libgfapi(self):
self.flags(qemu_allowed_storage_drivers=['gluster'])
libvirt_driver = volume.LibvirtGlusterfsVolumeDriver(self.fake_conn)
export_string = '192.168.1.1:/volume-00001'
name = 'volume-00001'
connection_info = {'data': {'export': export_string, 'name': name}}
disk_info = {
"dev": "vde",
"type": "disk",
"bus": "virtio",
}
conf = libvirt_driver.connect_volume(connection_info, disk_info)
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./driver').get('type'), 'raw')
source = tree.find('./source')
self.assertEqual(source.get('protocol'), 'gluster')
self.assertEqual(source.get('name'), 'volume-00001/volume-00001')
self.assertEqual(source.find('./host').get('name'), '192.168.1.1')
libvirt_driver.disconnect_volume(connection_info, "vde")
def fibrechan_connection(self, volume, location, wwn):
return {
'driver_volume_type': 'fibrechan',

View File

@ -69,6 +69,10 @@ volume_opts = [
cfg.StrOpt('scality_sofs_mount_point',
default='$state_path/scality',
help='Base dir where Scality SOFS shall be mounted'),
cfg.ListOpt('qemu_allowed_storage_drivers',
default=[],
help='Protocols listed here will be accessed directly '
'from QEMU. Currently supported protocols: [gluster]')
]
CONF = cfg.CONF
@ -609,11 +613,23 @@ class LibvirtGlusterfsVolumeDriver(LibvirtBaseVolumeDriver):
"""Connect the volume. Returns xml for libvirt."""
conf = super(LibvirtGlusterfsVolumeDriver,
self).connect_volume(connection_info, mount_device)
options = connection_info['data'].get('options')
path = self._ensure_mounted(connection_info['data']['export'], options)
path = os.path.join(path, connection_info['data']['name'])
conf.source_type = 'file'
conf.source_path = path
data = connection_info['data']
if 'gluster' in CONF.qemu_allowed_storage_drivers:
vol_name = data['export'].split('/')[1]
source_host = data['export'].split('/')[0][:-1]
conf.source_ports = [None]
conf.source_type = 'network'
conf.source_protocol = 'gluster'
conf.source_hosts = [source_host]
conf.source_name = '%s/%s' % (vol_name, data['name'])
else:
path = self._ensure_mounted(data['export'], data.get('options'))
path = os.path.join(path, data['name'])
conf.source_type = 'file'
conf.source_path = path
return conf
def _ensure_mounted(self, glusterfs_export, options=None):