[PATCH] NetTestResultSerializer: fix output of options

Jiri Pirko jpirko at redhat.com
Fri May 31 21:27:35 UTC 2013


Fri, May 31, 2013 at 03:48:30PM CEST, olichtne at redhat.com wrote:
>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
>
>_______________________________________________
>LNST-developers mailing list
>LNST-developers at lists.fedorahosted.org
>https://lists.fedorahosted.org/mailman/listinfo/lnst-developers

applied, thanks!


More information about the LNST-developers mailing list