[lnst] add support for per-port teamd configs
Jiří Pírko
jirka at fedoraproject.org
Fri Aug 17 15:03:35 UTC 2012
commit bc3d532c4e3bf4a5f3053a4f34d5b1075e9a0354
Author: Jiri Pirko <jiri at resnulli.us>
Date: Fri Aug 17 17:01:51 2012 +0200
add support for per-port teamd configs
https://fedorahosted.org/lnst/ticket/8
Signed-off-by: Jiri Pirko <jiri at resnulli.us>
NetConfig/NetConfigCommon.py | 5 +++-
NetConfig/NetConfigDevice.py | 23 ++++++++++++++++++-
NetTest/NetTestParse.py | 2 +-
recipes/team/netconfig-test1_002.xml | 38 ++++++++++++++++++++++++++++++++++
recipes/team/netconfig-test2_002.xml | 38 ++++++++++++++++++++++++++++++++++
recipes/team/recipe_002.xml | 13 +++++++++++
6 files changed, 115 insertions(+), 4 deletions(-)
---
diff --git a/NetConfig/NetConfigCommon.py b/NetConfig/NetConfigCommon.py
index f35d358..f3f2f5d 100644
--- a/NetConfig/NetConfigCommon.py
+++ b/NetConfig/NetConfigCommon.py
@@ -17,7 +17,10 @@ def get_slaves(netdev):
return set()
def get_option(netdev, opt_name):
- options = netdev["options"]
+ try:
+ options = netdev["options"]
+ except KeyError:
+ return None
for option, value in options:
if option == opt_name:
return value
diff --git a/NetConfig/NetConfigDevice.py b/NetConfig/NetConfigDevice.py
index 534e914..688077b 100644
--- a/NetConfig/NetConfigDevice.py
+++ b/NetConfig/NetConfigDevice.py
@@ -209,20 +209,35 @@ class NetConfigDeviceVlan(NetConfigDeviceGeneric):
else:
exec_cmd("vconfig rem %s" % dev_name)
+def prepare_json_str(json_str):
+ if not json_str:
+ return ""
+ json_str = json_str.replace('"', '\\"')
+ json_str = re.sub('\s+', ' ', json_str)
+ return json_str
+
class NetConfigDeviceTeam(NetConfigDeviceGeneric):
_pidfile = None
_modulename = "team_mode_roundrobin team_mode_activebackup team_mode_broadcast team_mode_loadbalance team"
_moduleload = False
_cleanupcmd = "killall -q teamd"
+ def _should_enable_dbus(self):
+ for slave_id in get_slaves(self._netdev):
+ port_netdev = self._config[slave_id]
+ if get_option(port_netdev, "teamd_port_config"):
+ return True
+ return False
+
def configure(self):
teamd_config = get_option(self._netdev, "teamd_config")
- teamd_config = teamd_config.replace('"', '\\"')
+ teamd_config = prepare_json_str(teamd_config)
dev_name = self._netdev["name"]
pidfile = "/var/run/teamd_%s.pid" % dev_name
- exec_cmd("teamd -r -d -c \"%s\" -t %s -p %s" % (teamd_config, dev_name, pidfile))
+ dbus_option = " -D" if self._should_enable_dbus() else ""
+ exec_cmd("teamd -r -d -c \"%s\" -t %s -p %s%s" % (teamd_config, dev_name, pidfile, dbus_option))
self._pidfile = pidfile
@@ -242,6 +257,10 @@ class NetConfigDeviceTeam(NetConfigDeviceGeneric):
dev_name = self._netdev["name"]
port_netdev = self._config[slaveid]
port_name = port_netdev["name"]
+ teamd_port_config = get_option(port_netdev, "teamd_port_config")
+ if teamd_port_config:
+ teamd_port_config = prepare_json_str(teamd_port_config)
+ exec_cmd("teamdctl %s PortConfigUpdate %s \"%s\"" % (dev_name, port_name, teamd_port_config))
NetConfigDevice(port_netdev, self._config).down()
exec_cmd("ip link set dev %s master %s" % (port_name, dev_name))
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 6439c4d..13141e9 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -226,10 +226,10 @@ class NetConfigParse(RecipeParser):
params = {"dev_id": dev_id}
scheme = {"addresses": self._addresses}
+ scheme["options"] = self._options
if dev["type"] == "eth":
pass
elif dev["type"] in ["bond", "bridge", "vlan", "macvlan", "team"]:
- scheme["options"] = self._options
scheme["slaves"] = self._slaves
else:
logging.warn("unknown type \"%s\"" % dev["type"])
diff --git a/recipes/team/netconfig-test1_002.xml b/recipes/team/netconfig-test1_002.xml
new file mode 100644
index 0000000..3dbf67d
--- /dev/null
+++ b/recipes/team/netconfig-test1_002.xml
@@ -0,0 +1,38 @@
+<netconfig>
+ <interface id="1" phys_id="1" type="eth">
+ <options>
+ <option name="teamd_port_config">
+ {
+ "prio": -10,
+ "sticky": true
+ }
+ </option>
+ </options>
+ </interface>
+ <interface id="2" phys_id="2" type="eth">
+ <options>
+ <option name="teamd_port_config">
+ {
+ "prio": 100
+ }
+ </option>
+ </options>
+ </interface>
+ <interface id="3" type="team">
+ <options>
+ <option name="teamd_config">
+ {
+ "runner": {"name": "activebackup"},
+ "link_watch": {"name": "ethtool"}
+ }
+ </option>
+ </options>
+ <slaves>
+ <slave id="1"/>
+ <slave id="2"/>
+ </slaves>
+ <addresses>
+ <address value="192.168.111.1/24"/>
+ </addresses>
+ </interface>
+</netconfig>
diff --git a/recipes/team/netconfig-test2_002.xml b/recipes/team/netconfig-test2_002.xml
new file mode 100644
index 0000000..06cfcef
--- /dev/null
+++ b/recipes/team/netconfig-test2_002.xml
@@ -0,0 +1,38 @@
+<netconfig>
+ <interface id="1" phys_id="1" type="eth">
+ <options>
+ <option name="teamd_port_config">
+ {
+ "prio": -10,
+ "sticky": true
+ }
+ </option>
+ </options>
+ </interface>
+ <interface id="2" phys_id="2" type="eth">
+ <options>
+ <option name="teamd_port_config">
+ {
+ "prio": 100
+ }
+ </option>
+ </options>
+ </interface>
+ <interface id="3" type="team">
+ <options>
+ <option name="teamd_config">
+ {
+ "runner": {"name": "activebackup"},
+ "link_watch": {"name": "ethtool"}
+ }
+ </option>
+ </options>
+ <slaves>
+ <slave id="1"/>
+ <slave id="2"/>
+ </slaves>
+ <addresses>
+ <address value="192.168.111.2/24"/>
+ </addresses>
+ </interface>
+</netconfig>
diff --git a/recipes/team/recipe_002.xml b/recipes/team/recipe_002.xml
new file mode 100644
index 0000000..ebb250d
--- /dev/null
+++ b/recipes/team/recipe_002.xml
@@ -0,0 +1,13 @@
+<nettestrecipe>
+ <machines>
+ <machine id="1">
+ <netmachineconfig source="netmachineconfig-test1.xml"/>
+ <netconfig source="netconfig-test1_002.xml"/>
+ </machine>
+ <machine id="2">
+ <netmachineconfig source="netmachineconfig-test2.xml"/>
+ <netconfig source="netconfig-test2_002.xml"/>
+ </machine>
+ </machines>
+ <command_sequence source="sequence_ping_simple.xml"/>
+</nettestrecipe>
More information about the LNST-developers
mailing list