def login():
     port = self.feedServer.getPortNum()
     self.assertAdditionalFDsOpen(1, 'connect (socket)')
     reactor.connectTCP('localhost', port, factory)
     self.assertAdditionalFDsOpen(2, 'connect (socket, client)')
     return factory.login(fpb.Authenticator(username='******',
                                            password='******'))
示例#2
0
    def testWrongUser(self):
        factory = pb.FPBClientFactory()

        # create
        a = pb.Authenticator(username="******",
                             password="******",
                             address="127.0.0.1")

        # send
        d = factory.login(a)
        c = reactor.connectTCP("127.0.0.1", self.portno, factory)

        def WrongUserCb(keycard):
            self.fail("Should have returned NotAuthenticatedError")

        def WrongUserEb(failure):
            # find copied failure
            self.failUnless(
                failure.check("flumotion.common.errors.NotAuthenticatedError"))
            return self.clientDisconnect(factory, None)

        d.addCallback(WrongUserCb)
        d.addErrback(WrongUserEb)

        return d
 def login():
     port = self.feedServer.getPortNum()
     self.assertAdditionalFDsOpen(1, 'connect (socket)')
     d = client.startConnecting('localhost', port,
                                fpb.Authenticator(username='******',
                                                  password='******'))
     self.assertAdditionalFDsOpen(2, 'connect (socket, client)')
     return d
示例#4
0
 def testIssueUACPP(self):
     # our authenticator by default only does challenge-based keycards
     a = pb.Authenticator(username="******",
                          password="******",
                          address="localhost")
     d = a.issue([
         "flumotion.common.keycards.KeycardGeneric",
     ])
     d.addCallback(lambda r: self.failIf(r))
示例#5
0
 def testIssueNoInfo(self):
     # not setting any useful auth info on the authenticator does not
     # allow us to issue a keycard
     a = pb.Authenticator(username="******")
     d = a.issue([
         "flumotion.common.keycards.KeycardGeneric",
     ])
     d.addCallback(lambda r: self.failIf(r))
     return d
示例#6
0
 def testIssueUACPCC(self):
     a = pb.Authenticator(username="******",
                          password="******",
                          address="localhost")
     d = a.issue([
         "flumotion.common.keycards.KeycardUACPCC",
     ])
     d.addCallback(
         lambda r: self.failUnless(isinstance(r, keycards.KeycardUACPCC)))
     return d
 def requestFeed():
     port = self.feedServer.getPortNum()
     self.assertAdditionalFDsOpen(1, 'connect (socket)')
     d = client.requestFeed('localhost', port,
                            fpb.Authenticator(username='******',
                                              password='******'),
                            '/foo/bar:baz')
     self.failIf(client.hasRemoteReference())
     self.assertAdditionalFDsOpen(2, 'connect (socket, client)')
     return d
示例#8
0
    def __init__(self):
        log.init()

        self.medium = admin.AdminModel()

        i = connection.PBConnectionInfo(
            "127.0.0.1", 7531, True,
            pb.Authenticator(username='******', password='******'))
        d = self.medium.connectToManager(i)
        d.addCallback(self.connected)
        d.addErrback(twistedlog.err)
示例#9
0
    def testWrongPassword(self):
        factory = pb.FPBClientFactory()
        a = pb.Authenticator()
        a = pb.Authenticator(username="******",
                             password="******",
                             address="127.0.0.1")
        d = factory.login(a)

        c = reactor.connectTCP("127.0.0.1", self.portno, factory)

        log.debug("trial", "wait for result")

        def WrongPasswordErrback(failure):
            self.failUnless(isinstance(factory.keycard,
                                       keycards.KeycardUACPCC))
            # This is a CopiedFailure
            self.assert_(
                failure.check("flumotion.common.errors.NotAuthenticatedError"))
            log.debug("trial", "got failure %r" % failure)
            c.disconnect()
            return True

        d.addErrback(WrongPasswordErrback)
        return d
