Browse Source

Merge "fix scsi disk unit number of the attaching volume when cdrom bus is scsi" into stable/queens

changes/23/742423/1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
0a36218bcf
2 changed files with 51 additions and 5 deletions
  1. +46
    -0
      nova/tests/unit/virt/libvirt/test_driver.py
  2. +5
    -5
      nova/virt/libvirt/driver.py

+ 46
- 0
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -4444,6 +4444,52 @@ class LibvirtConnTestCase(test.NoDBTestCase,
guest = libvirt_guest.Guest(FakeVirtDomain())
return drvr._get_serial_ports_from_guest(guest, mode=mode)

def test_get_scsi_controller_next_unit_from_guest(self):
xml = """
<domain type='kvm'>
<devices>
<disk type='file' device='disk'>
<target dev='sda' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
<target dev='sdc' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
</devices>
</domain>
"""
self._test_get_scsi_controller_next_unit_from_guest(xml, 2)

def test_get_scsi_controller_next_unit_from_guest_no_scsi(self):
xml = """
<domain type='kvm'>
<devices>
<disk type='file' device='disk'>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<target dev='vdb' bus='virtio'/>
</disk>
</devices>
</domain>
"""
self._test_get_scsi_controller_next_unit_from_guest(xml, 0)

@mock.patch.object(libvirt_guest.Guest, "get_xml_desc")
def _test_get_scsi_controller_next_unit_from_guest(self, xml,
expect_num,
mock_get_xml_desc):
mock_get_xml_desc.return_value = xml

drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
guest = libvirt_guest.Guest(FakeVirtDomain())
i = drvr._get_scsi_controller_next_unit(guest)
self.assertEqual(expect_num, i)

def test_get_guest_config_with_type_xen(self):
self.flags(enabled=True, group='vnc')
self.flags(virt_type='xen',


+ 5
- 5
nova/virt/libvirt/driver.py View File

@@ -1222,16 +1222,16 @@ class LibvirtDriver(driver.ComputeDriver):
for source in tcp_devices:
yield (source.get("host"), int(source.get("service")))

def _get_scsi_controller_max_unit(self, guest):
def _get_scsi_controller_next_unit(self, guest):
"""Returns the max disk unit used by scsi controller"""
xml = guest.get_xml_desc()
tree = etree.fromstring(xml)
addrs = "./devices/disk[@device='disk']/address[@type='drive']"
addrs = "./devices/disk[target/@bus='scsi']/address[@type='drive']"

ret = []
for obj in tree.findall(addrs):
for obj in tree.xpath(addrs):
ret.append(int(obj.get('unit', 0)))
return max(ret)
return max(ret) + 1 if ret else 0

@staticmethod
def _get_rbd_driver():
@@ -1557,7 +1557,7 @@ class LibvirtDriver(driver.ComputeDriver):
disk_info = blockinfo.get_info_from_bdm(
instance, CONF.libvirt.virt_type, instance.image_meta, bdm)
if disk_info['bus'] == 'scsi':
disk_info['unit'] = self._get_scsi_controller_max_unit(guest) + 1
disk_info['unit'] = self._get_scsi_controller_next_unit(guest)

conf = self._get_volume_config(connection_info, disk_info)



Loading…
Cancel
Save