Exemplo n.º 1
0
    def __init__(self, buildmaster_host, port, name, passwd, basedir,
                 keepalive, usePTY, keepaliveTimeout=None, umask=None,
                 maxdelay=300, numcpus=None, unicode_encoding=None,
                 allow_shutdown=None):

        # note: keepaliveTimeout is ignored, but preserved here for
        # backward-compatibility

        service.MultiService.__init__(self)
        WorkerBase.__init__(self, name, basedir, usePTY, umask=umask, unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        self.numcpus = numcpus
        self.shutdown_loop = None

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay)
        bf.startLogin(credentials.UsernamePassword(name, passwd), client=self.bot)
        self.connection = c = internet.TCPClient(buildmaster_host, port, bf)
        c.setServiceParent(self)
Exemplo n.º 2
0
    def __init__(self,
                 buildmaster_host,
                 port,
                 name,
                 passwd,
                 basedir,
                 keepalive,
                 usePTY=None,
                 keepaliveTimeout=None,
                 umask=None,
                 maxdelay=300,
                 numcpus=None,
                 unicode_encoding=None,
                 allow_shutdown=None,
                 maxRetries=None):

        # note: keepaliveTimeout is ignored, but preserved here for
        # backward-compatibility

        assert usePTY is None, "worker-side usePTY is not supported anymore"

        service.MultiService.__init__(self)
        WorkerBase.__init__(self,
                            name,
                            basedir,
                            umask=umask,
                            unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        name = unicode2bytes(name, self.bot.unicode_encoding)
        passwd = unicode2bytes(passwd, self.bot.unicode_encoding)

        self.numcpus = numcpus
        self.shutdown_loop = None
        self.maxRetries = maxRetries

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host,
                                  port,
                                  keepalive,
                                  maxdelay.bit_length,
                                  maxRetries=self.maxRetries,
                                  maxRetriesCallback=self.gracefulShutdown)
        bf.startLogin(credentials.UsernamePassword(name, passwd),
                      client=self.bot)
        self.connection = c = internet.TCPClient(
            buildmaster_host, port,
            HangCheckFactory(bf, hung_callback=self._hung_connection))
        c.setServiceParent(self)
Exemplo n.º 3
0
    def startService(self):
        WorkerBase.startService(self)

        if self.allow_shutdown == 'signal':
            log.msg("Setting up SIGHUP handler to initiate shutdown")
            signal.signal(signal.SIGHUP, self._handleSIGHUP)
        elif self.allow_shutdown == 'file':
            log.msg("Watching %s's mtime to initiate shutdown" % self.shutdown_file)
            if os.path.exists(self.shutdown_file):
                self.shutdown_mtime = os.path.getmtime(self.shutdown_file)
            self.shutdown_loop = l = task.LoopingCall(self._checkShutdownFile)
            l.start(interval=10)
Exemplo n.º 4
0
    def startService(self):
        WorkerBase.startService(self)

        if self.allow_shutdown == 'signal':
            log.msg("Setting up SIGHUP handler to initiate shutdown")
            signal.signal(signal.SIGHUP, self._handleSIGHUP)
        elif self.allow_shutdown == 'file':
            log.msg("Watching %s's mtime to initiate shutdown" %
                    self.shutdown_file)
            if os.path.exists(self.shutdown_file):
                self.shutdown_mtime = os.path.getmtime(self.shutdown_file)
            self.shutdown_loop = l = task.LoopingCall(self._checkShutdownFile)
            l.start(interval=10)
