tests: Share sanitize_xml helpers

This commit is contained in:
Cole Robinson 2015-09-22 11:34:15 -04:00
parent 29745a9f75
commit 7f1af40262
2 changed files with 5 additions and 20 deletions

View File

@ -23,6 +23,7 @@ import libvirt
import virtinst
import virtinst.cli
import virtinst.uri
# DON'T EDIT THIS. Use 'setup.py test --regenerate-output'
REGENERATE_OUTPUT = False
@ -144,24 +145,8 @@ def _libvirt_callback(ignore, err):
libvirt.registerErrorHandler(f=_libvirt_callback, ctx=None)
def sanitize_xml_for_define(xml):
# Libvirt throws errors since we are defining domain
# type='xen', when test driver can only handle type='test'
# Sanitize the XML so we can define
if not xml:
return xml
xml = xml.replace(">linux<", ">xen<")
for t in ["xen", "qemu", "kvm"]:
xml = xml.replace("<domain type=\"%s\">" % t,
"<domain type=\"test\">")
xml = xml.replace("<domain type='%s'>" % t,
"<domain type='test'>")
return xml
def test_create(testconn, xml, define_func="defineXML"):
xml = sanitize_xml_for_define(xml)
xml = virtinst.uri.sanitize_xml_for_test_define(xml)
try:
func = getattr(testconn, define_func)

View File

@ -23,7 +23,7 @@ import re
from .cli import VirtOptionString
def _sanitize_xml(xml):
def sanitize_xml_for_test_define(xml):
import difflib
orig = xml
@ -221,10 +221,10 @@ class MagicURI(object):
origcreate = conn.createLinux
origdefine = conn.defineXML
def newcreate(xml, flags):
xml = _sanitize_xml(xml)
xml = sanitize_xml_for_test_define(xml)
return origcreate(xml, flags)
def newdefine(xml):
xml = _sanitize_xml(xml)
xml = sanitize_xml_for_test_define(xml)
return origdefine(xml)
conn.createLinux = newcreate
conn.defineXML = newdefine