示例#10
0
    def testConnectFailure(self):
        def connected(_):
            self.fail('should not have connected')

        def failure(f):
            # ok!
            a.shutdown()

        a = admin.AdminModel()
        # create a connectionInfo that will not succeed
        i = connection.PBConnectionInfo(
            self.connectionInfo.host, self.connectionInfo.port,
            self.connectionInfo.use_ssl,
            pb.Authenticator(username='******', password='******'))
        d = a.connectToManager(i, writeConnection=False)
        d.addCallbacks(connected, failure)
        return d
示例#11
0
    def testOk(self):
        factory = pb.FPBClientFactory()
        a = pb.Authenticator(username="******",
                             password="******",
                             address="127.0.0.1")
        # send
        d = factory.login(a)
        c = reactor.connectTCP("127.0.0.1", self.portno, factory)

        def OkCallback(result):
            # make sure we really used an SHA256 challenge/response keycard
            self.failUnless(isinstance(factory.keycard,
                                       keycards.KeycardUASPCC))
            self.assert_(isinstance(result, tpb.RemoteReference))
            return self.clientDisconnect(factory, result)

        d.addCallback(OkCallback)
        return d
示例#12
0
    def testConnectFailure(self):
        def connected(_):
            self.fail('should not have connected')

        def failure(f):
            # ok!
            self.assertEqual(len(self.vishnu.adminHeaven.avatars), 0)
            self.assertEqual(m.admins, {})
            self.assertEqual(m._reconnectHandlerIds, {})

        m = multi.MultiAdminModel()
        i = connection.PBConnectionInfo(
            self.connectionInfo.host, self.connectionInfo.port,
            self.connectionInfo.use_ssl,
            pb.Authenticator(username='******', password='******'))
        d = m.addManager(i, writeConnection=False)
        d.addCallbacks(connected, failure)
        return d
示例#13
0
def parsePBConnectionInfo(string,
                          username='******',
                          password='******',
                          port=7531,
                          use_ssl=True):
    """
    Parse a string representation of a PB connection into a
    PBConnectionInfo object.

    The expected format is [user[:pass]@]host[:port]. Only the host is
    mandatory. The default values for username, password, and port will
    be taken from the optional username, password and port arguments.

    @param string:   A string describing the PB connection.
    @type  string:   str
    @param username: Default username, or 'user' if not given.
    @type  username: str
    @param password: Default password, or 'test' if not given.
    @type  password: str
    @param port:     Default port, or 7531 if not given.
    @type  port:     int
    @param use_ssl:  Whether to use SSL, or True if not given. Note that
                     there is no syntax in the connection string for specifying
                     whether or not to use SSL; if you want to control this you
                     will have to provide another method.
    @type  use_ssl:  bool

    @rtype: L{PBConnectionInfo}
    """
    auth = fpb.Authenticator(username=username, password=password)
    ret = PBConnectionInfo(None, port, use_ssl, auth)

    matched = _pat.search(string)
    if not matched:
        raise TypeError('Invalid connection string: %s '
                        '(looking for [user[:pass]@]host[/ssl|/tcp][:port])' %
                        string)

    groups = matched.groups()
    for o, k, i, f in ((auth, 'username', 1, str), (auth, 'password', 3, str),
                       (ret, 'host', 4, str), (ret, 'port', 6, int)):
        if groups[i]:
            setattr(o, k, f(groups[i]))
    return ret
