Skip to contentSkip to conversation

KVM-test: Setup private bridge in framework

PATCH Superseded Amos Kong 3 participants 6 messages May 4, 2011 1 message not in the archive KVM

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1303184574.2088.4.camel@freedom

Amos Kong

author
#1 lore raw

PATCH v2 1/2 KVM-test: Add qemu-ifup-atbr0

'atbr0' is a private bridge.
This script is used to setup tap device.

---
 client/tests/kvm/scripts/qemu-ifup-atbr0 |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/qemu-ifup-atbr0
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +6 -0
new file mode 100755
index 0000000..82c7efa
@@ -0,0 +1,6 @@
+#!/bin/sh
+switch=atbr0
+/sbin/ifconfig $1 0.0.0.0 up
+/usr/sbin/brctl addif ${switch} $1
+/usr/sbin/brctl setfd ${switch} 0
+/usr/sbin/brctl stp ${switch} off
#2 lore raw

Re: [PATCH v2 1/2] KVM-test: Add qemu-ifup-atbr0

Quoted 15 lines · Amos Kong

'atbr0' is a private bridge.
This script is used to setup tap device.

---
 client/tests/kvm/scripts/qemu-ifup-atbr0 |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/qemu-ifup-atbr0
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +0 -0
new file mode 100755
index 0000000..82c7efa

client/tests/kvm/scripts/qemu-ifup-atbr0 line 6

Quoted 6 lines
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +6 -0
@@ -0,0 +1,6 @@
+#!/bin/sh
+switch=atbr0
+/sbin/ifconfig $1 0.0.0.0 up
+/usr/sbin/brctl addif ${switch} $1
+/usr/sbin/brctl setfd ${switch} 0
+/usr/sbin/brctl stp ${switch} off

brctl is not in /usr/sbin but /sbin in some systems, e.g. Debian.

	hj:~# which brctl
	/sbin/brctl

Does dropping this absolute path to brctl sound better?

Signature · 2 lines
Best Regards,
Asias He
#3 lore raw

Re: [PATCH v2 1/2] KVM-test: Add qemu-ifup-atbr0

Quoted 25 lines · Asias He
Quoted 15 lines · Amos Kong

'atbr0' is a private bridge.
This script is used to setup tap device.

---
 client/tests/kvm/scripts/qemu-ifup-atbr0 |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/qemu-ifup-atbr0
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +0 -0
new file mode 100755
index 0000000..82c7efa

client/tests/kvm/scripts/qemu-ifup-atbr0 line 6

Quoted 6 lines
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +6 -0
@@ -0,0 +1,6 @@
+#!/bin/sh
+switch=atbr0
+/sbin/ifconfig $1 0.0.0.0 up
+/usr/sbin/brctl addif ${switch} $1
+/usr/sbin/brctl setfd ${switch} 0
+/usr/sbin/brctl stp ${switch} off

brctl is not in /usr/sbin but /sbin in some systems, e.g. Debian.

Quoted 4 lines
	hj:~# which brctl
	/sbin/brctl

Does dropping this absolute path to brctl sound better?

I was planning to revive Jason's patchset that replaced the qemu ifup scripts altogether. If the scripts were to be kept, yes, dropping the absolute path sound good.

Thanks!

author
#4 lore raw

PATCH v3 1/2 KVM-test: Add qemu-ifup-atbr0

'atbr0' is a private bridge.
This script is used to setup tap device.

Changes from v2:
- drop the absolute path of brctl and ifconfig

---
 client/tests/kvm/scripts/qemu-ifup-atbr0 |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/qemu-ifup-atbr0
client/tests/kvm/scripts/qemu-ifup-atbr0 new file +6 -0
new file mode 100755
index 0000000..59f91b5
@@ -0,0 +1,6 @@
+#!/bin/sh
+switch=atbr0
+ifconfig $1 0.0.0.0 up
+brctl addif ${switch} $1
+brctl setfd ${switch} 0
+brctl stp ${switch} off
author
#5 lore raw

PATCH 1/1 KVM-test: Drop the absolute path of brctl/ifconfig

In reply to Lucas Meneghel Rodrigues

The absolute paths of brctl are not same in different distribution.

---
 client/tests/kvm/scripts/qemu-ifup      |   12 ++++++------
 client/tests/kvm/scripts/qemu-ifup-ipv6 |   12 ++++++------
 2 files changed, 12 insertions(+), 12 deletions(-)
client/tests/kvm/scripts/qemu-ifup +6 -6
index c4debf5..2f9c7fe 100755
@@ -2,10 +2,10 @@
 
 # The following expression selects the first bridge listed by 'brctl show'.
 # Modify it to suit your needs.
-switch=$(/usr/sbin/brctl show | awk 'NR==2 { print $1 }')
+switch=$(brctl show | awk 'NR==2 { print $1 }')
 
-/bin/echo 1 > /proc/sys/net/ipv6/conf/${switch}/disable_ipv6
-/sbin/ifconfig $1 0.0.0.0 up
-/usr/sbin/brctl addif ${switch} $1
-/usr/sbin/brctl setfd ${switch} 0
-/usr/sbin/brctl stp ${switch} off
+echo 1 > /proc/sys/net/ipv6/conf/${switch}/disable_ipv6
+ifconfig $1 0.0.0.0 up
+brctl addif ${switch} $1
+brctl setfd ${switch} 0
+brctl stp ${switch} off
client/tests/kvm/scripts/qemu-ifup-ipv6 +6 -6
index d4b0592..a11c084 100755
@@ -2,10 +2,10 @@
 
 # The following expression selects the first bridge listed by 'brctl show'.
 # Modify it to suit your needs.
-switch=$(/usr/sbin/brctl show | awk 'NR==2 { print $1 }')
+switch=$(brctl show | awk 'NR==2 { print $1 }')
 
-/bin/echo 0 > /proc/sys/net/ipv6/conf/${switch}/disable_ipv6 
-/sbin/ifconfig $1 0.0.0.0 up
-/usr/sbin/brctl addif ${switch} $1
-/usr/sbin/brctl setfd ${switch} 0
-/usr/sbin/brctl stp ${switch} off
+echo 0 > /proc/sys/net/ipv6/conf/${switch}/disable_ipv6
+ifconfig $1 0.0.0.0 up
+brctl addif ${switch} $1
+brctl setfd ${switch} 0
+brctl stp ${switch} off
author
#6 lore raw

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

In reply to a message not in the archive

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

---

 0 files changed, 0 insertions(+), 0 deletions(-)
client/virt/virt_env_process.py +34 -0
index 625b422..d2c38f3 100644
@@ -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):
     """