[PATCH v2 2/2] KVM-test: Setup private bridge in framework

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux