def after_step(context, step): """Teardown after each step. Here we make screenshot and embed it (if one of formatters supports it) """ try: if problem.list(): problems = problem.list() for crash in problems: if hasattr(context, "embed"): context.embed('text/plain', "abrt has detected a crash: %s" % crash.reason) else: print("abrt has detected a crash: %s" % crash.reason) # Crash was stored, so it is safe to remove it now [x.delete() for x in problems] # Make screnshot if step has failed if hasattr(context, "embed"): os.system("gnome-screenshot -f /tmp/screenshot.jpg") context.embed('image/jpg', open("/tmp/screenshot.jpg", 'r').read()) # Test debugging - set DEBUG_ON_FAILURE to drop to ipdb on step failure if os.environ.get('DEBUG_ON_FAILURE'): import ipdb; ipdb.set_trace() # flake8: noqa except Exception as e: print("Error in after_step: %s" % e.message)
def after_step(context, step): """Teardown after each step. Here we make screenshot and embed it (if one of formatters supports it) """ try: if problem.list(): problems = problem.list() for crash in problems: if hasattr(context, "embed"): context.embed('text/plain', "abrt has detected a crash: %s" % crash.reason) else: print("abrt has detected a crash: %s" % crash.reason) # Crash was stored, so it is safe to remove it now [x.delete() for x in problems] if step.status == 'failed': # Make screnshot if step has failed if hasattr(context, "embed"): os.system("gnome-screenshot -f /tmp/screenshot.jpg") context.embed('image/jpg', open("/tmp/screenshot.jpg", 'r').read()) # Test debugging - set DEBUG_ON_FAILURE to drop to ipdb on step failure if os.environ.get('DEBUG_ON_FAILURE'): import ipdb; ipdb.set_trace() # flake8: noqa except Exception as e: print("Error in after_step: %s" % e.message)
def test_get_human_identifier(self): p0 = problem.list()[0] p3 = problem.list()[3] p4 = problem.list()[4] p0_t, p0_v = get_human_identifier(p0) p3_t, p3_v = get_human_identifier(p3) p4_t, p4_v = get_human_identifier(p4) self.assertEqual(p0_t, 'component') self.assertEqual(p0_v, p0.component) self.assertEqual(p3_t, 'executable') self.assertEqual(p3_v, p3.executable) self.assertEqual(p4_t, 'type') self.assertEqual(p4_v, p4.type)
def before_all(context): """Setup evolution stuff Being executed before all features """ # Reset GSettings schemas = [x for x in Gio.Settings.list_schemas() if 'evolution' in x.lower()] for schema in schemas: os.system("gsettings reset-recursively %s" % schema) # Skip warning dialog os.system("gsettings set org.gnome.evolution.shell skip-warning-dialog true") # Show switcher buttons as icons (to minimize tree scrolling) os.system("gsettings set org.gnome.evolution.shell buttons-style icons") # Wait for things to settle sleep(0.5) # Skip dogtail actions to print to stdout config.logDebugToStdOut = False config.typingDelay = 0.2 # Include assertion object context.assertion = dummy() # Kill initial setup os.system("killall /usr/libexec/gnome-initial-setup") # Delete existing ABRT problems if problem.list(): [x.delete() for x in problem.list()] try: from gi.repository import GnomeKeyring # Delete originally stored password (response, keyring) = GnomeKeyring.get_default_keyring_sync() if response == GnomeKeyring.Result.OK: if keyring is not None: delete_response = GnomeKeyring.delete_sync(keyring) assert delete_response == GnomeKeyring.Result.OK, "Delete failed: %s" % delete_response create_response = GnomeKeyring.create_sync("login", 'gnome') assert create_response == GnomeKeyring.Result.OK, "Create failed: %s" % create_response set_default_response = GnomeKeyring.set_default_keyring_sync('login') assert set_default_response == GnomeKeyring.Result.OK, "Set default failed: %s" % set_default_response unlock_response = GnomeKeyring.unlock_sync("login", 'gnome') assert unlock_response == GnomeKeyring.Result.OK, "Unlock failed: %s" % unlock_response except Exception as e: print("Exception while unlocking a keyring: %s" % e.message) context.app = App('evolution')
def get_match_data(authenticate=False): ''' Return tuple of two dictionaries: one with components as keys and one with short_ids as keys Utility function used by match_ functions ''' by_human_id = {} by_short_id = {} by_path = {} for prob in problem.list(auth=authenticate): _, val = get_human_identifier(prob) if val in by_human_id: by_human_id[val].append(prob) else: by_human_id[val] = [prob] if prob.short_id in by_short_id: by_short_id[prob.short_id].append(prob) else: by_short_id[prob.short_id] = [prob] by_path[prob.path] = prob return by_human_id, by_short_id, by_path
def before_all(context): """Setup soffice stuff Being executed before all features """ try: # Cleanup abrt crashes [x.delete() for x in problem.list()] # Skip dogtail actions to print to stdout config.logDebugToStdOut = False config.typingDelay = 0.5 # Include assertion object context.assertion = dummy() # Kill initial setup os.system("killall /usr/libexec/gnome-initial-setup") # Store scenario start time for session logs context.log_start_time = strftime("%Y-%m-%d %H:%M:%S", localtime()) context.app = LOApp('soffice', forceKill=True, parameters='--norecovery') except Exception as e: print("Error in before_all: %s" % e.message)
def get_match_data(auth=False): ''' Return tuple of two dictionaries: one with components as keys and one with short_ids as keys Utility function used by match_ functions ''' by_human_id = {} by_short_id = {} for prob in problem.list(auth=auth): comp_or_exe, val = get_human_identifier(prob) if val in by_human_id: by_human_id[val].append(prob) else: by_human_id[val] = [prob] if prob.short_id in by_short_id: by_short_id[prob.short_id].append(prob) else: by_short_id[prob.short_id] = [prob] return by_human_id, by_short_id
def list_problems(args): probs = sort_problems(problem.list(auth=args.auth)) if args.since: probs = filter_since_timestamp(probs, args.since) if args.until: probs = filter_until_timestamp(probs, args.until) if args.not_reported: probs = filter_not_reported(probs) if not args.fmt: fmt = config.MEDIUM_FMT else: fmt = args.fmt if args.pretty != 'medium': fmt = getattr(config, '{}_FMT'.format(args.pretty.upper())) out = fmt_problems(probs, fmt=fmt) if out: print(out) else: print(_('No problems'))
def test_fmt_problems(self): ''' Test default problem formatting ''' pl = problem.list() res = fmt_problems(pl) for prob in pl: self.assertIn(prob.short_id, res) field, value = get_human_identifier(prob) self.assertIn(value, res) self.assertIn(str(prob.count), res) self.assertIn('Bugzilla', res) self.assertIn('https://bugzilla.redhat.com/show_bug.cgi?id=1223349', res) self.assertIn('ABRT Server', res) furl = 'https://retrace.fedoraproject.org/faf/reports/bthash/' \ '3505a6db8a6bd51a3d690f1553b' self.assertIn(furl, res) self.assertIn('Not reportable', res) self.assertIn('Not reportable reason', res)
def match_get_problem(problem_match, allow_multiple=False, auth=False): ''' Return problem matching `problem_match` pattern or exit if there are no such problems or pattern results in multiple problems (unless `allow_multiple` is set to True). ''' prob = None if problem_match == 'last': probs = sort_problems(problem.list(auth=auth)) if not probs: print(_('No problems')) sys.exit(0) prob = probs[0] else: probs = match_lookup(problem_match, auth=auth) if not probs: print(_('No problem(s) matched')) sys.exit(1) elif len(probs) > 1: if allow_multiple: return probs match_collision(probs) sys.exit(1) else: prob = probs[0] return prob
def before_all(context): """Setup nautilus stuff Being executed before all features """ try: # Cleanup abrt crashes [x.delete() for x in problem.list()] # Do the cleanup os.system("python cleanup.py > /dev/null") # Skip dogtail actions to print to stdout config.logDebugToStdOut = False config.typingDelay = 0.2 # Include assertion object context.assertion = dummy() # Kill initial setup os.system("killall /usr/libexec/gnome-initial-setup") # Store scenario start time for session logs context.log_start_time = strftime("%Y-%m-%d %H:%M:%S", localtime()) context.app = App('gnome-software') except Exception as e: print("Error in before_all: %s" % e.message)
def test_filter_ids(self): problems = problem.list() self.assertListEqual(problems, filter_ids(problems, [])) ids = ['bc60a5cbddb4e3667511e718ceecac16133acc97', 'ccacca5'] problems = filter_ids(problems, ids) # There’s an ID collision. self.assertEqual(len(problems), 3)
def test_sort_problems(self): ''' Test if problems are sotred by time ''' pl = problem.list() spl = sort_problems(pl) self.assertTrue(spl[-1] == pl[2]) self.assertTrue(spl[0] == pl[3])
def test_list_all(self): prob = self.create_problem() prob.add_current_process_data() ident = prob.save() tools.ok_(ident in map(lambda x: x._probdir, problem.list(True, self.proxy))) prob.delete()
def test_list(self): prob = self.create_problem() prob.add_current_process_data() ident = prob.save() assert ident in map(lambda x: x._probdir, problem.list(False, self.proxy)) prob.delete()
def test_list_all(self): prob = self.create_problem() prob.add_current_process_data() ident = prob.save() tools.ok_( ident in map(lambda x: x._probdir, problem.list(True, self.proxy))) prob.delete()
def test_fmt_problems_oneline(self): ''' Test oneline problem formatting ''' pl = problem.list() res = fmt_problems(pl, fmt=ONELINE_FMT) self.assertIn('bc60a5c 15x pavucontrol', res) self.assertIn('ffe635c 1x /home/user/bin/user_app', res)
def test_filter_paths(self): problems = problem.list() self.assertListEqual(problems, filter_paths(problems, [])) paths = [ '/var/tmp/abrt/ccpp-2014-03-16-14:41:47-7729', '/var/tmp/abrt/ccpp-2015-03-16-14:41:47-7729', '/var/tmp/abrt/ccpp-2015-05-16-14:41:47-7729' ] problems = filter_paths(problems, paths) self.assertEqual(len(problems), 3)
def test_fmt_problems_custom_oneline(self): ''' Test custom problem formatting ''' pl = problem.list() fmt = '''{short_id} {uid_username}''' res = fmt_problems(pl, fmt=fmt) self.assertIn('1234', res) self.assertTrue(len(res.splitlines()) == len(pl))
def test_fmt_problems_custom(self): ''' Test custom problem formatting ''' pl = problem.list() fmt = '''#table|id,{short_id}|user id,{uid_username}| ''' res = fmt_problems(pl, fmt=fmt) self.assertIn('User id', res) self.assertIn('1234', res) self.assertTrue(len(res.splitlines()) > len(pl))
def after_step(context, step): """Teardown after each step. Here we make screenshot and embed it (if one of formatters supports it) """ try: # Make screnshot if step has failed if hasattr(context, "embed"): os.system("gnome-screenshot -f /tmp/screenshot.jpg") context.embed('image/jpg', open("/tmp/screenshot.jpg", 'r').read()) if step.status == 'failed' and os.environ.get('DEBUG_ON_FAILURE'): import ipdb; ipdb.set_trace() # flake8: noqa # Check for abrt problems if problem.list(): problems = problem.list() print("Found %s problem(s)" % len(problems)) for crash in problems: os.system("cat '%s' >> /tmp/evo.log" % crash.reason) step.status = 'failed' except Exception as e: print("Error in after_step: %s" % e.message)
def status(args): probs = problem.list(auth=args.auth) since_append = "" if args.since: probs = filter_since_timestamp(probs, args.since) since_append = " --since {}".format(args.since) if args.not_reported: probs = filter_not_reported(probs) if args.bare: print(len(probs)) return print(_("ABRT has detected {} problem(s). For more info run: abrt list{}").format(len(probs), since_append))
def status(args): probs = problem.list(auth=args.auth) since_append = '' if args.since: probs = filter_since_timestamp(probs, args.since) since_append = ' --since {}'.format(args.since) if args.not_reported: probs = filter_not_reported(probs) if args.bare: print(len(probs)) return print(_('ABRT has detected {} problem(s). For more info run: abrt list{}') .format(len(probs), since_append))
def get_reported_bugs(): """ Get bug numbers from local abrt reports """ if not HAS_ABRT: return set() bugs = set() for prob in problem.list(): if not hasattr(prob, 'reported_to'): continue for line in prob.reported_to.splitlines(): if line.startswith('Bugzilla:'): bug_num = int(line.split('=')[-1]) bugs.add(bug_num) return bugs
def match_lookup(patterns, authenticate=False, executables=None, components=None, since=None, until=None, n_latest=None, not_reported=False): ''' Return problems that match `in_arg` passed on command line ''' problems = problem.list(auth=authenticate) if not patterns: return sort_problems(problems)[:1] if '*' not in patterns: id_matches = filter_ids(problems, patterns) path_matches = filter_paths(problems, patterns) problems = list(set(id_matches) | set(path_matches)) problems = filter_executables(problems, executables) problems = filter_components(problems, components) if since: problems = filter_since_timestamp(problems, since) if until: problems = filter_until_timestamp(problems, until) if n_latest: problems = sort_problems(problems)[:n_latest] if not_reported: problems = filter_not_reported(problems) return problems
def before_all(context): """Setup gnome-weather stuff Being executed before all features """ try: # Cleanup abrt crashes [x.delete() for x in problem.list()] # Do the cleanup os.system("python cleanup.py > /dev/null") # Skip dogtail actions to print to stdout config.logDebugToStdOut = False config.typingDelay = 0.2 # Store scenario start time for session logs context.log_start_time = strftime("%Y-%m-%d %H:%M:%S", localtime()) context.app = App('gnome-weather') except Exception as e: print("Error in before_all: %s" % e.message)
def test_filter_until(self): pl = problem.list() until = datetime.datetime(2015, 1, 1, 1, 1, 1) res = filter_until(pl, until) self.assertEqual(len(res), 2)
def test_filter_since_timestamp(self): pl = problem.list() since = datetime.datetime(2015, 1, 1, 1, 1, 1) since_ts = since.strftime('%s') res = filter_since_timestamp(pl, since_ts) self.assertEqual(len(res), 3)
def test_filter_since(self): pl = problem.list() since = datetime.datetime(2015, 1, 1, 1, 1, 1) res = filter_since(pl, since) self.assertEqual(len(res), 3)
import problem for prob in problem.list(): assert prob.type == problem.CCPP prob.delete()
def test_filter_components(self): problems = problem.list() components = ['pavucontrol'] problems = filter_components(problems, components) self.assertEqual(len(problems), 2)
import problem for prob in problem.list(auth=True): print(prob) if hasattr(prob, 'username'): print('Problem belongs to {0}'.format(prob.username))
def test_get_problem_field(self): p = problem.list()[0] self.assertTrue(get_problem_field(p, 'count'), p.count) self.assertEqual(get_problem_field(p, 'notavail'), None)
def test_filter_until_timestamp(self): pl = problem.list() until = datetime.datetime(2015, 1, 1, 1, 1, 1) until_ts = until.strftime('%s') res = filter_until_timestamp(pl, until_ts) self.assertEqual(len(res), 2)
def test_filter_not_reported(self): pl = problem.list() res = filter_not_reported(pl) self.assertEqual(len(res), 4)
def test_filter_executables(self): problems = problem.list() executables = ['/home/user/bin/user_app'] problems = filter_executables(problems, executables) self.assertEqual(len(problems), 1)