mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Virt Template deploy, and serial xml tests
- Added virt templates to setup - moved NIC xml string template to file - added tests for serial xml
This commit is contained in:
parent
c7ae3ba592
commit
b95a5d9fd0
5 changed files with 64 additions and 14 deletions
|
@ -220,23 +220,23 @@ def _prepare_serial_port_xml(serial_type='pty', telnet_port='', console=True, **
|
|||
console=console)
|
||||
|
||||
def _prepare_nics_xml(interfaces):
|
||||
'''
|
||||
Prepares the network interface section of the VM xml
|
||||
|
||||
template_str = '''
|
||||
<interface type='{{ interface.type }}'>
|
||||
<source {{ interface.type }}='{{ interface.source }}'/>
|
||||
<mac address='{{ interface.mac }}'/>
|
||||
<model type='{{ interface.model }}'/>
|
||||
</interface>\n'''
|
||||
interfaces: list of dicts as returned from _nic_profile
|
||||
|
||||
results = []
|
||||
Returns string representing interfaces devices suitable for
|
||||
insertion into the VM XML definition
|
||||
'''
|
||||
|
||||
import jinja2
|
||||
template = jinja2.Template(template_str)
|
||||
template_name = 'interface.jinja'
|
||||
|
||||
for interface in interfaces:
|
||||
results.append(template.render(interface=interface))
|
||||
|
||||
return ''.join(results)
|
||||
try:
|
||||
template = JINJA.get_template(template_name)
|
||||
except jinja2.exceptions.TemplateNotFound:
|
||||
log.error('Could not load template {0}'.format(template_name))
|
||||
return ''
|
||||
return template.render(interfaces=interfaces)
|
||||
|
||||
def _gen_xml(name,
|
||||
cpu,
|
||||
|
|
7
salt/templates/virt/interface.jinja
Normal file
7
salt/templates/virt/interface.jinja
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% for interface in interfaces %}
|
||||
<interface type='{{ interface.type }}'>
|
||||
<source {{ interface.type }}='{{ interface.source }}'/>
|
||||
<mac address='{{ interface.mac }}'/>
|
||||
<model type='{{ interface.model }}'/>
|
||||
</interface>
|
||||
{% endfor %}
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
<serial type='pty'>
|
||||
<target port='0'/>
|
||||
</serial>
|
||||
|
|
6
setup.py
6
setup.py
|
@ -313,7 +313,11 @@ SETUP_KWARGS = {'name': NAME,
|
|||
'salt.log.handlers',
|
||||
'salt.templates',
|
||||
],
|
||||
'package_data': {'salt.templates': ['rh_ip/*.jinja']},
|
||||
'package_data': {'salt.templates': [
|
||||
'rh_ip/*.jinja',
|
||||
'virt/*.jinja'
|
||||
]
|
||||
},
|
||||
'data_files': [('share/man/man1',
|
||||
['doc/man/salt-master.1',
|
||||
'doc/man/salt-key.1',
|
||||
|
|
|
@ -32,6 +32,44 @@ virt.__salt__ = {
|
|||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class VirtTestCase(TestCase):
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_serial(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
xml_data = virt._gen_xml(
|
||||
'hello',
|
||||
1,
|
||||
512,
|
||||
diskp,
|
||||
nicp,
|
||||
'kvm',
|
||||
serial_type="pty",
|
||||
console=True
|
||||
)
|
||||
root = ElementTree.fromstring(xml_data)
|
||||
self.assertEquals(root.find('devices/serial').attrib['type'], 'pty')
|
||||
self.assertEquals(root.find('devices/console').attrib['type'], 'pty')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_serial_no_console(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
xml_data = virt._gen_xml(
|
||||
'hello',
|
||||
1,
|
||||
512,
|
||||
diskp,
|
||||
nicp,
|
||||
'kvm',
|
||||
serial_type="pty",
|
||||
console=False
|
||||
)
|
||||
root = ElementTree.fromstring(xml_data)
|
||||
self.assertEquals(root.find('devices/serial').attrib['type'], 'pty')
|
||||
self.assertEquals(root.find('devices/console'), None)
|
||||
|
||||
def test_default_disk_profile_hypervisor_esxi(self):
|
||||
mock = MagicMock(return_value={})
|
||||
with patch.dict(virt.__salt__, {'config.get': mock}):
|
||||
|
|
Loading…
Add table
Reference in a new issue