Exemplo n.º 5
0
    def __init__(self, buildmaster_host, port, name, passwd, basedir,
                 keepalive, usePTY=None, keepaliveTimeout=None, umask=None,
                 maxdelay=None, numcpus=None, unicode_encoding=None,
                 allow_shutdown=None, maxRetries=None, connection_string=None):

        assert usePTY is None, "worker-side usePTY is not supported anymore"
        assert (connection_string is None or
                (buildmaster_host, port) == (None, None)), (
                    "If you want to supply a connection string, "
                    "then set host and port to None")

        service.MultiService.__init__(self)
        WorkerBase.__init__(
            self, name, basedir, umask=umask, unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        name = unicode2bytes(name, self.bot.unicode_encoding)
        passwd = unicode2bytes(passwd, self.bot.unicode_encoding)

        self.numcpus = numcpus
        self.shutdown_loop = None

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay)
        bf.startLogin(
            credentials.UsernamePassword(name, passwd), client=self.bot)
        if connection_string is None:
            connection_string = 'tcp:host={}:port={}'.format(
                buildmaster_host.replace(':', r'\:'),  # escape ipv6 addresses
                port)
        endpoint = clientFromString(reactor, connection_string)

        def policy(attempt):
            if maxRetries and attempt >= maxRetries:
                reactor.stop()
            return backoffPolicy()(attempt)
        pb_service = ClientService(endpoint, bf,
                                   retryPolicy=policy)
        self.addService(pb_service)
Exemplo n.º 6
0
Arquivo: pb.py Projeto: rajul/buildbot
    def __init__(self,
                 buildmaster_host,
                 port,
                 name,
                 passwd,
                 basedir,
                 keepalive,
                 usePTY,
                 keepaliveTimeout=None,
                 umask=None,
                 maxdelay=300,
                 numcpus=None,
                 unicode_encoding=None,
                 allow_shutdown=None):

        # note: keepaliveTimeout is ignored, but preserved here for
        # backward-compatibility

        service.MultiService.__init__(self)
        WorkerBase.__init__(self,
                            name,
                            basedir,
                            usePTY,
                            umask=umask,
                            unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        self.numcpus = numcpus
        self.shutdown_loop = None

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay)
        bf.startLogin(credentials.UsernamePassword(name, passwd),
                      client=self.bot)
        self.connection = c = internet.TCPClient(buildmaster_host, port, bf)
        c.setServiceParent(self)
Exemplo n.º 7
0
    def startService(self):
        # importing here to avoid dependency on buildbot master package
        from buildbot.worker.protocols.null import Connection

        yield WorkerBase.startService(self)
        self.workername = self.name
        conn = Connection(self)
        # I don't have a master property, but my parent has.
        master = self.parent.master
        res = yield master.workers.newConnection(conn, self.name)
        if res:
            yield self.parent.attached(conn)
Exemplo n.º 8
0
    def startService(self):
        # importing here to avoid dependency on buildbot master package
        # requires buildot version >= 0.9.0b5
        from buildbot.worker.protocols.null import Connection

        yield WorkerBase.startService(self)
        self.workername = self.name
        conn = Connection(self.parent, self)
        # I don't have a master property, but my parent has.
        master = self.parent.master
        res = yield master.workers.newConnection(conn, self.name)
        if res:
            yield self.parent.attached(conn)
Exemplo n.º 9
0
    def __init__(self, buildmaster_host, port, name, passwd, basedir,
                 keepalive, usePTY=None, keepaliveTimeout=None, umask=None,
                 maxdelay=300, numcpus=None, unicode_encoding=None,
                 allow_shutdown=None, maxRetries=None):

        # note: keepaliveTimeout is ignored, but preserved here for
        # backward-compatibility

        assert usePTY is None, "worker-side usePTY is not supported anymore"

        service.MultiService.__init__(self)
        WorkerBase.__init__(
            self, name, basedir, umask=umask, unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        name = unicode2bytes(name, self.bot.unicode_encoding)
        passwd = unicode2bytes(passwd, self.bot.unicode_encoding)

        self.numcpus = numcpus
        self.shutdown_loop = None
        self.maxRetries = maxRetries

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay,
            maxRetries=self.maxRetries, maxRetriesCallback=self.gracefulShutdown)
        bf.startLogin(
            credentials.UsernamePassword(name, passwd), client=self.bot)
        self.connection = c = internet.TCPClient(
            buildmaster_host, port,
            HangCheckFactory(bf, hung_callback=self._hung_connection))
        c.setServiceParent(self)
