def test_ourServerOurClient(self):
        """
        Run the Conch server against the Conch client.  Set up several different
        channels which exercise different behaviors and wait for them to
        complete.  Verify that the channels with errors log them.
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.assertFalse(self.server.done and self.client.done)

        return self.client.completed.addCallback(self._verifyExpectedErrors)
Example #2
0
    def testOurServerOurClient(self):
        """test the Conch server against the Conch client
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.failIf(self.server.done and self.client.done)
    def testOurServerOurClient(self):
        """test the Conch server against the Conch client
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.failIf(self.server.done and self.client.done)
Example #4
0
    def test_ourServerOurClient(self):
        """
        Run the Conch server against the Conch client.  Set up several different
        channels which exercise different behaviors and wait for them to
        complete.  Verify that the channels with errors log them.
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.assertFalse(self.server.done and self.client.done)

        return self.client.completed.addCallback(self._verifyExpectedErrors)
Example #5
0
 def startService(self):
     log.msg('...Booting...', system="Bouser")
     self.reload_config()
     log.callWithContext({"system": "Bootstrap"}, boot.send, self)
     log.callWithContext({"system": "Checking Dependencies"}, check_deps.send, self)
     if self.fail:
         raise RuntimeError('Not all dependencies satisfied')
     else:
         MultiService.startService(self)
Example #6
0
 def startService(self):
     log.msg('...Booting...', system="Bouser")
     yield self.reload_config()
     log.callWithContext({"system": "Bootstrap"}, boot.send, self)
     log.callWithContext({"system": "Checking Dependencies"},
                         check_deps.send, self)
     if self.fail:
         raise RuntimeError('Not all dependencies satisfied')
     else:
         MultiService.startService(self)
 def testContext(self):
     catcher = self.catcher
     log.callWithContext({"subsystem": "not the default",
                          "subsubsystem": "a",
                          "other": "c"},
                         log.callWithContext,
                         {"subsubsystem": "b"}, log.msg, "foo", other="d")
     i = catcher.pop()
     self.assertEquals(i['subsubsystem'], 'b')
     self.assertEquals(i['subsystem'], 'not the default')
     self.assertEquals(i['other'], 'd')
     self.assertEquals(i['message'][0], 'foo')
Example #8
0
 def testContext(self):
     catcher = self.catcher
     log.callWithContext({"subsystem": "not the default",
                          "subsubsystem": "a",
                          "other": "c"},
                         log.callWithContext,
                         {"subsubsystem": "b"}, log.msg, "foo", other="d")
     i = catcher.pop()
     self.assertEqual(i['subsubsystem'], 'b')
     self.assertEqual(i['subsystem'], 'not the default')
     self.assertEqual(i['other'], 'd')
     self.assertEqual(i['message'][0], 'foo')
Example #9
0
 def testContext(self):
     catcher = self.catcher
     log.callWithContext(
         {"subsystem": "not the default", "subsubsystem": "a", "other": "c"},
         log.callWithContext,
         {"subsubsystem": "b"},
         log.msg,
         "foo",
         other="d",
     )
     i = catcher.pop()
     self.assertEqual(i["subsubsystem"], "b")
     self.assertEqual(i["subsystem"], "not the default")
     self.assertEqual(i["other"], "d")
     self.assertEqual(i["message"][0], "foo")
Example #10
0
 def testContext(self):
     catcher = self.catcher
     log.callWithContext(
         {"subsystem": "not the default", "subsubsystem": "a", "other": "c"},
         log.callWithContext,
         {"subsubsystem": "b"},
         log.msg,
         "foo",
         other="d",
     )
     i = catcher.pop()
     self.assertEquals(i["subsubsystem"], "b")
     self.assertEquals(i["subsystem"], "not the default")
     self.assertEquals(i["other"], "d")
     self.assertEquals(i["message"][0], "foo")
