[Zope3-checkins] SVN: zdaemon/trunk/ Fixed: The start command exited with a zero exit status even when

jim cvs-admin at zope.org
Mon Jul 30 17:47:19 UTC 2012


Log message for revision 127404:
  Fixed: The start command exited with a zero exit status even when
  the program being started failed to start (or exited imediately).
  

Changed:
  U   zdaemon/trunk/CHANGES.txt
  U   zdaemon/trunk/src/zdaemon/tests/tests.py
  U   zdaemon/trunk/src/zdaemon/tests/testuser.py
  U   zdaemon/trunk/src/zdaemon/zdctl.py

-=-
Modified: zdaemon/trunk/CHANGES.txt
===================================================================
--- zdaemon/trunk/CHANGES.txt	2012-07-30 13:59:51 UTC (rev 127403)
+++ zdaemon/trunk/CHANGES.txt	2012-07-30 17:47:14 UTC (rev 127404)
@@ -2,6 +2,12 @@
 Change log
 ==========
 
+3.0.4 (2012-07-30)
+==================
+
+- Fixed: The start command exited with a zero exit status even when
+  the program being started failed to start (or exited imediately).
+
 3.0.3 (2012-07-10)
 ==================
 

Modified: zdaemon/trunk/src/zdaemon/tests/tests.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/tests.py	2012-07-30 13:59:51 UTC (rev 127403)
+++ zdaemon/trunk/src/zdaemon/tests/tests.py	2012-07-30 17:47:14 UTC (rev 127404)
@@ -78,6 +78,7 @@
     >>> system("./zdaemon -Cconf start")
     . .
     daemon manager not running
+    Failed: 1
 
     """
 
@@ -267,7 +268,49 @@
     True
     """
 
+def nonzeo_exit_on_program_failure():
+    """
+    >>> write('conf',
+    ... '''
+    ... <runner>
+    ...   backoff-limit 1
+    ...   program nosuch
+    ... </runner>
+    ... ''')
 
+    >>> system("./zdaemon -Cconf start", echo=True) # doctest: +ELLIPSIS
+    ./zdaemon...
+    daemon manager not running
+    Failed: 1
+
+    >>> write('conf',
+    ... '''
+    ... <runner>
+    ...   backoff-limit 1
+    ...   program cat nosuch
+    ... </runner>
+    ... ''')
+
+    >>> system("./zdaemon -Cconf start", echo=True) # doctest: +ELLIPSIS
+    ./zdaemon...
+    daemon manager not running
+    Failed: 1
+
+    >>> write('conf',
+    ... '''
+    ... <runner>
+    ...   backoff-limit 1
+    ...   program pwd
+    ... </runner>
+    ... ''')
+
+    >>> system("./zdaemon -Cconf start", echo=True) # doctest: +ELLIPSIS
+    ./zdaemon...
+    daemon manager not running
+    Failed: 1
+
+    """
+
 def setUp(test):
     test.globs['_td'] = td = []
     here = os.getcwd()
@@ -292,7 +335,9 @@
     for f in test.globs['_td']:
         f()
 
-def system(command, input='', quiet=False):
+def system(command, input='', quiet=False, echo=False):
+    if echo:
+        print command
     p = subprocess.Popen(
         command, shell=True,
         stdin=subprocess.PIPE,

Modified: zdaemon/trunk/src/zdaemon/tests/testuser.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testuser.py	2012-07-30 13:59:51 UTC (rev 127403)
+++ zdaemon/trunk/src/zdaemon/tests/testuser.py	2012-07-30 17:47:14 UTC (rev 127404)
@@ -83,7 +83,8 @@
     ...   O(gr_gid=7, gr_mem =['h', ]),
     ... ]
 
-    >>> zdaemon.zdctl.main(['-C', 'conf', 'status'])
+    >>> with mock.patch('sys.exit'):
+    ...     zdaemon.zdctl.main(['-C', 'conf', 'status'])
     daemon manager not running
 
     >>> import pwd, os
@@ -108,6 +109,7 @@
     ... ''')
 
     >>> with mock.patch('os.geteuid') as geteuid:
+    ...   with mock.patch('sys.exit'):
     ...     geteuid.return_value = 99
     ...     zdaemon.zdctl.main(['-C', 'conf', 'status'])
     ...     os.geteuid.assert_called_with()

Modified: zdaemon/trunk/src/zdaemon/zdctl.py
===================================================================
--- zdaemon/trunk/src/zdaemon/zdctl.py	2012-07-30 13:59:51 UTC (rev 127403)
+++ zdaemon/trunk/src/zdaemon/zdctl.py	2012-07-30 17:47:14 UTC (rev 127404)
@@ -267,7 +267,7 @@
                     was_running = True
                 elif (was_running or n > 10) and not cond(n):
                     print "\ndaemon manager not running"
-                    return
+                    return 1
 
         except KeyboardInterrupt:
             print "^C"
@@ -318,9 +318,8 @@
             print "daemon process already running; pid=%d" % self.zd_pid
             return
         if self.options.daemon:
-            self.awhile(self._start_cond,
-                        "daemon process started, pid=%(zd_pid)d",
-                        )
+            return self.awhile(
+                self._start_cond, "daemon process started, pid=%(zd_pid)d")
 
     def _get_override(self, opt, name, svalue=None, flag=0):
         value = getattr(self.options, name)
@@ -611,7 +610,7 @@
         options = ZDCtlOptions()
     options.realize(args)
     c = cmdclass(options)
-    c.onecmd(" ".join(options.args))
+    sys.exit(c.onecmd(" ".join(options.args)))
 
 if __name__ == "__main__":
     main()



More information about the Zope3-Checkins mailing list