Exemplo n.º 10
0
    def startService(self):
        # importing here to avoid dependency on buildbot master package
        # requires buildot version >= 0.9.0b5
        from buildbot.worker.protocols.null import Connection

        yield WorkerBase.startService(self)
        # TODO: This is a workaround for using worker with "slave"-api with
        # updated master.  Later buildbot-slave package will be replaced with
        # buildbot-worker package which will be "slave"-free, and this patch
        # will not be needed.
        self._workername = self.name
        conn = Connection(self.parent, self)
        # I don't have a master property, but my parent has.
        master = self.parent.master
        # TODO: This is a workaround for using worker with "slave"-api with
        # updated master.  Later buildbot-slave package will be replaced with
        # buildbot-worker package which will be "slave"-free, and this patch
        # will not be needed.
        res = yield master.workers.newConnection(conn, self.name)
        if res:
            yield self.parent.attached(conn)
Exemplo n.º 11
0
    def startService(self):
        # importing here to avoid dependency on buildbot master package
        # requires buildot version >= 0.9.0b5
        from buildbot.worker.protocols.null import Connection

        yield WorkerBase.startService(self)
        # TODO: This is a workaround for using worker with "slave"-api with
        # updated master.  Later buildbot-slave package will be replaced with
        # buildbot-worker package which will be "slave"-free, and this patch
        # will not be needed.
        self._workername = self.name
        conn = Connection(self.parent, self)
        # I don't have a master property, but my parent has.
        master = self.parent.master
        # TODO: This is a workaround for using worker with "slave"-api with
        # updated master.  Later buildbot-slave package will be replaced with
        # buildbot-worker package which will be "slave"-free, and this patch
        # will not be needed.
        res = yield master.workers.newConnection(conn, self.name)
        if res:
            yield self.parent.attached(conn)
Exemplo n.º 12
0
 def stopService(self):
     yield self.parent.detached()
     yield WorkerBase.stopService(self)
Exemplo n.º 13
0
    def __init__(self,
                 buildmaster_host,
                 port,
                 name,
                 passwd,
                 basedir,
                 keepalive,
                 usePTY=None,
                 keepaliveTimeout=None,
                 umask=None,
                 maxdelay=None,
                 numcpus=None,
                 unicode_encoding=None,
                 useTls=None,
                 allow_shutdown=None,
                 maxRetries=None,
                 connection_string=None):

        assert usePTY is None, "worker-side usePTY is not supported anymore"
        assert (connection_string is None
                or (buildmaster_host, port) == (None, None)), (
                    "If you want to supply a connection string, "
                    "then set host and port to None")

        service.MultiService.__init__(self)
        WorkerBase.__init__(self,
                            name,
                            basedir,
                            umask=umask,
                            unicode_encoding=unicode_encoding)
        if keepalive == 0:
            keepalive = None

        name = unicode2bytes(name, self.bot.unicode_encoding)
        passwd = unicode2bytes(passwd, self.bot.unicode_encoding)

        self.numcpus = numcpus
        self.shutdown_loop = None

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown
        bf = self.bf = BotFactory(buildmaster_host, port, keepalive, maxdelay)
        bf.startLogin(credentials.UsernamePassword(name, passwd),
                      client=self.bot)
        if connection_string is None:
            if useTls:
                connection_type = 'tls'
            else:
                connection_type = 'tcp'

            connection_string = '{}:host={}:port={}'.format(
                connection_type,
                buildmaster_host.replace(':', r'\:'),  # escape ipv6 addresses
                port)
        endpoint = clientFromString(reactor, connection_string)

        def policy(attempt):
            if maxRetries and attempt >= maxRetries:
                reactor.stop()
            return backoffPolicy()(attempt)

        pb_service = ClientService(endpoint, bf, retryPolicy=policy)
        self.addService(pb_service)
Exemplo n.º 14
0
 def stopService(self):
     if self.shutdown_loop:
         self.shutdown_loop.stop()
         self.shutdown_loop = None
     yield WorkerBase.stopService(self)
     yield self.bf.waitForCompleteShutdown()
