mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
tests: Share sanitize_xml helpers
This commit is contained in:
parent
29745a9f75
commit
7f1af40262
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user