commit e96a033b5e6504cd194988356f109ee7b7bd1297
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Mon Aug 13 12:01:48 2012 +0200
NetTestParse: Adding support for libvirt-integration
This commit adds necessary changes to the parser in LNST in order
to support the libvirt device creation.
Netdevice tags are now grouped under a <netdevices> parent tag
within <netmachineconfig>.
On top of that a special mode for defining netdevices (called create)
was added. Devices defined in this mode are not present in the machine
and will be created on test execution.
This mode is available only on virtual test machines created using
libvirt. Here's an exmaple config of such a machine:
<machine id="1">
<netmachineconfig>
<info hostname="192.168.122.11" libvirt_domain="RHEL6"
rootpass="redhat"/>
<netdevices>
<libvirt_create>
<netdevice network="tnet" phys_id="1" type="eth"/>
<netdevice network="tnet" phys_id="2" type="eth"/>
</libvirt_create>
</netdevices>
</netmachineconfig>
<netconfig>
<interface id="1" phys_id="1" type="eth">
<addresses>
<address value="192.168.100.226/24"/>
</addresses>
</interface>
<interface id="2" phys_id="2" type="eth">
<addresses>
<address value="192.168.100.240/24"/>
</addresses>
</interface>
</netconfig>
</machine>
The dynamic devices are enclosed within the <libvirt_create> tag. Their
hwaddr doesn't need to be specified (it will be generated if missing).
Additionally, 'libvirt_bridge' attribute can be added to these devices
to override the default LNST internal bridge, that these devices are
connected to.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
NetTest/NetTestParse.py | 35 ++++++++++++++++++++++++++++++++---
1 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 746342c..fbe5adc 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -118,7 +118,7 @@ class NetMachineConfigParse(RecipeParser):
def parse(self, node):
scheme = {"info": self._info,
- "netdevice": self._netdevice}
+ "netdevices": self._netdevices}
self._process_child_nodes(node, scheme)
def _info(self, node, params):
@@ -127,6 +127,10 @@ class NetMachineConfigParse(RecipeParser):
info["hostname"] = self._get_attribute(node, "hostname")
+ if self._has_attribute(node, "libvirt_domain"):
+ info["libvirt_domain"] = self._get_attribute(node,
+ "libvirt_domain")
+
if self._has_attribute(node, "rootpass"):
info["rootpass"] = self._get_attribute(node, "rootpass")
@@ -138,18 +142,43 @@ class NetMachineConfigParse(RecipeParser):
self._trigger_event("machine_info_ready",
{"machine_id": self._machine_id})
+ def _netdevices(self, node, params):
+ scheme = {"netdevice": self._netdevice,
+ "libvirt_create": self._libvirt_create}
+
+ new_params = {"create": None}
+ self._process_child_nodes(node, scheme, new_params)
+
+ def _libvirt_create(self, node, params):
+ scheme = {"netdevice": self._netdevice}
+
+ new_params = {"create": "libvirt"}
+ self._process_child_nodes(node, scheme, new_params)
+
def _netdevice(self, node, params):
machine = self._machine
phys_id = self._get_attribute(node, "phys_id", int)
dev = machine["netdevices"][phys_id] = {}
+ dev["create"] = params["create"]
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"):
+ # hwaddr attribute is optional for dynamic devices,
+ # but it is required by non-dynamic devices
+ if dev["create"] == None or self._has_attribute(node, "hwaddr"):
+ hwaddr = self._get_attribute(node, "hwaddr")
+ dev["hwaddr"] = normalize_hwaddr(hwaddr)
+
+ # name attribute is only valid when the device is not dynamic
+ if dev["create"] == None and self._has_attribute(node, "name"):
dev["name"] = self._get_attribute(node, "name")
+ # bridge attribute is valid only when the device is dynamic
+ if dev["create"] == "libvirt" and \
+ self._has_attribute(node, "libvirt_bridge"):
+ dev["libvirt_bridge"] = self._get_attribute(node, "libvirt_bridge")
+
self._trigger_event("netdevice_ready", {"machine_id": self._machine_id,
"dev_id": phys_id})