public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH v2 2/2] KVM-test: Setup private bridge in framework
Date: Wed, 04 May 2011 11:01:25 +0800	[thread overview]
Message-ID: <20110504030125.16383.18741.stgit@t> (raw)
In-Reply-To: <1303184574.2088.4.camel@freedom>

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 <akong@redhat.com>
---
 0 files changed, 0 insertions(+), 0 deletions(-)

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):
     """

      parent reply	other threads:[~2011-05-04  3:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1303184574.2088.4.camel@freedom>
2011-05-04  3:01 ` [PATCH v2 1/2] KVM-test: Add qemu-ifup-atbr0 Amos Kong
2011-05-04  3:11   ` Asias He
2011-05-04  3:23     ` Lucas Meneghel Rodrigues
2011-05-04  6:08       ` [PATCH v3 " Amos Kong
2011-05-04  6:10       ` [PATCH] KVM-test: Drop the absolute path of brctl/ifconfig Amos Kong
2011-05-04  3:01 ` Amos Kong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110504030125.16383.18741.stgit@t \
    --to=akong@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox