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() tests.diff_compare(cloneobj.clone_xml, outfile)
def createVol(poolobj, volname=None, input_vol=None, clone_vol=None): volclass = StorageVolume.get_volume_for_pool(pool_object=poolobj) if volname == None: volname = poolobj.name() + "-vol" alloc = 5 * 1024 * 1024 * 1024 cap = 10 * 1024 * 1024 * 1024 vol_inst = volclass(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 or clone_vol: if not virtinst.Storage.is_create_vol_from_supported(poolobj._conn): return if input_vol: vol_inst.input_vol = input_vol elif clone_vol: vol_inst = virtinst.Storage.CloneVolume(volname, clone_vol) filename = os.path.join(basepath, vol_inst.name + ".xml") # Make sure permissions are properly set tests.diff_compare(vol_inst.get_xml_config(), filename) return vol_inst.install(meter=False)
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.device_from_node(conn, nodedev=nodedev) tests.diff_compare(dev.get_xml_config() + "\n", devfile)
def _compare(self, guest, filebase, do_install, do_disk_boot=False): filename = build_xmlfile(filebase) guest._prepare_install(progress.BaseMeter()) try: actualXML = guest.get_config_xml(install=do_install, disk_boot=do_disk_boot) tests.diff_compare(actualXML, filename) self._testCreate(guest.conn, actualXML) finally: guest._cleanup_install()
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") tests.diff_compare(xml, filename) iface = obj.install() newxml = iface.XMLDesc(0) logging.debug("Defined XML:\n%s" % newxml) iface.undefine()
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) tests.diff_compare(out_expect, outfile)
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) tests.diff_compare(out_expect, outfile)
def _image2XMLhelper(self, image_xml, output_xmls): image2guestdir = self.basedir + "image2guest/" image = virtinst.ImageParser.parse_file(self.basedir + image_xml) if type(output_xmls) is not list: output_xmls = [output_xmls] for idx in range(len(output_xmls)): fname = output_xmls[idx] inst = virtinst.ImageInstaller(image, self.caps, boot_index=idx) if inst.is_hvm(): g = xmlconfig.get_basic_fullyvirt_guest() else: g = xmlconfig.get_basic_paravirt_guest() g.installer = inst g._prepare_install(None) expect_out = tests.read_file(image2guestdir + fname) expect_out = expect_out.replace("REPLACEME", os.getcwd()) tests.diff_compare(g.get_config_xml(install=False), image2guestdir + fname, expect_out=expect_out)
def _testInstall(self, guest, instxml=None, bootxml=None, contxml=None): instname = build_xmlfile(instxml) bootname = build_xmlfile(bootxml) contname = build_xmlfile(contxml) consolecb = None meter = None removeOld = None wait = True dom = None old_getxml = guest.get_config_xml def new_getxml(install=True, disk_boot=False): xml = old_getxml(install, disk_boot) return sanitize_xml(xml) guest.get_config_xml = new_getxml try: dom = guest.start_install(consolecb, meter, removeOld, wait) dom.destroy() # Replace kernel/initrd with known info if (guest.installer._install_bootconfig and guest.installer._install_bootconfig.kernel): guest.installer._install_bootconfig.kernel = "kernel" guest.installer._install_bootconfig.initrd = "initrd" xmlinst = guest.get_config_xml(True, False) xmlboot = guest.get_config_xml(False, False) xmlcont = guest.get_config_xml(True, True) if instname: tests.diff_compare(xmlinst, instname) if contname: tests.diff_compare(xmlcont, contname) if bootname: tests.diff_compare(xmlboot, bootname) if guest.get_continue_inst(): guest.continue_install(consolecb, meter, wait) finally: if dom: try: dom.destroy() except: pass try: dom.undefine() except: pass
def poolCompare(pool_inst): filename = os.path.join(basepath, pool_inst.name + ".xml") tests.diff_compare(pool_inst.get_xml_config(), filename) return pool_inst.install(build=True, meter=None, create=True)