Merge pull request #21487 from rallytime/bp-21469

Backport #21469 to 2014.7
This commit is contained in:
Thomas S Hatch 2015-03-11 15:05:08 -06:00
commit 4873382184
3 changed files with 46 additions and 9 deletions

View File

@ -20,9 +20,9 @@ import logging
import yaml
import jinja2
import jinja2.exceptions
from xml.dom import minidom
try:
import libvirt
from xml.dom import minidom
HAS_ALL_IMPORTS = True
except ImportError:
HAS_ALL_IMPORTS = False
@ -799,8 +799,8 @@ def get_nics(vm_):
# driver, source, and match can all have optional attributes
if re.match('(driver|source|address)', v_node.tagName):
temp = {}
for key in v_node.attributes:
temp[key] = v_node.getAttribute(key)
for key, value in v_node.attributes.items():
temp[key] = value
nic[str(v_node.tagName)] = temp
# virtualport needs to be handled separately, to pick up the
# type attribute of the virtualport itself
@ -857,8 +857,8 @@ def get_graphics(vm_):
for node in doc.getElementsByTagName('domain'):
g_nodes = node.getElementsByTagName('graphics')
for g_node in g_nodes:
for key in g_node.attributes:
out[key] = g_node.getAttribute(key)
for key, value in g_node.attributes.items():
out[key] = value
return out

View File

@ -23,8 +23,8 @@ class VirtTest(integration.ModuleCase):
'''
profiles = self.run_function('virt.get_profiles', ['kvm'])
nicp = profiles['nic']['default']
self.assertTrue(nicp['eth0'].get('model', '') == 'virtio')
self.assertTrue(nicp['eth0'].get('bridge', '') == 'br0')
self.assertTrue(nicp[0].get('model', '') == 'virtio')
self.assertTrue(nicp[0].get('source', '') == 'br0')
diskp = profiles['disk']['default']
self.assertTrue(diskp[0]['system'].get('model', '') == 'virtio')
self.assertTrue(diskp[0]['system'].get('format', '') == 'qcow2')
@ -36,8 +36,8 @@ class VirtTest(integration.ModuleCase):
'''
profiles = self.run_function('virt.get_profiles', ['esxi'])
nicp = profiles['nic']['default']
self.assertTrue(nicp['eth0'].get('model', '') == 'e1000')
self.assertTrue(nicp['eth0'].get('bridge', '') == 'DEFAULT')
self.assertTrue(nicp[0].get('model', '') == 'e1000')
self.assertTrue(nicp[0].get('source', '') == 'DEFAULT')
diskp = profiles['disk']['default']
self.assertTrue(diskp[0]['system'].get('model', '') == 'scsi')
self.assertTrue(diskp[0]['system'].get('format', '') == 'vmdk')

View File

@ -500,6 +500,43 @@ class VirtTestCase(TestCase):
re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$',
interface_attrs['mac'], re.I))
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
' which comes with Python 2.7')
def test_get_graphics(self):
virt.get_xml = MagicMock(return_value='''<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>
''')
graphics = virt.get_graphics('test-vm')
self.assertEqual('vnc', graphics['type'])
self.assertEqual('5900', graphics['port'])
self.assertEqual('0.0.0.0', graphics['listen'])
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
' which comes with Python 2.7')
def test_get_nics(self):
virt.get_xml = MagicMock(return_value='''<domain type='kvm' id='7'>
<name>test-vm</name>
<devices>
<interface type='bridge'>
<mac address='ac:de:48:b6:8b:59'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
</devices>
</domain>
''')
nics = virt.get_nics('test-vm')
nic = nics[nics.keys()[0]]
self.assertEqual('bridge', nic['type'])
self.assertEqual('ac:de:48:b6:8b:59', nic['mac'])
if __name__ == '__main__':
from integration import run_tests