def end_process(dutstatus): """Mark process as ended""" dutstatus['running'] = 0 if 'pid' in dutstatus: del dutstatus['pid'] dutstatus['ended'] = time() get_autotest().duts.update( {'_id': dutstatus['_id']}, {'$set': { 'last_finish_time': dutstatus['ended'] }})
def start(dutdoc, dutstatus): """Start a new process""" dutstatus['started'] = time() log("Starting", dutdoc['name']) get_autotest().duts.update( {'_id': dutdoc['_id']}, {'$set': { 'last_launch_time': dutstatus['started'] }}) try: pid = fork() except OSError, exc: log('fork failed', exc) return
def main(): """implement CLI""" parser = optparse.OptionParser() parser.add_option('-e', '--enable', action='store_true', help='Enable BVT automation for machines') parser.add_option('-d', '--disable', action='store_true', help='Disable BVT automation for machines') options, args = parser.parse_args() mdb = mongodb.get_autotest() if not (options.enable or options.disable): if options.update == []: print 'Example commands:' for row in mdb.duts.find(): print '\tcontrol_automation', print('--disable' if row.get('run_bvt') else '--enable'), print row['name'], if row.get('run_bvt'): print ' # BVT controlled by', row['control_machine'], else: print ' # (automation disabled)', print sys.exit(1) else: sys.exit(0) if options.enable and options.disable: print 'ERROR: do not specify --enable and --disable' sys.exit(2) if len(args) == 0: print 'ERROR: specify at least one machine as an argument' machines = [] for arg in args: exitcode = call(['host', arg]) if exitcode != 0: print 'ERROR: no DNS record for host name', arg sys.exit(4) mongo = mongodb.get_autotest() for arg in args: if mongo.duts.find_one({'name': arg}) is None: print 'ERROR: no such machine', arg else: machines.append((arg)) if len(machines) != len(args): sys.exit(3) control_automation(machines, options.enable)
def clean_old_vhds(): """Clean up old VHDs""" references = set() builddir = VHD_WITH_TOOLS_PATTERN[:VHD_WITH_TOOLS_PATTERN.find('%')-1] builddocs = get_autotest().builds.find( {}, sort=[('build_time', DESCENDING)], limit=5) recentbuilds = [bd['_id'] for bd in builddocs] builds = listdir(builddir) for name in builds: if name not in recentbuilds: fname = builddir + '/'+ name print 'delete', fname run(['rm', '-rf', fname], ignore_failure=True) for (dirpath, dirnames, filenames) in walk('/home/xc_vhds/dev_vhds'): for name in filenames: full = dirpath+'/'+name if not islink(full): continue references.add(readlink(full)) print 'INFO: have references to', len(references), 'VHDs' for (dirpath, dirnames, filenames) in \ walk('/home/xc_bvt_output/archive-vhds'): for name in filenames: full = dirpath+'/'+name if full not in references: print 'INFO: deleting unreferenced', full try: unlink(full) except OSError: pass
def main(): """implement CLI""" parser = optparse.OptionParser() parser.add_option( '-e', '--enable', action='store_true', help='Enable BVT automation for machines') parser.add_option( '-d', '--disable', action='store_true', help='Disable BVT automation for machines') options, args = parser.parse_args() mdb = mongodb.get_autotest() if not (options.enable or options.disable): if options.update == []: print 'Example commands:' for row in mdb.duts.find(): print '\tcontrol_automation', print ('--disable' if row.get('run_bvt') else '--enable'), print row['name'], if row.get('run_bvt'): print ' # BVT controlled by', row['control_machine'], else: print ' # (automation disabled)', print sys.exit(1) else: sys.exit(0) if options.enable and options.disable: print 'ERROR: do not specify --enable and --disable' sys.exit(2) if len(args) == 0: print 'ERROR: specify at least one machine as an argument' machines = [] for arg in args: exitcode = call(['host', arg]) if exitcode != 0: print 'ERROR: no DNS record for host name', arg sys.exit(4) mongo = mongodb.get_autotest() for arg in args: if mongo.duts.find_one({'name':arg}) is None: print 'ERROR: no such machine', arg else: machines.append( (arg)) if len(machines) != len(args): sys.exit(3) control_automation(machines, options.enable)
def main(): """go go go""" rdb = database_cursor.open_results_db() mongo = mongodb.get_autotest() hostname = socket.gethostname() # note: we are deliberately ignoring results with foreign keys that # do not match in builds / test_cases / duts offset = 0 mdb = mongodb.get_autotest() while 1: rows = rdb.select('* FROM results NATURAL JOIN duts '+ 'NATURAL JOIN builds NATURAL JOIN test_cases WHERE ' 'start_time > %s ORDER BY start_time DESC OFFSET '+ str(offset)+' LIMIT 10', (datetime.datetime.today() - datetime.timedelta(14))) for row in rows: query = {'automation_server' : hostname, 'result_index' : row['result_index'] } doc = mdb.results.find_one(query) new = doc is None if new: doc = query for key, value in [ ('start_time', dt_to_epoch(row['start_time'])), ('end_time', dt_to_epoch(row['end_time'])), ('test_case', row['test_case']), ('automation_server', hostname), ('failure', row['failure']), ('build', row['build']), ('branch', row['branch']), ('dut', row['dut'])]: if value is not None: doc[key] = value offset += 1 _id = mdb.results.save(doc) doc['_id'] = _id print row['result_index'], '->', _id, 'NEW' if new else 'OLD', print row['start_time'] if new: process_result.process_result(doc, mongo=mongo) else: break if len(rows) < 10 or not new: break
def one_operation_logged(options, recording): try: mdb = mongodb.get_autotest() dut_document = mdb.duts.find_one({'name':options.machine}) for job in mdb.jobs.find(): control_pid = job.get('control_pid') if ((control_pid is None or not os.path.isdir('/proc/'+str(control_pid))) and job.get('status', '').startswith('running')): mdb.jobs.update({'_id': job['_id']}, {'$set': { 'status': \ 'control process '+str(control_pid)+ ' disppeared without clearing up'}}) print 'TESTLAUNCH: experiment override', dut_document.get('experiment') job = get_job(mdb, options.machine) if job: def update_job(field, value): """Update one field in job""" mdb.jobs.update({'_id':job['_id']}, {'$set': {field: value}}) def set_status(status): """Update mongo status""" update_job('status', status) set_status('running') update_job('launch_time', time.time()) update_job('control_pid', os.getpid()) update_job('control_machine', gethostname()) update_job('dut', options.machine) print 'I should run', job, 'on', options.machine command_line = list(job['command']) + [ '-m', options.machine] print 'running', command_line, 'with', job['timeout'], \ 'seconds timeout' def show(output): """show stderr""" for line in output.splitlines(): print line make_log_entry(line, job_id=job['_id'], dut=options.machine) def finish(status, exc=None): """Mark test as finished""" set_status(status) if exc: update_job('failure', str(exc)) update_job('finish_time', time.time()) try: run(command_line, timeout=job['timeout'], output_callback=show, error_callback=show) finish('completed') except SubprocessError, exc: finish('failed (non zero exit code)', exc) except TimeoutError, exc: finish('failed (timed out)', exc)
def choose_test(dut, current_install=False, test_case_regexp=None): """select a test for dut""" mdb = mongodb.get_autotest() minimum_n = minimum = None current_build = get_build(dut, timeout=20) domlist = [] if current_build: try: domlist = list_vms(dut) except Exception, exc: print 'INFO: unable to list domains', exc
def main(): """Main""" call(['pkill', '-f', 'launch.py']) running = {} def sigchld(*_): """Check for children who have exited; called from SIGCHLD and regularly""" for dutstatus in running.values(): if dutstatus.get('running'): try: status = waitpid(dutstatus['pid'], WNOHANG) except OSError as err: if err.errno == ECHILD: status = dutstatus['pid'] else: log('waitpid on', dutstatus, 'returned with', err.errno, err) else: if dutstatus['pid'] == status: end_process(dutstatus) def medea(): """Kill my children""" for dutstatus in running.values(): if dutstatus.get('pid'): kill(-dutstatus['pid'], SIGKILL) def terminate(*args): """Time to die""" log("shutting down on signal %r" % (repr(args))) medea() signal(SIGCHLD, sigchld) signal(SIGTERM, terminate) signal(SIGINT, terminate) while 1: sleep( 1) # to avoid spinning hard if there's a problem running launch.py if DEBUG: print '----', asctime() sigchld() try: dutdocs = list(get_autotest().duts.find().sort([('name', ASCENDING) ])) except Exception as exc: log("exception", exc, "reading duts collection") sleep(10) continue for dutdoc in dutdocs: handle_dut(dutdoc, running) if ONCE: break sleep(10)
def one_operation(options): """Launch a single operation""" mdb = mongodb.get_autotest() dut_document = mdb.duts.find_one({'name':options.machine}) with StdoutFilter(verbose=options.verbose) as recording: with RecordTest(record=True, dut=options.machine, stdout_filter=recording) as recording: with ConsoleMonitor(options.machine, recording.result_id): one_operation_logged(options, recording)
def latest_build(dut): """Return the most recent build on branch as a tag name string""" mdb = mongodb.get_autotest() print 'LATEST: finding latest build for', dut tag_regexp = get_tag_regexp(dut) print 'LATEST: finding latest build matching', tag_regexp build = mdb.builds.find_one( {'_id':{'$regex':tag_regexp}, 'suppress' : {'$exists':0}}, sort=[('build_time', mongodb.DESCENDING)]) if build is None: raise NoMatchingBuilds(tag_regexp) print 'LATEST: latest build matching', tag_regexp, 'is', build['_id'] return build['_id']
def describe_dut(dut): """Return a string describing a dut""" try: dutdoc = get_autotest().duts.find_one({'name':dut}) except NoMongoHost: return dut if dutdoc is None: return dut attrs = [pretty(f, dutdoc[f]) for f in DUT_FIELDS if f in dutdoc] out = dut if attrs: out += ' ('+ (' '.join(attrs))+')' return out
def do_iteration(i, options): """Do one iteration of the test loop""" set_experiment_install_flag(options.machine, (options.install_first or not options.soak_power_level) and (i == 1)) try: mdb = mongodb.get_autotest() dutdoc = mdb.duts.find_one({'name':options.machine}) except NoMongoHost: dutdoc = {'write':True} write = (dutdoc if dutdoc else {}).get('write') test_parameters = { 'dut':options.machine, 'record': options.record, 'status_report_mode': STATUS_REPORTS_ALWAYS if options.diagnostic_status_report else STATUS_REPORTS_NEVER, 'stash_guests' : options.guest, 'verbose' : options.verbose, 'stash_on_failure' : options.stash_on_failure, 'reinstall_on_failure' : options.reinstall_on_failure} def trigger_tests(condition, guest=None): """Trigger test cases matching condition for guest""" for test_case in test_cases.TEST_CASES: if test_case.get('trigger') == condition: run_test(test_parameters, test_case, options, guest) trigger_tests('first') if write: trigger_tests('platform install') trigger_tests('build ready') trigger_tests('soakup') trigger_tests('platform ready') for guest in options.guest if options.guest else []: try: find_domain(options.machine, guest) have_domain = True except CannotFindDomain: have_domain = False print 'check for domain', guest, 'returned', have_domain write_guest = options.rebuild_vms or write or not have_domain if write_guest: trigger_tests('VM install', guest) domain = find_domain(options.machine, guest) if domain['status'] == 'stopped': run(['xec-vm', '-n', domain['name'], 'start'], host=options.machine, timeout=600) if write_guest: trigger_tests('VM configure', guest) trigger_tests('VM accelerate', guest) trigger_tests('VM ready', guest) trigger_tests('soakdown')
def set_build_information(build, changes): """make changes to records about build""" track = get_track() autotest = get_autotest() change = False builddoc = autotest.builds.find_one({'_id':build}) if builddoc: for field in changes: if changes[field] != builddoc.get(field): print 'SET_BUILD: field', field, 'changed on', build change = True if change: autotest.builds.update({'_id':build}, {'$set':changes}) track.updates.save({'build': build, 'action' : 'new build information'})
def store_installer_status_report(dut, reason='unknown'): """Make a status report using the installer""" build_doc = mongodb.get_autotest().builds.find_one( {'branch':'master'}, sort=[('build_time', mongodb.DESCENDING)]) print 'STATUS_REPORT: chose installer of %(_id)s on %(branch)s' % build_doc default_build = str(build_doc['_id']) print 'STATUS_REPORT: getting installer status report reason', reason set_pxe_build(dut, default_build, 'ssh') power_cycle(dut, pxe=True) wait_to_come_up(dut, timeout=600) print 'STAUTS_REPORT: connected to port 22' return store_status_report( dut, port=22, command='status-report', reason=reason, try_installer=False, label='-installer')
def get_power_control_type(dut): """Get power control type for dut""" if dut == 'blinkenlights': # for debugging, without having to define a spurious semihost in the hosts table return 'snmp-apc:flipper:8' mdb = get_autotest() dutdoc = mdb.duts.find_one({'name':dut}) if dutdoc is None: raise UnknownMachine(dut) if dutdoc.get('power_control') is None: mdb.duts.update( {'name':dut}, {'$set':{'power_control': DEFAULT_POWER_CONTROL}}, upset=True) dutdoc = mdb.duts.find_one({'name':dut}) return dutdoc['power_control']
def __enter__(self): """Start recording a test""" try: run(['logger', 'BVT', 'starting', self.full_description()], host=self.dut, timeout=2) except SubprocessError: print 'INFO: unable to mark test log' if not self.record: return self if self.result_id is None: self.mdb = get_autotest() terms = {'test_case':self.description or 'to be determined', 'automation_user': getpwuid(getuid()).pw_gecos.split(',')[0], 'control_pid' : getpid(), 'start_time' : time(), 'development_mode' : 0, 'command_line':abbreviate(' '.join(sys.argv))} if self.dut: dutdoc = self.mdb.duts.find_one({'name':self.dut}) self.dut_id = terms['dut'] = dutdoc['_id'] terms['dut_name'] = dutdoc['name'] if 'development_mode' in dutdoc: terms['development_mode'] = dutdoc['development_mode'] self.result_id = self.mdb.results.save(terms) if self.build is None and self.dut: self.build = get_build(self.dut, timeout=10) self.mdb.results.update({'_id':self.result_id}, {'$set':{'build':self.build}}) if self.dut: self.mdb.duts.update({'_id':terms['dut']}, {'$set': { 'build':self.build, 'control_command_line': abbreviate(' '.join(sys.argv)), 'result_id' : self.result_id}}) if self.stdout_filter: self.record_queue = Queue() self.stream_process = Process( target=service_queue, args=[self.record_queue, self.result_id, self.dut, self.dut_id]) self.stream_process.start() self.stdout_filter.add_callback(self, lambda *x: self.record_queue.put(x)) if self.description: print 'HEADLINE: starting', self.full_description() get_track().updates.save({'result_id':self.result_id, 'action':'new result record'}) return self
def control_automation(machines, automate=1): """Implement automation changes""" mongo = mongodb.get_autotest() for host in machines: existing = mongo.duts.find_one({'name': host}) set_update = {'run_bvt': 1} if existing is None or existing.get('control_machine') is None: set_update['control_machine'] = socket.gethostname() update = { '$set': set_update } if automate else { '$unset': { 'run_bvt': True } } if existing is None: mongo.duts.insert({'name': host}) mongo.dut_changes.save({ 'dut': host, 'hostname': gethostname(), 'user': getuser(), 'uid': getuid(), 'epoch': time(), 'localtime': asctime(localtime()), 'dut_record_before': mongo.duts.find_one({'name': host}), 'pid': getpid(), 'run_bvt': 1 if automate else 0 }) mongo.duts.update({'name': host}, update, upsert=True) if not automate: print 'cleared PXE automation for', host set_pxe_build(host, action='boot') else: print 'leaving PXE automation for', host, 'alone'
def recount(build, verbose=True): """Update counts in build record""" mdb = get_autotest() existing = mdb.builds.find_one({'_id':build}) if existing is None: existing = dict() specimens = existing.get('failure_specimens', dict()) if type(specimens) == type([]): specimens = {} ignored = {} cases = 0 for test in mdb.test_cases.find(): if test.get('ignored_for_completion_count'): ignored[test['description']] = True else: cases += 1 counts = {'passes':0, 'failures':0, 'in_progress':0, 'infrastructure_problems':0} covered = {} for result in mdb.results.find({'build':build, 'development_mode':0}): testcase = result.get('test_case') infra = False code = categorise(result) if code in ['in_progress', 'passes']: pass elif code == 'infrastructure_problems': if testcase in specimens and result['_id'] == specimens[testcase]['_id']: del specimens[testcase] infra = True else: code = 'failures' if testcase and (testcase not in specimens or specimens[testcase]['_id'] == result['_id']): specimens[testcase] = result if testcase not in ignored and not infra: covered[testcase] = True counts[code] += 1 counts['run_cases'] = len(covered) counts['total_cases'] = cases set_build_information(build, {'tests': counts, 'failure_specimens':specimens}) if verbose: print 'RECOUNT: count for', build, counts, len(specimens)
def futile(dut, guest, os_name, build, domlist): """Would it be futile to accelerate graphics?""" if not (os_name.startswith('win') or os_name=='xp'): return os_name+' is not supported for accelerate graphics (has to start "win")' mdb = get_autotest() dut_doc = mdb.duts.find_one({'name': dut}) supported = dut_doc.get('platform') in PVM_PLATFORMS print 'ACCELERATE_GRAPHICS:', dut_doc.get('platform'), 'is', \ 'SUPPORTED' if supported else 'UNSUPPORTED', 'for PVMs' if not supported: return 'platform %r not supported (only %r supported)' % ( dut_doc.get('platform'), PVM_PLATFORMS) for dom in domlist: print 'ACCELERATE_GRAPHICS: consider domain', dom if tools_install_problems(dut, dom['name']): return 'tools install problems in '+dom['name'] try: if have_accelerated_graphics(dut, dom['name'], timeout=5): return dom['name'] + " already has accelerated graphics" except Exception, exc: print 'ACCELERATE_GRAPHICS: Unable to determine accelerated graphics state on', dom
def service_queue(queue, result_id, dut, dut_id): """Runs in a subprocess to push stdout updates to database""" mdb = get_autotest() ldb = get_logging() count = 0 while 1: mesg =queue.get() if mesg == 'finish': print >>sys.stderr, '[logged %d lines to %s for %s]' % ( count, result_id, dut) break (ts, kind, message) = mesg count += 1 if type(message) ==type(''): message = unicode(message, encoding='utf8') if type(kind) == type(''): kind = unicode(kind, encoding = 'utf8') handle = '%s_%d_%f_%s' % (dut if dut else dut_id, count, ts, HOSTNAME) terms = {'message':message, 'kind': kind, 'time': ts, '_id': handle} if dut_id: terms['dut_id'] = dut_id if dut: terms['dut_name'] = dut if result_id: terms['result_id'] = result_id if kind in ['HEADLINE', 'RESULT'] and result_id and dut: rdoc = mdb.results.find_one({'_id':result_id}) if rdoc: build = rdoc.get('build') if build: set_build_information(build, {'test_status': [ts, dut, message]}) else: print 'no build for headline' else: print 'no result for headline' ldb.logs.save(terms)
def control_automation(machines, automate=1): """Implement automation changes""" mongo = mongodb.get_autotest() for host in machines: existing = mongo.duts.find_one({'name':host}) set_update = {'run_bvt':1} if existing is None or existing.get('control_machine') is None: set_update['control_machine'] = socket.gethostname() update = {'$set': set_update} if automate else { '$unset': {'run_bvt':True}} if existing is None: mongo.duts.insert({'name':host}) mongo.dut_changes.save( {'dut':host, 'hostname':gethostname(), 'user': getuser(), 'uid': getuid(), 'epoch': time(), 'localtime':asctime(localtime()), 'dut_record_before': mongo.duts.find_one({'name':host}), 'pid': getpid(), 'run_bvt':1 if automate else 0}) mongo.duts.update({'name':host}, update, upsert=True) if not automate: print 'cleared PXE automation for', host set_pxe_build(host, action='boot') else: print 'leaving PXE automation for', host, 'alone'
def validate_dut_name(dut): """Check dut is a valid test device name""" mdb = mongodb.get_autotest() if mdb.duts.find_one({'name':dut}) is None: try: run(['host', dut], timeout=2) except SubprocessError: print 'ERROR: unable to determine DNS record for DUT ' + \ dut + '; did you spell it right?' exit(1) else: print 'INFO: confirmed DNS record for', dut mdb.duts.save({'name':dut, '_id':dut}) dut_document = mdb.duts.find_one({'name':dut}) if dut_document.get('mem') is None: try: out = run(['xenops', 'physinfo'], host=dut, split=True) for spl in out: if spl[:1] == ['total_pages'] and len(spl) == 5: upd = {'$set' : {'mem':int(spl[-2][1:])}} mdb.duts.update({'name':dut}, upd) except SubprocessError, exc: print 'WARNING: unable to discover memory in', dut, exc
def set_experiment_install_flag(dut, value): """Set write flag for machine named dut""" mongodb.get_autotest().duts.update({'name':dut}, {'$set':{'write':value}})
# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # from bvtlib import mongodb db = mongodb.get_autotest() class Point: def __init__(self, build, time): self.build = build self.time = time self.values = [] def getaverage(self): return sum(self.values, 0.0) / len(self.values) average = property(getaverage) def __cmp__(self, other): return cmp(self.time, other.time)
def main(): parser = optparse.OptionParser( 'find_log [options]\n\nfinds autotest_number values for recent tests\n') parser.add_option('-b', '--build', action='store_true', help = 'Show build name') parser.add_option('-s', '--status', action='store_true', help = 'Show status field') parser.add_option('-m', '--machine', action='store_true', help = 'Show machine field') parser.add_option('--model', action='store_true', help = 'Show model field') parser.add_option('-t', '--timestamps', action='store_true', help = 'Show start time of tests') parser.add_option('-c', '--test-case', action='store_true', help = 'Show test case') parser.add_option('-F', '--failure-regexp', action='store', default = [], metavar='REGEXP', help = 'Show cases where failure contains REGEXP') parser.add_option('-M', '--machine-name', action='append', default = [], metavar='DUT', help = 'Show cases on DUT') parser.add_option('-N', '--negative', action='store_true', help = 'Show only tests that failed') parser.add_option('-U', '--uninvestigated', action='store_true', help = 'Show only uninvestigated failures, i.e. ' 'where there is no whiteboard entry') parser.add_option('-C', '--test-case-regexp',action='store',default=[], help = 'Show only tests where test cases matches REGEXP', metavar='REGEXP') parser.add_option('-S', '--log-regexp', action='store', default=[], help = 'Show only tests with log entries ' ' where REGEXP can be found', metavar='REGEXP') parser.add_option('-L', '--limit', action='store', metavar='N', default=20, help = 'Show at most N tests (default 20)') parser.add_option('-u', '--unformatted-output', action='store_true', help='Disable formatting') options, args = parser.parse_args() query = {'test_case': {'$exists':True}} if options.uninvestigated: query['whiteboard'] = {'$exists':True} if options.negative or options.uninvestigated: query['failure'] = {'$exists':True} if options.failure_regexp: query['failure'] = {'$regex': options.failure_regexp} if options.test_case_regexp: query['test_case'] = {'$regex': options.failure_regexp} if options.machine_name: query['dut'] = {'$in': options.machine_name } i = 0 lines = [] mdb = mongodb.get_autotest() try: for row in mdb.results.find(query, sort=[('start_time', mongodb.DESCENDING)], limit=int(options.limit)): if options.log_regexp: if mdb.logs.find_one( { 'result_id':row['_id'], 'message': {'$regex': options.log_regexp}}) is None: continue line = [] line.append(str(row['_id'])) if options.timestamps: line.append( time.asctime(time.localtime(row['start_time']))) if options.machine: line.append( row.get('dut') or '[unknown dut]') if options.model: line.append( row.get('model')) if options.test_case: line.append( row['test_case'] or '[unknown case]') if options.build: line.append( row['build'] or '[unknown buid]') f = row.get('failure') if options.status: if row.get('end_time') and not f: line.append('PASS') elif f: line.append('FAILED %r ' % f) else: line.append('RUNNING') i += 1 if options.unformatted_output: print ' '.join(str(x) for x in line) else: lines.append(line) if len(line) == 1: print line[0] if options.limit != '-' and i == int(options.limit): break except IOError, e: print 'IO error',e if 'Broken pipe' in repr(e): return else: raise
def do_iteration(i, options): """Do one iteration of the test loop""" mdb = mongodb.get_autotest() set_experiment_install_flag(options.machine, (options.install_first or not options.soak_power_level) and (i == 1)) dutdoc = mdb.duts.find_one({'name':options.machine}) write = (dutdoc if dutdoc else {}).get('write') test_parameters = { 'dut':options.machine, 'record': options.record, 'status_report_mode': STATUS_REPORTS_ALWAYS if options.diagnostic_status_report else STATUS_REPORTS_NEVER, 'stash_guests' : options.guest, 'verbose' : options.verbose, 'stash_on_failure' : options.stash_on_failure, 'reinstall_on_failure' : options.reinstall_on_failure} def trigger_tests(condition, guest=None): """Trigger test cases matching condition for guest""" for test_case in test_cases.TEST_CASES: if test_case.get('trigger') == condition: run_test(test_parameters, test_case, options, guest) trigger_tests('first') if write: trigger_tests('platform install') trigger_tests('build ready') trigger_tests('soakup') ############# x = 0 trace = [] if(not options.test_suite): signal.signal(signal.SIGINT, signal_handler) print 'Press Ctrl-C to stop' while(1): trace.append(x) #testFinder.getTag(x)) trigger_tests(str(x)) x = random.randint(1, 102) #testGraph.randF(x, 0) else: if mongodb.get_autotest().status.find_one({'name':options.machine}): print '\n\n','-'*10,'Found a saved test state for your machine, Do you want to continue','-'*10 while 1: input = raw_input("yes/no: ") if input in 'yes': break elif input in 'no': return saved = mongodb.get_autotest().status.find_one({'name':options.machine},{'steps':1,'_id':0}) list = saved['steps'] else: list = testFinder.keyde(int(options.test_suite)) print list mongodb.get_autotest().status.insert({'name':options.machine, 'steps':list}) listTemp = list[:] for i in list: print "running test ",i trigger_tests(i) #testFinder.getkey(int(i)).func_name) listTemp.pop(0) mongodb.get_autotest().status.update({'name':options.machine},{'$set':{'steps':listTemp}}) mongodb.get_autotest().status.remove({'name':options.machine}) ############ for guest in options.guest if options.guest else []: try: find_domain(options.machine, guest) have_domain = True except CannotFindDomain: have_domain = False print 'check for domain', guest, 'returned', have_domain write_guest = write or not have_domain if write_guest: trigger_tests('VM install', guest) domain = find_domain(options.machine, guest) if domain['status'] == 'stopped': run(['xec-vm', '-n', domain['name'], 'start'], host=options.machine, timeout=600) if write_guest: trigger_tests('VM configure', guest) trigger_tests('VM accelerate', guest) trigger_tests('VM ready', guest) trigger_tests('soakdown')
def update_dut_records(verbose=False): """Contact DHCP servers""" print 'UPDATE_DUT_RECORDS: starting' mdb = get_autotest() duts = mdb.duts.find() dutmap = dict([ (dut['name'], dut) for dut in duts if 'name' in dut]) leases = dhcp_leases() print 'UPDATE_DUT_RECORDS: considering', len(leases), 'leases' for (mac, _, _, name) in dhcp_leases(): def read(path, lsplit=True): """read path with in assets system""" filename = ASSETS_BY_MAC % (mac.upper(), path) content = file(filename, 'r').readlines() if not lsplit: return content return [line.split() for line in content] lname = name.split('.')[0] if name else None if lname not in dutmap: continue updates = {'mac_address' : mac.upper(), 'name' : lname} try: symlink = readlink(MAC_LINKS+'/'+mac) except OSError: pass else: asset_id = symlink.split('/')[-1] if match('[0-9a-f]{8}', asset_id): updates['asset_id'] = asset_id if 'development_mode' not in dutmap[lname]: updates['development_mode'] = 0 try: lshw = read('lshw/lshw.txt') except IOError: pass else: updates['model'] = ' '.join(lshw[2][1:]) updates['make'] = ' '.join(lshw[3][1:]) try: lspci = read('lspci/lspci.txt', lsplit=False) except IOError: pass else: for line in lspci: if line.startswith('00:02.0'): m = search(r'\[([0-9a-f]{4}):(([0-9a-f]{4}))', line) if m: vid, pid = m.group(1), m.group(2) platform = None if vid == '8086': if pid == '0126': platform = 'Huron River' if pid == '0046': platform = 'Calpella' if pid == '2a42': platform = 'Montevina' if platform: updates['platform' ] = platform else: print 'ERROR:', lname, 'unrecognised', vid, pid else: print 'ERROR:', lname, 'could not find VID/PID' try: meminfo = read('meminfo/meminfo.txt') except IOError: pass else: updates['memory'] = int(meminfo[0][1]) * 1024 if verbose: print 'for', lname, 'set', updates mdb.duts.update({'name':lname}, {'$set':updates}) dutdocs = list(mdb.duts.find()) print 'UPDATE_DUT_RECORDS: considering', len(dutdocs), 'docs' for dutdoc in dutdocs: if 'asset_id' not in dutdoc: if verbose: print 'no asset ID for', dutdoc['name'], dutdoc['_id'] continue if dutdoc['asset_id'] == dutdoc['_id']: if verbose: print 'asset ID correct for', dutdoc['name'], dutdoc['asset_id'] continue results = mdb.results.find({'dut':dutdoc['_id']}).count() print 'WARNING: should migrate', dutdoc['name'], 'to asset ID', \ dutdoc['asset_id'], 'and', results, 'results' if mdb.duts.find_one({'_id': dutdoc['asset_id']}) is None: dutdocid = dict(dutdoc, _id = dutdoc['asset_id']) mdb.duts.save(dutdocid) print 'created dut record by ID' mdb.duts.remove({'_id': dutdoc['_id']}) mdb.results.update({'dut': dutdoc['_id']}, {'$set': {'dut': dutdoc['asset_id'], 'dut_name' : dutdoc['name']}}, multi=True)
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # from pprint import pprint from bvtlib.mongodb import get_autotest, DESCENDING from sys import stderr from bvtlib.process_result import process_result from time import asctime, localtime MDB = get_autotest() import argparse from pymongo.objectid import ObjectId results = 0 kinds = {} query = {} parser = argparse.ArgumentParser(description="Reclassify results") parser.add_argument('indices', nargs='*', metavar='ID', help='Specifically process ID') parser.add_argument('-v', '--verbose', action='store_true', help='Show actions')
def set_experiment_install_flag(dut, value): """Set write flag for machine named dut""" try: mongodb.get_autotest().duts.update({'name':dut}, {'$set':{'write':value}}) except NoMongoHost: print 'NOTE: no mongodb so not setting install flag'
"""Show duts""" from django.shortcuts import render_to_response from django.template import RequestContext from bvtlib.mongodb import get_autotest from pymongo import DESCENDING, ASCENDING from serverlib.tags import html_fragment, td, a, \ stan_input, div, h2, ol, li, tr, form, em, pre from serverlib.show_table import produce_table from serverlib.constraints import cross_reference, parse from time import localtime, strftime, mktime, time from django.core.context_processors import csrf from subprocess import Popen, PIPE from os import getuid from pwd import getpwuid from bvtlib.set_pxe_build import set_pxe_build CONNECTION = get_autotest() INSTRUCTIONS = [ h2['XenClient test laptop control'], ol[li['To allocate yourself a laptop: type your email address ', 'in to the owner column and hit change.'], li['To release a laptop for scheduled tests and BVT: ', 'clear the owner column and hit change.'], li['Automated test reports only include experiments ', 'done on laptops where the publish is ticked.'], li['The right hand side of the page shows how many ' 'automated tes got run recently.'], li['Asset ID and MAC address are available as a tooltip ', 'on the dut name']]] def model(max_age):
def get_tag_regexp(dut): """Return the list of branches that dut should test""" mdb = mongodb.get_autotest() dutdoc = mdb.duts.find_one({'name':dut}) return dutdoc.get('tag_regexp', DEFAULT_TAG_REGEXP)
def main(): parser = optparse.OptionParser( 'usage: cat_log [options] result_guid [result_guid...]\n' '\n' '\n autotest_number values can be obtained from find_log or the\n' 'web interface.\n') parser.add_option('-k', '--kind', metavar='KIND', action='append', default=[], help='Show log entries with class substring KIND ' '(case insensitve)') parser.add_option('-a', '--all', action='store_true', help='Show log entries with all classes ' '(implicit if -k unused)') parser.add_option('-s', '--substring', action='append', metavar='SUBSTRING', help='Show log entries containing SUBSTRING') parser.add_option('-e', '--eliminate-substrings', action='store_true', help=' Eliminate substrings specified by --substring ' 'from the output') parser.add_option('-t', '--timestamps', action='store_true', help='Show timestamps') parser.add_option('-d', '--delta', action='store_true', help='Show time deltas') parser.add_option('-A', '--after', action='store', metavar='N', help='Show N lines after each matching line') parser.add_option('-B', '--before', action='store', metavar='N', help='Show N lines before each matching line') parser.add_option('-F', '--format', action='store_true', help='Tabulate output (involves two passes)') parser.add_option('-f', '--follow', action='store_true', help='Follow mode; wait for new output') parser.add_option('-n', '--lines', action='store', metavar='N', help='Show only the last N lines of output') parser.add_option('--summary', action='store_true', help='Show only HEADLINES, INFO and RESULTS if ' 'no kinds are specified, and show deltas ' '(implied by ' 'running this program with a name containing ' 'the text "summary")') options, args = parser.parse_args() if len(args) == 0: parser.error('supply at least one autotest_number') before = int(options.before) if options.before else 0 after = int(options.after) if options.after else 0 if options.summary or 'summary' in sys.argv[0]: options.delta = True options.format = True if options.kind == []: options.kind = ['HEADLINE', 'INFO', 'RESULT'] if options.all or options.kind == []: kindf = [] else: kindf = [ '(' + ' OR '.join("kind LIKE '%%%s%%'" % (kind.upper()) for kind in options.kind) + ')' ] if options.substring: kindf.append('(' + ' OR '.join("message LIKE '%s'" % ('%' + subs + '%') for subs in options.substring) + ')') db = mongodb.get_autotest() db.logs.ensure_index([('result_id', ASCENDING)]) acc = [] latest_shown = {} errors = 0 while True: for arg in args: result_doc = db.results.find_one( {'_id': pymongo.objectid.ObjectId(arg)}) if result_doc is None: print 'ERROR: could not find result', arg errors += 1 continue result_id = result_doc['_id'] covered = 0 lshown = latest_shown.get(arg, 0) kindf2 = kindf + ['time>' + str(lshown)] spec = {'result_id': result_id} if options.kind: spec['kind'] = {'$in': options.kind} cursor = db.logs.find(spec, max_scan=1000000) if options.lines: cursor2 = cursor.limit(options.lines) else: cursor2 = cursor.limit(100000) results = list(cursor2) if options.lines: results.reverse() base_time = min(row['time'] for row in results) if results else 0 for row in results: covered, lines = show_lines(db, row, before, after, options, covered, base_time, result_id) latest_shown[arg] = max(latest_shown.get(arg, 0), row['time']) if not options.format: for line in lines: print ' '.join(line) else: acc += lines if not options.follow: break time.sleep(1) text_table.text_table(acc) sys.exit(errors)
# """Show scheduler queue and manipulate it""" from serverlib.tags import html_fragment, h2, form, stan_input, span from serverlib.tags import select, option, a, div, em from bvtlib import mongodb from serverlib import show_table from django.shortcuts import render_to_response from django.template import RequestContext from serverlib.constraints import cross_reference from time import time, asctime, gmtime from django.core.context_processors import csrf from re import match from pymongo.objectid import ObjectId from pymongo import ASCENDING, DESCENDING CONNECTION = mongodb.get_autotest() def scheduler(request): """Render HTML""" def myform(text, *members): """Return an HTML POST form back to this page with CSRF support""" tok = csrf(request) return form(method='post', action='/scheduler')[ stan_input(type='hidden', name='operation', value=text), stan_input(type='hidden', name='csrftoken', value=tok), list(members), stan_input(type='submit', value=text)] post_message = None if request.method == 'POST': operation = request.POST['operation'] if operation == 'cancel': row = request.POST['id']
def pxe_install_xc(dut, build=None, release=None, watch_tftp=None, upgrade=False, mac_address=None): """PXE install build on dut""" print 'HEADLINE:', 'upgrading' if upgrade else 'installing', \ release or build, 'XT on', dut if watch_tftp is None: watch_tftp = 'autotest' in gethostname() if isdir(build): repository_directory = build+'/repository' else: build_info = select_build(build, release) netboot, variant = select_variant(build_info) repository_directory = build_info['build_directory']+'/repository' if variant == 'kent': repository_directory += '-kent' print 'INFO: bi=', build_info, repository_directory with TemporaryWebServer(path=repository_directory) as web: out = urlopen(web.url+'/packages.main/XC-PACKAGES').read() print 'INFO: XC-PACKAGES is', repr(out) target_build_info = set_pxe_build(dut, build=build, release=release, action='upgrade' if upgrade else 'install', mac_address=mac_address, build_url = web.url) print 'PXE_INSTALL: set PXE server' if upgrade: try: platform_transition(dut, 'reboot') except SubprocessError: print 'HEADLINE: unable to contact', dut, 'to do clean shutodwn' else: wait_to_go_down(dut) power_cycle(dut, pxe=True) process = Process(target=watch, args=(dut, '/var/log/installer')) process.start() try: print 'PXE_INSTALL: waiting to come up in installer' wait_to_come_up(dut, installer_okay=True, timeout=600) if not is_installer_running(dut, timeout=60): raise PlatformCameUpInsteadOfInstaller(dut) print 'HEADLINE: SSH response from installer' set_pxe_build(dut, action='boot') print 'INFO: set PXE back to default' wait_to_come_up(dut, installer_okay=False, timeout=3600) print 'INFO: response from', dut if not isdir(build): found = get_build_number_branch(dut, timeout=3600) else: found = True finally: process.terminate() if found == True: pass elif found: bn, br= found print 'PXE_INSTALL:', dut, 'now has', bn, br, 'installed' tag = build if build else (target_build_info['tag'] if target_build_info and target_build_info.get('tag') else None) if tag and (bn not in tag or br not in tag): raise UnexpectedInstallAfterInstallation( 'found=', bn, br, 'wanted=', build, 'on', dut) else: raise UnableToContactAfterInstallation('wanted=',build,'on',dut) print 'HEADLINE: succesfully', 'upgraded' if upgrade else 'installed', \ (release or build), 'on', dut get_autotest().duts.update({'name':dut}, {'$unset': {'test_failed':1}})
def experiments(): """Run test cases""" parser = OptionParser() parser.add_option( '-v', '--verbose', action='store_true', help='Show all logging on stdout') parser.add_option( '-m', '--machine', metavar='MACHINE', help='Do test on MACHINE (e.g. kermit)') parser.add_option( '-g', '--guest', metavar='GUEST',action='append', help='Test vm GUEST (e.g. win7 or vista or xp). ' 'Optionally you may specify ' 'a name for the VM like this win7:fish xp:soup.') for test_case in test_cases.TEST_CASES: optlist = test_case.get('command_line_options') if optlist: parser.add_option(*optlist, **{'action' : 'store_true', 'help':test_case['description']}) store_list = test_case.get('store_list') if store_list: parser.add_option(*store_list, **{'action' : 'store', 'help':test_case['description']}) parser.add_option( '-b', '--build', action='store', help='Have --xen-client install BUILD', metavar='BUILD') parser.add_option( '-B', '--branch', action='store', help='Have --xen-client install BRANCH. Ignored if ' 'build specified with --build', metavar='BRANCH') parser.add_option( '-n', '--network-test', action='store_true', help='Do some quick network traffic tests') parser.add_option( '-l', '--loop', action='store_true', help='Repeat until failure') parser.add_option( '-c','--loop-iterations', metavar='NUMBER', help='Stop test loop after NUMBER iterations') parser.add_option( '--reboot', action='store', help='Enable reboot loop for N hours', metavar='N') parser.add_option( '--soak-power-level', action='append', metavar='LEVEL', help='Do soak test involving transition to LEVEL (e.g. s3)') parser.add_option( '--read-test', action='store_true', help='Do a read test when installing VHDs') parser.add_option( '--private', action='store_true', help='Do not store result and logs in autotest databases [default!]') parser.add_option( '-r', '--record', action='store_true', help='Store records in database') parser.add_option( '--synchronizer-name', action='store', help='Name of Synchronizer host to run tests against') parser.add_option( '--xcbe-version', action='store', help='X-XCBE-version header to send to Synchronizer') parser.add_option('-S', '--stash-on-failure', action='store_true', help='Stash away VHDs on failure') parser.add_option('-R', '--reinstall-on-failure', action='store_true', help='Reinstall after stress test failures') parser.add_option('-F', '--install-first', action='store_true', help='Install at start, even for stress tests. ' 'For non-stress tests (i.e. -s not specified) this is ' 'standard behaviour so this option has no effect.') parser.add_option('--do-not-detect-build', action='store_true', help='Do not detect the build') parser.add_option('--xen-server', action='store', metavar='SERVER', help='Activate xen server') parser.add_option('-s', '--source-directory', action='store', metavar='DIRECTORY', help='Assume extra source code for testing is ' 'in DIRECTORY') parser.add_option('-D', '--debugger-on-failure', action='store_true', help="Start PDB if a test failure occurs") parser.add_option('-E', '--encrypt-vhd', action='store_true', help='Create encrypted VHD files during OS ' 'install from ISO') parser.add_option( '--ts', action='store', dest='test_suite', help='Runs a test suite') parser.add_option( '--vm', action='store', dest='vmlist', help='List of VMs under test') parser.add_option( '--block', action='store', dest='teststeps', help='List of test steps') parser.add_option( '--step', action='store', dest='testpath', help='Name of the step to be run for debugging') parser.add_option( '--build_list', action='store', dest='buildlist', help='Build from which upgrade needs to be done') parser.add_option( '--upgrade_to', action='store', dest='upgradeto', help='Build to which upgrade needs to be done') parser.add_option( '--list', action='store_true', help='Display test flow') parser.add_option( '--listall', action='store_true', help='Display test flow') parser.add_option( '--clean', action='store_true', help='Reset saved state of the test') parser.add_option( '--ff', action='store', dest='ff', help='Fast Forward') options, args = parser.parse_args() if args and options.machine is None: options.machine = args[0] args = args[1:] if options.build is None: branch = options.branch or 'master' query = {'branch':branch} if options.install_xen_client or options.upgrade_xt or \ options.install_xt: build_doc = mongodb.get_autotest().builds.find_one( query, sort=[('build_time', mongodb.DESCENDING)]) print 'HEADLINE: chose %(_id)s on %(branch)s' % build_doc options.build = str(build_doc['_id']) assert branch == build_doc['branch'] if options.listall: count = mongodb.get_autotest().ts_cases.count() print count for i in range(1,count): temp = mongodb.get_autotest().ts_cases.find_one({'_id':str(i)}) print temp return if options.test_suite: if not(options.testpath): options.testpath = 'all' #else:test_path = options.testpath if (options.test_suite == 'list'): print '='*90 print "Avaliable test suits are" print '-'*90 print " install :- Installs build, VM and XC tools" print " upgrade :- Tests XC upgrade" print " smoke :- Smoke tests (only power operations)" print " lifecycle_win7x64_install :- VM lifecycle install tests for Win7x64" print " lifecycle_win7x64_powerops :- VM lifecycle power tests on Win7x64" print " lifecycle_win7x32_install :- VM lifecycle install tests for Win7x32" print " lifecycle_win7x32_powerops :- VM lifecycle power tests on Win7x32" print " lifecycle_vista_install :- VM lifecycle install tests for Vista" print " lifecycle_vista_powerops :- VM lifecycle power tests on Vista" print " lifecycle_xp_install :- VM lifecycle install tests for XP" print " lifecycle_xp_powerops :- VM lifecycle power tests on XP" print " power_management :- Power management test cases" print " gruboptions :- Tests different grub options" print "\n XT Test cases" print '-'*90 print " XT-ALL :- Run all test cases(excluding XT-install)" print " XT-install :- Install VM on encrypted VHD" print " XT-TPM :- TPM test cases" print " XT-selinux :- Selinux test cases" print " XT-autoboot :- Setting VM autoboot" print " XT-audio :- Audio policies" print " XT-USB :- USB pass through" print " XT-policies :- XT policies" print " XT-resetOnBoot :- Reset VM on boot" print " XT-nilfvm :- NILFVM testcases" print " XT-viptables :- vip tables" print " XT-attach-stubdom :- Attach stubdom to test VM" print " XT-detach-stubdom :- Detach stubdom from test VM" print " XT-powerops :- Host SVM power operations" print " XT-3Dpowerops :- Host PVM power operations" print '.'*90 print "steps :--- Run with --block <x,y> to block steps x & y" print " vm_force_shutdown, vm_hibernate, vm_shutdown, vm_sleep, vm_reboot" print " host_hibernate, host_sleep, host_reboot, host_shutdown" print '='*90 return elif options.test_suite == 'install': options.test_suite = '1002003' elif options.test_suite == 'upgrade': print "Tests are not ready, Exiting..." return elif options.test_suite == 'smoke': options.test_suite = '004005006007008009010011012013014015016' elif options.test_suite == 'lifecycle_win7x64_install': options.test_suite = '020021' elif options.test_suite == 'lifecycle_win7x64_powerops': options.test_suite = '023024025026027028029030031032033034' elif options.test_suite == 'lifecycle_win7x32_install': options.test_suite = '036037' elif options.test_suite == 'lifecycle_win7x32_powerops': options.test_suite = '038040041042043044045046047048049050' elif options.test_suite == 'lifecycle_vista_install': options.test_suite = '054055' elif options.test_suite == 'lifecycle_vista_powerops': options.test_suite = '056057058059060061062063064065066067068' elif options.test_suite == 'lifecycle_xp_install': options.test_suite = '072073' elif options.test_suite == 'lifecycle_xp_powerops': options.test_suite = '074075076077078079080081082083084085086' elif options.test_suite == 'power_management': options.test_suite = '089090091092093094095096097098099100101102' elif options.test_suite == 'gruboptions': print "Tests are not ready, Exiting..." return ###XT# elif options.test_suite == 'XT-install': options.test_suite = '104' elif options.test_suite == 'XT-TPM': options.test_suite = '106107108' elif options.test_suite == 'XT-selinux': options.test_suite = '112113' elif options.test_suite == 'XT-autoboot': options.test_suite = '115' elif options.test_suite == 'XT-audio': options.test_suite = '118117' elif options.test_suite == 'XT-USB': options.test_suite = '119' elif options.test_suite == 'XT-policies': options.test_suite = '120' elif options.test_suite == 'XT-resetOnBoot': options.test_suite = '122' elif options.test_suite == 'XT-nilfvm': options.test_suite = '125127' elif options.test_suite == 'XT-viptables': options.test_suite = '129130' elif options.test_suite == 'XT-attach-stubdom': options.test_suite = '131' elif options.test_suite == 'XT-powerops': options.test_suite = '109' elif options.test_suite == 'XT-3Dpowerops': options.test_suite = '110' elif options.test_suite == 'XT-detach-stubdom': options.test_suite = '132' ###XT# elif int(options.test_suite) not in range(1,800): print "**** Test suite does not exist ****" if options.clean: mongodb.get_autotest().status.remove({'name':options.machine}) return if options.ff: saved = mongodb.get_autotest().status.find_one({'name':options.machine},{'steps':1,'_id':0}) if saved: list = saved['steps'] else: list = testFinder.keyde(int(options.test_suite)) mongodb.get_autotest().status.insert({'name':options.machine, 'steps':list}) for j in range(0, int(options.ff)): list.pop(0) mongodb.get_autotest().status.update({'name':options.machine},{'$set':{'steps':list}}) return if options.list: saved = mongodb.get_autotest().status.find_one({'name':options.machine},{'steps':1,'_id':0}) if saved: list = saved['steps'] else: list = testFinder.keyde(int(options.test_suite)) for i in list: temp = mongodb.get_autotest().ts_cases.find_one({'_id':i}) print temp['description'] return os.system('ssh-copy-id -i /root/.ssh/id_rsa.pub '+options.machine) if args and options.machine is None: options.machine = args[0] args = args[1:] if options.teststeps is None: options.teststeps = 'nil' if options.machine: validate_dut_name(options.machine) top_loop(options)
# Copyright (c) 2011 Citrix Systems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # from bvtlib.mongodb import get_autotest db = get_autotest() # The boot_time "time" field stores the time of the build, not the time of the measure for sample in db.boot_time.find(): time = db.builds.find_one({'_id': sample['build']})['tag_time'] db.boot_time.update({'_id':sample['_id']}, {'$set': {"time":time}}) # The "counts" collection are no longer used for collection in db.collection_names(): if collection.startswith('counts'): db[collection].drop()
# Copyright (c) 2011 Citrix Systems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # from bvtlib.mongodb import get_autotest db = get_autotest() # The boot_time "time" field stores the time of the build, not the time of the measure for sample in db.boot_time.find(): time = db.builds.find_one({'_id': sample['build']})['tag_time'] db.boot_time.update({'_id': sample['_id']}, {'$set': {"time": time}}) # The "counts" collection are no longer used for collection in db.collection_names(): if collection.startswith('counts'): db[collection].drop()
def launch(): """entry point""" parser = OptionParser() parser.add_option( '-m', '--machine', metavar='MACHINE', action='store', help='Do test on MACHINE (e.g. kermit)') parser.add_option( '-f','--force', action = 'store_true', help='Do test even if automate not set to 1 in duts ' 'table of resultsdb') parser.add_option( '-q', '--quieter', action='store_true', help='Do not write stuff going through the log system to stdout') parser.add_option( '-c', '--current-install', action='store_true', help='Use the current install; do not install a more recent build') parser.add_option('-p', '--pretend', action='store_true', help='Only work out what should be done; do not ' 'touch machine') parser.add_option('-v', '--verbose', action='store_true', help='Show all logging') parser.add_option('-l', '--loop', action='store_true', help='Run repeatedly until we get an exception') parser.add_option('-r', '--resume', action='store_true', help='In loop mode, resume after unhandled exception') parser.add_option('-g', '--disable-git-check', action='store_true', help='Disable the git check that exits the loop when the ' 'git version changes') parser.add_option('-t', '--test-case-regexp', action='store', metavar='REGEXP', help='Run only test cases matching REGEXP') parser.add_option('-s', '--source-directory', action='store', metavar='DIRECTORY', help='Assume extra source code for testing is ' 'in DIRECTORY') options, args = parser.parse_args() if options.machine is None: if len(args) == 1: options.machine = args[0] else: print 'ERROR: machine not specified' print 'HINT: specify something like --machine fozzie' exit(1) mdb = mongodb.get_autotest() dutdoc = mdb.duts.find_one({'name':options.machine}) if dutdoc is None: print 'ERROR: machine', dutdoc, 'not in database' print 'add it for instance by running experiments on it' exit(2) validate_dut_name(options.machine) if (dutdoc.get('run_bvt', 0) != 1 or dutdoc.get('control_machine') != gethostname()) and not options.force: why = '' if dutdoc.get('run_bvt', 0) != 1: why += 'disabled ' if dutdoc.get('control_machine') != gethostname(): why += 'machine=='+ dutdoc.get('control_machine') print 'ERROR: automation for', options.machine, why print 'HINT: use --force to proceed anyway' exit(1) version = get_version() while 1: try: one_operation(options) except Exception: if options.resume: time.sleep(60) else: raise if not options.loop: break nversion = get_version() if version != nversion and not options.disable_git_check: print 'HEADLINE: git version changed from', version, 'to', nversion, 'so exiting test loop' break else: print 'INFO: still running', nversion