2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
# Used to ensure consistent SDL xml output
25
os.environ["HOME"] = "/tmp"
26
os.environ["DISPLAY"] = ":3.4"
29
_testuri = "test:///%s/tests/testdriver.xml" % _cwd
30
_fakeuri = "__virtinst_test__" + _testuri + ",predictable"
31
_kvmcaps = "%s/tests/capabilities-xml/libvirt-0.7.6-qemu-caps.xml" % _cwd
32
_kvmuri = "%s,caps=%s,qemu" % (_fakeuri, _kvmcaps)
35
return ("DEBUG_TESTS" in os.environ and
36
os.environ["DEBUG_TESTS"] == "1")
38
def open_testdriver():
39
return virtinst.cli.getConnection(_testuri)
41
def open_testkvmdriver():
42
return virtinst.cli.getConnection(_kvmuri)
44
# Register libvirt handler
45
def libvirt_callback(ignore, err):
46
logging.warn("libvirt errmsg: %s" % err[2])
47
libvirt.registerErrorHandler(f=libvirt_callback, ctx=None)
49
def sanitize_xml_for_define(xml):
50
# Libvirt throws errors since we are defining domain
51
# type='xen', when test driver can only handle type='test'
52
# Sanitize the XML so we can define
56
xml = xml.replace("<domain type='xen'>",
57
"<domain type='test'>")
58
xml = xml.replace(">linux<", ">xen<")
62
def test_create(testconn, xml):
63
xml = sanitize_xml_for_define(xml)
66
dom = testconn.defineXML(xml)
68
raise RuntimeError(str(e) + "\n" + xml)
84
def read_file(filename):
85
"""Helper function to read a files contents and return them"""
86
f = open(filename, "r")
92
def diff_compare(actual_out, filename=None, expect_out=None):
93
"""Compare passed string output to contents of filename"""
95
expect_out = read_file(filename)
97
diff = "".join(difflib.unified_diff(expect_out.splitlines(1),
98
actual_out.splitlines(1),
100
tofile="Generated Output"))
102
raise AssertionError("Conversion outputs did not match.\n%s" % diff)