示例#14
0
def _runInterface(options):
    # initialise curses

    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.nodelay(1)
    stdscr.keypad(1)

    reactor.addSystemEventTrigger('after',
                                  'shutdown', cleanup_curses, stdscr)


    # first lets sort out logging in
    username = '******'
    password = '******'
    hostname = 'localhost'
    insecure = False
    port = 7531
    if options.username and options.password and options.hostname:
        username = options.username
        password = options.password
        hostname = options.hostname
        if options.port:
            try:
                port = int(options.port)
            except ValueError:
                pass
        if options.insecure:
            insecure = True
        authenticator = fpb.Authenticator(username=username, password=password)
        info = PBConnectionInfo(hostname, port, not insecure, authenticator)
        connection.connect_to_manager(stdscr, info)

    else:
        # do greeter
        # get recent connections
        greeter = AdminTextGreeter(stdscr)
        reactor.addReader(greeter)
        greeter.show()
示例#15
0
    def connectToManager(self, connection):
        """
        Connect to a manager.

        @type  connection: L{flumotion.common.connection.PBConnectionInfo}

        @rtype: L{defer.Deferred} firing L{flumotion.admin.admin.AdminModel}
        """
        from flumotion.twisted import pb as fpb
        if not connection.authenticator:
            connection.authenticator = fpb.Authenticator(
                username=connection.username,
                password=connection.password,
                address=connection.host)
        # platform-3/trunk compatibility stuff to guard against
        # gratuitous changes
        try:
            # platform-3
            adminMedium = admin.AdminModel(connection.authenticator)
            self.debug("code is platform-3")
        except TypeError:
            # trunk
            adminMedium = admin.AdminModel()
            self.debug("code is trunk")

        if hasattr(adminMedium, 'connectToHost'):
            # platform-3
            d = adminMedium.connectToHost(connection.host, connection.port,
                                          not connection.use_ssl)
        else:
            d = adminMedium.connectToManager(connection)

        d.addCallback(self._connectToManagerCb, adminMedium)
        d.addErrback(self._connectToManagerEb)

        return d
示例#16
0
    def doRead(self):
        c = self.stdscr.getch()
        if self.state == 0:
            if c == curses.KEY_DOWN:
                if self.current_connection >= self.displayed_connections:
                    self.current_connection = 0
                else:
                    self.current_connection = self.current_connection + 1
                self.show()
            elif c == curses.KEY_UP:
                if self.current_connection == 0:
                    self.current_connection = self.displayed_connections
                else:
                    self.current_connection = self.current_connection - 1
                self.show()
            elif c == curses.KEY_ENTER or c == 10:
                # if new connection, ask for username, password, hostname etc.
                if self.current_connection == self.displayed_connections:
                    curses.curs_set(1)
                    self.current_input = self.inputs[1]
                    self.state = 1
                    self.display_current_input_line()
                else:
                    # ok a recent connection has been selected
                    curses.curs_set(1)
                    c = self.connections[self.current_connection]
                    info = c.info
                    reactor.removeReader(self)
                    connection.connect_to_manager(self.stdscr, info)
        else:
            if c == curses.KEY_ENTER or c == 10:
                if self.state < 6:
                    self.inputs[self.state] = self.current_input
                if self.state < 5:
                    self.current_input = self.inputs[self.state + 1]
                    self.state = self.state + 1
                    self.display_current_input_line()
                else:
                    # connect
                    reactor.removeReader(self)
                    try:
                        port = int(self.inputs[2])
                    except ValueError:
                        port = 7531
                    info = PBConnectionInfo(
                        self.inputs[1], port, self.inputs[3] == 'Yes',
                        fpb.Authenticator(username=self.inputs[4],
                                          password=self.inputs[5]))

                    connection.connect_to_manager(self.stdscr, info)
                    pass
            elif c == curses.KEY_BACKSPACE or c == 127:
                self.current_input = self.current_input[:-1]
                self.display_current_input_line()
            elif c == curses.KEY_UP:
                if self.state > 0:
                    self.current_input = self.inputs[self.state - 1]
                    self.state = self.state - 1
                if self.state == 0:
                    # turn off cursor
                    curses.curs_set(0)
                self.display_current_input_line()
            elif c == curses.KEY_DOWN:
                pass
            else:
                self.current_input = self.current_input + chr(c)
                self.display_current_input_line()
