def update_testrun__bad(db, filename_persist, testrun_props_by_candidate, snapshots_dir, snapshots_reference_dir=None): """ snapshots_reference_dir : dir to move snapshots; if None no move """ if snapshots_reference_dir: if not os.path.isdir(snapshots_dir): raise ValueError("snapshot dir not found or not a dir:%s" % snapshots_dir) if not os.path.exists(snapshots_reference_dir): os.makedirs(snapshots_reference_dir) checked_in, ignored, unknown = _update_testrun(db, testrun_props_by_candidate, snapshots_dir) move_failed = set() if snapshots_reference_dir: # move snapshots to reference dir for script in checked_in: snapshots = db.get_prop_value(script, "expected_snapshots") moved, cant_move = doers.move_files(snapshots, snapshots_dir, snapshots_reference_dir) if cant_move: move_failed.add(script) # update history text_1 = doers.pprint_to_string(checked_in) text_2 = doers.pprint_to_string(move_failed) text_3 = doers.pprint_to_string(unknown) text_history = "\n".join(["checked_in:", text_1, "move_failed:", text_2, "unknown:", text_3]) db.history_add("update_testrun__bad", text_history) if filename_persist: dbm.db_save(db, filename_persist) return checked_in, unknown, move_failed
def update_7(db, filename_persist): """add new tests""" text = """ test/test_schedule_interval.py : new, svn add done test/test_aspect_ratio_on_resize.py : new, svn add done """ candidates = doers.scripts_names_from_text(text, end_mark=":") hl.add_entities(db, filename_persist, candidates) db.history_add("added tests", text) dbm.db_save(db, filename_persist)
def update_10(db, filename_persist, snapshots_dir): """ delete this entities, they were added with wrong path""" text = """ tools/autotest/test/test_aspect_ratio_on_resize.py tools/autotest/test/test_schedule_interval.py tools/autotest/test_aspect_ratio_on_resize.py """ candidates = doers.scripts_names_from_text(text, end_mark=":") for name in candidates: db.del_entity(name) db.history_add("deleted unwanted entities", text) dbm.db_save(db, filename_persist)
def add_entities(db, filename_persist, targets): """Adds entities to the db 's default testbed :Parameters: `db` : remembercases.TestbedEntityPropDB `filename_persist` : filename used to persist the new db `names` : iterable yielding entity names """ for name in targets: db.add_entity(name) db.history_add('add_acripts','\n'.join(targets)) if filename_persist: dbm.db_save(db, filename_persist)
def add_entities(db, filename_persist, targets): """Adds entities to the db 's default testbed :Parameters: `db` : remembercases.TestbedEntityPropDB `filename_persist` : filename used to persist the new db `names` : iterable yielding entity names """ for name in targets: db.add_entity(name) db.history_add('add_acripts', '\n'.join(targets)) if filename_persist: dbm.db_save(db, filename_persist)
def update_testrun__pass(db, filename_persist, candidates, snapshots_dir, snapshots_reference_dir=None): """ snapshots_reference_dir : dir to move snapshots; if None no move """ if snapshots_reference_dir: if not os.path.isdir(snapshots_dir): raise ValueError("snapshot dir not found or not a dir:%s" % snapshots_dir) if not os.path.exists(snapshots_reference_dir): os.makedirs(snapshots_reference_dir) pass_dict = { 'testrun_success': 'pass', 'testrun_diagnostic': '', } testrun_props_by_candidate = dict([(k, pass_dict) for k in candidates]) checked_in, ignored, unknown = _update_testrun(db, testrun_props_by_candidate, snapshots_dir) move_failed = set() if snapshots_reference_dir: # move snapshots to reference dir for script in checked_in: snapshots = db.get_prop_value(script, 'expected_snapshots') moved, cant_move = doers.move_files(snapshots, snapshots_dir, snapshots_reference_dir) if cant_move: db.del_groupdict(script, 'testrun') move_failed.add(script) checked_in -= move_failed # update history text_1 = doers.pprint_to_string(checked_in) text_2 = doers.pprint_to_string(move_failed) text_3 = doers.pprint_to_string(unknown) text_history = '\n'.join( ["checked_in:", text_1, "move_failed:", text_2, "unknown:", text_3]) db.history_add("update_testrun__pass", text_history) if filename_persist: dbm.db_save(db, filename_persist) return checked_in, unknown, move_failed
def update_testrun__pass(db, filename_persist, candidates, snapshots_dir, snapshots_reference_dir=None): """ snapshots_reference_dir : dir to move snapshots; if None no move """ if snapshots_reference_dir: if not os.path.isdir(snapshots_dir): raise ValueError("snapshot dir not found or not a dir:%s"%snapshots_dir) if not os.path.exists(snapshots_reference_dir): os.makedirs(snapshots_reference_dir) pass_dict = { 'testrun_success': 'pass', 'testrun_diagnostic': '', } testrun_props_by_candidate = dict([(k, pass_dict) for k in candidates]) checked_in, ignored, unknown = _update_testrun(db, testrun_props_by_candidate, snapshots_dir) move_failed = set() if snapshots_reference_dir: # move snapshots to reference dir for script in checked_in: snapshots = db.get_prop_value(script, 'expected_snapshots') moved, cant_move = doers.move_files(snapshots, snapshots_dir, snapshots_reference_dir) if cant_move: db.del_groupdict(script, 'testrun') move_failed.add(script) checked_in -= move_failed # update history text_1 = doers.pprint_to_string(checked_in) text_2 = doers.pprint_to_string(move_failed) text_3 = doers.pprint_to_string(unknown) text_history = '\n'.join(["checked_in:", text_1, "move_failed:", text_2, "unknown:", text_3 ]) db.history_add("update_testrun__pass", text_history) if filename_persist: dbm.db_save(db, filename_persist) return checked_in, unknown, move_failed
def update_testrun__bad(db, filename_persist, testrun_props_by_candidate, snapshots_dir, snapshots_reference_dir=None): """ snapshots_reference_dir : dir to move snapshots; if None no move """ if snapshots_reference_dir: if not os.path.isdir(snapshots_dir): fmt = "snapshot dir not found or not a dir:%s" raise ValueError(fmt % snapshots_dir) if not os.path.exists(snapshots_reference_dir): os.makedirs(snapshots_reference_dir) checked_in, ignored, unknown = _update_testrun(db, testrun_props_by_candidate, snapshots_dir) move_failed = set() if snapshots_reference_dir: # move snapshots to reference dir for script in checked_in: snapshots = db.get_prop_value(script, 'expected_snapshots') moved, cant_move = doers.move_files(snapshots, snapshots_dir, snapshots_reference_dir) if cant_move: move_failed.add(script) # update history text_1 = doers.pprint_to_string(checked_in) text_2 = doers.pprint_to_string(move_failed) text_3 = doers.pprint_to_string(unknown) text_history = '\n'.join( ["checked_in:", text_1, "move_failed:", text_2, "unknown:", text_3]) db.history_add("update_testrun__bad", text_history) if filename_persist: dbm.db_save(db, filename_persist) return checked_in, unknown, move_failed
def update_scanprops(db, filename_persist, candidates): """ For each script in candidates the props in 'scan' group are calculated and stored as script props. candidates should be known entities in the db """ known_scripts, unknowns = db.entities(candidates=candidates) for script in known_scripts: fname = db.fname_from_canonical(script) scanprops = scanprops_from_fname(fname) db.set_groupdict(script, 'scan', scanprops) # update history text = '\n'.join(known_scripts) db.history_add('update_scanprops', text) if filename_persist: dbm.db_save(db, filename_persist) return known_scripts, unknowns
def new_db(filename_persist=None): """Instantiates and saves a new db :Parameters: `filename_persist` : str filename used to persist the new db, defaults to None if filename_persist is None, the new db is not stored to disk If file exists a ValueError is raised. The new db is an instance of remembercases.TestbedEntityPropDB. The stored db is retrieved to ensure it can be read. """ if filename_persist and os.path.exists(filename_persist): msg = "initial_recon refuses to overwrite an existing file: %s" msg = msg % filename_persist raise ValueError(msg) db = dbm.TestbedEntityPropDB() if filename_persist: dbm.db_save(db, filename_persist) new = dbm.db_load(filename_persist) return db
def update_11(db, filename_persist, snapshots_dir): """ Reflect some test renames (added but without testinfo): delete, add If there were snapshots or testrun props more caoutious aproach is needed""" text1 = """ test/test_rotate_move_reverse.py test/test_local_coordinates.py """ candidates = doers.scripts_names_from_text(text1, end_mark=":") for name in candidates: db.del_entity(name) text2 = """ test/test_rotate_reverse.py test/test_rect.py """ candidates = doers.scripts_names_from_text(text2, end_mark=":") hl.hl.add_entities(db, filename_persist, candidates) text = text1 + "\nto\n" + text2 db.history_add("renamed entities", text) dbm.db_save(db, filename_persist)
def update_snapshots(db, filename_persist, target_scripts, snapshots_dir): """ runs the scripts in target scripts, taking snapshots as indicated by the testinfo in the script, and updating the snapshots related info in the db. Params: db: a remembercases.TestbedEntityPropDB object filename_persist: filename to persist the db after updating target_scripts: iterable yielding scripts. If None, all scripts known in the default testbed are assumed. snapshots_dir: directory to store the snapshots Returns (valid_scripts, rejected) where: valid_scripts : scripts in target_scripts that are known in the default testbed and have valid testinfo rejected : scripts in target_scripts that are unknown in the default testbed or dont have valid testinfo Db operations are done over the default testbed, which should have been set bejore calling here. For each valid entity the following props are set: 'snapshots_success': bool, True if (no traceback or timeout when running the script, also all expected snapshots had been produced), else False 'snapshots_diagnostic': string, '' means no errors, else description of failure while trying to take snapshots 'missing_snapshots': list of missing snapshots filenames """ proxy_abspath = os.path.abspath('proxy_snapshots.py') if not os.path.exists(proxy_abspath): raise ValueError("proxy script not found:%s"%proxy_abspath) snapshots_abspath = os.path.abspath(snapshots_dir) if not os.path.exists(snapshots_abspath): os.makedirs(snapshots_abspath) valid_scripts, rejected = db.entities(fn_allow=fn_allow_testinfo_valid, candidates=target_scripts) for script in valid_scripts: # get the exercise plan stored_testinfo = db.get_prop_value(script, 'testinfo') # delete old snapshots if they exist expected_snapshots = db.get_prop_value(script, 'expected_snapshots') for name in expected_snapshots: p = os.path.join(snapshots_abspath, name) if os.path.exists(p): os.remove(p) # exercise the script acording to testinfo, snapshots would be taken fname = db.fname_from_canonical(script) timeout_hit, err = proxy.proxy_run(proxy_abspath, fname, [stored_testinfo, snapshots_abspath]) # calc and store missing_snapshots prop missing = [ s for s in expected_snapshots if not os.path.exists(os.path.join(snapshots_abspath, s))] db.set_prop_value(script, 'missing_snapshots', missing) # calc and store snapshots_success prop snapshots_success = (err=='' and not timeout_hit and len(missing)==0) db.set_prop_value(script, 'snapshots_success', snapshots_success) # calc and store snapshots_diagnostic prop snapshots_diagnostic = '' if not snapshots_success: if timeout_hit: err = ('Timeout hit. Remember in this case it is posible not all stderr captured.\n' + err) if len(missing): missing = [ os.path.basename(s) for s in missing ] err += '\nNot all snapshots captured - missing snapshots:\n' err += '\n'.join(missing) snapshots_diagnostic = err print('err:', err) db.set_prop_value(script, 'snapshots_diagnostic', snapshots_diagnostic) # update history text = '\n'.join(valid_scripts) db.history_add('update_snapshots', text) if filename_persist: dbm.db_save(db, filename_persist) return valid_scripts, rejected
def update_snapshots(db, filename_persist, target_scripts, snapshots_dir): """ runs the scripts in target scripts, taking snapshots as indicated by the testinfo in the script, and updating the snapshots related info in the db. Params: db: a remembercases.TestbedEntityPropDB object filename_persist: filename to persist the db after updating target_scripts: iterable yielding scripts. If None, all scripts known in the default testbed are assumed. snapshots_dir: directory to store the snapshots Returns (valid_scripts, rejected) where: valid_scripts : scripts in target_scripts that are known in the default testbed and have valid testinfo rejected : scripts in target_scripts that are unknown in the default testbed or dont have valid testinfo Db operations are done over the default testbed, which should have been set bejore calling here. For each valid entity the following props are set: 'snapshots_success': bool, True if (no traceback or timeout when running the script, also all expected snapshots had been produced), else False 'snapshots_diagnostic': string, '' means no errors, else description of failure while trying to take snapshots 'missing_snapshots': list of missing snapshots filenames """ proxy_abspath = os.path.abspath('proxy_snapshots.py') if not os.path.exists(proxy_abspath): raise ValueError("proxy script not found:%s" % proxy_abspath) snapshots_abspath = os.path.abspath(snapshots_dir) if not os.path.exists(snapshots_abspath): os.makedirs(snapshots_abspath) valid_scripts, rejected = db.entities(fn_allow=fn_allow_testinfo_valid, candidates=target_scripts) for script in valid_scripts: # get the exercise plan stored_testinfo = db.get_prop_value(script, 'testinfo') # delete old snapshots if they exist expected_snapshots = db.get_prop_value(script, 'expected_snapshots') for name in expected_snapshots: p = os.path.join(snapshots_abspath, name) if os.path.exists(p): os.remove(p) # exercise the script acording to testinfo, snapshots would be taken fname = db.fname_from_canonical(script) timeout_hit, err = proxy.proxy_run( proxy_abspath, fname, [stored_testinfo, snapshots_abspath]) # calc and store missing_snapshots prop missing = [ s for s in expected_snapshots if not os.path.exists(os.path.join(snapshots_abspath, s)) ] db.set_prop_value(script, 'missing_snapshots', missing) # calc and store snapshots_success prop snapshots_success = (err == '' and not timeout_hit and len(missing) == 0) db.set_prop_value(script, 'snapshots_success', snapshots_success) # calc and store snapshots_diagnostic prop snapshots_diagnostic = '' if not snapshots_success: if timeout_hit: err = ( 'Timeout hit. Remember in this case it is posible not all stderr captured.\n' + err) if len(missing): missing = [os.path.basename(s) for s in missing] err += '\nNot all snapshots captured - missing snapshots:\n' err += '\n'.join(missing) snapshots_diagnostic = err print 'err:', err db.set_prop_value(script, 'snapshots_diagnostic', snapshots_diagnostic) # update history text = '\n'.join(valid_scripts) db.history_add('update_snapshots', text) if filename_persist: dbm.db_save(db, filename_persist) return valid_scripts, rejected