[PATCH 01/12] NetTest: Adding 'network' attribute to netdevice

rpazdera at redhat.com rpazdera at redhat.com
Fri Aug 10 10:49:04 UTC 2012


From: Radek Pazdera <rpazdera at redhat.com>

This commit introduces networks into LNST netdevices. Up to this point
we were unaware of how the devices are connected to each other. The
network attribute adds this information directly into the recipe.

So if you later receive a recipe, you can configure your underlying
physical network accordingly. This will be also useful with the
upcomming virtual networks and interfaces, because LNST will be able
to set up the virtual network automatically.

See the following example:

  Machine 1:
    <netdevice hwaddr="52:54:00:11:D5:A8" network="channel-1"
               phys_id="1" type="eth"/>
    <netdevice hwaddr="52:54:00:2E:CD:A8" network="channel-2"
               phys_id="1" type="eth"/>

  Machine 2:
    <netdevice hwaddr="52:54:00:2E:D5:A8" network="channel-1"
               phys_id="1" type="eth"/>
    <netdevice hwaddr="52:54:00:2E:D5:A8" network="channel-2"
               phys_id="1" type="eth"/>

Machine 1 is connected to machine 2 with two networks, channel-1 and
channel-2.

Signed-off-by: Radek Pazdera <rpazdera at redhat.com>
---
 NetTest/NetTestController.py |   16 +++++++++++++++-
 NetTest/NetTestParse.py      |    1 +
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index 4e34c90..8e23152 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -39,11 +39,14 @@ class NetTestController:
         self._recipe = {}
         definitions = {"recipe": self._recipe}
 
+        self._recipe["networks"] = {}
+
         ntparse = NetTestParse(recipe_path)
         ntparse.set_recipe(self._recipe)
         ntparse.set_definitions(definitions)
 
-        ntparse.register_event_handler("netdevice_ready", ignore_event)
+        ntparse.register_event_handler("netdevice_ready",
+                                        self._prepare_device)
         ntparse.register_event_handler("machine_info_ready",
                                         self._prepare_slave)
         ntparse.register_event_handler("interface_config_ready",
@@ -75,6 +78,17 @@ class NetTestController:
                                         session.command, status)
         raise Exception("Session Die.")
 
+    def _prepare_device(self, machine_id, dev_id):
+        info = self._get_machineinfo(machine_id)
+        dev = self._recipe["machines"][machine_id]["netdevices"][dev_id]
+
+        dev_net = dev["network"]
+        networks = self._recipe["networks"]
+        if not dev_net in networks:
+            networks[dev_net] = {"members": []}
+
+        networks[dev_net]["members"].append((machine_id, dev_id))
+
     def _prepare_interface(self, machine_id, netdev_config_id):
         rpc = self._get_machinerpc(machine_id)
         info = self._get_machineinfo(machine_id)
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index e52f0f3..32d75e1 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -145,6 +145,7 @@ class NetMachineConfigParse(RecipeParser):
 
         dev = machine["netdevices"][phys_id] = {}
         dev["type"] = self._get_attribute(node, "type")
+        dev["network"] = self._get_attribute(node, "network")
         dev["hwaddr"] = normalize_hwaddr(self._get_attribute(node, "hwaddr"))
 
         if self._has_attribute(node, "name"):
-- 
1.7.7.6



More information about the LNST-developers mailing list