Changeset 1332


Ignore:
Timestamp:
27/07/06 11:43:56 (13 years ago)
Author:
spascoe
Message:

Added an API hook to use bbftpd_log to log messages from python code.

Location:
TI05-delivery/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1259 r1332  
    1515#include "util.h" 
    1616#include <structures.h> 
     17#include <bbftpd_log.h> 
    1718 
    1819extern char **environ; 
     
    200201 */ 
    201202 
     203/* log message to bbftpd logger */ 
     204static PyObject *pybbftpd_log(PyObject *self, PyObject *args) { 
     205  int priority; 
     206  char *message; 
     207 
     208  if (!PyArg_ParseTuple(args, "is", &priority, &message)) { 
     209    return NULL; 
     210  } 
     211 
     212  bbftpd_log(priority, message); 
     213 
     214  Py_RETURN_NONE; 
     215} 
     216 
    202217/* send(string) */ 
    203 static PyObject *bbftpd_send(PyObject *self, PyObject *args) { 
     218static PyObject *pybbftpd_send(PyObject *self, PyObject *args) { 
    204219  char *buffer, logmessage[1024]; 
    205220  int len; 
     
    223238 
    224239/* recv(length) -> string */ 
    225 static PyObject *bbftpd_recv(PyObject *self, PyObject *args) { 
     240static PyObject *pybbftpd_recv(PyObject *self, PyObject *args) { 
    226241  char *buffer, logmessage[1024]; 
    227242  int len; 
     
    253268 * Main entry point for the python module. 
    254269 */ 
    255 static PyObject *bbftpd_run(PyObject *self, PyObject *args) { 
     270static PyObject *pybbftpd_run(PyObject *self, PyObject *args) { 
    256271  int argc, i; 
    257272  char **argv, **arg_p; 
     
    315330static PyMethodDef BbftpdMethods[] = { 
    316331  { 
    317     "run", bbftpd_run, METH_VARARGS,  
     332    "run", pybbftpd_run, METH_VARARGS,  
    318333    "Execute the bbftpd server.\n" 
    319334    "\n" 
     
    325340  }, 
    326341  { 
    327     "send", bbftpd_send, METH_VARARGS, 
     342    "send", pybbftpd_send, METH_VARARGS, 
    328343    "Send an authentication message to the client.\n" 
    329344    "\n" 
     
    334349  }, 
    335350  { 
    336     "recv", bbftpd_recv, METH_VARARGS, 
     351    "recv", pybbftpd_recv, METH_VARARGS, 
    337352    "Receive an authentication message from the client.\n" 
    338353    "\n" 
     
    342357    "@return: A string containing the message\n" 
    343358    "@raise IOError: if bbftpd_private_recv() call fails\n" 
     359  }, 
     360  { 
     361    "log", pybbftpd_log, METH_VARARGS, 
     362    "Send a message to the bbftpd logger.\n" 
     363    "\n" 
     364    "@param priority: as syslog priority\n" 
     365    "@param message: A string containing the message to send\n" 
    344366  }, 
    345367  {NULL, NULL, 0, NULL} 
  • TI05-delivery/trunk/test/test_embedded.py

    r1289 r1332  
    3737 
    3838        msg = self.recv() 
    39         syslog.syslog(syslog.LOG_DEBUG, 'AuthContext received Auth message: %s' % msg) 
     39        self.logMessage('AuthContext received Auth message: %s' % msg) 
    4040                 
    4141        self.send(NDG_HANDSHAKE) 
    4242 
    4343        privatestr = self.recv() 
    44         syslog.syslog(syslog.LOG_DEBUG, "AuthContext received privatestr: %s" % privatestr) 
     44        self.logMessage("AuthContext received privatestr: %s" % privatestr) 
    4545         
    4646        return self.makeAuthzHandler(msg, "TestCaseUser") 
     
    4848    def makeAuthzHandler(self, msg, user): 
    4949        return TestAuthzHandler(msg, "TestCaseUser") 
     50 
     51    def logMessage(self, msg): 
     52        server.bbftpd.log(syslog.LOG_DEBUG, msg) 
    5053 
    5154class TestAuthzHandler(server.LiberalAuthzHandler): 
     
    7174 
    7275    def authzControl(self, msgcode, transferopt, path): 
    73         syslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 
     76        server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 
    7477        return self.authzPath(path) 
    7578 
     
    8386        mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE]) 
    8487        if (mode & 0004): 
    85             syslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler OK') 
     88            server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler OK') 
    8689            return True 
    8790        else: 
    88             syslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler FAIL') 
     91            server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler FAIL') 
    8992            raise server.AuthorisationFailure, "TestPermAuthzHandler: no read perms" 
    9093 
     
    9699    def setUp(self): 
    97100        # We want to mark the beginning of this test case in syslog 
    98         syslog.openlog('test_embedded.py', 0, syslog.LOG_LOCAL0) 
    99         syslog.syslog(syslog.LOG_DEBUG, 'Starting TestCase') 
    100  
     101        #syslog.openlog('test_embedded.py', 0, syslog.LOG_LOCAL0) 
     102        #syslog.syslog(syslog.LOG_DEBUG, 'Starting TestCase') 
     103 
     104        self._clearLog() 
    101105        self._startServer() 
    102106 
    103107    def tearDown(self): 
    104108        self._stopServer() 
    105         syslog.syslog(syslog.LOG_DEBUG, 'Ended TestCase') 
    106         syslog.closelog() 
     109        #syslog.syslog(syslog.LOG_DEBUG, 'Ended TestCase') 
     110        #syslog.closelog() 
    107111 
    108112    #---------------------------------------------------------------------------------- 
     
    117121        os.kill(self.pid, signal.SIGTERM) 
    118122        os.waitpid(self.pid, 0) 
    119         syslog.syslog(syslog.LOG_DEBUG, 'Stopping server') 
     123        #syslog.syslog(syslog.LOG_DEBUG, 'Stopping server') 
    120124 
    121125 
     
    137141        fh = os.popen('sh -c "%s %s %s -u %s -r 1 -e \'%s\' localhost" 2>&1 ' % (BBFTP, f, p, user, cmd)) 
    138142        return fh 
     143 
     144    def _clearLog(self, logfile="./bbftpd.log"): 
     145        os.remove(logfile) 
     146 
     147    def _readLog(self, logfile="./bbftpd.log"): 
     148        return open(logfile).read() 
     149     
    139150 
    140151    def _readSyslog(self, logfile="/var/log/bbftpd/bbftpd.log"): 
     
    191202     
    192203    def testStartup(self): 
    193         lines = self._readSyslog() 
     204        lines = self._readLog() 
    194205        # Give syslog time to flush it's logs. 
    195206        time.sleep(1) 
     
    208219                        r' f .*/foo', r' f .*/bar', r' f .*/baz'], output) 
    209220 
    210         lines = self._readSyslog() 
     221        lines = self._readLog() 
    211222        self.assertLines(['.*Getting new bbftp connexion.*', 
    212223                          r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', 
     
    223234        self.assertLines(['Received Auth handshake: NDG-Delivery-server %s' % VERSION], output) 
    224235 
    225         lines = self._readSyslog() 
     236        lines = self._readLog() 
    226237 
    227238        self.assertLines(['.*AuthContext received Auth message: NDG-Delivery-client %s' % VERSION], lines) 
     
    234245        output = fh.read() 
    235246 
    236         lines = self._readSyslog() 
     247        lines = self._readLog() 
    237248        self.assertLines(['.*AuthContext received privatestr: testPrivateStr'], lines) 
    238249 
     
    254265 
    255266        # Check syslog 
    256         lines = self._readSyslog() 
     267        lines = self._readLog() 
    257268        self.assertLines(['.*Authz: RETR .*/foo', '.*GET TestCaseUser .*/foo.*'], lines) 
    258269 
     
    277288 
    278289        # Check syslog 
    279         lines = self._readSyslog() 
     290        lines = self._readLog() 
    280291        self.assertLines(['.*Authz: STORE .*/new_bar', '.*PUT TestCaseUser .*/new_bar.*'], lines) 
    281292 
     
    292303        output = fh.read() 
    293304 
    294         lines = self._readSyslog() 
     305        lines = self._readLog() 
    295306 
    296307        self.assertLines(['.*Error while private authentication.*'], output) 
     
    315326        output = fh.read() 
    316327 
    317         lines = self._readSyslog() 
     328        lines = self._readLog() 
    318329 
    319330 
     
    329340        output = fh.read() 
    330341 
    331         lines = self._readSyslog() 
    332  
    333         self.assertLines(['BBFTP-ERROR.* ndg_authz_control: AuthorisationFailure.* no read perms', 
     342        lines = self._readLog() 
     343 
     344        self.assertLines(['.* ndg_authz_control: AuthorisationFailure.* no read perms', 
    334345                          'stat /.*/bar FAILED'], output) 
    335346        self.assertLines(['.*Authz: MSG_STAT .*/bar', '.* TestPermAuthzHandler FAIL', 
     
    351362                          r'stat .*'], output) 
    352363 
    353         lines = self._readSyslog() 
     364        lines = self._readLog() 
    354365        self.assertLines(['.*Getting new bbftp connexion.*', 
    355366                          r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', 
Note: See TracChangeset for help on using the changeset viewer.