[PATCH 4/4] Ticket #4: bg_id from int to string

olichtne at redhat.com olichtne at redhat.com
Wed Aug 22 13:19:18 UTC 2012


From: Ondrej Lichtner <olichtne at redhat.com>

Background ids are now treated as strings as well.
Changes were made to parsing of the attribute, and to formatting strings
where it is later used.

Signed-off-by: Ondrej Lichtner <olichtne at redhat.com>
---
 NetTest/NetTestCommand.py | 16 ++++++++--------
 NetTest/NetTestParse.py   |  8 ++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py
index 5403621..e89f606 100644
--- a/NetTest/NetTestCommand.py
+++ b/NetTest/NetTestCommand.py
@@ -24,7 +24,7 @@ def str_command(command):
     if "timeout" in command:
         out += ", timeout (%d)" % command["timeout"]
     if "bg_id" in command:
-        out += ", bg_id (%d)" % command["bg_id"]
+        out += ", bg_id (%s)" % command["bg_id"]
     if "desc" in command:
         out += ", desc (%s)" % command["desc"]
     return out
@@ -176,9 +176,9 @@ class NetTestCommandSystemConfig(NetTestCommandGeneric):
 
 class NetTestCommandWait(NetTestCommandGeneric):
     def run(self):
-        bg_id = int(self._command["value"])
+        bg_id = self._command["value"]
         pid = bg_processes.get_pid(bg_id)
-        logging.debug("Waiting for background id \"%d\", pid \"%d\"" % (bg_id, pid))
+        logging.debug("Waiting for background id \"%s\", pid \"%d\"" % (bg_id, pid))
         os.waitpid(pid, 0)
         result = bg_processes.get_bg_process_result(bg_id)
         bg_processes.remove(bg_id)
@@ -186,9 +186,9 @@ class NetTestCommandWait(NetTestCommandGeneric):
 
 class NetTestCommandIntr(NetTestCommandGeneric):
     def run(self):
-        bg_id = int(self._command["value"])
+        bg_id = self._command["value"]
         pid = bg_processes.get_pid(bg_id)
-        logging.debug("Interrupting background id \"%d\", pid \"%d\"" % (bg_id, pid))
+        logging.debug("Interrupting background id \"%s\", pid \"%d\"" % (bg_id, pid))
         os.killpg(os.getpgid(pid), signal.SIGINT)
         os.waitpid(pid, 0)
         result = bg_processes.get_bg_process_result(bg_id)
@@ -197,9 +197,9 @@ class NetTestCommandIntr(NetTestCommandGeneric):
 
 class NetTestCommandKill(NetTestCommandGeneric):
     def run(self):
-        bg_id = int(self._command["value"])
+        bg_id = self._command["value"]
         pid = bg_processes.get_pid(bg_id)
-        logging.debug("Killing background id \"%d\", pid \"%d\"" % (bg_id, pid))
+        logging.debug("Killing background id \"%s\", pid \"%d\"" % (bg_id, pid))
         os.killpg(os.getpgid(pid), signal.SIGKILL)
         bg_processes.remove(bg_id)
         self.set_result({"passed": True})
@@ -236,7 +236,7 @@ class NetTestCommand:
             if pid:
                 os.close(write_pipe)
                 logging.debug("Running in background with"
-                              " id \"%d\", pid \"%d\"" % (bg_id, pid))
+                              " id \"%s\", pid \"%d\"" % (bg_id, pid))
                 bg_processes.add(bg_id, pid, read_pipe)
                 return {"passed": True}
             os.close(read_pipe)
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 542f820..21bfdd5 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -356,7 +356,7 @@ class CommandSequenceParse(RecipeParser):
 
             cmd_type = command["type"]
             if cmd_type in ["wait", "intr", "kill"]:
-                bg_id = int(command["value"])
+                bg_id = command["value"]
                 if bg_id in bg_ids[machine_id]:
                     bg_ids[machine_id].remove(bg_id)
                 else:
@@ -370,14 +370,14 @@ class CommandSequenceParse(RecipeParser):
                 if not bg_id in bg_ids[machine_id]:
                     bg_ids[machine_id].add(bg_id)
                 else:
-                    logging.error("Command \"%d\" uses bg_id \"%d\" on machine "
+                    logging.error("Command \"%d\" uses bg_id \"%s\" on machine "
                               "\"%s\" which is already used",
                                             i, bg_id, machine_id)
                     err = True
 
         for machine_id in bg_ids:
             for bg_id in bg_ids[machine_id]:
-                logging.error("bg_id \"%d\" on machine \"%s\" has no kill/wait "
+                logging.error("bg_id \"%s\" on machine \"%s\" has no kill/wait "
                           "command to it", bg_id, machine_id)
                 err = True
         if err:
@@ -416,7 +416,7 @@ class CommandParse(RecipeParser):
             command["timeout"] = self._get_attribute(node, "timeout", int)
 
         if self._has_attribute(node, "bg_id"):
-            command["bg_id"] = self._get_attribute(node, "bg_id", int)
+            command["bg_id"] = self._get_attribute(node, "bg_id")
 
         if self._has_attribute(node, "desc"):
             command["desc"] = self._get_attribute(node, "desc")
-- 
1.7.11.4



More information about the LNST-developers mailing list