Esempio n. 1
0
 def test_versions(self):
     master = self.make_master(url='h:/a/b/')
     rsrc = rest.RestRootResource(master)
     self.assertEqual(
         sorted(rsrc.listNames()),
         sorted(['latest'] +
                ['v%d' % v for v in range(2, self.maxVersion + 1)]))
Esempio n. 2
0
 def test_versions_limited(self):
     master = self.make_master(url='h:/a/b/')
     master.config.www['rest_minimum_version'] = 2
     rsrc = rest.RestRootResource(master)
     self.assertEqual(sorted(rsrc.listNames()),
                      sorted(['latest'] +
                             ['v%d' % v for v in range(2, self.maxVersion + 1)]))
Esempio n. 3
0
    def test_render(self):
        master = self.make_master(url='h:/a/b/')
        rsrc = rest.RestRootResource(master)

        rv = yield self.render_resource(rsrc, b'/')

        self.assertIn(b'api_versions', rv)
Esempio n. 4
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []

        # we're going to need at least the base plugin (buildbot-www)
        if 'base' not in self.apps:
            raise RuntimeError("could not find buildbot-www; is it installed?")

        root = self.apps.get('base').resource
        self.configPlugins(root, new_config)
        # /
        root.putChild(b'', wwwconfig.IndexResource(
            self.master, self.apps.get('base').static_dir))

        # /auth
        root.putChild(b'auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild(b'avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild(b'api', rest.RestRootResource(self.master))

        # /ws
        root.putChild(b'ws', ws.WsResource(self.master))

        # /sse
        root.putChild(b'sse', sse.EventResource(self.master))

        # /change_hook
        resource_obj = change_hook.ChangeHookResource(master=self.master)

        # FIXME: this does not work with reconfig
        change_hook_auth = new_config.www.get('change_hook_auth')
        if change_hook_auth is not None:
            resource_obj = self.setupProtectedResource(
                resource_obj, change_hook_auth)
        root.putChild(b"change_hook", resource_obj)

        self.root = root

        rotateLength = new_config.www.get(
            'logRotateLength') or self.master.log_rotation.rotateLength
        maxRotatedFiles = new_config.www.get(
            'maxRotatedFiles') or self.master.log_rotation.maxRotatedFiles

        httplog = None
        if new_config.www['logfileName']:
            httplog = os.path.abspath(
                os.path.join(self.master.basedir, new_config.www['logfileName']))
        self.site = BuildbotSite(root, logPath=httplog, rotateLength=rotateLength,
                                 maxRotatedFiles=maxRotatedFiles)

        self.site.sessionFactory = None

        # Make sure site.master is set. It is required for poller change_hook
        self.site.master = self.master
        # convert this to a tuple so it can't be appended anymore (in
        # case some dynamically created resources try to get reconfigs)
        self.reconfigurableResources = tuple(self.reconfigurableResources)
Esempio n. 5
0
 def test_versions_limited(self):
     master = self.make_master(url='h:/a/b/')
     master.config.www['rest_minimum_version'] = 2
     rsrc = rest.RestRootResource(master)
     versions = [unicode2bytes(f'v{v}')
                 for v in range(2, self.maxVersion + 1)]
     versions.append(b'latest')
     self.assertEqual(sorted(rsrc.listNames()), sorted(versions))
Esempio n. 6
0
 def test_versions(self):
     master = self.make_master(url='h:/a/b/')
     rsrc = rest.RestRootResource(master)
     versions = [unicode2bytes(f'v{v}')
                 for v in range(2, self.maxVersion + 1)]
     versions = [unicode2bytes(v) for v in versions]
     versions.append(b'latest')
     self.assertEqual(sorted(rsrc.listNames()), sorted(versions))
Esempio n. 7
0
    def test_render(self):
        master = self.make_master(url='h:/a/b/')
        rsrc = rest.RestRootResource(master)

        d = self.render_resource(rsrc, '/')

        @d.addCallback
        def check(rv):
            self.assertIn('api_versions', rv)
        return d
Esempio n. 8
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []
        root = self.apps.get('base').resource
        for key, plugin in new_config.www.get('plugins', {}).items():
            if key not in self.apps:
                raise RuntimeError(
                    "could not find plugin %s; is it installed?" % (key, ))
            print "putChild", key, self.apps.get(key).resource
            root.putChild(key, self.apps.get(key).resource)

        # /
        root.putChild(
            '',
            wwwconfig.IndexResource(self.master,
                                    self.apps.get('base').static_dir))

        # /auth
        root.putChild('auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild('avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild('api', rest.RestRootResource(self.master))

        # /ws
        root.putChild('ws', ws.WsResource(self.master))

        # /sse
        root.putChild('sse', sse.EventResource(self.master))

        self.root = root
        self.site = server.Site(root)

        # todo: need to store session infos in the db for multimaster
        # rough examination, it looks complicated, as all the session APIs are sync
        self.site.sessionFactory = server.Session

        # convert this to a tuple so it can't be appended anymore (in
        # case some dynamically created resources try to get reconfigs)
        self.reconfigurableResources = tuple(self.reconfigurableResources)
Esempio n. 9
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []

        # we're going to need at least the base plugin (buildbot-www)
        if 'base' not in self.apps:
            raise RuntimeError("could not find buildbot-www; is it installed?")

        root = self.apps.get('base').resource
        for key, plugin in iteritems(new_config.www.get('plugins', {})):
            log.msg("initializing www plugin %r" % (key,))
            if key not in self.apps:
                raise RuntimeError(
                    "could not find plugin %s; is it installed?" % (key,))
            self.apps.get(key).setMaster(self.master)
            root.putChild(key, self.apps.get(key).resource)
        known_plugins = set(new_config.www.get('plugins', {})) | set(['base'])
        for plugin_name in set(self.apps.names) - known_plugins:
            log.msg("NOTE: www plugin %r is installed but not "
                    "configured" % (plugin_name,))

        # /
        root.putChild('', wwwconfig.IndexResource(
            self.master, self.apps.get('base').static_dir))

        # /auth
        root.putChild('auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild('avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild('api', rest.RestRootResource(self.master))

        # /ws
        root.putChild('ws', ws.WsResource(self.master))

        # /sse
        root.putChild('sse', sse.EventResource(self.master))

        # /change_hook
        resource_obj = change_hook.ChangeHookResource(master=self.master)

        # FIXME: this does not work with reconfig
        change_hook_auth = new_config.www.get('change_hook_auth')
        if change_hook_auth is not None:
            resource_obj = self.setupProtectedResource(
                resource_obj, change_hook_auth)
        root.putChild("change_hook", resource_obj)

        self.root = root

        rotateLength = new_config.www.get(
            'logRotateLength') or self.master.log_rotation.rotateLength
        maxRotatedFiles = new_config.www.get(
            'maxRotatedFiles') or self.master.log_rotation.maxRotatedFiles

        class RotateLogSite(server.Site):

            """ A Site that logs to a separate file: http.log, and rotate its logs """

            def _openLogFile(self, path):
                try:
                    from twisted.python.logfile import LogFile
                    log.msg("Setting up http.log rotating %s files of %s bytes each" %
                            (maxRotatedFiles, rotateLength))
                    # not present in Twisted-2.5.0
                    if hasattr(LogFile, "fromFullPath"):
                        return LogFile.fromFullPath(path, rotateLength=rotateLength, maxRotatedFiles=maxRotatedFiles)
                    else:
                        log.msg(
                            "WebStatus: rotated http logs are not supported on this version of Twisted")
                except ImportError as e:
                    log.msg(
                        "WebStatus: Unable to set up rotating http.log: %s" % e)

                # if all else fails, just call the parent method
                return server.Site._openLogFile(self, path)

        httplog = None
        if new_config.www['logfileName']:
            httplog = os.path.abspath(
                os.path.join(self.master.basedir, new_config.www['logfileName']))
        self.site = RotateLogSite(root, logPath=httplog)

        self.site.sessionFactory = BuildbotSession

        # Make sure site.master is set. It is required for poller change_hook
        self.site.master = self.master
        # convert this to a tuple so it can't be appended anymore (in
        # case some dynamically created resources try to get reconfigs)
        self.reconfigurableResources = tuple(self.reconfigurableResources)
Esempio n. 10
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []
        root = self.apps.get('base').resource
        for key, plugin in new_config.www.get('plugins', {}).items():
            if key not in self.apps:
                raise RuntimeError(
                    "could not find plugin %s; is it installed?" % (key, ))
            print "putChild", key, self.apps.get(key).resource
            root.putChild(key, self.apps.get(key).resource)

        # /
        root.putChild(
            '',
            wwwconfig.IndexResource(self.master,
                                    self.apps.get('base').static_dir))

        # /auth
        root.putChild('auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild('avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild('api', rest.RestRootResource(self.master))

        # /ws
        root.putChild('ws', ws.WsResource(self.master))

        # /sse
        root.putChild('sse', sse.EventResource(self.master))

        self.root = root

        def either(a, b):  # a if a else b for py2.4
            if a:
                return a
            else:
                return b

        rotateLength = either(new_config.www.get('logRotateLength'),
                              self.master.log_rotation.rotateLength)
        maxRotatedFiles = either(new_config.www.get('maxRotatedFiles'),
                                 self.master.log_rotation.maxRotatedFiles)

        class RotateLogSite(server.Site):
            """ A Site that logs to a separate file: http.log, and rotate its logs """
            def _openLogFile(self, path):
                try:
                    from twisted.python.logfile import LogFile
                    log.msg(
                        "Setting up http.log rotating %s files of %s bytes each"
                        % (maxRotatedFiles, rotateLength))
                    if hasattr(LogFile,
                               "fromFullPath"):  # not present in Twisted-2.5.0
                        return LogFile.fromFullPath(
                            path,
                            rotateLength=rotateLength,
                            maxRotatedFiles=maxRotatedFiles)
                    else:
                        log.msg(
                            "WebStatus: rotated http logs are not supported on this version of Twisted"
                        )
                except ImportError, e:
                    log.msg(
                        "WebStatus: Unable to set up rotating http.log: %s" %
                        e)

                # if all else fails, just call the parent method
                return server.Site._openLogFile(self, path)
Esempio n. 11
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []

        # we're going to need at least the the base plugin (buildbot-www)
        if 'base' not in self.apps:
            raise RuntimeError("could not find buildbot-www; is it installed?")

        root = self.apps.get('base').resource
        for key, plugin in new_config.www.get('plugins', {}).items():
            log.msg("initializing www plugin %r" % (key, ))
            if key not in self.apps:
                raise RuntimeError(
                    "could not find plugin %s; is it installed?" % (key, ))
            self.apps.get(key).setMaster(self.master)
            root.putChild(key, self.apps.get(key).resource)
        known_plugins = set(new_config.www.get('plugins', {})) | set(['base'])
        for plugin_name in set(self.apps.names) - known_plugins:
            log.msg("NOTE: www plugin %r is installed but not "
                    "configured" % (plugin_name, ))

        # /
        root.putChild(
            '',
            wwwconfig.IndexResource(self.master,
                                    self.apps.get('base').static_dir))

        # /auth
        root.putChild('auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild('avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild('api', rest.RestRootResource(self.master))

        # /ws
        root.putChild('ws', ws.WsResource(self.master))

        # /sse
        root.putChild('sse', sse.EventResource(self.master))

        # /change_hook
        resource_obj = change_hook.ChangeHookResource(master=self.master)

        # FIXME: this does not work with reconfig
        change_hook_auth = new_config.www.get('change_hook_auth')
        if change_hook_auth is not None:
            resource_obj = self.setupProtectedResource(resource_obj,
                                                       change_hook_auth)
        root.putChild("change_hook", resource_obj)

        self.root = root

        def either(a, b):  # a if a else b for py2.4
            if a:
                return a
            else:
                return b

        rotateLength = either(new_config.www.get('logRotateLength'),
                              self.master.log_rotation.rotateLength)
        maxRotatedFiles = either(new_config.www.get('maxRotatedFiles'),
                                 self.master.log_rotation.maxRotatedFiles)

        class RotateLogSite(server.Site):
            """ A Site that logs to a separate file: http.log, and rotate its logs """
            def _openLogFile(self, path):
                try:
                    from twisted.python.logfile import LogFile
                    log.msg(
                        "Setting up http.log rotating %s files of %s bytes each"
                        % (maxRotatedFiles, rotateLength))
                    if hasattr(LogFile,
                               "fromFullPath"):  # not present in Twisted-2.5.0
                        return LogFile.fromFullPath(
                            path,
                            rotateLength=rotateLength,
                            maxRotatedFiles=maxRotatedFiles)
                    else:
                        log.msg(
                            "WebStatus: rotated http logs are not supported on this version of Twisted"
                        )
                except ImportError, e:
                    log.msg(
                        "WebStatus: Unable to set up rotating http.log: %s" %
                        e)

                # if all else fails, just call the parent method
                return server.Site._openLogFile(self, path)
Esempio n. 12
0
    def setupSite(self, new_config):
        self.reconfigurableResources = []

        # we're going to need at least the base plugin (buildbot-www)
        if 'base' not in self.apps:
            raise RuntimeError("could not find buildbot-www; is it installed?")

        root = self.apps.get('base').resource
        known_plugins = set(new_config.www.get('plugins', {})) | set(['base'])
        for key, plugin in list(iteritems(new_config.www.get('plugins', {}))):
            log.msg("initializing www plugin %r" % (key, ))
            if key not in self.apps:
                raise RuntimeError(
                    "could not find plugin %s; is it installed?" % (key, ))
            app = self.apps.get(key)
            app.setMaster(self.master)
            app.setConfiguration(plugin)
            root.putChild(unicode2bytes(key), app.resource)
            if not app.ui:
                del new_config.www['plugins'][key]
        for plugin_name in set(self.apps.names) - known_plugins:
            log.msg("NOTE: www plugin %r is installed but not "
                    "configured" % (plugin_name, ))

        # /
        root.putChild(
            b'',
            wwwconfig.IndexResource(self.master,
                                    self.apps.get('base').static_dir))

        # /auth
        root.putChild(b'auth', auth.AuthRootResource(self.master))

        # /avatar
        root.putChild(b'avatar', avatar.AvatarResource(self.master))

        # /api
        root.putChild(b'api', rest.RestRootResource(self.master))

        # /ws
        root.putChild(b'ws', ws.WsResource(self.master))

        # /sse
        root.putChild(b'sse', sse.EventResource(self.master))

        # /change_hook
        resource_obj = change_hook.ChangeHookResource(master=self.master)

        # FIXME: this does not work with reconfig
        change_hook_auth = new_config.www.get('change_hook_auth')
        if change_hook_auth is not None:
            resource_obj = self.setupProtectedResource(resource_obj,
                                                       change_hook_auth)
        root.putChild(b"change_hook", resource_obj)

        self.root = root

        rotateLength = new_config.www.get(
            'logRotateLength') or self.master.log_rotation.rotateLength
        maxRotatedFiles = new_config.www.get(
            'maxRotatedFiles') or self.master.log_rotation.maxRotatedFiles

        httplog = None
        if new_config.www['logfileName']:
            httplog = os.path.abspath(
                os.path.join(self.master.basedir,
                             new_config.www['logfileName']))
        self.site = BuildbotSite(root,
                                 logPath=httplog,
                                 rotateLength=rotateLength,
                                 maxRotatedFiles=maxRotatedFiles)

        self.site.sessionFactory = None

        # Make sure site.master is set. It is required for poller change_hook
        self.site.master = self.master
        # convert this to a tuple so it can't be appended anymore (in
        # case some dynamically created resources try to get reconfigs)
        self.reconfigurableResources = tuple(self.reconfigurableResources)