예제 #1
0
 def __init__(self, cfg, statedir, testName):
     self.server = RESTMain(cfg, statedir)
     self.testName = testName
     self.cofig = cfg
     self.port = cfg.main.port
     self.host = '127.0.0.1'
     self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application)
     ## test permission
     #test_authz_key = fake_authz_key_file()
     #self.header = fake_authz_headers(test_authz_key.data, roles = {"Global Admin": {'group': ['global']}})        
     self.jsonSender = JSONRequests(self.serverUrl)
예제 #2
0
 def __init__(self, cfg, statedir, testName):
     self.server = RESTMain(cfg, statedir)
     self.testName = testName
     self.config = cfg
     self.port = cfg.main.port
     self.host = '127.0.0.1'
     self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application)
     
     ## test authentication using fake filepermission
     self.test_authz_key = fake_authz_key_file(False)
     self.config.main.tools.cms_auth.key_file = self.test_authz_key.name
     #self.header = fake_authz_headers(test_authz_key.data, roles = {"Admin": {'group': ['ReqMgr']}})        
     
     self.jsonSender = JSONRequests(self.serverUrl)
예제 #3
0
class RESTMainTestServer(object):
    def __init__(self, cfg, statedir, testName):
        self.server = RESTMain(cfg, statedir)
        self.testName = testName
        self.config = cfg
        self.port = cfg.main.port
        self.host = '127.0.0.1'
        self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port,
                                               cfg.main.application)

        ## test authentication using fake filepermission
        self.test_authz_key = fake_authz_key_file(False)
        self.config.main.tools.cms_auth.key_file = self.test_authz_key.name
        #self.header = fake_authz_headers(test_authz_key.data, roles = {"Admin": {'group': ['ReqMgr']}})

        self.jsonSender = JSONRequests(self.serverUrl)

    def getLastTest(self):
        global lastTest
        return lastTest

    def setLastTest(self):
        global lastTest
        lastTest = self.testName

    def start(self, blocking=True):
        self.server.validate_config()
        self.server.setup_server()
        self.server.install_application()
        cherrypy.config.update({'server.socket_port': self.port})
        cherrypy.config.update({'server.socket_host': self.host})
        cherrypy.config.update({'request.show_tracebacks': True})
        cherrypy.config.update({'environment': 'test_suite'})
        cherrypy.config.update({'server.thread_pool': 10})
        cherrypy.config.update({'server.accepted_queue_size': -1})
        cherrypy.config.update({'server.accepted_queue_timeout': 10})
        for app in viewvalues(cherrypy.tree.apps):
            if '/' in app.config:
                app.config["/"]["request.show_tracebacks"] = True

        cherrypy.server.httpserver = None
        cherrypy.engine.start()
        if blocking:
            cherrypy.engine.block()

    def stop(self):
        """
        Stop the server
        """
        cherrypy.engine.exit()
        cherrypy.engine.stop()

        # Ensure the next server that's started gets fresh objects
        for name, server in viewitems(getattr(cherrypy, 'servers', {})):
            server.unsubscribe()
            del cherrypy.servers[name]

        self.test_authz_key.close()
        os.remove(self.test_authz_key.name)
예제 #4
0
class RESTMainTestServer(object):

    def __init__(self, cfg, statedir, testName):
        self.server = RESTMain(cfg, statedir)
        self.testName = testName
        self.config = cfg
        self.port = cfg.main.port
        self.host = '127.0.0.1'
        self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application)

        ## test authentication using fake filepermission
        self.test_authz_key = fake_authz_key_file(False)
        self.config.main.tools.cms_auth.key_file = self.test_authz_key.name
        #self.header = fake_authz_headers(test_authz_key.data, roles = {"Admin": {'group': ['ReqMgr']}})

        self.jsonSender = JSONRequests(self.serverUrl)

    def getLastTest(self):
        global lastTest
        return lastTest

    def setLastTest(self):
        global lastTest
        lastTest = self.testName


    def start(self, blocking = True):
        self.server.validate_config()
        self.server.setup_server()
        self.server.install_application()
        cherrypy.config.update({'server.socket_port': self.port})
        cherrypy.config.update({'server.socket_host': self.host})
        cherrypy.config.update({'request.show_tracebacks': True})
        cherrypy.config.update({'environment': 'test_suite'})
        for app in cherrypy.tree.apps.values():
            if '/' in app.config:
                app.config["/"]["request.show_tracebacks"] = True

        cherrypy.server.httpserver = None
        cherrypy.engine.start()
        if blocking:
            cherrypy.engine.block()


    def stop(self):
        """
        Stop the server
        """
        cherrypy.engine.exit()
        cherrypy.engine.stop()

        # Ensure the next server that's started gets fresh objects
        for name, server in getattr(cherrypy, 'servers', {}).items():
            server.unsubscribe()
            del cherrypy.servers[name]

        self.test_authz_key.close()
        os.remove(self.test_authz_key.name)
