[Supervisor-checkins] r792 - in supervisor/branches/gsoc/src/supervisor: . tests
Siddhant Goel
siddhantgoel at gmail.com
Sat Aug 9 13:06:02 EDT 2008
Author: Siddhant Goel <siddhantgoel at gmail.com>
Date: Sat Aug 9 13:06:02 2008
New Revision: 792
Log:
Modified:
supervisor/branches/gsoc/src/supervisor/supervisorctl.py
supervisor/branches/gsoc/src/supervisor/tests/base.py
supervisor/branches/gsoc/src/supervisor/tests/test_supervisorctl.py
Modified: supervisor/branches/gsoc/src/supervisor/supervisorctl.py
==============================================================================
--- supervisor/branches/gsoc/src/supervisor/supervisorctl.py (original)
+++ supervisor/branches/gsoc/src/supervisor/supervisorctl.py Sat Aug 9 13:06:02 2008
@@ -114,7 +114,7 @@
self.vocab = ['add','exit','maintail','pid','reload',
'restart','start','stop','version','clear',
'fg','open','quit','remove','shutdown','status',
- 'tail']
+ 'tail','help']
cmd.Cmd.__init__(self, completekey, stdin, stdout)
for name, factory, kwargs in self.options.plugin_factories:
plugin = factory(self, **kwargs)
@@ -916,25 +916,26 @@
if not self.ctl.upcheck():
return
if not args:
+ self.ctl.output('Error: no process name supplied')
self.help_fg()
return
args=args.split()
if len(args)>1:
- self.ctl.output('ERROR : too many process names supplied')
+ self.ctl.output('Error: too many process names supplied')
return
program=args[0]
supervisor=self.ctl.get_supervisor()
try:
info=supervisor.getProcessInfo(program)
except xmlrpclib.Fault, msg:
- if msg.faultCode == 10:
- self.ctl.output('Bad process name supplied')
+ if msg.faultCode == xmlrpc.Faults.BAD_NAME:
+ self.ctl.output('Error: bad process name supplied')
return
# for any other fault
self.ctl.output(str(msg))
return
- if info['pid'] == 0:
- self.ctl.output('ERROR : Process not running')
+ if not info['statename'] == 'RUNNING':
+ self.ctl.output('Error: process not running')
return
# everything good; continue
try:
@@ -948,10 +949,20 @@
try:
supervisor.sendProcessStdin(program,inp)
except xmlrpclib.Fault, msg:
- self.ctl.output('Error -- %s' % msg)
- continue
+ if msg.faultCode == 70:
+ self.ctl.output('Process got killed')
+ self.ctl.output('Exiting foreground')
+ a.kill()
+ return
+ info = supervisor.getProcessInfo(program)
+ if not info['statename'] == 'RUNNING':
+ self.ctl.output('Process got killed')
+ self.ctl.output('Exiting foreground')
+ a.kill()
+ return
+ continue
except KeyboardInterrupt:
- a.kill() # kill the thread
+ a.kill()
self.ctl.output('Exiting foreground')
return
Modified: supervisor/branches/gsoc/src/supervisor/tests/base.py
==============================================================================
--- supervisor/branches/gsoc/src/supervisor/tests/base.py (original)
+++ supervisor/branches/gsoc/src/supervisor/tests/base.py Sat Aug 9 13:06:02 2008
@@ -660,19 +660,19 @@
return self.all_process_info
def getProcessInfo(self, name):
+ from supervisor import xmlrpc
+ import xmlrpclib
from supervisor.process import ProcessStates
- return {
- 'name':'foo',
- 'group':'foo',
- 'pid':11,
- 'state':ProcessStates.RUNNING,
- 'statename':'RUNNING',
- 'start':_NOW - 100,
- 'stop':0,
- 'spawnerr':'',
- 'now':_NOW,
- 'description':'foo description',
- }
+ for i in self.all_process_info:
+ if i['name']==name:
+ info=i
+ return info
+ if name == 'BAD_NAME':
+ raise xmlrpclib.Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
+ if name == 'FAILED':
+ raise xmlrpclib.Fault(xmlrpc.Faults.FAILED, 'FAILED')
+ if name == 'NO_FILE':
+ raise xmlrpclib.Fault(xmlrpc.Faults.NO_FILE, 'NO_FILE')
def startProcess(self, name):
from supervisor import xmlrpc
Modified: supervisor/branches/gsoc/src/supervisor/tests/test_supervisorctl.py
==============================================================================
--- supervisor/branches/gsoc/src/supervisor/tests/test_supervisorctl.py (original)
+++ supervisor/branches/gsoc/src/supervisor/tests/test_supervisorctl.py Sat Aug 9 13:06:02 2008
@@ -584,6 +584,38 @@
self.assertEqual(plugin.ctl.stdout.getvalue(),
'supervisord: ERROR (unknown error reading log)\n')
+ def test_fg_toofewargs(self):
+ plugin=self._makeOne()
+ result=plugin.do_fg('')
+ lines=plugin.ctl.stdout.getvalue().split('\n')
+ self.assertEqual(result,None)
+ self.assertEqual(lines[0],'Error: no process name supplied')
+
+ def test_fg_toomanyargs(self):
+ plugin=self._makeOne()
+ result=plugin.do_fg('foo bar')
+ line=plugin.ctl.stdout.getvalue()
+ self.assertEqual(result,None)
+ self.assertEqual(line,'Error: too many process names supplied\n')
+
+ def test_fg_badprocname(self):
+ plugin=self._makeOne()
+ result=plugin.do_fg('BAD_NAME')
+ line=plugin.ctl.stdout.getvalue()
+ self.assertEqual(result,None)
+ self.assertEqual(line,'Error: bad process name supplied\n')
+
+ def test_fg_procnotrunning(self):
+ plugin=self._makeOne()
+ result=plugin.do_fg('bar')
+ line=plugin.ctl.stdout.getvalue()
+ self.assertEqual(result,None)
+ self.assertEqual(line,'Error: process not running\n')
+ result=plugin.do_fg('baz_01')
+ lines=plugin.ctl.stdout.getvalue().split('\n')
+ self.assertEqual(result,None)
+ self.assertEqual(lines[-2],'Error: process not running')
+
class DummyListener:
def __init__(self):
self.errors = []
More information about the Supervisor-checkins
mailing list