コード例 #1
0
    def test_get_issues(self):
        raised_issues = {}
        with open(os.path.join(self.plugin_tmp_dir, 'yaml'), 'w') as fd:
            fd.write(yaml.dump(raised_issues))

        mgr = IssuesManager()
        ret = mgr.load_issues()
        self.assertEqual(ret, raised_issues)
コード例 #2
0
 def test_issue_not_machine_readable(self):
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"))
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT: {
                 'MemoryWarnings': ['test (origin=testplugin.01part)']
             }
         })
コード例 #3
0
 def test_issue_machine_readable(self):
     setup_config(MACHINE_READABLE=True)
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"))
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'origin': 'testplugin.01part'
             }]
         })
コード例 #4
0
 def test_add_issue_w_empty_context(self):
     setup_config(MACHINE_READABLE=True)
     ctxt = IssueContext()
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"), ctxt)
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'origin': 'testplugin.01part'
             }]
         })
コード例 #5
0
 def test_add_issue_empty_context(self):
     setup_config(MACHINE_READABLE=True)
     ctxt = IssueContext()
     ctxt.set(linenumber=123, path='/foo/bar')
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"), ctxt)
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'context': {
                     'path': '/foo/bar',
                     'linenumber': 123
                 },
                 'origin': 'testplugin.01part'
             }]
         })
コード例 #6
0
ファイル: plugintools.py プロジェクト: hemanthnakkina/hotsos
    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()