예제 #5
0
    def __init__(self, cfg, statedir, testName):
        self.server = RESTMain(cfg, statedir)
        self.testName = testName
        self.config = cfg
        self.port = cfg.main.port
        self.host = '127.0.0.1'
        self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application)

        ## test authentication using fake filepermission
        self.test_authz_key = fake_authz_key_file(False)
        self.config.main.tools.cms_auth.key_file = self.test_authz_key.name
        #self.header = fake_authz_headers(test_authz_key.data, roles = {"Admin": {'group': ['ReqMgr']}})

        self.jsonSender = JSONRequests(self.serverUrl)
예제 #6
0
def setup_dummy_server(module_name,
                       class_name,
                       app_name=None,
                       authz_key_file=None,
                       port=8888):
    """Helper function to set up a :class:`~.RESTMain` server from given
    module and class. Creates a fake server configuration and instantiates
    the server application from it.

    :arg str module_name: module from which to import test class.
    :arg str class_type: name of the server test class.
    :arg str app_name: optional test application name, 'test' by default.
    :returns: tuple with the server object and authz hmac signing key."""
    if authz_key_file:
        test_authz_key = authz_key_file
    else:
        test_authz_key = fake_authz_key_file()

    cfg = Configuration()
    main = cfg.section_('main')
    main.application = app_name or 'test'
    main.silent = True
    main.index = 'top'
    main.authz_defaults = {'role': None, 'group': None, 'site': None}
    main.section_('tools').section_('cms_auth').key_file = test_authz_key.name

    app = cfg.section_(app_name or 'test')
    app.admin = '*****@*****.**'
    app.description = app.title = 'Test'

    views = cfg.section_('views')
    top = views.section_('top')
    top.object = module_name + "." + class_name

    server = RESTMain(cfg, os.getcwd())
    server.validate_config()
    server.setup_server()
    server.install_application()
    cherrypy.config.update({'server.socket_port': port})
    cherrypy.config.update({'server.socket_host': '127.0.0.1'})
    cherrypy.config.update({'request.show_tracebacks': True})
    cherrypy.config.update({'environment': 'test_suite'})
    for app in viewvalues(cherrypy.tree.apps):
        if '/' in app.config:
            app.config["/"]["request.show_tracebacks"] = True

    return server, test_authz_key
예제 #7
0
파일: Admin.py 프로젝트: nikmagini/sitedb
def setup_server():
    """Create and set up an internal REST server for admin operations."""
    global server, authz_key
    authz_key = fake_authz_key_file()
    cfg = Config(authkey=authz_key.name)
    delattr(cfg.views, 'ui')
    cfg.main.index = 'data'
    cfg.main.silent = True
    cfg.views.data.object = "SiteDB.Admin.AdminServer"
    cfg.views.data.db = "SiteDB.Admin.AUTH"
    server = RESTMain(cfg, os.getcwd())
    server.validate_config()
    server.setup_server()
    server.install_application()
    cherrypy.config.update({'server.socket_port': 8888})
    cherrypy.config.update({'server.socket_host': '127.0.0.1'})
    cherrypy.config.update({'request.show_tracebacks': True})
    cherrypy.config.update({'environment': 'test_suite'})
    cherrypy.config.update({'log.screen': 'True'})
예제 #8
0
class RESTMainTestServer(object):

    def __init__(self, cfg, statedir, testName):
        self.server = RESTMain(cfg, statedir)
        self.testName = testName
        self.cofig = cfg
        self.port = cfg.main.port
        self.host = '127.0.0.1'
        self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application)
        ## test permission
        #test_authz_key = fake_authz_key_file()
        #self.header = fake_authz_headers(test_authz_key.data, roles = {"Global Admin": {'group': ['global']}})        
        self.jsonSender = JSONRequests(self.serverUrl)
        
    def getLastTest(self):
        global lastTest
        return lastTest

    def setLastTest(self):
        global lastTest
        lastTest = self.testName
    
        
    def start(self, blocking = True):    
        self.server.validate_config()
        self.server.setup_server()
        self.server.install_application()
        cherrypy.config.update({'server.socket_port': self.port})
        cherrypy.config.update({'server.socket_host': self.host})
        cherrypy.config.update({'request.show_tracebacks': True})
        cherrypy.config.update({'environment': 'test_suite'})
        for app in cherrypy.tree.apps.values():
            app.config["/"]["request.show_tracebacks"] = True
            
        cherrypy.server.httpserver = None
        cherrypy.engine.start()
        if blocking:
            cherrypy.engine.block()


    def stop(self):
        """
        Stop the server
        """
        cherrypy.engine.exit()
        cherrypy.engine.stop()

        # Ensure the next server that's started gets fresh objects
        for name, server in getattr(cherrypy, 'servers', {}).items():
            server.unsubscribe()
            del cherrypy.servers[name]
