From patchwork Wed May 4 03:01:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 752502 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4431t49014956 for ; Wed, 4 May 2011 03:01:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754880Ab1EDDBw (ORCPT ); Tue, 3 May 2011 23:01:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57001 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754742Ab1EDDBw (ORCPT ); Tue, 3 May 2011 23:01:52 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4431pAk030237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 May 2011 23:01:51 -0400 Received: from [127.0.0.1] (dhcp-8-167.nay.redhat.com [10.66.8.167]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4431nj8021751; Tue, 3 May 2011 23:01:50 -0400 Subject: [PATCH v2 2/2] KVM-test: Setup private bridge in framework To: autotest@test.kernel.org From: Amos Kong Cc: lmr@redhat.com, kvm@vger.kernel.org Date: Wed, 04 May 2011 11:01:25 +0800 Message-ID: <20110504030125.16383.18741.stgit@t> In-Reply-To: <1303184574.2088.4.camel@freedom> References: <1303184574.2088.4.camel@freedom> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 04 May 2011 03:01:55 +0000 (UTC) KVM users always use bridge network, there are also some limits in userspace network, and userspace network is not officially supported by some companys. Framework will clean configuration when private bridge is not used. We can replace user net with private bridge if this setup is stable and general enough. Configure parameters: bridge = private priv_brname = atbr0 priv_subnet = 192.168.58 nic_script = scripts/qemu-ifup-atbr0 Signed-off-by: Amos Kong --- 0 files changed, 0 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/client/virt/virt_env_process.py b/client/virt/virt_env_process.py index 625b422..d2c38f3 100644 --- a/client/virt/virt_env_process.py +++ b/client/virt/virt_env_process.py @@ -196,6 +196,28 @@ def preprocess(test, params, env): @param env: The environment (a dict-like object). """ error.context("preprocessing") + + if params.get("bridge") == "private": + priv_brname = params.get("priv_brname", 'atbr0') + priv_subnet = params.get("priv_subnet", '192.168.58') + if priv_brname not in commands.getoutput("btctl show"): + logging.info("Setup private bridge: %s" % priv_brname) + commands.getoutput("brctl addbr %s" % priv_brname) + file("/proc/sys/net/ipv4/ip_forward", "w").write("1\n") + commands.getoutput("brctl stp %s on" % priv_brname) + commands.getoutput("brctl setfd %s 0" % priv_brname) + commands.getoutput("ifconfig %s %s.1 up" % (priv_brname, + priv_subnet)) + commands.getoutput("iptables -t nat -A POSTROUTING -s %s.254/24 !" + " -d %s.254/24 -j MASQUERADE" % (priv_subnet, priv_subnet)) + commands.getoutput("service dnsmasq stop") + commands.getoutput("dnsmasq --strict-order --bind-interfaces" + " --listen-address %s.1 --dhcp-range %s.1,%s.254" + " --pid-file=/tmp/dnsmasq.pid" % + (priv_subnet, priv_subnet, priv_subnet)) + if priv_brname not in commands.getoutput("brctl show"): + raise error.TestError("Fail to setup private bridge.") + # Start tcpdump if it isn't already running if "address_cache" not in env: env["address_cache"] = {} @@ -365,6 +387,18 @@ def postprocess(test, params, env): int(params.get("post_command_timeout", "600")), params.get("post_command_noncritical") == "yes") + if params.get("bridge") == "private": + priv_brname = params.get("priv_brname", 'atbr0') + priv_subnet = params.get("priv_subnet", '192.168.58') + if len(commands.getoutput("brctl show|grep %s" % + priv_brname).split()) < 4: + logging.info("Remove private bridge: %s" % priv_brname) + pid = file("/tmp/dnsmasq.pid").read() + os.kill(int(pid), 9) + commands.getoutput("ifconfig %s down" % priv_brname) + commands.getoutput("brctl delbr %s" % priv_brname) + commands.getoutput("iptables -t nat -D POSTROUTING -s %s.254/24 !" + " -d %s.254/24 -j MASQUERADE" % (priv_subnet, priv_subnet)) def postprocess_on_error(test, params, env): """