示例#17
0
 def getConnectionInfo(self):
     thost = self._tport.getHost()
     authenticator = fpb.Authenticator(username='******', password='******')
     return connection.PBConnectionInfo(thost.host, thost.port, True,
                                        authenticator)
示例#18
0
def main(args):
    parser = _createParser()
    log.debug('worker', 'Parsing arguments (%r)' % ', '.join(args))
    options, args = parser.parse_args(args)

    # Force options down configure's throat
    for d in ['logdir', 'rundir']:
        o = getattr(options, d, None)
        if o:
            log.debug('worker', 'Setting configure.%s to %s' % (d, o))
            setattr(configure, d, o)

    # translate feederports string to range
    if options.feederports:
        if not '-' in options.feederports:
            raise errors.OptionError("feederports '%s' does not contain '-'" %
                options.feederports)
        (lower, upper) = options.feederports.split('-')
        options.feederports = range(int(lower), int(upper) + 1)

    # check if a config file was specified; if so, parse config and copy over
    if len(args) > 1:
        workerFile = args[1]
        _readConfig(workerFile, options)

    # set default values for all unset options
    if not options.host:
        options.host = 'localhost'
    if not options.transport:
        options.transport = 'ssl'
    if not options.port:
        if options.transport == "tcp":
            options.port = configure.defaultTCPManagerPort
        elif options.transport == "ssl":
            options.port = configure.defaultSSLManagerPort

    # set a default name if none is given
    if not options.name:
        if options.host == 'localhost':
            options.name = 'localhost'
            log.debug('worker', 'Setting worker name localhost')
        else:
            import socket
            options.name = socket.gethostname()
            log.debug('worker', 'Setting worker name %s (from hostname)' %
                options.name)

    if options.feederports is None and not options.randomFeederports:
        options.feederports = configure.defaultGstPortRange
        log.debug('worker', 'Using default feederports %r' %
            options.feederports)

    # check for wrong options/arguments
    if not options.transport in ['ssl', 'tcp']:
        sys.stderr.write('ERROR: wrong transport %s, must be ssl or tcp\n' %
            options.transport)
        return 1

    # reset FLU_DEBUG which could be different after parsing XML file
    if options.debug:
        log.setFluDebug(options.debug)

    if options.daemonizeTo and not options.daemonize:
        sys.stderr.write(
            'ERROR: --daemonize-to can only be used with -D/--daemonize.\n')
        return 1

    if options.serviceName and not options.daemonize:
        sys.stderr.write(
            'ERROR: --service-name can only be used with -D/--daemonize.\n')
        return 1

    brain = worker.WorkerBrain(options)

    # Now bind and listen to our unix and tcp sockets
    if not brain.listen():
        sys.stderr.write('ERROR: Failed to listen on worker ports.\n')
        return 1

    name = options.name
    if options.daemonize:
        if options.serviceName:
            name = options.serviceName
        if not options.daemonizeTo:
            options.daemonizeTo = "/"

    startup("worker", name, options.daemonize, options.daemonizeTo)

    log.debug('worker', 'Running Flumotion version %s' %
        configure.version)
    import twisted.copyright
    log.debug('worker', 'Running against Twisted version %s' %
        twisted.copyright.version)

    # register all package paths (FIXME: this should go away when
    # components come from manager)
    from flumotion.common import setup
    setup.setupPackagePath()

    # FIXME: why address='localhost' ?
    authenticator = pb.Authenticator(username=options.username,
                                     password=options.password,
                                     address='localhost',
                                     avatarId=options.name)
    info = connection.PBConnectionInfo(options.host, options.port,
                                       options.transport == "ssl",
                                       authenticator)
    brain.login(info)

    log.info('worker',
             'Connecting to manager %s using %s' % (info,
                                                    options.transport.upper()))


    # go into the reactor main loop
    reactor.run()

    return 0