Beispiel #1
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)
Beispiel #2
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
Beispiel #3
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
Beispiel #4
0
    def setUp(self):
        from flumotion.twisted import pb
        from flumotion.common import server, connection
        from flumotion.manager import manager, config
        from StringIO import StringIO

        managerConf = """
        <planet>
        <manager name="planet">
            <host>localhost</host>
            <port>0</port>
            <transport>tcp</transport>
            <component name="manager-bouncer" type="htpasswdcrypt-bouncer">
              <property name="data"><![CDATA[
        user:PSfNpHTkpTx1M
        ]]></property>
            </component>
          </manager>
        </planet>
        """

        conf = config.ManagerConfigParser(StringIO(managerConf)).manager
        self.vishnu = manager.Vishnu(conf.name,
                                     unsafeTracebacks=True)
        self.vishnu.loadManagerConfigurationXML(StringIO(managerConf))
        s = server.Server(self.vishnu)
        if conf.transport == "ssl":
            p = s.startSSL(conf.host, conf.port, conf.certificate,
                           configure.configdir)
        elif conf.transport == "tcp":
            p = s.startTCP(conf.host, conf.port)
        self.tport = p
        self.port = p.getHost().port
        i = connection.PBConnectionInfo('localhost', self.port,
                                        conf.transport == 'ssl',
                                        pb.Authenticator(username='******',
                                                         password='******'))
        self.connectionInfo = i
Beispiel #5
0
 def getConnectionInfo(self):
     thost = self._tport.getHost()
     authenticator = fpb.Authenticator(username='******', password='******')
     return connection.PBConnectionInfo(thost.host, thost.port, True,
                                        authenticator)
Beispiel #6
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