Exemplo n.º 15
0
    def __init__(self,
                 buildmaster_host,
                 port,
                 name,
                 passwd,
                 basedir,
                 keepalive,
                 usePTY=None,
                 keepaliveTimeout=None,
                 umask=None,
                 maxdelay=None,
                 numcpus=None,
                 unicode_encoding=None,
                 protocol='pb',
                 useTls=None,
                 allow_shutdown=None,
                 maxRetries=None,
                 connection_string=None,
                 delete_leftover_dirs=False,
                 proxy_connection_string=None):

        assert usePTY is None, "worker-side usePTY is not supported anymore"
        assert (connection_string is None
                or (buildmaster_host, port) == (None, None)), (
                    "If you want to supply a connection string, "
                    "then set host and port to None")

        if protocol == 'pb':
            bot_class = BotPb
        elif protocol == 'msgpack_experimental_v1':
            if sys.version_info.major < 3:
                raise NotImplementedError(
                    'Msgpack protocol is not supported in Python2')
            bot_class = BotMsgpack
        else:
            raise ValueError('Unknown protocol {}'.format(protocol))

        WorkerBase.__init__(self,
                            name,
                            basedir,
                            bot_class,
                            umask=umask,
                            unicode_encoding=unicode_encoding,
                            delete_leftover_dirs=delete_leftover_dirs)
        if keepalive == 0:
            keepalive = None

        name = unicode2bytes(name, self.bot.unicode_encoding)

        self.numcpus = numcpus
        self.shutdown_loop = None

        if allow_shutdown == 'signal':
            if not hasattr(signal, 'SIGHUP'):
                raise ValueError("Can't install signal handler")
        elif allow_shutdown == 'file':
            self.shutdown_file = os.path.join(basedir, 'shutdown.stamp')
            self.shutdown_mtime = 0

        self.allow_shutdown = allow_shutdown

        if protocol == 'pb':
            passwd = unicode2bytes(passwd, self.bot.unicode_encoding)

            bf = self.bf = BotFactory(buildmaster_host, port, keepalive,
                                      maxdelay)
            bf.startLogin(credentials.UsernamePassword(name, passwd),
                          client=self.bot)
        elif protocol == 'msgpack_experimental_v1':
            if connection_string is None:
                ws_conn_string = "ws://{}:{}".format(buildmaster_host, port)
            else:
                from urllib.parse import urlparse

                parsed_url = urlparse(connection_string)
                ws_conn_string = "ws://{}:{}".format(parsed_url.hostname,
                                                     parsed_url.port)

            bf = self.bf = BuildbotWebSocketClientFactory(ws_conn_string)
            bf.protocol = BuildbotWebSocketClientProtocol
            self.bf.buildbot_bot = self.bot
            self.bf.name = name
            self.bf.password = passwd
        else:
            raise ValueError('Unknown protocol {}'.format(protocol))

        def get_connection_string(host, port):
            if useTls:
                connection_type = 'tls'
            else:
                connection_type = 'tcp'

            return '{}:host={}:port={}'.format(
                connection_type,
                host.replace(':', r'\:'),  # escape ipv6 addresses
                port)

        assert not (proxy_connection_string and connection_string), (
            "If you want to use HTTP tunneling, then supply build master "
            "host and port rather than a connection string")

        if proxy_connection_string:
            log.msg("Using HTTP tunnel to connect through proxy")
            proxy_endpoint = clientFromString(reactor, proxy_connection_string)
            endpoint = HTTPTunnelEndpoint(buildmaster_host, port,
                                          proxy_endpoint)
            if useTls:
                from twisted.internet.endpoints import wrapClientTLS
                from twisted.internet.ssl import optionsForClientTLS

                contextFactory = optionsForClientTLS(hostname=buildmaster_host)
                endpoint = wrapClientTLS(contextFactory, endpoint)
        else:
            if connection_string is None:
                connection_string = get_connection_string(
                    buildmaster_host, port)
            endpoint = clientFromString(reactor, connection_string)

        def policy(attempt):
            if maxRetries and attempt >= maxRetries:
                reactor.stop()
            return backoffPolicy()(attempt)

        pb_service = ClientService(endpoint, bf, retryPolicy=policy)
        self.addService(pb_service)
Exemplo n.º 16
0
 def stopService(self):
     yield self.parent.detached()
     yield WorkerBase.stopService(self)