def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()

        custom_versions = [('test compoent', '0.1.2'), ('test component 2', '0.2.1')]

        master = self.make_master(url='h:/a/b/', auth=_auth, versions=custom_versions)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config: configjson

        vjson = json.dumps(rsrc.getEnvironmentVersions() + custom_versions)

        res = yield self.render_resource(rsrc, '/')
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"email": "*****@*****.**", "name": "me"}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)

        master = self.make_master(url='h:/a/c/', auth=_auth, versions=custom_versions)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)
Exemple #2
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()
        master = self.make_master(url='h:/a/b/', auth=_auth)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config: configjson

        res = yield self.render_resource(rsrc, '/')
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"email": "*****@*****.**", "name": "me"}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)

        master = self.make_master(url='h:/a/c/', auth=_auth)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)
    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)
Exemple #4
0
 def test_CustomTemplateDir(self):
     master = self.make_master(url='h:/a/b/')
     rsrc = config.IndexResource(master, "foo")
     master.config.www['custom_templates_dir'] = 'foo'
     rsrc.parseCustomTemplateDir = mock.Mock(return_value="returnvalue")
     rsrc.reconfigResource(master.config)
     self.assertNotIn('custom_templates_dir', master.config.www)
     self.assertEqual('returnvalue', rsrc.custom_templates)
Exemple #5
0
 def test_parseCustomTemplateDir(self):
     exp = {'views/builds.html': '<div>\n</div>'}
     try:
         # we make the test work if pyjade is present or note
         # It is better than just skip if pyjade is not there
         import pyjade  # pylint: disable=import-outside-toplevel
         [pyjade]
         exp.update({'plugin/views/plugin.html':
                     '<div class="myclass"><pre>this is customized</pre></div>'})
     except ImportError:
         log.msg("Only testing html based template override")
     template_dir = util.sibpath(__file__, "test_templates_dir")
     master = self.make_master(url='h:/a/b/')
     rsrc = config.IndexResource(master, "foo")
     res = rsrc.parseCustomTemplateDir(template_dir)
     self.assertEqual(res, exp)
Exemple #6
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)
Exemple #7
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)
Exemple #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

        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)
Exemple #9
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)
Exemple #10
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()

        custom_versions = [
            ['test compoent', '0.1.2'], ['test component 2', '0.2.1']]

        master = self.make_master(
            url='h:/a/b/', auth=_auth, versions=custom_versions)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config, custom_templates: configjson

        vjson = [list(v)
                 for v in rsrc.getEnvironmentVersions()] + custom_versions

        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"anonymous": True},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"email": "*****@*****.**", "name": "me"},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)

        master = self.make_master(
            url='h:/a/c/', auth=_auth, versions=custom_versions)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"anonymous": True},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)
Exemple #11
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)