本文整理汇总了Python中tests.utils.diff_compare函数的典型用法代码示例。如果您正苦于以下问题:Python diff_compare函数的具体用法?Python diff_compare怎么用?Python diff_compare使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diff_compare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testNode2DeviceCompare
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None, is_dup=False):
devfile = os.path.join("tests/nodedev-xml/devxml", devfile)
if not nodedev:
nodedev = self._nodeDevFromName(nodename)
dev = VirtualHostDevice.device_from_node(conn, nodedev=nodedev, is_dup=is_dup)
utils.diff_compare(dev.get_xml_config() + "\n", devfile)
示例2: _clone_compare
def _clone_compare(self, cloneobj, outbase):
"""Helps compare output from passed clone instance with an xml file"""
outfile = os.path.join(clonexml_dir, outbase + "-out.xml")
cloneobj.setup()
utils.diff_compare(cloneobj.clone_xml, outfile)
示例3: _image2XMLhelper
def _image2XMLhelper(self, image_xml, output_xmls, qemu=False):
image2guestdir = self.basedir + "image2guest/"
image = virtinst.ImageParser.parse_file(self.basedir + image_xml)
if type(output_xmls) is not list:
output_xmls = [output_xmls]
conn = qemu and self.qemuconn or self.conn
caps = qemu and self.qemucaps or self.caps
gtype = qemu and "qemu" or "xen"
for idx in range(len(output_xmls)):
fname = output_xmls[idx]
inst = virtinst.ImageInstaller(image, caps, boot_index=idx,
conn=conn)
utils.set_conn(conn)
if inst.is_hvm():
g = utils.get_basic_fullyvirt_guest(typ=gtype)
else:
g = utils.get_basic_paravirt_guest()
g.installer = inst
g._prepare_install(None)
actual_out = g.get_xml_config(install=False)
expect_file = os.path.join(image2guestdir + fname)
expect_out = utils.read_file(expect_file)
expect_out = expect_out.replace("REPLACEME", os.getcwd())
utils.diff_compare(actual_out,
expect_file,
expect_out=expect_out)
utils.reset_conn()
示例4: _convert_helper
def _convert_helper(self, infile, outfile, in_type, disk_format):
outbuf = StringIO.StringIO()
def print_cb(msg):
print >> outbuf, msg
converter = VirtConverter(conn, infile, print_cb=print_cb)
if converter.parser.name != in_type:
raise AssertionError("find_parser_by_file for '%s' returned "
"wrong parser type.\n"
"Expected: %s\n"
"Received: %s\n" %
(infile, in_type, converter.parser.name))
converter.convert_disks(disk_format, dry=True)
guest = converter.get_guest()
ignore, out_xml = guest.start_install(return_xml=True)
out_expect = out_xml
if outbuf.getvalue():
out_expect += ("\n\n" + outbuf.getvalue().replace(base_dir, ""))
if not conn.check_support(conn.SUPPORT_CONN_VMPORT):
self.skipTest("Not comparing XML because vmport isn't supported")
utils.diff_compare(out_expect, outfile)
utils.test_create(converter.conn, out_xml)
示例5: _image2XMLhelper
def _image2XMLhelper(self, image_xml, output_xmls, qemu=False):
image2guestdir = self.basedir + "image2guest/"
image = virtimage.parse_file(self.basedir + image_xml)
if type(output_xmls) is not list:
output_xmls = [output_xmls]
conn = qemu and self.qemuconn or self.conn
gtype = qemu and "qemu" or "xen"
for idx in range(len(output_xmls)):
fname = output_xmls[idx]
inst = virtimage.ImageInstaller(conn, image, boot_index=idx)
capsguest, capsdomain = inst.get_caps_guest()
if capsguest.os_type == "hvm":
g = utils.get_basic_fullyvirt_guest(typ=gtype)
else:
g = utils.get_basic_paravirt_guest()
utils.set_conn(conn)
g.os.os_type = capsguest.os_type
g.type = capsdomain.hypervisor_type
g.os.arch = capsguest.arch
g.installer = inst
# pylint: disable=unpacking-non-sequence
ignore, actual_out = g.start_install(return_xml=True, dry=True)
actual_out = g.get_install_xml(install=False)
expect_file = os.path.join(image2guestdir + fname)
actual_out = actual_out.replace(os.getcwd(), "/tmp")
utils.diff_compare(actual_out, expect_file)
utils.reset_conn()
示例6: createVol
def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
volclass = Storage.StorageVolume.get_volume_for_pool(pool_object=poolobj)
if volname is None:
volname = poolobj.name() + "-vol"
alloc = 5 * 1024 * 1024 * 1024
cap = 10 * 1024 * 1024 * 1024
vol_inst = volclass(conn,
name=volname, capacity=cap, allocation=alloc,
pool=poolobj)
perms = {}
perms["mode"] = 0700
perms["owner"] = 10736
perms["group"] = 10736
vol_inst.perms = perms
if input_vol:
vol_inst.input_vol = input_vol
elif clone_vol:
vol_inst = Storage.CloneVolume(conn, volname, clone_vol)
filename = os.path.join(basepath, vol_inst.name + ".xml")
# Make sure permissions are properly set
utils.diff_compare(vol_inst.get_xml_config(), filename)
return vol_inst.install(meter=False)
示例7: run
def run(self, tests):
filename = self.compare_file
err = None
try:
code, output = self._get_output()
if code == self.SKIP:
tests.skipTest(output)
return
if bool(code) == self.check_success:
raise AssertionError(
("Expected command to %s, but failed.\n" %
(self.check_success and "pass" or "fail")) +
("Command was: %s\n" % self.cmdstr) +
("Error code : %d\n" % code) +
("Output was:\n%s" % output))
if filename:
# Generate test files that don't exist yet
if not os.path.exists(filename):
file(filename, "w").write(output)
utils.diff_compare(output, filename)
except AssertionError, e:
err = self.cmdstr + "\n" + str(e)
示例8: createVol
def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
if volname is None:
volname = poolobj.name() + "-vol"
# Format here depends on libvirt-1.2.0 and later
if clone_vol and conn.local_libvirt_version() < 1002000:
logging.debug("skip clone compare")
return
alloc = 5 * 1024 * 1024 * 1024
cap = 10 * 1024 * 1024 * 1024
vol_inst = StorageVolume(conn)
vol_inst.pool = poolobj
vol_inst.name = volname
vol_inst.capacity = cap
vol_inst.allocation = alloc
vol_inst.permissions.mode = "0700"
vol_inst.permissions.owner = "10736"
vol_inst.permissions.group = "10736"
if input_vol:
vol_inst.input_vol = input_vol
vol_inst.sync_input_vol()
elif clone_vol:
vol_inst = StorageVolume(conn, parsexml=clone_vol.XMLDesc(0))
vol_inst.input_vol = clone_vol
vol_inst.sync_input_vol()
vol_inst.name = volname
vol_inst.validate()
filename = os.path.join(basepath, vol_inst.name + ".xml")
utils.diff_compare(vol_inst.get_xml_config(), filename)
return vol_inst.install(meter=False)
示例9: testCPUUnknownClear
def testCPUUnknownClear(self):
# Make sure .clear() even removes XML elements we don't know about
basename = "clear-cpu-unknown-vals"
infile = "tests/xmlparse-xml/%s-in.xml" % basename
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
guest = virtinst.Guest(conn, parsexml=file(infile).read())
guest.cpu.clear()
utils.diff_compare(guest.get_xml_config(), outfile)
示例10: poolCompare
def poolCompare(pool_inst):
filename = os.path.join(basepath, pool_inst.name + ".xml")
out_expect = pool_inst.get_xml_config()
if not os.path.exists(filename):
open(filename, "w").write(out_expect)
utils.diff_compare(out_expect, filename)
return pool_inst.install(build=True, meter=None, create=True)
示例11: _testNode2DeviceCompare
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None):
devfile = os.path.join("tests/nodedev-xml/devxml", devfile)
if not nodedev:
nodedev = self._nodeDevFromName(nodename)
dev = DeviceHostdev(self.conn)
dev.set_from_nodedev(nodedev)
dev.set_defaults(Guest(self.conn))
utils.diff_compare(dev.get_xml() + "\n", devfile)
示例12: run
def run(self, tests):
err = None
try:
conn = None
for idx in reversed(range(len(self.argv))):
if self.argv[idx] == "--connect":
conn = utils.openconn(self.argv[idx + 1])
break
if not conn:
raise RuntimeError("couldn't parse URI from command %s" %
self.argv)
skipmsg = self._skip_msg(conn)
if skipmsg is not None:
tests.skipTest(skipmsg)
return
code, output = self._get_output(conn)
if bool(code) == self.check_success:
raise AssertionError(
("Expected command to %s, but it didn't.\n" %
(self.check_success and "pass" or "fail")) +
("Command was: %s\n" % self.cmdstr) +
("Error code : %d\n" % code) +
("Output was:\n%s" % output))
if self.compare_file:
if (self.compare_check and not
conn.check_support(self.compare_check)):
tests.skipTest(
"Skipping compare check due to lack of support")
return
# Generate test files that don't exist yet
filename = self.compare_file
if utils.REGENERATE_OUTPUT or not os.path.exists(filename):
file(filename, "w").write(output)
if "--print-diff" in self.argv and output.count("\n") > 3:
# 1) Strip header
# 2) Simplify context lines to reduce churn when
# libvirt or testdriver changes
newlines = []
for line in output.splitlines()[3:]:
if line.startswith("@@"):
line = "@@"
newlines.append(line)
output = "\n".join(newlines)
utils.diff_compare(output, filename)
except AssertionError, e:
err = self.cmdstr + "\n" + str(e)
示例13: _compare
def _compare(self, guest, filebase, do_install):
filename = os.path.join("tests/xmlconfig-xml", filebase + ".xml")
inst_xml, boot_xml = guest.start_install(return_xml=True, dry=True)
if do_install:
actualXML = inst_xml
else:
actualXML = boot_xml
utils.diff_compare(actualXML, filename)
utils.test_create(guest.conn, actualXML)
示例14: _clone_compare
def _clone_compare(self, cloneobj, outbase, clone_disks_file=None):
"""Helps compare output from passed clone instance with an xml file"""
outfile = os.path.join(clonexml_dir, outbase + "-out.xml")
cloneobj.setup()
utils.diff_compare(cloneobj.clone_xml, outfile)
if clone_disks_file:
xml_clone_disks = ""
for i in cloneobj.get_clone_disks():
xml_clone_disks += i.get_vol_install().get_xml_config()
utils.diff_compare(xml_clone_disks, clone_disks_file)
示例15: testISCSIPool
def testISCSIPool(self):
basename = "pool-iscsi"
infile = "tests/storage-xml/%s.xml" % basename
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
pool = virtinst.StoragePool(conn, parsexml=file(infile).read())
check = self._make_checker(pool)
check("host", "some.random.hostname", "my.host")
check("iqn", "foo.bar.baz.iqn", "my.iqn")
utils.diff_compare(pool.get_xml_config(), outfile)
utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")