Merge "Adding Read-Only volume attaching support to Nova"
This commit is contained in:
commit
7c68f0e787
@ -277,6 +277,10 @@ class InvalidVolume(Invalid):
|
||||
msg_fmt = _("Invalid volume") + ": %(reason)s"
|
||||
|
||||
|
||||
class InvalidVolumeAccessMode(Invalid):
|
||||
msg_fmt = _("Invalid volume access mode") + ": %(access_mode)s"
|
||||
|
||||
|
||||
class InvalidMetadata(Invalid):
|
||||
msg_fmt = _("Invalid metadata") + ": %(reason)s"
|
||||
|
||||
|
@ -1487,6 +1487,31 @@ class LibvirtConfigNodeDevicePciCapTest(LibvirtConfigBaseTest):
|
||||
self.assertEqual(obj.fun_capability[1].device_addrs,
|
||||
[("0000", '0x0a', '0x1', "0x1"), ])
|
||||
|
||||
def test_config_read_only_disk(self):
|
||||
obj = config.LibvirtConfigGuestDisk()
|
||||
obj.source_type = "disk"
|
||||
obj.source_device = "disk"
|
||||
obj.driver_name = "kvm"
|
||||
obj.target_dev = "/dev/hdc"
|
||||
obj.target_bus = "virtio"
|
||||
obj.readonly = True
|
||||
|
||||
xml = obj.to_xml()
|
||||
self.assertXmlEqual(xml, """
|
||||
<disk type="disk" device="disk">
|
||||
<driver name="kvm"/>
|
||||
<target bus="virtio" dev="/dev/hdc"/>
|
||||
<readonly/>
|
||||
</disk>""")
|
||||
|
||||
obj.readonly = False
|
||||
xml = obj.to_xml()
|
||||
self.assertXmlEqual(xml, """
|
||||
<disk type="disk" device="disk">
|
||||
<driver name="kvm"/>
|
||||
<target bus="virtio" dev="/dev/hdc"/>
|
||||
</disk>""")
|
||||
|
||||
|
||||
class LibvirtConfigNodeDevicePciSubFunctionCap(LibvirtConfigBaseTest):
|
||||
|
||||
|
@ -194,6 +194,36 @@ class LibvirtVolumeTestCase(test.NoDBTestCase):
|
||||
self.assertEqual('200', tree.find('./iotune/read_iops_sec').text)
|
||||
self.assertEqual('200', tree.find('./iotune/write_iops_sec').text)
|
||||
|
||||
def test_libvirt_volume_driver_readonly(self):
|
||||
libvirt_driver = volume.LibvirtVolumeDriver(self.fake_conn)
|
||||
connection_info = {
|
||||
'driver_volume_type': 'fake',
|
||||
'data': {
|
||||
"device_path": "/foo",
|
||||
'access_mode': 'bar',
|
||||
},
|
||||
}
|
||||
disk_info = {
|
||||
"bus": "virtio",
|
||||
"dev": "vde",
|
||||
"type": "disk",
|
||||
}
|
||||
self.assertRaises(exception.InvalidVolumeAccessMode,
|
||||
libvirt_driver.connect_volume,
|
||||
connection_info, self.disk_info)
|
||||
|
||||
connection_info['data']['access_mode'] = 'rw'
|
||||
conf = libvirt_driver.connect_volume(connection_info, disk_info)
|
||||
tree = conf.format_dom()
|
||||
readonly = tree.find('./readonly')
|
||||
self.assertEqual(readonly, None)
|
||||
|
||||
connection_info['data']['access_mode'] = 'ro'
|
||||
conf = libvirt_driver.connect_volume(connection_info, disk_info)
|
||||
tree = conf.format_dom()
|
||||
readonly = tree.find('./readonly')
|
||||
self.assertNotEqual(readonly, None)
|
||||
|
||||
def iscsi_connection(self, volume, location, iqn):
|
||||
return {
|
||||
'driver_volume_type': 'iscsi',
|
||||
|
@ -479,6 +479,7 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice):
|
||||
self.disk_total_iops_sec = None
|
||||
self.logical_block_size = None
|
||||
self.physical_block_size = None
|
||||
self.readonly = False
|
||||
|
||||
def format_dom(self):
|
||||
dev = super(LibvirtConfigGuestDisk, self).format_dom()
|
||||
@ -573,6 +574,9 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice):
|
||||
|
||||
dev.append(blockio)
|
||||
|
||||
if self.readonly:
|
||||
dev.append(etree.Element("readonly"))
|
||||
|
||||
return dev
|
||||
|
||||
def parse_dom(self, xmldoc):
|
||||
|
@ -131,6 +131,18 @@ class LibvirtBaseVolumeDriver(object):
|
||||
LOG.warn(_('Unknown content in connection_info/'
|
||||
'qos_specs: %s') % specs)
|
||||
|
||||
# Extract access_mode control parameters
|
||||
if 'access_mode' in data and data['access_mode']:
|
||||
access_mode = data['access_mode']
|
||||
if access_mode in ('ro', 'rw'):
|
||||
conf.readonly = access_mode == 'ro'
|
||||
else:
|
||||
msg = (_('Unknown content in connection_info/access_mode: %s')
|
||||
% access_mode)
|
||||
LOG.error(msg)
|
||||
raise exception.InvalidVolumeAccessMode(
|
||||
access_mode=access_mode)
|
||||
|
||||
return conf
|
||||
|
||||
def disconnect_volume(self, connection_info, disk_dev):
|
||||
|
Loading…
x
Reference in New Issue
Block a user