From: Ray Spear <ray.sp...@hp.com>

Return a non-zero status if it is asked to display information about
a specific object and that object does not exist.

test.py:  modify to return:
    0:  on success
    1:  on failure
    2:  on partial success
  updated description to explain and give example.

topic_common:
    fixed a couple of typos in comments
    modified illegal_arg routine to save error in failuer rather than display 
the message.
    the message will be display later by "show_all_failures".

Changes from v1:
 * Add assignment line missing from previous commit.

Signed-off-by: Raymond Spear <ray.sp...@hp.com>
---
 cli/atest.py        |   37 ++++++++++++++++++++++++++++++++++++-
 cli/topic_common.py |   11 ++++++++---
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/cli/atest.py b/cli/atest.py
index 57dd847..2c71e71 100644
--- a/cli/atest.py
+++ b/cli/atest.py
@@ -12,6 +12,32 @@ on the command line and imports the site_<topic> or <topic> 
module.
 
 It then creates a <topic>_<action> object, and calls it parses),
 execute() and output() methods.
+
+There are three return values possible:
+0: the operation requested succeeded
+1: the operation requested failed
+2: the operation requested worked partially
+
+EXAMPLE:
+
+(1) host list goodsys badsys
+goodsys exists and its info is displayed
+badsys does not exist and a "host not found" message is displayed.
+
+this will exit with a value of 2.
+
+(2) host list badsys
+badsys does not exist and a "host not found" message is displayed.
+
+this will exit with a value of 1.
+
+(3) host list goodsys
+goodsys exists and its info is displayed
+
+this will exit 0
+
+(4) host list pattern
+this will exit 0 whether pattern displays anything or not
 """
 
 __author__ = 'jmeu...@google.com (Jean-Marc Eurin)'
@@ -93,6 +119,7 @@ def main():
     action_obj = action_class()
 
     action_obj.parse()
+    results = 0
     try:
         try:
             results = action_obj.execute()
@@ -107,4 +134,12 @@ def main():
             except Exception:
                 traceback.print_exc()
     finally:
-        return action_obj.show_all_failures()
+        # set rtn = 0 if there were no errors
+        # set rtn = 1 if there were only errors
+        # set rtn = 2 if there was both output and error
+        rtn = action_obj.show_all_failures()
+        if ( results ):
+            if ( rtn ):
+                #  we had errors and output
+                rtn = 2
+        return rtn
diff --git a/cli/topic_common.py b/cli/topic_common.py
index 6021574..dc057bf 100644
--- a/cli/topic_common.py
+++ b/cli/topic_common.py
@@ -50,7 +50,7 @@ High Level Algorithm:
    should return results.
 
 4. Output
-   The child output() method is called with the execute() resutls as a
+   The child output() method is called with the execute() results as a
    parameter.  This is child-specific, but should leverage the
    atest.print_*() methods.
 """
@@ -113,7 +113,7 @@ FAIL_TAG = '<XYZ>'
 UPLOAD_SOCKET_TIMEOUT = 60*30
 
 
-# Convertion functions to be called for printing,
+# Conversion functions to be called for printing,
 # e.g. to print True/False for booleans.
 def __convert_platform(field):
     if field is None:
@@ -253,7 +253,12 @@ class atest(object):
         if self.kill_on_failure:
             self.invalid_syntax(header + rest)
         else:
-            print >> sys.stderr, header + rest
+            #don't print the message here.
+            #  It will be displayed later by "show_all_failures"
+            # header ends with ":\n"
+            # so, strip it off
+            msg = header.rstrip().rstrip(":")   
+            self.failure(rest, item="", what_failed=msg)
 
 
     def invalid_syntax(self, msg):
-- 
1.7.10.4

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to