Example #11
0
    def test_ourServerOurClient(self):
        """
        Run the Conch server against the Conch client.  Set up several different
        channels which exercise different behaviors and wait for them to
        complete.  Verify that the channels with errors log them.
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.assertFalse(self.server.done and self.client.done)

        errors = self.flushLoggedErrors(error.ConchError)
        errors.sort(key=lambda reason: reason.value.args)

        # Two errors exactly are expected.  Report the whole list if we get a
        # different number.
        self.assertEquals(len(errors), 2,
                          "Expected two errors, got: %r" % (errors, ))

        # SSHUnknownChannel causes this to be logged.
        self.assertEquals(errors[0].value.args, (3, 'unknown channel'))
        # SSHTestFailExecChannel causes this to be logged.
        self.assertEquals(errors[1].value.args, ('bad exec', None))
Example #12
0
    def test_ourServerOurClient(self):
        """
        Run the Conch server against the Conch client.  Set up several different
        channels which exercise different behaviors and wait for them to
        complete.  Verify that the channels with errors log them.
        """
        realm = ConchTestRealm()
        p = portal.Portal(realm)
        sshpc = ConchTestSSHChecker()
        sshpc.registerChecker(ConchTestPasswordChecker())
        sshpc.registerChecker(ConchTestPublicKeyChecker())
        p.registerChecker(sshpc)
        fac = ConchTestServerFactory()
        fac.portal = p
        fac.startFactory()
        self.server = fac.buildProtocol(None)
        self.clientTransport = LoopbackRelay(self.server)
        self.client = ConchTestClient()
        self.serverTransport = LoopbackRelay(self.client)

        self.server.makeConnection(self.serverTransport)
        self.client.makeConnection(self.clientTransport)

        while self.serverTransport.buffer or self.clientTransport.buffer:
            log.callWithContext({'system': 'serverTransport'},
                                self.serverTransport.clearBuffer)
            log.callWithContext({'system': 'clientTransport'},
                                self.clientTransport.clearBuffer)
        self.assertFalse(self.server.done and self.client.done)

        errors = self.flushLoggedErrors(error.ConchError)
        errors.sort(key=lambda reason: reason.value.args)

        # Two errors exactly are expected.  Report the whole list if we get a
        # different number.
        self.assertEquals(
            len(errors), 2, "Expected two errors, got: %r" % (errors,))

        # SSHUnknownChannel causes this to be logged.
        self.assertEquals(errors[0].value.args, (3, 'unknown channel'))
        # SSHTestFailExecChannel causes this to be logged.
        self.assertEquals(errors[1].value.args, ('bad exec', None))
Example #13
0
 def _canRun(true):
     log.msg(message)
     try:
         d = log.callWithContext({'system': 'pypickupbot %s %s'%(self.channel,self.cmd)}, self.bot.commands[self.cmd][0], self, self.args)
         if isinstance(d, defer.Deferred):
             d.addErrback(_catchInputError).addErrback(_catchInternalError)
     except InputError as e:
         self.reply(str(e))
     except Exception as e:
         self.reply(_("Internal error."))
         log.err()
Example #14
0
 def message_received(self, client, message):
     """
     Зднсь должен происходить некоторый роутинг
     :type client: bouser.simargl.client.SimarglClient
     :type message: bouser.simargl.message.Message
     :param client:
     :param message:
     :return:
     """
     if client is not None:
         name = client.name
         if client is not self.clients.get(name):
             log.msg('Name mismatch', system="Simargl")
             return
     if self.uuid.hex in message.hops:
         # log.msg('Short circuit detected', system="Simargl")
         return
     message.hops.append(self.uuid.hex)
     for recipient in self.clients.itervalues():
         log.callWithContext({'subsystem': 'Simargl:Client:%s' % recipient.fq_name}, recipient.send, message)
Example #15
0
 def write(self, data):
     twisted_log.callWithContext(dict(system=self._system), self._stream.write, data)
Example #16
0
 def __call__(self, event):
     if self.log_context_sentinel in event:
         return
     if self.worker_id not in (event.get('system') or '').split(','):
         return
     log.callWithContext(self.log_context, self._log_to_file, event)
Example #17
0
 def __call__(self, event):
     if self.log_context_sentinel in event:
         return
     if self.worker_id not in (event.get('system') or '').split(','):
         return
     log.callWithContext(self.log_context, self._log_to_file, event)
Example #18
0
 def log_err(self, error=None, why=None, source=None):
     log.callWithContext({"system": (self._get_log_system(source))},
                         log.err, error, why)
Example #19
0
 def log(self, msg, source=None):
     log.callWithContext({"system": self._get_log_system(source)}, log.msg,
                         msg)
Example #20
0
    def render(self, resrc):
        """
        Ask a resource to render itself.

        @param resrc: a L{twisted.web.resource.IResource}.
        """
        try:
            body = yield defer.maybeDeferred(resrc.render, self)
        except OptionsFinish:
            self.write(b'')
            self.finish()
            return
        except error.UnsupportedMethod as e:
            allowedMethods = e.allowedMethods
            if (self.method == b"HEAD") and (b"GET" in allowedMethods):
                # We must support HEAD (RFC 2616, 5.1.1).  If the
                # resource doesn't, fake it by giving the resource
                # a 'GET' request and then return only the headers,
                # not the body.
                log.msg("Using GET to fake a HEAD request for %s" %
                        (resrc,))
                self.method = b"GET"
                self._inFakeHead = True
                body = resrc.render(self)

                if body is NOT_DONE_YET:
                    log.msg("Tried to fake a HEAD request for %s, but "
                            "it got away from me." % resrc)
                    # Oh well, I guess we won't include the content length.
                else:
                    self.setHeader(b'content-length', intToBytes(len(body)))

                self._inFakeHead = False
                self.method = b"HEAD"
                self.write(b'')
                self.finish()
                return

            if self.method in (supportedMethods):
                # We MUST include an Allow header
                # (RFC 2616, 10.4.6 and 14.7)
                self.setHeader('Allow', ', '.join(allowedMethods))
                s = ('''Your browser approached me (at %(URI)s) with'''
                     ''' the method "%(method)s".  I only allow'''
                     ''' the method%(plural)s %(allowed)s here.''' % {
                         'URI': microdom.escape(self.uri),
                         'method': self.method,
                         'plural': ((len(allowedMethods) > 1) and 's') or '',
                         'allowed': ', '.join(allowedMethods)
                     })
                epage = resource.ErrorPage(http.NOT_ALLOWED,
                                           "Method Not Allowed", s)
                body = epage.render(self)
            else:
                epage = resource.ErrorPage(
                    http.NOT_IMPLEMENTED, "Huh?",
                    "I don't know how to treat a %s request." %
                    (microdom.escape(self.method.decode("charmap")),))
                body = epage.render(self)
        except Exception as e:
            import traceback
            tb = traceback.format_exc()
            callWithContext({'system': 'RequestError'}, traceback.print_exc)

            body = resource.ErrorPage(
                http.INTERNAL_SERVER_ERROR,
                "Request failed",
                error_page(self, resrc, e, tb)
            ).render(self)

        if body == NOT_DONE_YET:
            return
        if not isinstance(body, bytes):
            body = resource.ErrorPage(
                http.INTERNAL_SERVER_ERROR,
                "Request did not return bytes",
                error_page(self, resrc, body)
            ).render(self)

        if self.method == b"HEAD":
            if len(body) > 0:
                # This is a Bad Thing (RFC 2616, 9.4)
                log.msg("Warning: HEAD request %s for resource %s is"
                        " returning a message body."
                        "  I think I'll eat it."
                        % (self, resrc))
                self.setHeader(b'content-length',
                               intToBytes(len(body)))
            self.write(b'')
        else:
            self.setHeader(b'content-length',
                           intToBytes(len(body)))
            self.write(body)
        self.finish()
Example #21
0
 def __call__(self, event):
     if self.log_context_sentinel in event:
         return
     log.callWithContext(self.log_context, self._log_to_sentry, event)
Example #22
0
 def privmsg_(self, user, channel, message):
     """when we receive a message"""
     log.callWithContext(
         {'system': user},
         LineProcessor, self, user, channel, message)