[lnst] NetTestResultSerializer: add support for command_sequences

Jiří Pírko jirka at fedoraproject.org
Fri May 31 11:33:34 UTC 2013


commit b720b424b695ec49dd41d6992cd82f6b317a2959
Author: Ondrej Lichtner <olichtne at redhat.com>
Date:   Fri May 31 11:06:38 2013 +0200

    NetTestResultSerializer: add support for command_sequences
    
    This commit extends the xml format used by the result serializer to
    include command sequences of the original recipe. I added this because
    we use a lot of recipes with multiple command sequences and it can get
    pretty confusing trying to figure out which commands are in the same
    command sequence, when you're not directly looking at the recipe.
    
    I also added a 'result' attribute to the <recipe> node, that contains
    the cumulative result of the recipe. This is a little bit redundant
    because you can deduce it from the results of individual commands. But
    it's more convenient like this.
    
    Signed-off-by: Ondrej Lichtner <olichtne at redhat.com>
    Signed-off-by: Jiri Pirko <jiri at resnulli.us>

 lnst/Controller/NetTestController.py       |    1 +
 lnst/Controller/NetTestResultSerializer.py |   15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index a43c299..3cf3f91 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -285,6 +285,7 @@ class NetTestController:
 
         for sequence in self._recipe["sequences"]:
             try:
+                self._res_serializer.add_command_sequence()
                 res = self._run_command_sequence(sequence)
             except CommandException as exc:
                 logging.debug(exc)
diff --git a/lnst/Controller/NetTestResultSerializer.py b/lnst/Controller/NetTestResultSerializer.py
index 499a076..17b7f51 100644
--- a/lnst/Controller/NetTestResultSerializer.py
+++ b/lnst/Controller/NetTestResultSerializer.py
@@ -35,6 +35,7 @@ class NetTestResultSerializer:
         self._dom = impl.createDocument(None, "results", None)
         self._top_el = self._dom.documentElement
         self._cur_recipe_el = None
+        self._cur_cmd_seq_el = None
 
     def __str__(self):
         return self._dom.toprettyxml()
@@ -42,12 +43,20 @@ class NetTestResultSerializer:
     def add_recipe(self, name):
         recipe_el = self._dom.createElement("recipe")
         recipe_el.setAttribute("name", name)
+        recipe_el.setAttribute("result", "FAIL")
         self._top_el.appendChild(recipe_el)
         self._cur_recipe_el = recipe_el
+        self._cur_cmd_seq_el = None
+        self._first_command = True
+
+    def add_command_sequence(self):
+        cmd_seq_el = self._dom.createElement("command_sequence")
+        self._cur_recipe_el.appendChild(cmd_seq_el)
+        self._cur_cmd_seq_el = cmd_seq_el
 
     def add_cmd_result(self, command, cmd_res):
         command_el = self._dom.createElement("command")
-        self._cur_recipe_el.appendChild(command_el)
+        self._cur_cmd_seq_el.appendChild(command_el)
 
         for key in command:
             if key == "options":
@@ -59,9 +68,13 @@ class NetTestResultSerializer:
 
         if cmd_res["passed"]:
             res = "PASS"
+            if self._first_command:
+                self._cur_recipe_el.setAttribute("result", "PASS")
         else:
             res = "FAIL"
+            self._cur_recipe_el.setAttribute("result", "FAIL")
         result_el.setAttribute("result", res)
+        self._first_command = False
 
         if "err_msg" in cmd_res:
             err_el = self._dom.createElement("error_message")


More information about the LNST-developers mailing list