浏览代码

Return BAD_NAME fault if no process to tail. Fixes #488

Mike Naberezny 10 年之前
父节点
当前提交
4ad7283514
共有 3 个文件被更改,包括 51 次插入0 次删除
  1. 3 0
      CHANGES.txt
  2. 6 0
      supervisor/rpcinterface.py
  3. 42 0
      supervisor/tests/test_rpcinterfaces.py

+ 3 - 0
CHANGES.txt

@@ -2,6 +2,9 @@
 ----------------------------
 
 
+- Fixed a bug where ``tail group:*`` would cause a 500 Internal Server Error
+  rather than returning a BAD_NAME fault.
+
 3.1.1 (2014-08-11)
 ------------------
 

+ 6 - 0
supervisor/rpcinterface.py

@@ -555,6 +555,9 @@ class SupervisorNamespaceRPCInterface:
     def _readProcessLog(self, name, offset, length, channel):
         group, process = self._getGroupAndProcess(name)
 
+        if process is None:
+            raise RPCError(Faults.BAD_NAME, name)
+
         logfile = getattr(process.config, '%s_logfile' % channel)
 
         if logfile is None or not os.path.exists(logfile):
@@ -593,6 +596,9 @@ class SupervisorNamespaceRPCInterface:
     def _tailProcessLog(self, name, offset, length, channel):
         group, process = self._getGroupAndProcess(name)
 
+        if process is None:
+            raise RPCError(Faults.BAD_NAME, name)
+
         logfile = getattr(process.config, '%s_logfile' % channel)
 
         if logfile is None or not os.path.exists(logfile):

+ 42 - 0
supervisor/tests/test_rpcinterfaces.py

@@ -1123,6 +1123,17 @@ class SupervisorNamespaceXMLRPCInterfaceTests(TestBase):
         finally:
             os.remove(logfile)
 
+    def test_readProcessStdoutLog_bad_name_no_process(self):
+        from supervisor import xmlrpc
+        options = DummyOptions()
+        pconfig = DummyPConfig(options, 'process1', '/bin/process1', priority=1,
+                               stdout_logfile='/tmp/process1.log')
+        supervisord = PopulatedDummySupervisor(options, 'foo', pconfig)
+        interface = self._makeOne(supervisord)
+        self._assertRPCError(xmlrpc.Faults.BAD_NAME,
+                             interface.readProcessStdoutLog,
+                             'foo:*', offset=0, length=1)
+
     def test_readProcessStdoutLog(self):
         options = DummyOptions()
         pconfig = DummyPConfig(options, 'foo', '/bin/foo',
@@ -1190,6 +1201,17 @@ class SupervisorNamespaceXMLRPCInterfaceTests(TestBase):
         finally:
             os.remove(logfile)
 
+    def test_readProcessStderrLog_bad_name_no_process(self):
+        from supervisor import xmlrpc
+        options = DummyOptions()
+        pconfig = DummyPConfig(options, 'process1', '/bin/process1', priority=1,
+                               stdout_logfile='/tmp/process1.log')
+        supervisord = PopulatedDummySupervisor(options, 'foo', pconfig)
+        interface = self._makeOne(supervisord)
+        self._assertRPCError(xmlrpc.Faults.BAD_NAME,
+                             interface.readProcessStderrLog,
+                             'foo:*', offset=0, length=1)
+
     def test_readProcessStderrLog(self):
         options = DummyOptions()
         pconfig = DummyPConfig(options, 'foo', '/bin/foo',
@@ -1222,6 +1244,16 @@ class SupervisorNamespaceXMLRPCInterfaceTests(TestBase):
         self._assertRPCError(xmlrpc.Faults.BAD_NAME,
                              interface.tailProcessStdoutLog, 'BAD_NAME', 0, 10)
 
+    def test_tailProcessStdoutLog_bad_name_no_process(self):
+        from supervisor import xmlrpc
+        options = DummyOptions()
+        pconfig = DummyPConfig(options, 'process1', '/bin/process1', priority=1,
+                               stdout_logfile='/tmp/process1.log')
+        supervisord = PopulatedDummySupervisor(options, 'foo', pconfig)
+        interface = self._makeOne(supervisord)
+        self._assertRPCError(xmlrpc.Faults.BAD_NAME,
+                             interface.tailProcessStdoutLog, 'foo:*', 0, 10)
+
     def test_tailProcessStdoutLog_all(self):
         # test entire log is returned when offset==0 and logsize < length
         from string import letters
@@ -1336,6 +1368,16 @@ class SupervisorNamespaceXMLRPCInterfaceTests(TestBase):
         self._assertRPCError(xmlrpc.Faults.BAD_NAME,
                              interface.tailProcessStderrLog, 'BAD_NAME', 0, 10)
 
+    def test_tailProcessStderrLog_bad_name_no_process(self):
+        from supervisor import xmlrpc
+        options = DummyOptions()
+        pconfig = DummyPConfig(options, 'process1', '/bin/process1', priority=1,
+                               stdout_logfile='/tmp/process1.log')
+        supervisord = PopulatedDummySupervisor(options, 'foo', pconfig)
+        interface = self._makeOne(supervisord)
+        self._assertRPCError(xmlrpc.Faults.BAD_NAME,
+                             interface.tailProcessStderrLog, 'foo:*', 0, 10)
+
     def test_tailProcessStderrLog_all(self):
         # test entire log is returned when offset==0 and logsize < length
         from string import letters