def _compare(self, guest, filebase, do_install, do_disk_boot=False, do_create=True): filename = filebase and build_xmlfile(filebase) or None cont_xml = None inst_xml, boot_xml = guest.start_install(return_xml=True, dry=True) if do_disk_boot: cont_xml, boot_xml = guest.continue_install(return_xml=True, dry=True) if do_disk_boot: actualXML = cont_xml elif do_install: actualXML = inst_xml else: actualXML = boot_xml if filename: utils.diff_compare(actualXML, filename) if do_create: utils.test_create(guest.conn, actualXML)
def _convert_helper(self, in_path, out_path, in_type, disk_format): outbuf = io.StringIO() def print_cb(msg): print(msg, file=outbuf) conn = utils.URIs.open_kvm() converter = VirtConverter(conn, in_path, 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" % (in_path, 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, out_path) utils.test_create(conn, out_xml)
def testNetOpen(self): basename = "network-open" infile = "tests/xmlparse-xml/%s-in.xml" % basename outfile = "tests/xmlparse-xml/%s-out.xml" % basename net = virtinst.Network(conn, parsexml=open(infile).read()) check = self._make_checker(net) check("name", "open", "new-foo") check("domain_name", "open", "newdom") check = self._make_checker(net.forward) check("mode", "open") check("dev", None) self.assertEqual(len(net.ips), 1) check = self._make_checker(net.ips[0]) check("address", "192.168.100.1", "192.168.101.1") check("netmask", "255.255.255.0", "255.255.254.0") check = self._make_checker(net.ips[0].ranges[0]) check("start", "192.168.100.128", "192.168.101.128") check("end", "192.168.100.254", "192.168.101.254") utils.diff_compare(net.get_xml_config(), outfile) utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
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)
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)
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)
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()
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()
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)
def testNetVfPool(self): basename = "network-vf-pool" infile = "tests/xmlparse-xml/%s-in.xml" % basename outfile = "tests/xmlparse-xml/%s-out.xml" % basename net = virtinst.Network(conn, parsexml=open(infile).read()) check = self._make_checker(net) check("name", "passthrough", "new-foo") check = self._make_checker(net.forward) check("mode", "hostdev") check("managed", "yes") check = self._make_checker(net.forward.pf[0]) check("dev", "eth3") check = self._make_checker(net.forward.vfs[0]) check("type", "pci") check("domain", 0x0000) check("bus", 0x03) check("slot", 0x10) check("function", 0x0) utils.diff_compare(net.get_xml_config(), outfile) utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
def testReplaceChildParse(): conn = utils.URIs.open_testdefault_cached() buildfile = DATADIR + "replace-child-build.xml" parsefile = DATADIR + "replace-child-parse.xml" def mkdisk(target): disk = virtinst.DeviceDisk(conn) disk.device = "cdrom" disk.bus = "scsi" disk.target = target return disk guest = virtinst.Guest(conn) guest.add_device(mkdisk("sda")) guest.add_device(mkdisk("sdb")) guest.add_device(mkdisk("sdc")) guest.add_device(mkdisk("sdd")) guest.add_device(mkdisk("sde")) guest.add_device(mkdisk("sdf")) guest.devices.replace_child(guest.devices.disk[2], mkdisk("sdz")) guest.set_defaults(guest) utils.diff_compare(guest.get_xml(), buildfile) guest = virtinst.Guest(conn, parsexml=guest.get_xml()) newdisk = virtinst.DeviceDisk(conn, parsexml=mkdisk("sdw").get_xml()) guest.devices.replace_child(guest.devices.disk[4], newdisk) utils.diff_compare(guest.get_xml(), parsefile)
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)
def testNetOpen(): conn = utils.URIs.open_testdefault_cached() basename = "network-open" infile = DATADIR + "%s-in.xml" % basename outfile = DATADIR + "%s-out.xml" % basename net = virtinst.Network(conn, parsexml=open(infile).read()) check = _make_checker(net) check("name", "open", "new-foo") check("domain_name", "open", "newdom") check = _make_checker(net.forward) check("mode", "open") check("dev", None) assert len(net.ips) == 1 check = _make_checker(net.ips[0]) check("address", "192.168.100.1", "192.168.101.1") check("netmask", "255.255.255.0", "255.255.254.0") check = _make_checker(net.ips[0].ranges[0]) check("start", "192.168.100.128", "192.168.101.128") check("end", "192.168.100.254", "192.168.101.254") utils.diff_compare(net.get_xml(), outfile) utils.test_create(conn, net.get_xml(), "networkDefineXML")
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)
def testDomainRoundtrip(): conn = utils.URIs.open_testdefault_cached() # Make sure our XML engine doesn't mangle non-libvirt XML bits infile = DATADIR + "domain-roundtrip.xml" outfile = DATADIR + "domain-roundtrip.xml" guest = virtinst.Guest(conn, parsexml=open(infile).read()) utils.diff_compare(guest.get_xml(), outfile)
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None): devfile = os.path.join("tests/nodedev-xml/devxml", devfile) if not nodedev: nodedev = self._nodeDevFromName(nodename) dev = VirtualHostDevice(conn) dev.set_from_nodedev(nodedev) utils.diff_compare(dev.get_xml_config() + "\n", devfile)
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)
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)
def _testNode2DeviceCompare(conn, nodename, devfile, nodedev=None): devfile = os.path.join(DATADIR, "devxml", devfile) if not nodedev: nodedev = _nodeDevFromName(conn, nodename) dev = DeviceHostdev(conn) dev.set_from_nodedev(nodedev) dev.set_defaults(Guest(conn)) utils.diff_compare(dev.get_xml() + "\n", devfile)
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)
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None): devfile = os.path.join("tests/data/nodedev/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)
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)
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)
def testCPUUnknownClear(): # Make sure .clear() even removes XML elements we don't know about kvmconn = utils.URIs.open_kvm() basename = "clear-cpu-unknown-vals" infile = DATADIR + "%s-in.xml" % basename outfile = DATADIR + "%s-out.xml" % basename guest = virtinst.Guest(kvmconn, parsexml=open(infile).read()) guest.cpu.copy_host_cpu(guest) guest.cpu.clear() utils.diff_compare(guest.get_xml(), outfile)
def testInterfaceVLAN(self): basename = "test-vlan" infile = "tests/interface-xml/%s.xml" % basename outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename iface = virtinst.Interface(conn, parsexml=file(infile).read()) check = self._make_checker(iface) check("tag", 123, 456) check("parent_interface", "eth2", "foonew") utils.diff_compare(iface.get_xml_config(), outfile) utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
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)
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")
def testNetMulti(self): basename = "network-multi" infile = "tests/xmlparse-xml/%s-in.xml" % basename outfile = "tests/xmlparse-xml/%s-out.xml" % basename net = virtinst.Network(conn, parsexml=file(infile).read()) check = self._make_checker(net) check("name", "ipv6_multirange", "new-foo") check("uuid", "41b4afe4-87bb-8087-6724-5e208a2d483a", "41b4afe4-87bb-8087-6724-5e208a2d1111") check("bridge", "virbr3", "virbr3new") check("stp", True, False) check("delay", 0, 2) check("domain_name", "net7", "newdom") check("ipv6", None, True) check("macaddr", None, "52:54:00:69:eb:FF") check = self._make_checker(net.forward) check("mode", "nat", "route") check("dev", None, "eth22") self.assertEqual(len(net.ips), 4) check = self._make_checker(net.ips[0]) check("address", "192.168.7.1", "192.168.8.1") check("netmask", "255.255.255.0", "255.255.254.0") check("tftp", None, "/var/lib/tftproot") check("bootp_file", None, "pxeboot.img") check("bootp_server", None, "1.2.3.4") check = self._make_checker(net.ips[0].ranges[0]) check("start", "192.168.7.128", "192.168.8.128") check("end", "192.168.7.254", "192.168.8.254") check = self._make_checker(net.ips[0].hosts[1]) check("macaddr", "52:54:00:69:eb:91", "52:54:00:69:eb:92") check("name", "badbob", "newname") check("ip", "192.168.7.3", "192.168.8.3") check = self._make_checker(net.ips[1]) check("family", "ipv6", "ipv6") check("prefix", 64, 63) r = net.add_route() r.family = "ipv4" r.address = "192.168.8.0" r.prefix = "24" r.gateway = "192.168.8.10" check = self._make_checker(r) check("netmask", None, "foo", None) utils.diff_compare(net.get_xml_config(), outfile) utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
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_original() cloneobj.setup_clone() utils.diff_compare(cloneobj.clone_xml, outfile) if clone_disks_file: xml_clone_disks = "" for i in cloneobj.clone_disks: xml_clone_disks += i.get_vol_install().get_xml() utils.diff_compare(xml_clone_disks, clone_disks_file)
def testGlusterPool(): conn = utils.URIs.open_testdefault_cached() basename = "pool-gluster" infile = utils.DATADIR + "/storage/%s.xml" % basename outfile = DATADIR + "%s-out.xml" % basename pool = virtinst.StoragePool(conn, parsexml=open(infile).read()) check = _make_checker(pool) check("source_path", "/some/source/path", "/foo") check = _make_checker(pool.hosts[0]) check("name", "some.random.hostname", "my.host") utils.diff_compare(pool.get_xml(), outfile) utils.test_create(conn, pool.get_xml(), "storagePoolDefineXML")
def testISCSIPool(): conn = utils.URIs.open_testdefault_cached() basename = "pool-iscsi" infile = utils.DATADIR + "/storage/%s.xml" % basename outfile = DATADIR + "%s-out.xml" % basename pool = virtinst.StoragePool(conn, parsexml=open(infile).read()) check = _make_checker(pool) check("iqn", "foo.bar.baz.iqn", "my.iqn") check = _make_checker(pool.hosts[0]) check("name", "some.random.hostname", "my.host") utils.diff_compare(pool.get_xml(), outfile) utils.test_create(conn, pool.get_xml(), "storagePoolDefineXML")
def testChangeSnapshot(self): basename = "change-snapshot" infile = "tests/xmlparse-xml/%s-in.xml" % basename outfile = "tests/xmlparse-xml/%s-out.xml" % basename snap = virtinst.DomainSnapshot(conn, parsexml=file(infile).read()) check = self._make_checker(snap) check("name", "offline-root-child1", "name-foo") check("state", "shutoff", "somestate") check("description", "offline desk", "foo\nnewline\n indent") check("parent", "offline-root", "newparent") check("creationTime", 1375905916, 1234) utils.diff_compare(snap.get_xml_config(), outfile)
def testInterfaceBondMii(self): basename = "test-bond-mii" infile = "tests/interface-xml/%s.xml" % basename outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename iface = virtinst.Interface(conn, parsexml=file(infile).read()) check = self._make_checker(iface) check("mii_frequency", 123, 111) check("mii_downdelay", 34, 22) check("mii_updelay", 12, 33) check("mii_carrier_mode", "netif", "ioctl") utils.diff_compare(iface.get_xml_config(), outfile) utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
def define_xml(self, obj, compare=True): xml = obj.get_xml_config() logging.debug("Defining interface XML:\n%s", xml) if compare: filename = os.path.join(datadir, obj.name + ".xml") utils.diff_compare(xml, filename) iface = obj.install() newxml = iface.XMLDesc(0) logging.debug("Defined XML:\n%s", newxml) iface.undefine()
def _compare(self, guest, filebase, do_install, do_disk_boot=False, do_create=True): filename = filebase and build_xmlfile(filebase) or None guest._prepare_install(progress.BaseMeter()) try: actualXML = guest.get_xml_config(install=do_install, disk_boot=do_disk_boot) if filename: utils.diff_compare(actualXML, filename) if do_create: utils.test_create(guest.conn, actualXML) finally: guest._cleanup_install()
def testGlusterPool(self): if not conn.check_support(conn.SUPPORT_CONN_POOL_GLUSTERFS): raise unittest.SkipTest("Gluster pools not supported with this " "libvirt version.") basename = "pool-gluster" 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("source_dir", None, "/foo") utils.diff_compare(pool.get_xml_config(), outfile) utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
def testInterfaceBondArp(self): basename = "test-bond-arp" infile = "tests/interface-xml/%s.xml" % basename outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename iface = virtinst.Interface(conn, parsexml=file(infile).read()) check = self._make_checker(iface) check("start_mode", "onboot", "hotplug") check("macaddr", "AA:AA:AA:AA:AA:AA", "AA:AA:AA:11:AA:AA") check("mtu", 1501, 1234) check("bond_mode", None, "active-backup") check("arp_interval", 100, 234) check("arp_target", "192.168.100.200", "1.2.3.4") check("arp_validate_mode", "backup", "active") utils.diff_compare(iface.get_xml_config(), outfile) utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
def _convert_helper(self, infile, outfile, in_type, out_type): inp = virtconv.formats.find_parser_by_file(infile) outp = virtconv.formats.parser_by_name(out_type) if not inp or inp.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, str((not inp) and str(inp) or inp.name))) vmdef = inp.import_file(infile) out_expect = outp.export(vmdef) if not os.path.exists(outfile): open(outfile, "w").write(out_expect) utils.diff_compare(out_expect, outfile)
def testRBDPool(self): basename = "pool-rbd" infile = "tests/xmlparse-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.hosts[0]) check("name", "ceph-mon-1.example.com") check("port", 6789, 1234) check = self._make_checker(pool.hosts[1]) check("name", "ceph-mon-2.example.com", "foo.bar") check("port", 6789) check = self._make_checker(pool.hosts[2]) check("name", "ceph-mon-3.example.com") check("port", 6789, 1000) pool.add_host("frobber", "5555") utils.diff_compare(pool.get_xml_config(), outfile) utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
def testVol(self): basename = "pool-dir-vol" infile = "tests/xmlparse-xml/%s-in.xml" % basename outfile = "tests/xmlparse-xml/%s-out.xml" % basename vol = virtinst.StorageVolume(conn, parsexml=file(infile).read()) check = self._make_checker(vol) check("key", None, "fookey") check("capacity", 10737418240, 2000) check("allocation", 5368709120, 1000) check("format", "raw", "qcow2") check("target_path", None, "/foo/bar") check("backing_store", "/foo/bar/baz", "/my/backing") check = self._make_checker(vol.permissions) check("mode", "0700", "0744") check("owner", "10736", "10000") check("group", "10736", "10000") check("label", None, "foo.label") utils.diff_compare(vol.get_xml_config(), outfile)
def _testInstall(self, guest, instxml=None, bootxml=None, contxml=None): instname = build_xmlfile(instxml) bootname = build_xmlfile(bootxml) contname = build_xmlfile(contxml) meter = None try: guest.start_install(meter=meter) guest.domain.destroy() xmlinst = guest.get_install_xml(True, False) xmlboot = guest.get_install_xml(False, False) xmlcont = guest.get_install_xml(True, True) if instname: utils.diff_compare(xmlinst, instname) if contname: utils.diff_compare(xmlcont, contname) if bootname: utils.diff_compare(xmlboot, bootname) if guest.get_continue_inst(): guest.continue_install(meter=meter) finally: try: guest.domain.destroy() except: pass try: guest.domain.undefine() except: pass
def testInterfaceBridgeIP(self): basename = "test-bridge-ip" infile = "tests/interface-xml/%s.xml" % basename outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename iface = virtinst.Interface(conn, parsexml=file(infile).read()) self.assertEquals(len(iface.protocols), 2) self.assertEquals(len(iface.interfaces), 3) check = self._make_checker(iface) check("type", "bridge", "foo", "bridge") check("name", "test-bridge-ip", "foo-new") check("stp", None, True) check("delay", None, 2) check = self._make_checker(iface.protocols[0]) check("family", "ipv4", "foo", "ipv4") check("dhcp_peerdns", True, False) check("gateway", "1.2.3.4", "5.5.5.5") self.assertEquals(iface.protocols[0].ips[1].address, "255.255.255.0") check = self._make_checker(iface.protocols[1]) check("dhcp", True, False) check("autoconf", True, False) check = self._make_checker(iface.protocols[1].ips[1]) check("address", "fe80::215:58ff:fe6e:5", "2002::") check("prefix", 64, 38) # Remove a child interface, verify it's data remains intact child_iface = iface.interfaces[1] iface.remove_interface(child_iface) check = self._make_checker(child_iface) check("name", "bond-brbond") self.assertEquals(len(child_iface.interfaces), 2) utils.diff_compare(iface.get_xml_config(), outfile) utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
def testFSPool(self): basename = "pool-fs" infile = "tests/xmlparse-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("type", "fs", "dir") check("name", "pool-fs", "foo-new") check("uuid", "10211510-2115-1021-1510-211510211510", "10211510-2115-1021-1510-211510211999") check("capacity", 984373075968, 200000) check("allocation", 756681687040, 150000) check("available", 227691388928, 50000) check("format", "auto", "ext3") check("source_path", "/some/source/path", "/dev/foo/bar") check("target_path", "/some/target/path", "/mnt/my/foo") check("source_name", None, "fooname") utils.diff_compare(pool.get_xml_config(), outfile) utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")