From: Ondrej Lichtner <olichtne(a)redhat.com>
to_list reconstructs an XmlCollection object as a normal Python list
to_dict reconstructs an XmlData object as a normal Python dictionary
This caused issues when sending Open vSwitch configuration to the slave,
because object types were preserved by serialization (pickled) and
during deserialization on the slave these objects could access their
constructor since it is only on the Controller.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/NetTestController.py | 2 +-
lnst/Controller/XmlProcessing.py | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 005aa09..c5a9fc9 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -326,7 +326,7 @@ class NetTestController:
iface.set_option(opt["name"], opt["value"])
if "ovs_conf" in iface_xml_data:
- iface.set_ovs_conf(iface_xml_data["ovs_conf"])
+ iface.set_ovs_conf(iface_xml_data["ovs_conf"].to_dict())
if iface_xml_data["netns"] != None:
iface.set_netns(iface_xml_data["netns"])
diff --git a/lnst/Controller/XmlProcessing.py b/lnst/Controller/XmlProcessing.py
index b8d1127..5da0289 100644
--- a/lnst/Controller/XmlProcessing.py
+++ b/lnst/Controller/XmlProcessing.py
@@ -119,6 +119,21 @@ class XmlCollection(list):
it = super(XmlCollection, self).__iter__()
return XmlDataIterator(it)
+ def to_list(self):
+ new_list = list()
+ for value in self:
+ if isinstance(value, XmlData):
+ new_val = value.to_dict()
+ elif isinstance(value, XmlCollection):
+ new_val = value.to_list()
+ elif isinstance(value, XmlTemplateString):
+ new_val = str(value)
+ else:
+ new_val = value
+ new_list.append(new_val)
+
+ return new_list
+
class XmlData(dict):
def __init__(self, node=None):
super(XmlData, self).__init__()
@@ -162,6 +177,21 @@ class XmlData(dict):
it = super(XmlData, self).itervalues()
return XmlDataIterator(it)
+ def to_dict(self):
+ new_dict = dict()
+ for key, value in self.iteritems():
+ if isinstance(value, XmlData):
+ new_val = value.to_dict()
+ elif isinstance(value, XmlCollection):
+ new_val = value.to_list()
+ elif isinstance(value, XmlTemplateString):
+ new_val = str(value)
+ else:
+ new_val = value
+ new_dict[key] = new_val
+
+ return new_dict
+
class XmlTemplateString(object):
def __init__(self, param=None, node=None):
if type(param) == str:
--
2.1.0