Ok, applied, thanks! On Mon, Oct 22, 2012 at 1:20 AM, Qingtang Zhou <[email protected]> wrote: > Move this tapfd_helper tool from autotest repo into > this virt-test repo, since it's a virt-test only tool. > > This script can help us boot up guest with autotest > generated qemu command line, it creates tap device > and updates the tapfd in given qemu cli. > > Signed-off-by: Qingtang Zhou <[email protected]> > --- > tools/tapfd_helper.py | 63 > +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 63 insertions(+) > create mode 100755 tools/tapfd_helper.py > > diff --git a/tools/tapfd_helper.py b/tools/tapfd_helper.py > new file mode 100755 > index 0000000..0ab695e > --- /dev/null > +++ b/tools/tapfd_helper.py > @@ -0,0 +1,63 @@ > +#!/usr/bin/python > + > +import sys, os, re, logging > +import common > +from autotest.client.shared import logging_manager > +from virttest import utils_misc > + > + > +def destroy_tap(tapfd_list): > + for tapfd in tapfd_list: > + try: > + os.close(tapfd) > + # File descriptor is already closed > + except OSError: > + pass > + > + > +if __name__ == "__main__": > + logging_manager.configure_logging(utils_misc.VirtLoggingConfig(), > + verbose=True) > + if len(sys.argv) <= 2: > + logging.info("Usage: %s bridge_name qemu_command_line", sys.argv[0]) > + sys.exit(255) > + > + brname = sys.argv[1] > + cmd_line = ' '.join(sys.argv[2:]) > + > + if re.findall("-netdev\s", cmd_line): > + # so we get the new qemu cli with netdev parameter. > + tap_list_re = r"tap,id=(.*?)," > + tap_replace_re = r"(tap,id=%s.*?,fd=)\d+" > + else: > + # the old cli contain "-net" parameter. > + tap_list_re = r"tap,vlan=(\d+)," > + tap_replace_re = r"(tap,vlan=%s,fd=)\d+" > + > + tap_list = re.findall(tap_list_re, cmd_line) > + if not tap_list: > + print "Could not find tap device." > + sys.exit(1) > + > + tapfd_list = [] > + > + for tap in tap_list: > + try: > + ifname = "tap-%s" % tap > + tapfd = utils_misc.open_tap("/dev/net/tun", ifname) > + utils_misc.add_to_bridge(ifname, brname) > + utils_misc.bring_up_ifname(ifname) > + pattern = tap_replace_re % tap > + cmd_line = re.sub(pattern, "\g<1>%s " % tapfd, cmd_line) > + tapfd_list.append(tapfd) > + except Exception, e: > + destroy_tap(tapfd_list) > + print "Error: %s" % e > + sys.exit(2) > + > + try: > + # Run qemu command. > + logging.info("TAP fd open to %s: %s", brname, tapfd_list) > + os.system(cmd_line) > + finally: > + destroy_tap(tapfd_list) > -- > 1.7.12.1 > > _______________________________________________ > Virt-test-devel mailing list > [email protected] > https://www.redhat.com/mailman/listinfo/virt-test-devel
-- Lucas _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
