[lnst] NetTestResultSerializer: fix output of options

Jiří Pírko jirka at fedoraproject.org
Fri May 31 21:27:21 UTC 2013


commit be77f657244e2c13699e45989b2696fac8b571f3
Author: Ondrej Lichtner <olichtne at redhat.com>
Date:   Fri May 31 15:48:30 2013 +0200

    NetTestResultSerializer: fix output of options
    
    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>
    Signed-off-by: Jiri Pirko <jiri at resnulli.us>

 lnst/Controller/NetTestResultSerializer.py |   10 +++++++---
 1 files 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))


More information about the LNST-developers mailing list