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
(cherry picked from commit 376a902cab
)
This commit is contained in:
parent
6c67eee6f4
commit
bcf110fe7c
|
@ -1058,6 +1058,42 @@ class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest):
|
||||||
<address type="drive" controller="1" bus="2" target="3" unit="4"/>
|
<address type="drive" controller="1" bus="2" target="3" unit="4"/>
|
||||||
</disk>""", obj.to_xml())
|
</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):
|
def test_config_disk_device_address_type_virtio_mmio(self):
|
||||||
xml = """
|
xml = """
|
||||||
<disk type='file' device='disk'>
|
<disk type='file' device='disk'>
|
||||||
|
|
|
@ -1201,6 +1201,20 @@ class LibvirtConfigGuestDeviceAddressPCI(LibvirtConfigGuestDeviceAddress):
|
||||||
self.slot = None
|
self.slot = None
|
||||||
self.function = 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):
|
def parse_dom(self, xmldoc):
|
||||||
self.domain = xmldoc.get('domain')
|
self.domain = xmldoc.get('domain')
|
||||||
self.bus = xmldoc.get('bus')
|
self.bus = xmldoc.get('bus')
|
||||||
|
|
Loading…
Reference in New Issue