예제 #9
0
파일: Admin.py 프로젝트: ticoann/sitedb
def setup_server():
  """Create and set up an internal REST server for admin operations."""
  global server, authz_key
  authz_key = fake_authz_key_file()
  cfg = Config(authkey = authz_key.name)
  delattr(cfg.views, 'ui')
  cfg.main.index = 'data'
  cfg.main.silent = True
  cfg.views.data.object = "SiteDB.Admin.AdminServer"
  cfg.views.data.db = "SiteDB.Admin.AUTH"
  server = RESTMain(cfg, os.getcwd())
  server.validate_config()
  server.setup_server()
  server.install_application()
  cherrypy.config.update({'server.socket_port': 8888})
  cherrypy.config.update({'server.socket_host': '127.0.0.1'})
  cherrypy.config.update({'request.show_tracebacks': True})
  cherrypy.config.update({'environment': 'test_suite'})
  cherrypy.config.update({'log.screen': 'True'})
예제 #10
0
파일: Test.py 프로젝트: dciangot/WMCore
def setup_dummy_server(module_name, class_name, app_name=None, authz_key_file=None, port=8888):
    """Helper function to set up a :class:`~.RESTMain` server from given
    module and class. Creates a fake server configuration and instantiates
    the server application from it.

    :arg str module_name: module from which to import test class.
    :arg str class_type: name of the server test class.
    :arg str app_name: optional test application name, 'test' by default.
    :returns: tuple with the server object and authz hmac signing key."""
    if authz_key_file:
        test_authz_key = authz_key_file
    else:
        test_authz_key = fake_authz_key_file()

    cfg = Configuration()
    main = cfg.section_("main")
    main.application = app_name or "test"
    main.silent = True
    main.index = "top"
    main.authz_defaults = {"role": None, "group": None, "site": None}
    main.section_("tools").section_("cms_auth").key_file = test_authz_key.name

    app = cfg.section_(app_name or "test")
    app.admin = "*****@*****.**"
    app.description = app.title = "Test"

    views = cfg.section_("views")
    top = views.section_("top")
    top.object = module_name + "." + class_name

    server = RESTMain(cfg, os.getcwd())
    server.validate_config()
    server.setup_server()
    server.install_application()
    cherrypy.config.update({"server.socket_port": port})
    cherrypy.config.update({"server.socket_host": "127.0.0.1"})
    cherrypy.config.update({"request.show_tracebacks": True})
    cherrypy.config.update({"environment": "test_suite"})
    for app in cherrypy.tree.apps.values():
        if "/" in app.config:
            app.config["/"]["request.show_tracebacks"] = True

    return server, test_authz_key
예제 #11
0
def setup_test_server(module_name, class_name, app_name = None, authz_key_file=None, port=8888):
    """Helper function to set up a :class:`~.RESTMain` server from given
    module and class. Creates a fake server configuration and instantiates
    the server application from it.

    :arg str module_name: module from which to import test class.
    :arg str class_type: name of the server test class.
    :arg str app_name: optional test application name, 'test' by default.
    :returns: tuple with the server object and authz hmac signing key."""
    if authz_key_file:
        test_authz_key = authz_key_file
    else:
        test_authz_key = fake_authz_key_file()

    cfg = Configuration()
    main = cfg.section_('main')
    main.application = app_name or 'test'
    main.silent = True
    main.index = 'top'
    main.authz_defaults = { 'role': None, 'group': None, 'site': None }
    main.section_('tools').section_('cms_auth').key_file = test_authz_key.name

    app = cfg.section_(app_name or 'test')
    app.admin = '*****@*****.**'
    app.description = app.title = 'Test'

    views = cfg.section_('views')
    top = views.section_('top')
    top.object = module_name + "." + class_name

    server = RESTMain(cfg, os.getcwd())
    server.validate_config()
    server.setup_server()
    server.install_application()
    cherrypy.config.update({'server.socket_port': port})
    cherrypy.config.update({'server.socket_host': '127.0.0.1'})
    cherrypy.config.update({'request.show_tracebacks': True})
    cherrypy.config.update({'environment': 'test_suite'})
    for app in cherrypy.tree.apps.values():
        if '/' in app.config:
            app.config["/"]["request.show_tracebacks"] = True

    return server, test_authz_key
