fix lxml compatibility issues
Some unit tests were performing string matches on xml data with inputs that were generated using lxml. This is problematic as while white space between element tags is important in xml ordering of attributes within a tag is not. In the latest version of lxml the ordering asserted in the test no longer matches the order returned by lxml on python 3.6+. This change updates the failing test to use the XMLMatcher class to compare xml strings instead. Closes-Bug: #1838666 Related-Bug: #1841667 Change-Id: I1649a850ccb9ac85d7a962936ffef51d573b6f78
This commit is contained in:
parent
912a46c9d4
commit
58ffff49ac
|
@ -8083,12 +8083,13 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
self.context, connection_info, instance, '/dev/vdc')
|
||||
|
||||
mock_get_domain.assert_called_with(instance)
|
||||
mock_dom.detachDeviceFlags.assert_called_with(
|
||||
"""<disk type="file" device="disk">
|
||||
<source file="/path/to/fake-volume"/>
|
||||
<target bus="virtio" dev="vdc"/>
|
||||
</disk>
|
||||
""", flags=flags)
|
||||
call = mock_dom.detachDeviceFlags.mock_calls[0]
|
||||
xml = """<disk type="file" device="disk">
|
||||
<source file="/path/to/fake-volume"/>
|
||||
<target bus="virtio" dev="vdc"/>
|
||||
</disk>"""
|
||||
self.assertXmlEqual(xml, call.args[0])
|
||||
self.assertEqual({"flags": flags}, call.kwargs)
|
||||
mock_disconnect_volume.assert_called_with(
|
||||
self.context, connection_info, instance, encryption=None)
|
||||
|
||||
|
@ -10279,8 +10280,9 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
config = etree.fromstring(config, parser)
|
||||
target_xml = etree.fromstring(target_xml, parser)
|
||||
self.assertEqual(etree.tostring(target_xml, encoding='unicode'),
|
||||
etree.tostring(config, encoding='unicode'))
|
||||
self.assertXmlEqual(
|
||||
etree.tostring(target_xml, encoding='unicode'),
|
||||
etree.tostring(config, encoding='unicode'))
|
||||
|
||||
def test_live_migration_uri(self):
|
||||
addresses = ('127.0.0.1', '127.0.0.1:4444', '[::1]:4444',
|
||||
|
@ -14688,10 +14690,9 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
]
|
||||
|
||||
self.assertEqual(2, mock_detachDeviceFlags.call_count)
|
||||
mock_detachDeviceFlags.assert_has_calls([
|
||||
mock.call(expected_xml[0], flags=1),
|
||||
mock.call(expected_xml[1], flags=1)
|
||||
])
|
||||
for index, call in enumerate(mock_detachDeviceFlags.mock_calls):
|
||||
self.assertXmlEqual(expected_xml[index], call.args[0])
|
||||
self.assertEqual({"flags": 1}, call.kwargs)
|
||||
|
||||
def test_resume(self):
|
||||
dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
|
||||
|
@ -21033,10 +21034,10 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
|
|||
# NOTE(gcb): etree.tostring(node) returns an extra line with
|
||||
# some white spaces, need to strip it.
|
||||
actual_diska_xml = guest.get_disk('vda').to_xml()
|
||||
self.assertEqual(diska_xml.strip(), actual_diska_xml.strip())
|
||||
self.assertXmlEqual(diska_xml, actual_diska_xml)
|
||||
|
||||
actual_diskb_xml = guest.get_disk('vdb').to_xml()
|
||||
self.assertEqual(diskb_xml.strip(), actual_diskb_xml.strip())
|
||||
self.assertXmlEqual(diskb_xml, actual_diskb_xml)
|
||||
|
||||
self.assertIsNone(guest.get_disk('vdc'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue