def testConcurrentThreads(self): DB = testbase.DB if DB.startswith('sqlite'): return conf = ConfigParser.ConfigParser() conf.add_section('clusto') conf.set('clusto', 'dsn', testbase.DB) clusto.connect(conf, echo=testbase.ECHO) clusto.init_clusto() firstver = clusto.get_latest_version_number() threadcount = 5 threads = [] barrier = barrier_creator(threadcount) for i in range(threadcount): threads.append(ClustoWorkThread(DB, testbase.ECHO, barrier)) for i in threads: i.start() for i in threads: i.join() self.assertEqual(clusto.get_latest_version_number(), threadcount + firstver)
def testConcurrentThreads(self): DB = testbase.DB if DB.startswith('sqlite'): return conf = ConfigParser.ConfigParser() conf.add_section('clusto') conf.set('clusto', 'dsn', testbase.DB) clusto.connect(conf, echo=testbase.ECHO) clusto.init_clusto() firstver = clusto.get_latest_version_number() threadcount = 5 threads = [] barrier = barrier_creator(threadcount) for i in range(threadcount): threads.append(ClustoWorkThread(DB, testbase.ECHO, barrier)) for i in threads: i.start() for i in threads: i.join() self.assertEqual(clusto.get_latest_version_number(), threadcount+firstver)
def setUp(self): clusto.SESSION.clusto_version = clusto.working_version() clusto.connect(DB,echo=ECHO) clusto.clear() clusto.SESSION.close() clusto.init_clusto() self.data()
def setUp(self): conf = ConfigParser.ConfigParser() conf.add_section('clusto') conf.set('clusto', 'dsn', DB) clusto.connect(conf,echo=ECHO) clusto.clear() clusto.SESSION.close() clusto.init_clusto() self.data()
def setUp(self): # Mostly cribbed from clusto's test framework conf = ConfigParser.ConfigParser() conf.add_section('clusto') conf.set('clusto', 'dsn', 'sqlite:///:memory:') clusto.connect(conf) clusto.clear() clusto.SESSION.close() clusto.init_clusto() self.data()
def setUp(self): conf = ConfigParser.ConfigParser() conf.add_section('clusto') conf.set('clusto', 'dsn', DB) clusto.SESSION.clusto_version = clusto.working_version() clusto.connect(conf, echo=ECHO) clusto.clear() clusto.SESSION.close() clusto.init_clusto() self.data()
def testInitClustoIdempotent(self): clusto.init_clusto() clusto.init_clusto() clusto.init_clusto() clusto.init_clusto() self.assertEqual(SESSION.query(ClustoVersioning).count(), 2)
def run(self): clusto.connect(self.conf, echo=self.echo) clusto.init_clusto() try: clusto.begin_transaction() e = clusto.Entity('foo' + self.getName()) self.barrier() clusto.commit() except Exception, x: clusto.rollback_transaction() raise x
def run(self): clusto.connect(self.conf,echo=self.echo) clusto.init_clusto() try: clusto.begin_transaction() e = clusto.Entity('foo'+self.getName()) self.barrier() clusto.commit() except Exception, x: clusto.rollback_transaction() raise x
def init_script(name=os.path.basename(sys.argv[0]), configfile=None, initializedb=False): """Initialize the clusto environment for clusto scripts. Connects to the clusto database, returns a python SafeConfigParser and a logger. Uses get_clusto_config and setup_logging """ config = get_clusto_config(filename=configfile) clusto.connect(config=config) if initializedb: clusto.init_clusto() logger = setup_logging(config=config, name=name) return (config, logger)
def init_script( name=os.path.basename(sys.argv[0]), configfile=None, initializedb=False): """Initialize the clusto environment for clusto scripts. Connects to the clusto database, returns a python SafeConfigParser and a logger. Uses get_clusto_config and setup_logging """ config = get_clusto_config(filename=configfile) clusto.connect(config=config) if initializedb: clusto.init_clusto() logger = setup_logging(config=config, name=name) return (config, logger)
def run(self, args): try: clusto.init_clusto() except Exception, e: print 'Error creating clusto database: %s' % str(e) return -1
def run(self, args): clusto.init_clusto()
def _configure(config={}, configfile=None, init_data={}): """ Configure the root app """ if configfile: cfg = configfile else: cfg = os.environ.get( 'CLUSTOCONFIG', '/etc/clusto/clusto.conf' ) cfg = script_helper.load_config(cfg) clusto.connect(cfg) # This is an idempotent operation clusto.init_clusto() # If init_data is provided, populate it in the clusto database if init_data: for name, data in init_data.items(): ent = clusto.get_or_create( name, data['driver'], **data.get('attrs', {}) ) for pool in data.get('member_of', []): clusto.get_by_name(pool).insert(ent) for attr in data.get('attr_list', []): ent.set_attr(**attr) kwargs = {} kwargs['host'] = config.get( 'host', script_helper.get_conf( cfg, 'apiserver.host', default='127.0.0.1' ), ) kwargs['port'] = config.get( 'port', script_helper.get_conf( cfg, 'apiserver.port', default=9664, datatype=int ), ) kwargs['server'] = config.get( 'server', script_helper.get_conf( cfg, 'apiserver.server', default='wsgiref' ), ) kwargs['server_kwargs'] = config.get( 'server_kwargs', script_helper.get_conf( cfg, 'apiserver.server_kwargs', default={}, datatype=dict ), ) kwargs['debug'] = config.get( 'debug', script_helper.get_conf( cfg, 'apiserver.debug', default=False, datatype=bool ) ) kwargs['quiet'] = config.get( 'quiet', script_helper.get_conf( cfg, 'apiserver.quiet', default=False, datatype=bool ) ) kwargs['reloader'] = config.get( 'reloader', script_helper.get_conf( cfg, 'apiserver.reloader', default=False, datatype=bool ) ) mount_apps = config.get( 'apps', script_helper.get_conf( cfg, 'apiserver.apps', default={}, datatype=dict ) ) response_headers = config.get( 'response_headers', script_helper.get_conf( cfg, 'apiserver.response_headers', default={}, datatype=dict ) ) root_app.route('/__doc__', 'GET', functools.partial(build_docs)) for mount_point, cls in mount_apps.items(): module = importlib.import_module(cls) root_app.mount(mount_point, module.app) # Documentation endpoints module.app.route('/__doc__', 'GET', functools.partial(build_docs, cls)) module.app.route('/__doc__/', 'GET', functools.partial(build_docs, cls)) # OPTIONS dummy routers module.app.route('/', 'OPTIONS', functools.partial(options)) module.app.route('/<url:re:.+>', 'OPTIONS', functools.partial(options)) @root_app.hook('before_request') def enable_response_headers(): for header, value in response_headers.items(): bottle.response.headers[header] = value return kwargs
def _configure(config={}, configfile=None, init_data={}): """ Configure the root app """ if configfile: cfg = configfile else: cfg = os.environ.get( 'CLUSTOCONFIG', '/etc/clusto/clusto.conf' ) cfg = script_helper.load_config(cfg) clusto.connect(cfg) # This is an idempotent operation clusto.init_clusto() # If init_data is provided, populate it in the clusto database if init_data: for name, data in init_data.items(): ent = clusto.get_or_create( name, data['driver'], **data.get('attrs', {}) ) for pool in data.get('member_of', []): clusto.get_by_name(pool).insert(ent) kwargs = {} kwargs['host'] = config.get( 'host', script_helper.get_conf( cfg, 'apiserver.host', default='127.0.0.1' ), ) kwargs['port'] = config.get( 'port', script_helper.get_conf( cfg, 'apiserver.port', default=9664, datatype=int ), ) kwargs['server'] = config.get( 'server', script_helper.get_conf( cfg, 'apiserver.server', default='wsgiref' ), ) kwargs['debug'] = config.get( 'debug', script_helper.get_conf( cfg, 'apiserver.debug', default=False, datatype=bool ) ) kwargs['quiet'] = config.get( 'quiet', script_helper.get_conf( cfg, 'apiserver.quiet', default=False, datatype=bool ) ) kwargs['reloader'] = config.get( 'reloader', script_helper.get_conf( cfg, 'apiserver.reloader', default=False, datatype=bool ) ) mount_apps = config.get( 'apps', script_helper.get_conf( cfg, 'apiserver.apps', default={}, datatype=dict ) ) root_app.route('/__doc__', 'GET', functools.partial(build_docs, '/', __name__)) for mount_point, cls in mount_apps.items(): module = importlib.import_module(cls) path = '/__doc__%s' % (mount_point,) root_app.route(path, 'GET', functools.partial(build_docs, path, cls)) root_app.mount(mount_point, module.app) return kwargs