def test_add_issue(self): known_bugs = { IssuesManager.SUMMARY_OUT_BUGS_ROOT: [{ 'id': 'https://bugs.launchpad.net/bugs/1', 'desc': None, 'origin': 'testplugin.01part' }] } with open(os.path.join(self.plugin_tmp_dir, 'known_bugs.yaml'), 'w') as fd: fd.write(yaml.dump(known_bugs)) mgr = IssuesManager() mgr.add(LaunchpadBug(2, None)) ret = mgr.load_bugs() expected = { IssuesManager.SUMMARY_OUT_BUGS_ROOT: [{ 'id': 'https://bugs.launchpad.net/bugs/1', 'desc': None, 'origin': 'testplugin.01part' }, { 'id': 'https://bugs.launchpad.net/bugs/2', 'desc': None, 'origin': 'testplugin.01part' }] } self.assertEqual(ret, expected)
def test_add_issue_first(self): mgr = IssuesManager() mgr.add(LaunchpadBug(1, None)) ret = mgr.load_bugs() self.assertEqual( ret, { IssuesManager.SUMMARY_OUT_BUGS_ROOT: [{ 'id': 'https://bugs.launchpad.net/bugs/1', 'desc': None, 'origin': 'testplugin.01part' }] })
def run_parts(self, parts, debug_mode=False): failed_parts = [] # The following are executed as part of each plugin run (but not last). ALWAYS_RUN = {'auto_scenario_check': YScenarioChecker} for name, always_parts in ALWAYS_RUN.items(): # update current env to reflect actual part being run setup_config(PART_NAME=name) try: always_parts()() except Exception as exc: failed_parts.append(name) log.exception("part '%s' raised exception: %s", name, exc) if debug_mode: raise # NOTE: we don't expect these parts to produce any output # for the summary so we wont check for it (the only raise # issues and bugs which are handled independently). for name, part_info in parts.items(): # update current env to reflect actual part being run setup_config(PART_NAME=name) for cls in part_info['objects']: inst = cls() # Only run plugin if it delares itself runnable. if not inst.plugin_runnable: log.debug("%s.%s.%s not runnable - skipping", HotSOSConfig.PLUGIN_NAME, name, cls.__name__) continue log.debug("running %s.%s.%s", HotSOSConfig.PLUGIN_NAME, name, cls.__name__) try: inst() # NOTE: since all parts are expected to be implementations # of PluginPartBase we expect them to always define an # output property. output = inst.output subkey = inst.summary_subkey except Exception as exc: failed_parts.append(name) log.exception("part '%s' raised exception: %s", name, exc) output = None if debug_mode: raise if output: for key, entry in output.items(): out = {key: entry.data} if subkey: out = {subkey: out} part_max = PluginPartBase.PLUGIN_PART_OFFSET_MAX part_offset = part_info['part_yaml_offset'] offset = ((part_offset * part_max) + entry.offset) save_part(out, offset=offset) if failed_parts: # always put these at the top save_part({'failed-parts': failed_parts}, offset=0) imgr = IssuesManager() bugs = imgr.load_bugs() raised_issues = imgr.load_issues() summary_end_offset = PluginPartBase.PLUGIN_PART_OFFSET_MAX ** 2 # Add detected known_bugs and raised issues to end summary. if bugs: save_part(bugs, offset=summary_end_offset) # Add raised issues to summary. if raised_issues: save_part(raised_issues, offset=summary_end_offset) return dump_all_parts()