libvirt: move LibvirtAOEVolumeDriver into it's own module
Note that with commit e6cdd1693b
we don't have any unit test coverage of connect/disconnect/get_config
for the AOE volume driver anymore. We should add some test coverage
again later in a separate change - not done here since this is a refactor
series, not refactor + add test coverage.
Part of blueprint consolidate-libvirt-fs-volume-drivers
Change-Id: I934c092a3975987c77e9959cc47648cad186c540
This commit is contained in:
1 parent
e18ccd2e42
commit
c10f8a153b
6 files changed
+98
-52
No files matched your search
@@ -101,8 +101,8 @@ dd: CommandFilter, dd, root
|
||||
# nova/virt/xenapi/volume_utils.py: 'iscsiadm', '-m', ...
|
||||
iscsiadm: CommandFilter, iscsiadm, root
|
||||
|
||||
# nova/virt/libvirt/volume.py: 'aoe-revalidate', aoedev
|
||||
# nova/virt/libvirt/volume.py: 'aoe-discover'
|
||||
# nova/virt/libvirt/volume/aoe.py: 'aoe-revalidate', aoedev
|
||||
# nova/virt/libvirt/volume/aoe.py: 'aoe-discover'
|
||||
aoe-revalidate: CommandFilter, aoe-revalidate, root
|
||||
aoe-discover: CommandFilter, aoe-discover, root
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from os_brick.initiator import connector
|
||||
|
||||
from nova.tests.unit.virt.libvirt.volume import test_volume
|
||||
from nova.virt.libvirt.volume import aoe
|
||||
|
||||
|
||||
class LibvirtAOEVolumeDriverTestCase(test_volume.LibvirtVolumeBaseTestCase):
|
||||
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
def test_libvirt_aoe_driver(self, exists):
|
||||
libvirt_driver = aoe.LibvirtAOEVolumeDriver(self.fake_conn)
|
||||
self.assertIsInstance(libvirt_driver.connector,
|
||||
connector.AoEConnector)
|
||||
@@ -645,12 +645,6 @@ Setting up iSCSI targets: unused
|
||||
]
|
||||
self.assertEqual(expected_commands, self.executes)
|
||||
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
def test_libvirt_aoe_driver(self, exists):
|
||||
libvirt_driver = volume.LibvirtAOEVolumeDriver(self.fake_conn)
|
||||
self.assertIsInstance(libvirt_driver.connector,
|
||||
connector.AoEConnector)
|
||||
|
||||
@mock.patch.object(libvirt_utils, 'is_mounted')
|
||||
def test_libvirt_smbfs_driver(self, mock_is_mounted):
|
||||
mnt_base = '/mnt'
|
||||
|
||||
@@ -281,7 +281,7 @@ libvirt_volume_drivers = [
|
||||
'sheepdog=nova.virt.libvirt.volume.volume.LibvirtNetVolumeDriver',
|
||||
'nfs=nova.virt.libvirt.volume.volume.LibvirtNFSVolumeDriver',
|
||||
'smbfs=nova.virt.libvirt.volume.volume.LibvirtSMBFSVolumeDriver',
|
||||
'aoe=nova.virt.libvirt.volume.volume.LibvirtAOEVolumeDriver',
|
||||
'aoe=nova.virt.libvirt.volume.aoe.LibvirtAOEVolumeDriver',
|
||||
'glusterfs='
|
||||
'nova.virt.libvirt.volume.glusterfs.LibvirtGlusterfsVolumeDriver',
|
||||
'fibre_channel='
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from os_brick.initiator import connector
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from nova import utils
|
||||
from nova.virt.libvirt.volume import volume as libvirt_volume
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
volume_opts = [
|
||||
cfg.IntOpt('num_aoe_discover_tries',
|
||||
default=3,
|
||||
help='Number of times to rediscover AoE target to find volume'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(volume_opts, 'libvirt')
|
||||
|
||||
|
||||
class LibvirtAOEVolumeDriver(libvirt_volume.LibvirtBaseVolumeDriver):
|
||||
"""Driver to attach AoE volumes to libvirt."""
|
||||
def __init__(self, connection):
|
||||
super(LibvirtAOEVolumeDriver,
|
||||
self).__init__(connection, is_block_dev=True)
|
||||
|
||||
# Call the factory here so we can support
|
||||
# more than x86 architectures.
|
||||
self.connector = connector.InitiatorConnector.factory(
|
||||
'AOE', utils._get_root_helper(),
|
||||
device_scan_attempts=CONF.libvirt.num_aoe_discover_tries)
|
||||
|
||||
def get_config(self, connection_info, disk_info):
|
||||
"""Returns xml for libvirt."""
|
||||
conf = super(LibvirtAOEVolumeDriver,
|
||||
self).get_config(connection_info, disk_info)
|
||||
|
||||
conf.source_type = "block"
|
||||
conf.source_path = connection_info['data']['device_path']
|
||||
return conf
|
||||
|
||||
def connect_volume(self, connection_info, mount_device):
|
||||
LOG.debug("Calling os-brick to attach AoE Volume")
|
||||
device_info = self.connector.connect_volume(connection_info['data'])
|
||||
LOG.debug("Attached AoE volume %s", device_info)
|
||||
|
||||
connection_info['data']['device_path'] = device_info['path']
|
||||
|
||||
def disconnect_volume(self, connection_info, disk_dev):
|
||||
"""Detach the volume from instance_name."""
|
||||
|
||||
LOG.debug("calling os-brick to detach AoE Volume %s",
|
||||
connection_info)
|
||||
self.connector.disconnect_volume(connection_info['data'], None)
|
||||
LOG.debug("Disconnected AoE Volume %s", disk_dev)
|
||||
|
||||
super(LibvirtAOEVolumeDriver,
|
||||
self).disconnect_volume(connection_info, disk_dev)
|
||||
@@ -65,9 +65,6 @@ volume_opts = [
|
||||
help='Mount options passed to the SMBFS client. See '
|
||||
'mount.cifs man page for details. Note that the '
|
||||
'libvirt-qemu uid and gid must be specified.'),
|
||||
cfg.IntOpt('num_aoe_discover_tries',
|
||||
default=3,
|
||||
help='Number of times to rediscover AoE target to find volume'),
|
||||
cfg.BoolOpt('iscsi_use_multipath',
|
||||
default=False,
|
||||
help='Use multipath connection of the iSCSI volume'),
|
||||
@@ -484,43 +481,3 @@ class LibvirtSMBFSVolumeDriver(LibvirtBaseVolumeDriver):
|
||||
# Remove the Domain Name from user name
|
||||
mount_options = self.username_regex.sub(r'\1=\2', mount_options)
|
||||
return mount_options.strip(", ").split(' ')
|
||||
|
||||
|
||||
class LibvirtAOEVolumeDriver(LibvirtBaseVolumeDriver):
|
||||
"""Driver to attach AoE volumes to libvirt."""
|
||||
def __init__(self, connection):
|
||||
super(LibvirtAOEVolumeDriver,
|
||||
self).__init__(connection, is_block_dev=True)
|
||||
|
||||
# Call the factory here so we can support
|
||||
# more than x86 architectures.
|
||||
self.connector = connector.InitiatorConnector.factory(
|
||||
'AOE', utils._get_root_helper(),
|
||||
device_scan_attempts=CONF.libvirt.num_aoe_discover_tries)
|
||||
|
||||
def get_config(self, connection_info, disk_info):
|
||||
"""Returns xml for libvirt."""
|
||||
conf = super(LibvirtAOEVolumeDriver,
|
||||
self).get_config(connection_info, disk_info)
|
||||
|
||||
conf.source_type = "block"
|
||||
conf.source_path = connection_info['data']['device_path']
|
||||
return conf
|
||||
|
||||
def connect_volume(self, connection_info, mount_device):
|
||||
LOG.debug("Calling os-brick to attach AoE Volume")
|
||||
device_info = self.connector.connect_volume(connection_info['data'])
|
||||
LOG.debug("Attached AoE volume %s", device_info)
|
||||
|
||||
connection_info['data']['device_path'] = device_info['path']
|
||||
|
||||
def disconnect_volume(self, connection_info, disk_dev):
|
||||
"""Detach the volume from instance_name."""
|
||||
|
||||
LOG.debug("calling os-brick to detach AoE Volume %s",
|
||||
connection_info)
|
||||
self.connector.disconnect_volume(connection_info['data'], None)
|
||||
LOG.debug("Disconnected AoE Volume %s", disk_dev)
|
||||
|
||||
super(LibvirtAOEVolumeDriver,
|
||||
self).disconnect_volume(connection_info, disk_dev)
|
||||
Reference in new issue
Block a user