def testLoading3(self): """ loading of a single job in the N jobs task """ # log information logging.info("Test Loading 3: load of a single job in a %s jobs task" \ % self.N) start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template for task task = Task() task['name'] = 'task2' # create template for jobs with particular logFile job = Job() job['name'] = 'job1' # add to task template task.addJob(job) # load partial task (jobs with logFile 'output.log') try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg))
def connect(self): """ recreate a session and db access """ # create a session and db access if self.session is None: self.session = SafeSession(dbInstance=self.dbInstance)
def connect ( self ) : """ recreate a session and db access """ # create a session and db access if self.session is None: self.session = SafeSession(pool = self.pool)
def testCreation2(self): """ creates a single task with N jobs """ # log information logging.info("Test Creation 2: creating a task with %s jobs" % self.N) start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create a task task = Task() task['name'] = 'task2' task['startDirectory'] = '/tmp/startdir' task['outputDirectory'] = '/tmp/outdir' task['globalSandbox'] = '/tmp/data_area' # create template for jobs template = { 'inputFiles': ['a.txt', 'b.txt'], 'executable': 'production.sh', 'arguments': "-o c.txt", 'outputFiles': ['c.txt'], 'logFile': 'output.log' } # create list of N jobs jobs = [] for index in range(1, self.N + 1): # set specific parameters template['name'] = 'job' + str(index) if index <= int(self.N / 2): template['logFile'] = 'output.log' else: template['logFile'] = 'useful.log' template['outputFiles'] = ['a.txt', 'b.txt'] # add job to list jobs.append(Job(template)) # add jobs to task task.addJobs(jobs) # save task (and jobs) in single transaction try: rows = task.save(db) session.commit() except TaskError, msg: self.fail("Error: " + str(msg))
def installMySQL(self, schemaLocation): """ install MySQL database """ import getpass from ProdCommon.Database.MysqlInstance import MysqlInstance # ask for password (optional) print userName = raw_input(""" Please provide the mysql user name (typically "root") for updating the database server (leave empty if not needed): ') """) if userName == '': userName = '******' print passwd = getpass.getpass( """Please provide mysql passwd associated to this user name for updating the database server: """) # define connection type from copy import deepcopy rootConfig = deepcopy(self.dbConfig) rootConfig.update({ 'dbName': 'mysql', 'user': userName, 'passwd': passwd }) dbInstance = MysqlInstance(rootConfig) session = SafeSession(dbInstance=dbInstance) # check if db exists create = True query = "show databases like '" + self.dbConfig['dbName'] + "'" try: session.execute(query) session.commit() results = session.fetchall() if results[0][0] == self.dbConfig['dbName']: print "DB ", self.dbConfig['dbName'], "already exists." print "Installing just BossLite tables.\n" create = False except IndexError: pass except Exception, msg: session.close() raise DbError(str(msg))
def testCreation1(self): """ creates a single task with 2 jobs """ # log information print "Creation tests" logging.info("Test Creation 1: creating a task with two jobs") start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create a task task = Task() task['name'] = 'task1' task['startDirectory'] = '/tmp/startdir' task['outputDirectory'] = '/tmp/output' task['globalSandbox'] = '/tmp/inputdata' # create first job job1 = Job() job1['name'] = 'job1' job1['executable'] = 'test.sh' job1['inputFiles'] = ['a.txt', 'b.txt'] job1['outputFiles'] = ['c.txt'] # create second job job2 = Job() job2['name'] = 'job2' job2['executable'] = 'production.sh' job2['arguments'] = "-o c.txt" # add jobs to task task.addJobs([job1, job2]) # save task in single transaction try: rows = task.save(db) session.commit() except TaskError, msg: self.fail("Error: " + str(msg))
def testUpdate1(self): """ updating task object """ # log information logging.info("Test Updating 1: updating task object") start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template for task task = Task() task['name'] = 'task2' # load task try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg))
def testLoading4(self): """ checking update of full output path for output files and input files """ # log information logging.info("Test Loading 4: testing full path operations") start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template for task task = Task() task['name'] = 'task2' # load task try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg))
def installSQlite(self, schemaLocation): """ install SQLite database """ # create a session and db access session = SafeSession(dbInstance=self.dbInstance) # execute check query query = "select tbl_name from sqlite_master where tbl_name='bl_task'" try: # if bl_task exists, no further operations are needed session.execute(query) results = session.fetchall() if results[0][0] == self.dbConfig['dbName']: print "DB ", self.dbConfig['dbName'], "already exists.\n" return session.close() return except IndexError: pass except StandardError: pass try: # if bl_task exists, no further operations are needed session.execute("select count(*) from bl_task") session.close() return except StandardError: pass # execute query queries = open(schemaLocation).read() try: for query in queries.split(';'): session.execute(query) except Exception, msg: raise DbError(str(msg))
def __init__(self, argv): """ initialize test instance """ # initialize super class super(jobUnitTests, self).__init__(argv) # read configuration self.configure() # MySQL: get DB configuration from config file if self.database == "MySQL": from ProdAgentCore.Configuration import loadProdAgentConfiguration cfg = loadProdAgentConfiguration() dbConfig = cfg.getConfig("ProdAgentDB") dbConfig['dbName'] += '_BOSS' # create DB instance self.dbInstance = MysqlInstance(dbConfig) else: dbConfig = {} dbConfig['dbName'] = 'ProdAgentDB_BOSS' # create DB instance self.dbInstance = SqliteInstance(dbConfig) # remove all information from database session = SafeSession(dbInstance=self.dbInstance) try: session.execute("delete from bl_runningjob") session.execute("delete from bl_job") session.execute("delete from bl_task") session.commit() except DbError, msg: print "Cannot erase database contents: " + str(msg) sys.exit(1)
def testCreation3(self): """ creating a running instance """ # log information logging.info("Test Updating 1: updating task object") start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template for job task = Task({'name': 'task1'}) job = Job({'name': 'job1'}) task.addJob(job) # load information try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg))
def testLoading1(self): """ deep load of a task with 2 jobs and a task with N jobs """ # log information print "\nLoading tests" logging.info("Test Loading 1: deep load of tasks with 2 and %s jobs" \ % self.N) start = time() # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template task = Task() task['name'] = 'task1' # load complete task try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg))
# update information about task in database try: task.update(db) session.commit except TaskError, msg: self.fail("Cannot update task: " + str(msg)) # close session session.close() ##################################### # verify operation ##################################### # create a session and db access session = SafeSession(dbInstance=self.dbInstance) db = TrackingDB(session) # create template for task task = Task() task['name'] = 'task2' # load task try: task.load(db) except TaskError, msg: self.fail("Cannot load task: " + str(msg)) # update all jobs for job in task.jobs: if job['standardError'] != 'output.err':