libvirt: Modify the interface address object assignment
In some other arch such as AArch64, the interface of the device has the address "virtio-mmio", not "PCI" or "Drive", so assign the default object "LibvirtConfigGuestDeviceAddress" to the interface. Also fix problem for S390x, s390x has address "ccw". Closes-Bug: #1598370 Change-Id: I10004c2060ff8f5a60e065b237311fe5b9fd1876 Signed-off-by: Kevin Zhao <kevin.zhao@linaro.org>
This commit is contained in:
parent
dc723362d5
commit
a221eb4cc6
|
@ -1002,6 +1002,42 @@ class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest):
|
|||
obj.device_addr.unit))
|
||||
self.assertIsNone(obj.device_addr.format_address())
|
||||
|
||||
def test_config_disk_device_address_type_virtio_mmio(self):
|
||||
xml = """
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='none'/>
|
||||
<source file='/var/lib/libvirt/images/generic.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='virtio-mmio'/>
|
||||
</disk>"""
|
||||
|
||||
obj = config.LibvirtConfigGuestDisk()
|
||||
obj.parse_str(xml)
|
||||
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressPCI)
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressDrive)
|
||||
|
||||
def test_config_disk_device_address_type_ccw(self):
|
||||
xml = """
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/var/lib/libvirt/images/test.qcow2'/>
|
||||
<backingStore/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<alias name='virtio-disk0'/>
|
||||
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
|
||||
</disk>"""
|
||||
|
||||
obj = config.LibvirtConfigGuestDisk()
|
||||
obj.parse_str(xml)
|
||||
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressPCI)
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressDrive)
|
||||
|
||||
|
||||
class LibvirtConfigGuestSnapshotDiskTest(LibvirtConfigBaseTest):
|
||||
|
||||
|
@ -1686,6 +1722,42 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):
|
|||
config.LibvirtConfigGuestDeviceAddressPCI)
|
||||
self.assertEqual('0000:00:03.0', obj.device_addr.format_address())
|
||||
|
||||
def test_config_interface_address_type_virtio_mmio(self):
|
||||
xml = """
|
||||
<interface type='network'>
|
||||
<mac address='fa:16:3e:d1:28:e4'/>
|
||||
<source network='default'/>
|
||||
<model type='virtio'/>
|
||||
<address type='virtio-mmio'/>
|
||||
</interface>"""
|
||||
|
||||
obj = config.LibvirtConfigGuestInterface()
|
||||
obj.parse_str(xml)
|
||||
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressPCI)
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressDrive)
|
||||
|
||||
def test_config_interface_address_type_ccw(self):
|
||||
xml = """
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:14:6f:50'/>
|
||||
<source network='default' bridge='virbr0'/>
|
||||
<target dev='vnet0'/>
|
||||
<model type='virtio'/>
|
||||
<alias name='net0'/>
|
||||
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0001'/>
|
||||
</interface>"""
|
||||
|
||||
obj = config.LibvirtConfigGuestInterface()
|
||||
obj.parse_str(xml)
|
||||
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressPCI)
|
||||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressDrive)
|
||||
|
||||
|
||||
class LibvirtConfigGuestFeatureTest(LibvirtConfigBaseTest):
|
||||
|
||||
|
|
|
@ -1611,6 +1611,20 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
<address type='pci' domain='0x0000' bus='0x00' slot='0x09'
|
||||
function='0x0'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='none'/>
|
||||
<source file='/var/lib/libvirt/images/generic.qcow2'/>
|
||||
<target dev='vdb' bus='virtio'/>
|
||||
<address type='virtio-mmio'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/var/lib/libvirt/images/test.qcow2'/>
|
||||
<backingStore/>
|
||||
<target dev='vdc' bus='virtio'/>
|
||||
<alias name='virtio-disk1'/>
|
||||
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
|
||||
</disk>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:f6:35:8f'/>
|
||||
<source network='default'/>
|
||||
|
@ -1625,6 +1639,20 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04'
|
||||
function='0x1'/>
|
||||
</interface>
|
||||
<interface type='network'>
|
||||
<mac address='fa:16:3e:d1:28:e4'/>
|
||||
<source network='default'/>
|
||||
<model type='virtio'/>
|
||||
<address type='virtio-mmio'/>
|
||||
</interface>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:14:6f:50'/>
|
||||
<source network='default' bridge='virbr0'/>
|
||||
<target dev='vnet0'/>
|
||||
<model type='virtio'/>
|
||||
<alias name='net0'/>
|
||||
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0001'/>
|
||||
</interface>
|
||||
</devices>
|
||||
</domain>"""
|
||||
|
||||
|
@ -1655,6 +1683,14 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
{'id': 5,
|
||||
'source_type': 'volume', 'destination_type': 'volume',
|
||||
'device_name': '/dev/vda', 'tag': "nfvfunc3"}),
|
||||
fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 6,
|
||||
'source_type': 'volume', 'destination_type': 'volume',
|
||||
'device_name': '/dev/vdb', 'tag': "nfvfunc4"}),
|
||||
fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 7,
|
||||
'source_type': 'volume', 'destination_type': 'volume',
|
||||
'device_name': '/dev/vdc', 'tag': "nfvfunc5"}),
|
||||
]
|
||||
)
|
||||
vif = obj_vif.VirtualInterface(context=self.context)
|
||||
|
@ -1669,7 +1705,19 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
vif1.instance_uuid = '32dfcb37-5af1-552b-357c-be8c3aa38310'
|
||||
vif1.uuid = 'abec4b21-ef22-6c21-534b-ba3e3ab3a312'
|
||||
vif1.tag = None
|
||||
vifs = [vif, vif1]
|
||||
vif2 = obj_vif.VirtualInterface(context=self.context)
|
||||
vif2.address = 'fa:16:3e:d1:28:e4'
|
||||
vif2.network_id = 123
|
||||
vif2.instance_uuid = '32dfcb37-5af1-552b-357c-be8c3aa38310'
|
||||
vif2.uuid = '645686e4-7086-4eab-8c2f-c41f017a1b16'
|
||||
vif2.tag = 'mytag2'
|
||||
vif3 = obj_vif.VirtualInterface(context=self.context)
|
||||
vif3.address = '52:54:00:14:6f:50'
|
||||
vif3.network_id = 123
|
||||
vif3.instance_uuid = '32dfcb37-5af1-552b-357c-be8c3aa38310'
|
||||
vif3.uuid = '99cc3604-782d-4a32-a27c-bc33ac56ce86'
|
||||
vif3.tag = 'mytag3'
|
||||
vifs = [vif, vif1, vif2, vif3]
|
||||
|
||||
with test.nested(
|
||||
mock.patch('nova.objects.VirtualInterfaceList'
|
||||
|
@ -1683,7 +1731,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
metadata_obj = drvr._build_device_metadata(self.context,
|
||||
instance_ref)
|
||||
metadata = metadata_obj.devices
|
||||
self.assertEqual(5, len(metadata))
|
||||
self.assertEqual(9, len(metadata))
|
||||
self.assertIsInstance(metadata[0],
|
||||
objects.DiskMetadata)
|
||||
self.assertIsInstance(metadata[0].bus,
|
||||
|
@ -1710,11 +1758,23 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
self.assertEqual(['nfvfunc3'], metadata[3].tags)
|
||||
self.assertEqual('0000:00:09.0', metadata[3].bus.address)
|
||||
self.assertIsInstance(metadata[4],
|
||||
objects.DiskMetadata)
|
||||
self.assertEqual(['nfvfunc4'], metadata[4].tags)
|
||||
self.assertIsInstance(metadata[5],
|
||||
objects.DiskMetadata)
|
||||
self.assertEqual(['nfvfunc5'], metadata[5].tags)
|
||||
self.assertIsInstance(metadata[6],
|
||||
objects.NetworkInterfaceMetadata)
|
||||
self.assertIsInstance(metadata[4].bus,
|
||||
self.assertIsInstance(metadata[6].bus,
|
||||
objects.PCIDeviceBus)
|
||||
self.assertEqual(['mytag1'], metadata[4].tags)
|
||||
self.assertEqual('0000:00:03.0', metadata[4].bus.address)
|
||||
self.assertEqual(['mytag1'], metadata[6].tags)
|
||||
self.assertEqual('0000:00:03.0', metadata[6].bus.address)
|
||||
self.assertIsInstance(metadata[7],
|
||||
objects.NetworkInterfaceMetadata)
|
||||
self.assertEqual(['mytag2'], metadata[7].tags)
|
||||
self.assertIsInstance(metadata[8],
|
||||
objects.NetworkInterfaceMetadata)
|
||||
self.assertEqual(['mytag3'], metadata[8].tags)
|
||||
|
||||
@mock.patch.object(host.Host, 'get_connection')
|
||||
@mock.patch.object(nova.virt.libvirt.guest.Guest, 'get_xml_desc')
|
||||
|
|
|
@ -892,8 +892,7 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice):
|
|||
elif c.tag == 'shareable':
|
||||
self.shareable = True
|
||||
elif c.tag == 'address':
|
||||
obj = LibvirtConfigGuestDeviceAddress.factory(c)
|
||||
obj.parse_dom(c)
|
||||
obj = LibvirtConfigGuestDeviceAddress.parse_dom(c)
|
||||
self.device_addr = obj
|
||||
elif c.tag == 'boot':
|
||||
self.boot_order = c.get('order')
|
||||
|
@ -1146,12 +1145,16 @@ class LibvirtConfigGuestDeviceAddress(LibvirtConfigObject):
|
|||
self.type = type
|
||||
|
||||
@staticmethod
|
||||
def factory(xmldoc):
|
||||
def parse_dom(xmldoc):
|
||||
addr_type = xmldoc.get('type')
|
||||
if addr_type == 'pci':
|
||||
return LibvirtConfigGuestDeviceAddressPCI()
|
||||
obj = LibvirtConfigGuestDeviceAddressPCI()
|
||||
elif addr_type == 'drive':
|
||||
return LibvirtConfigGuestDeviceAddressDrive()
|
||||
obj = LibvirtConfigGuestDeviceAddressDrive()
|
||||
else:
|
||||
return None
|
||||
obj.parse_dom(xmldoc)
|
||||
return obj
|
||||
|
||||
|
||||
class LibvirtConfigGuestDeviceAddressDrive(LibvirtConfigGuestDeviceAddress):
|
||||
|
@ -1398,8 +1401,7 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice):
|
|||
if sub.get('peak'):
|
||||
self.vif_outbound_peak = int(sub.get('peak'))
|
||||
elif c.tag == 'address':
|
||||
obj = LibvirtConfigGuestDeviceAddress.factory(c)
|
||||
obj.parse_dom(c)
|
||||
obj = LibvirtConfigGuestDeviceAddress.parse_dom(c)
|
||||
self.device_addr = obj
|
||||
|
||||
def add_filter_param(self, key, value):
|
||||
|
|
|
@ -7521,18 +7521,20 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
def _prepare_device_bus(dev):
|
||||
"""Determins the device bus and it's hypervisor assigned address
|
||||
"""
|
||||
bus = None
|
||||
address = (dev.device_addr.format_address() if
|
||||
dev.device_addr else None)
|
||||
if isinstance(dev.device_addr,
|
||||
vconfig.LibvirtConfigGuestDeviceAddressPCI):
|
||||
bus = objects.PCIDeviceBus()
|
||||
elif dev.target_bus == 'scsi':
|
||||
bus = objects.SCSIDeviceBus()
|
||||
elif dev.target_bus == 'ide':
|
||||
bus = objects.IDEDeviceBus()
|
||||
elif dev.target_bus == 'usb':
|
||||
bus = objects.USBDeviceBus()
|
||||
if address is not None:
|
||||
elif isinstance(dev, vconfig.LibvirtConfigGuestDisk):
|
||||
if dev.target_bus == 'scsi':
|
||||
bus = objects.SCSIDeviceBus()
|
||||
elif dev.target_bus == 'ide':
|
||||
bus = objects.IDEDeviceBus()
|
||||
elif dev.target_bus == 'usb':
|
||||
bus = objects.USBDeviceBus()
|
||||
if address is not None and bus is not None:
|
||||
bus.address = address
|
||||
return bus
|
||||
|
||||
|
@ -7569,9 +7571,10 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
bus = self._prepare_device_bus(dev)
|
||||
device = objects.NetworkInterfaceMetadata(
|
||||
mac=vif.address,
|
||||
bus=bus,
|
||||
tags=[vif.tag]
|
||||
)
|
||||
if bus:
|
||||
device.bus = bus
|
||||
devices.append(device)
|
||||
|
||||
# Build disks related metedata
|
||||
|
@ -7580,7 +7583,9 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
if not bdm:
|
||||
continue
|
||||
bus = self._prepare_device_bus(dev)
|
||||
device = objects.DiskMetadata(bus=bus, tags=[bdm.tag])
|
||||
device = objects.DiskMetadata(tags=[bdm.tag])
|
||||
if bus:
|
||||
device.bus = bus
|
||||
devices.append(device)
|
||||
if devices:
|
||||
dev_meta = objects.InstanceDeviceMetadata(devices=devices)
|
||||
|
|
Loading…
Reference in New Issue