Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Porting #52574 to master #54687

Merged
merged 3 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,9 @@ def get_xml(vm_, **kwargs):
salt '*' virt.get_xml <domain>
'''
conn = __get_conn(**kwargs)
xml_desc = _get_domain(conn, vm_).XMLDesc(0)
xml_desc = vm_.XMLDesc(0) if isinstance(
vm_, libvirt.virDomain
) else _get_domain(conn, vm_).XMLDesc(0)
conn.close()
return xml_desc

Expand Down
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