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 utils.diff_compare(vol_inst.get_xml_config(), filename) return vol_inst.install(meter=False)
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 _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_config_xml(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 run(self): filename = self.compare_file err = None try: code, output = runcomm(self.cmd or self.cmdstr) 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: # Uncomment to generate new test files if not os.path.exists(filename): file(filename, "w").write(output) utils.diff_compare(output, filename) write_pass() except AssertionError, e: write_fail() err = self.cmdstr + "\n" + str(e)
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) 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 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 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_config_xml(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 _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 run(self): filename = self.compare_file err = None try: code, output = self._get_output() 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 _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 utils.sanitize_xml_for_define(xml) guest.get_xml_config = 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: 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(consolecb, meter, wait) finally: if dom: try: dom.destroy() except: pass try: dom.undefine() except: pass
def _alter_compare(self, actualXML, outfile): utils.test_create(conn, actualXML) utils.diff_compare(actualXML, outfile)
def _roundtrip_compare(self, filename): expectXML = sanitize_file_xml(file(filename).read()) guest = virtinst.Guest(conn=conn, parsexml=expectXML) actualXML = guest.get_config_xml() utils.diff_compare(actualXML, expect_out=expectXML)