Add format_dom for PCI device addresses
In case of having a PCI device, its address can not be output properly in the instance XML because of the missing format_dom method. This change adds this method. Closes-Bug: #1709319 Change-Id: I1a8023ee6e8c85eed1c7c55a21f996371a0dd80a
This commit is contained in:
parent
5971dde5d9
commit
376a902cab
|
@ -1058,6 +1058,42 @@ class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest):
|
|||
<address type="drive" controller="1" bus="2" target="3" unit="4"/>
|
||||
</disk>""", obj.to_xml())
|
||||
|
||||
def test_config_disk_device_address_pci(self):
|
||||
obj = config.LibvirtConfigGuestDeviceAddressPCI()
|
||||
obj.domain = 1
|
||||
obj.bus = 2
|
||||
obj.slot = 3
|
||||
obj.function = 4
|
||||
|
||||
xml = """
|
||||
<address type="pci" domain="1" bus="2" slot="3" function="4"/>
|
||||
"""
|
||||
self.assertXmlEqual(xml, obj.to_xml())
|
||||
|
||||
def test_config_disk_device_address_pci_added(self):
|
||||
obj = config.LibvirtConfigGuestDisk()
|
||||
obj.source_type = "network"
|
||||
obj.source_name = "volumes/volume-0"
|
||||
obj.source_protocol = "rbd"
|
||||
obj.source_hosts = ["192.168.1.1"]
|
||||
obj.source_ports = ["1234"]
|
||||
obj.target_dev = "hdb"
|
||||
obj.target_bus = "virtio"
|
||||
obj.device_addr = config.LibvirtConfigGuestDeviceAddressPCI()
|
||||
obj.device_addr.domain = 1
|
||||
obj.device_addr.bus = 2
|
||||
obj.device_addr.slot = 3
|
||||
obj.device_addr.function = 4
|
||||
|
||||
self.assertXmlEqual("""
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="rbd" name="volumes/volume-0">
|
||||
<host name="192.168.1.1" port="1234"/>
|
||||
</source>
|
||||
<target bus="virtio" dev="hdb"/>
|
||||
<address type="pci" domain="1" bus="2" slot="3" function="4"/>
|
||||
</disk>""", obj.to_xml())
|
||||
|
||||
def test_config_disk_device_address_type_virtio_mmio(self):
|
||||
xml = """
|
||||
<disk type='file' device='disk'>
|
||||
|
|
|
@ -1221,6 +1221,20 @@ class LibvirtConfigGuestDeviceAddressPCI(LibvirtConfigGuestDeviceAddress):
|
|||
self.slot = None
|
||||
self.function = None
|
||||
|
||||
def format_dom(self):
|
||||
xml = super(LibvirtConfigGuestDeviceAddressPCI, self).format_dom()
|
||||
|
||||
if self.domain is not None:
|
||||
xml.set("domain", str(self.domain))
|
||||
if self.bus is not None:
|
||||
xml.set("bus", str(self.bus))
|
||||
if self.slot is not None:
|
||||
xml.set("slot", str(self.slot))
|
||||
if self.function is not None:
|
||||
xml.set("function", str(self.function))
|
||||
|
||||
return xml
|
||||
|
||||
def parse_dom(self, xmldoc):
|
||||
self.domain = xmldoc.get('domain')
|
||||
self.bus = xmldoc.get('bus')
|
||||
|
|
Loading…
Reference in New Issue