Skip to content

Commit

Permalink
Added unit test for virt.get_xml().
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0def committed Apr 18, 2019
1 parent 70787c7 commit b2698d1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class LibvirtMock(MagicMock): # pylint: disable=too-many-ancestors
'''
Libvirt library mock
'''
class virDomain(MagicMock):
'''
virDomain mock
'''

class libvirtError(Exception):
'''
Expand Down Expand Up @@ -76,7 +80,7 @@ def set_mock_vm(self, name, xml):
Define VM to use in tests
'''
self.mock_conn.listDefinedDomains.return_value = [name] # pylint: disable=no-member
mock_domain = MagicMock()
mock_domain = self.mock_libvirt.virDomain()
self.mock_conn.lookupByName.return_value = mock_domain # pylint: disable=no-member
mock_domain.XMLDesc.return_value = xml # pylint: disable=no-member

Expand Down Expand Up @@ -1437,6 +1441,23 @@ def test_get_nics(self):
self.assertEqual('bridge', nic['type'])
self.assertEqual('ac:de:48:b6:8b:59', nic['mac'])

def test_get_xml(self):
'''
Test virt.get_xml()
'''
xml = '''<domain type='kvm' id='7'>
<name>test-vm</name>
<devices>
<graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
</devices>
</domain>
'''
domain = self.set_mock_vm("test-vm", xml)
self.assertEqual(xml, virt.get_xml('test-vm'))
self.assertEqual(xml, virt.get_xml(domain))

def test_parse_qemu_img_info(self):
'''
Make sure that qemu-img info output is properly parsed
Expand Down

0 comments on commit b2698d1

Please sign in to comment.