def _getDbConnection(couchUrl, dbName): """ Check if the database exists, create if not. """ couchServer = CouchServer(couchUrl) if not dbName in couchServer.listDatabases(): logging.info("Database '%s' does not exits, creating it." % dbName) db = couchServer.createDatabase(dbName) else: logging.debug("Database '%s' exists." % dbName) db = Database(dbName, couchUrl) couchapps = "../../../src/couchapp" stat_couchapp = "%s/stat" % couchapps harness = CouchAppTestHarness(dbName, couchUrl) harness.create() harness.pushCouchapps(stat_couchapp) return couchServer, db
def setUp(self): """ setup for test. """ myThread = threading.currentThread() self.testInit = TestInitCouchApp(__file__) self.testInit.setLogging() self.testInit.setDatabaseConnection(destroyAllDatabase = True) self.testInit.setSchema(customModules = ["WMCore.WMBS", "WMCore.ResourceControl"], useDefault = False) self.testDir = self.testInit.generateWorkDir() self.testInit.setupCouch("asynctrackerpoller_t_wmstats", "WMStats") self.testInit.setupCouch("jobtracker_t/jobs", "JobDump") self.testInit.setupCouch("jobtracker_t/fwjrs", "FWJRDump") couchapps = os.path.join(os.path.dirname(AsyncStageOut.__file__), "../../couchapp") self.couchServer = CouchServer(dburl = os.getenv("COUCHURL")) self.async_couchapp = "%s/AsyncTransfer" % couchapps self.monitor_couchapp = "%s/monitor" % couchapps self.user_monitoring_couchapp = "%s/UserMonitoring" % couchapps self.stat_couchapp = "%s/stat" % couchapps self.daoFactory = DAOFactory(package = "WMCore.WMBS", logger = myThread.logger, dbinterface = myThread.dbi) harness = CouchAppTestHarness("asynctransfer2_t") harness.create() harness.pushCouchapps(self.async_couchapp) harness.pushCouchapps(self.monitor_couchapp) harness_user_mon = CouchAppTestHarness("user_monitoring_asynctransfer_t") harness_user_mon.create() harness_user_mon.pushCouchapps(self.user_monitoring_couchapp) harness_stat = CouchAppTestHarness("asynctransfer_stat_t") harness_stat.create() harness_stat.pushCouchapps(self.stat_couchapp) self.harness = harness self.harness_user_mon = harness_user_mon self.harness_stat = harness_stat
def setUp(self): """ setup for test. """ self.myThread = threading.currentThread() self.myThread.dbFactory = None self.myThread.logger = None self.database_interface = None if hasattr(self.myThread, 'dbi'): self.database_interface = self.myThread.dbi self.testInit = TestInitCouchApp(__file__) self.testInit.setLogging() self.config = self.getConfig() self.testInit.setupCouch("wmagent_jobdump/fwjrs", "FWJRDump") self.testInit.setupCouch("agent_database", "Agent") couchapps = "../../../src/couchapp" self.async_couchapp = "%s/AsyncTransfer" % couchapps self.publication_couchapp = "%s/DBSPublisher" % couchapps self.monitor_couchapp = "%s/monitor" % couchapps self.user_monitoring_couchapp = "%s/UserMonitoring" % couchapps self.stat_couchapp = "%s/stat" % couchapps harness = CouchAppTestHarness("asynctransfer") harness.create() harness.pushCouchapps(self.async_couchapp) harness.pushCouchapps(self.publication_couchapp) harness.pushCouchapps(self.monitor_couchapp) harness_user_mon = CouchAppTestHarness("user_monitoring_asynctransfer") harness_user_mon.create() harness_user_mon.pushCouchapps(self.user_monitoring_couchapp) harness_stat = CouchAppTestHarness("asynctransfer_stat") harness_stat.create() harness_stat.pushCouchapps(self.stat_couchapp) # Connect to db self.async_server = CouchServer( os.getenv("COUCHURL") ) self.db = self.async_server.connectDatabase( "asynctransfer" ) self.monitoring_db = self.async_server.connectDatabase( "user_monitoring_asynctransfer" ) self.dbStat = self.async_server.connectDatabase( "asynctransfer_stat" ) self.dbSource = self.async_server.connectDatabase( "wmagent_jobdump/fwjrs" ) doc = {"_id": "T1_IT_INFN", "state": "running", "countries": [ "IT", "AT", "HU", "PL" ], "url": "https://fts.cr.cnaf.infn.it:8443/glite-data-transfer-fts/services/FileTransfer", "couchapp": { } } self.db.queue(doc, True) self.db.commit() doc = { "_id": "MONITORING_DB_UPDATE", "db_update": 1, "couchapp": { } } self.monitoring_db.queue(doc, True) self.monitoring_db.commit() self.config = self.getConfig() self.testConfig = self.getTestConfig() self.users = ['fred', 'barney', 'wilma', 'betty'] self.sites = ['T2_IT_Pisa', 'T2_IT_Rome', 'T2_IT_Bari'] self.lfn = ['/this/is/a/lfnA', '/this/is/a/lfnB', '/this/is/a/lfnC', '/this/is/a/lfnD', '/this/is/a/lfnE'] return