libvirt: set device address tag only if setting disk unit
In Pike, we began setting disk unit values manually for the
'virtio-scsi' controller model in order to allow up to 256 devices [1].
We do this by setting the disk unit of the address tag manually for the
guest config. If we do not set the address tag manually, libvirt would
autogenerate it for us.
A problem occurs when a user has a SCSI disk that is a volume or isn't
using the 'virtio-scsi' controller model because we're not guarding our
manual setting of the address tag in the guest config by the disk unit,
in addition to the SCSI bus. This means that for a SCSI volume, we
generate an address tag like '<address type="drive" controller="0"/>'
for any SCSI volume, so a user with more than one device will get the
following error when they try to boot an instance:
Failed to start libvirt guest: libvirtError: unsupported
configuration: Found duplicate drive address for disk with target name
'sda' controller='0' bus='0' target='0' unit='0'
This updates the conditionals to only manually set the address tag if
the bus is SCSI _and_ the disk unit has been specified. Otherwise, let
libvirt autogenerate the address tag and take care of avoiding
collisions.
[1] https://bugs.launchpad.net/nova/+bug/1686116
Closes-Bug: #1792077
Change-Id: Iefab05e84ccc0bf8f15bdbbf515a290d282dbc5d
(cherry picked from commit 48fd81648a
)
This commit is contained in:
parent
353985210b
commit
7500c1910c
|
@ -20,6 +20,7 @@ import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from castellan import key_manager
|
from castellan import key_manager
|
||||||
|
import ddt
|
||||||
import fixtures
|
import fixtures
|
||||||
import mock
|
import mock
|
||||||
from oslo_concurrency import lockutils
|
from oslo_concurrency import lockutils
|
||||||
|
@ -58,6 +59,7 @@ class FakeConn(object):
|
||||||
return FakeSecret()
|
return FakeSecret()
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class _ImageTestCase(object):
|
class _ImageTestCase(object):
|
||||||
|
|
||||||
def mock_create_image(self, image):
|
def mock_create_image(self, image):
|
||||||
|
@ -207,6 +209,28 @@ class _ImageTestCase(object):
|
||||||
self.assertEqual(2361393152, image.get_disk_size(image.path))
|
self.assertEqual(2361393152, image.get_disk_size(image.path))
|
||||||
get_disk_size.assert_called_once_with(image.path)
|
get_disk_size.assert_called_once_with(image.path)
|
||||||
|
|
||||||
|
def _test_libvirt_info_scsi_with_unit(self, disk_unit):
|
||||||
|
# The address should be set if bus is scsi and unit is set.
|
||||||
|
# Otherwise, it should not be set at all.
|
||||||
|
image = self.image_class(self.INSTANCE, self.NAME)
|
||||||
|
disk_info = {
|
||||||
|
'bus': 'scsi',
|
||||||
|
'dev': '/dev/sda',
|
||||||
|
'type': 'disk',
|
||||||
|
}
|
||||||
|
disk = image.libvirt_info(disk_info, cache_mode='none', extra_specs={},
|
||||||
|
hypervisor_version=4004001,
|
||||||
|
disk_unit=disk_unit)
|
||||||
|
if disk_unit:
|
||||||
|
self.assertEqual(0, disk.device_addr.controller)
|
||||||
|
self.assertEqual(disk_unit, disk.device_addr.unit)
|
||||||
|
else:
|
||||||
|
self.assertIsNone(disk.device_addr)
|
||||||
|
|
||||||
|
@ddt.data(5, None)
|
||||||
|
def test_libvirt_info_scsi_with_unit(self, disk_unit):
|
||||||
|
self._test_libvirt_info_scsi_with_unit(disk_unit)
|
||||||
|
|
||||||
|
|
||||||
class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
|
class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
|
|
||||||
|
@ -1279,6 +1303,7 @@ class EncryptedLvmTestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
model)
|
model)
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class RbdTestCase(_ImageTestCase, test.NoDBTestCase):
|
class RbdTestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
FSID = "FakeFsID"
|
FSID = "FakeFsID"
|
||||||
POOL = "FakePool"
|
POOL = "FakePool"
|
||||||
|
@ -1503,6 +1528,17 @@ class RbdTestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
|
|
||||||
super(RbdTestCase, self).test_libvirt_info()
|
super(RbdTestCase, self).test_libvirt_info()
|
||||||
|
|
||||||
|
@ddt.data(5, None)
|
||||||
|
@mock.patch.object(rbd_utils.RBDDriver, "get_mon_addrs")
|
||||||
|
def test_libvirt_info_scsi_with_unit(self, disk_unit, mock_mon_addrs):
|
||||||
|
def get_mon_addrs():
|
||||||
|
hosts = ["server1", "server2"]
|
||||||
|
ports = ["1899", "1920"]
|
||||||
|
return hosts, ports
|
||||||
|
mock_mon_addrs.side_effect = get_mon_addrs
|
||||||
|
|
||||||
|
super(RbdTestCase, self)._test_libvirt_info_scsi_with_unit(disk_unit)
|
||||||
|
|
||||||
@mock.patch.object(rbd_utils.RBDDriver, "get_mon_addrs")
|
@mock.patch.object(rbd_utils.RBDDriver, "get_mon_addrs")
|
||||||
def test_get_model(self, mock_mon_addrs):
|
def test_get_model(self, mock_mon_addrs):
|
||||||
pool = "FakePool"
|
pool = "FakePool"
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
from oslo_utils.fixture import uuidsentinel as uuids
|
from oslo_utils.fixture import uuidsentinel as uuids
|
||||||
|
|
||||||
|
@ -140,6 +141,7 @@ class LibvirtISCSIVolumeBaseTestCase(LibvirtVolumeBaseTestCase):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class LibvirtVolumeTestCase(LibvirtISCSIVolumeBaseTestCase):
|
class LibvirtVolumeTestCase(LibvirtISCSIVolumeBaseTestCase):
|
||||||
|
|
||||||
def _assertDiskInfoEquals(self, tree, disk_info):
|
def _assertDiskInfoEquals(self, tree, disk_info):
|
||||||
|
@ -383,3 +385,21 @@ class LibvirtVolumeTestCase(LibvirtISCSIVolumeBaseTestCase):
|
||||||
conf = libvirt_driver.get_config(connection_info, self.disk_info)
|
conf = libvirt_driver.get_config(connection_info, self.disk_info)
|
||||||
tree = conf.format_dom()
|
tree = conf.format_dom()
|
||||||
self.assertIsNone(tree.find("encryption"))
|
self.assertIsNone(tree.find("encryption"))
|
||||||
|
|
||||||
|
@ddt.data(5, None)
|
||||||
|
def test_libvirt_volume_driver_address_tag_scsi_unit(self, disk_unit):
|
||||||
|
# The address tag should be set if bus is scsi and unit is set.
|
||||||
|
# Otherwise, it should not be set at all.
|
||||||
|
libvirt_driver = volume.LibvirtVolumeDriver(self.fake_host)
|
||||||
|
connection_info = {'data': {'device_path': '/foo'}}
|
||||||
|
disk_info = {'bus': 'scsi', 'dev': 'sda', 'type': 'disk'}
|
||||||
|
if disk_unit:
|
||||||
|
disk_info['unit'] = disk_unit
|
||||||
|
conf = libvirt_driver.get_config(connection_info, disk_info)
|
||||||
|
tree = conf.format_dom()
|
||||||
|
address = tree.find('address')
|
||||||
|
if disk_unit:
|
||||||
|
self.assertEqual('0', address.attrib['controller'])
|
||||||
|
self.assertEqual(str(disk_unit), address.attrib['unit'])
|
||||||
|
else:
|
||||||
|
self.assertIsNone(address)
|
||||||
|
|
|
@ -180,11 +180,17 @@ class Image(object):
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def disk_scsi(self, info, disk_unit):
|
def disk_scsi(self, info, disk_unit):
|
||||||
# The driver is responsible to create the SCSI controller
|
# NOTE(melwitt): We set the device address unit number manually in the
|
||||||
# at index 0.
|
# case of the virtio-scsi controller, in order to allow attachment of
|
||||||
info.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive()
|
# up to 256 devices. So, we should only be setting the address tag
|
||||||
info.device_addr.controller = 0
|
# if we intend to set the unit number. Otherwise, we will let libvirt
|
||||||
|
# handle autogeneration of the address tag.
|
||||||
|
# See https://bugs.launchpad.net/nova/+bug/1792077 for details.
|
||||||
if disk_unit is not None:
|
if disk_unit is not None:
|
||||||
|
# The driver is responsible to create the SCSI controller
|
||||||
|
# at index 0.
|
||||||
|
info.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive()
|
||||||
|
info.device_addr.controller = 0
|
||||||
# In order to allow up to 256 disks handled by one
|
# In order to allow up to 256 disks handled by one
|
||||||
# virtio-scsi controller, the device addr should be
|
# virtio-scsi controller, the device addr should be
|
||||||
# specified.
|
# specified.
|
||||||
|
|
|
@ -94,16 +94,21 @@ class LibvirtBaseVolumeDriver(object):
|
||||||
if data.get('discard', False) is True:
|
if data.get('discard', False) is True:
|
||||||
conf.driver_discard = 'unmap'
|
conf.driver_discard = 'unmap'
|
||||||
|
|
||||||
if disk_info['bus'] == 'scsi':
|
# NOTE(melwitt): We set the device address unit number manually in the
|
||||||
|
# case of the virtio-scsi controller, in order to allow attachment of
|
||||||
|
# up to 256 devices. So, we should only be setting the address tag
|
||||||
|
# if we intend to set the unit number. Otherwise, we will let libvirt
|
||||||
|
# handle autogeneration of the address tag.
|
||||||
|
# See https://bugs.launchpad.net/nova/+bug/1792077 for details.
|
||||||
|
if disk_info['bus'] == 'scsi' and 'unit' in disk_info:
|
||||||
# The driver is responsible to create the SCSI controller
|
# The driver is responsible to create the SCSI controller
|
||||||
# at index 0.
|
# at index 0.
|
||||||
conf.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive()
|
conf.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive()
|
||||||
conf.device_addr.controller = 0
|
conf.device_addr.controller = 0
|
||||||
if 'unit' in disk_info:
|
# In order to allow up to 256 disks handled by one
|
||||||
# In order to allow up to 256 disks handled by one
|
# virtio-scsi controller, the device addr should be
|
||||||
# virtio-scsi controller, the device addr should be
|
# specified.
|
||||||
# specified.
|
conf.device_addr.unit = disk_info['unit']
|
||||||
conf.device_addr.unit = disk_info['unit']
|
|
||||||
|
|
||||||
if connection_info.get('multiattach', False):
|
if connection_info.get('multiattach', False):
|
||||||
# Note that driver_cache should be disabled (none) when using
|
# Note that driver_cache should be disabled (none) when using
|
||||||
|
|
Loading…
Reference in New Issue