[PATCH] NetTestResultSerializer: fix output of options

olichtne at redhat.com olichtne at redhat.com
Fri May 31 13:48:30 UTC 2013


From: Ondrej Lichtner <olichtne at redhat.com>

The serializer function we use transforms dict objects directly to xml.
For this it uses the keys as tag names. This however results in invalid
tags for system_config options which begin with a '/' character. This
commit fixes that by detecting if the parent tag is named 'options'.
This is not a very universal way to do this as these special characters
can theoretically appear anywhere, but a nice universal solution
probably doesnt exist without defining a strict result data interface,
which we currently don't have.

Signed-off-by: Ondrej Lichtner <olichtne at redhat.com>
---
 lnst/Controller/NetTestResultSerializer.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lnst/Controller/NetTestResultSerializer.py b/lnst/Controller/NetTestResultSerializer.py
index 57577e7..7e83759 100644
--- a/lnst/Controller/NetTestResultSerializer.py
+++ b/lnst/Controller/NetTestResultSerializer.py
@@ -18,7 +18,11 @@ import logging
 def serialize_obj(obj, dom, el, upper_name="unnamed"):
     if isinstance(obj, dict):
         for key in obj:
-            new_el = dom.createElement(key)
+            if upper_name == "options":
+                new_el = dom.createElement("option")
+                new_el.setAttribute("name", key)
+            else:
+                new_el = dom.createElement(key)
             el.appendChild(new_el)
             serialize_obj(obj[key], dom, new_el, upper_name=key)
     elif isinstance(obj, list):
@@ -203,12 +207,12 @@ class NetTestResultSerializer:
             result_data_node = result_data_nodes[0]
             options_nodes = result_data_node.getElementsByTagName("options")
             for options_node in options_nodes:
-                for option in options_node.childNodes:
+                for option in options_node.getElementsByTagName("option"):
                     previous_node = option.getElementsByTagName("previous_val")[0]
                     current_node = option.getElementsByTagName("current_val")[0]
                     previous_val = get_node_val(previous_node)
                     current_val = get_node_val(current_node)
-                    opt_left = 12*" "+"%s" % option.tagName
+                    opt_left = 12*" "+"%s" % option.getAttribute("name")
                     opt_right = "previous: %s current: %s" \
                                 % (previous_val, current_val)
                     output_pairs.append((opt_left, opt_right))
-- 
1.8.1.4



More information about the LNST-developers mailing list