def test_two_sections(self): section1 = Section(name="first") section2 = Section(name="second") self.report.add(section1, section2) self.assertEquals("first\n" + self.div + "\nsecond\n" + self.div, str(PlainTextReport(self.report)))
def test_two_sections(self): section1 = Section(name="first") section2 = Section(name="second") self.report.add(section1, section2) self.assertEquals( u''.join([ self.pluglist.format(pluglist=" first second"), self.div, "\nfirst", self.div, "\nsecond" ]), PlainTextReport(self.report).unicode())
def test_multiple_sections(self): report = Report() section = Section(name="section") report.add(section) section2 = Section(name="section2") report.add(section2) expected = json.dumps({"section": {}, "section2": {}, }) self.assertEquals(expected, str(report))
def plain_report(self): report = Report() for plugname, plug in self.loaded_plugins: section = Section(name=plugname) for alert in plug.alerts: section.add(Alert(alert)) if plug.custom_text: section.add(Note(plug.custom_text)) for f in plug.copied_files: section.add(CopiedFile(name=f['srcpath'], href= ".." + f['dstpath'])) for cmd in plug.executed_commands: section.add(Command(name=cmd['exe'], return_code=0, href="../" + cmd['file'])) for content, f in plug.copy_strings: section.add(CreatedFile(name=f)) report.add(section) fd = self.get_temp_file() fd.write(str(PlainTextReport(report))) fd.flush() self.archive.add_file(fd.name, dest=os.path.join('sos_reports', 'sos.txt'))
def test_nested_section(self): report = Report() section = Section(name="section") report.add(section) expected = json.dumps({"section": {}}) self.assertEquals(expected, str(report))
def setUp(self): self.report = Report() self.section = Section(name="plugin") self.div = '\n' + PlainTextReport.PLUGDIVIDER self.pluglist = "Loaded Plugins:\n{pluglist}" self.defaultheader = u''.join([ self.pluglist.format(pluglist=" plugin"), self.div, "\nplugin\n" ])
def test_deeply_nested(self): report = Report() section = Section(name="section") command = Command(name="a command", return_code=0, href="does/not/matter") section.add(command) report.add(section) expected = json.dumps({"section": {"commands": [{"name": "a command", "return_code": 0, "href": "does/not/matter"}]}}) self.assertEquals(expected, str(report))
def plain_report(self): report = Report() for plugname, plug in self.loaded_plugins: section = Section(name=plugname) for alert in plug.alerts: section.add(Alert(alert)) if plug.custom_text: section.add(Note(plug.custom_text)) for f in plug.copied_files: section.add( CopiedFile(name=f['srcpath'], href=".." + f['dstpath'])) for cmd in plug.executed_commands: section.add( Command(name=cmd['exe'], return_code=0, href="../" + cmd['file'])) for content, f in plug.copy_strings: section.add(CreatedFile(name=f)) report.add(section) try: fd = self.get_temp_file() fd.write(str(PlainTextReport(report))) fd.flush() self.archive.add_file(fd.name, dest=os.path.join('sos_reports', 'sos.txt')) except (OSError, IOError) as e: if e.errno in fatal_fs_errors: self.ui_log.error("") self.ui_log.error(" %s while writing text report" % e.strerror) self.ui_log.error("") self._exit(1)
def setUp(self): self.report = Report() self.section = Section(name="plugin") self.div = PlainTextReport.DIVIDER