예제 #12
0
    def __init__(self, app, config, mount):
        self.base = config.base
        self.rootdir = '/'.join(WMCore.__file__.split('/')[:-1])
        if config and not isinstance(config, dict):
            web_config = config.dictionary_()
        if not config:
            web_config = {'base': self.base}
        TemplatedPage.__init__(self, web_config)
        imgdir = os.environ.get('RM_IMAGESPATH', os.getcwd() + '/images')
        self.imgdir = web_config.get('imgdir', imgdir)
        cssdir = os.environ.get('RM_CSSPATH', os.getcwd() + '/css')
        self.cssdir = web_config.get('cssdir', cssdir)
        jsdir = os.environ.get('RM_JSPATH', os.getcwd() + '/js')
        self.jsdir = web_config.get('jsdir', jsdir)
        spdir = os.environ.get('RM_SPECPATH', os.getcwd() + '/specs')
        self.spdir = web_config.get('spdir', spdir)
        # read scripts area and initialize data-ops scripts
        self.sdir = os.environ.get('RM_SCRIPTS', os.getcwd() + '/scripts')
        self.sdir = web_config.get('sdir', self.sdir)
        self.sdict_thr = web_config.get('sdict_thr',
                                        600)  # put reasonable 10 min interval
        self.sdict = {'ts': time.time()}  # placeholder for data-ops scripts
        self.update_scripts(force=True)

        # To be filled at run time
        self.cssmap = {}
        self.jsmap = {}
        self.imgmap = {}
        self.yuimap = {}

        std_specs_dir = os.path.join(self.rootdir, 'WMSpec/StdSpecs')
        self.std_specs = spec_list(std_specs_dir, 'WMSpec.StdSpecs')
        self.std_specs.sort()

        # Update CherryPy configuration
        mime_types = ['text/css']
        mime_types += [
            'application/javascript', 'text/javascript',
            'application/x-javascript', 'text/x-javascript'
        ]
        cherryconf.update({
            'tools.encode.on': True,
            'tools.gzip.on': True,
            'tools.gzip.mime_types': mime_types,
        })
        self._cache = {}

        # initialize rest API
        statedir = '/tmp'
        app = RESTMain(config, statedir)  # REST application
        mount = '/rest'  # mount point for cherrypy service
        api = RestApiHub(app, config.reqmgr, mount)

        # initialize access to reqmgr2 APIs
        self.reqmgr = ReqMgr(config.reqmgr.reqmgr2_url)
        # only gets current view (This might cause to reponse time much longer,
        # If upto date view is not needed overwrite Fale)
        self.reqmgr._noStale = True

        # admin helpers
        self.admin_info = Info(app, api, config.reqmgr, mount=mount + '/info')
        self.admin_group = Group(app,
                                 api,
                                 config.reqmgr,
                                 mount=mount + '/group')
        self.admin_team = Team(app, api, config.reqmgr, mount=mount + '/team')

        # get fields which we'll use in templates
        cdict = config.reqmgr.dictionary_()
        self.couch_url = cdict.get('couch_host', '')
        self.couch_dbname = cdict.get('couch_reqmgr_db', '')
        self.couch_wdbname = cdict.get('couch_workload_summary_db', '')
        self.acdc_url = cdict.get('acdc_host', '')
        self.acdc_dbname = cdict.get('acdc_db', '')
        self.configcache_url = cdict.get('couch_config_cache_url',
                                         self.couch_url)
        self.dbs_url = cdict.get('dbs_url', '')
        self.dqm_url = cdict.get('dqm_url', '')
        self.sw_ver = cdict.get('default_sw_version', 'CMSSW_5_2_5')
        self.sw_arch = cdict.get('default_sw_scramarch', 'slc5_amd64_gcc434')
예제 #13
0
파일: Main_t.py 프로젝트: vytjan/WMCore
from WMCore.REST.Main import RESTDaemon
from WMCore.REST.Test import fake_authz_key_file
from WMCore.Configuration import Configuration
from cherrypy import Application
import os

def dummy():
    return ""

import os

authz_key = fake_authz_key_file()
cfg = Configuration()
main = cfg.section_('main')
main.application = 'test'
main.silent = True
main.index = 'top'
main.authz_defaults = { 'role': None, 'group': None, 'site': None }
main.section_('tools').section_('cms_auth').key_file = authz_key.name
app = cfg.section_('test')
app.admin = '*****@*****.**'
app.description = app.title = 'Test'
views = cfg.section_('views')
top = views.section_('top')
top.object = os.path.abspath(__file__).rsplit("/", 1)[-1].split(".")[0] + ".Test"

ProfiledApp(Application(dummy, "/", {"/": {}}), ".")
Logger()
RESTMain(cfg, ".")
RESTDaemon(cfg, ".")