Esempio n. 1
0
    def test_copied_file(self):
        cf = CopiedFile(name="/etc/hosts", href="etc/hosts")
        self.section.add(cf)
        self.report.add(self.section)

        self.assertEquals("plugin\n" + self.div + "\n-  files copied:\n  * /etc/hosts",
                PlainTextReport(self.report).unicode())
Esempio n. 2
0
    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'))
Esempio n. 3
0
    def test_alert(self):
        alrt = Alert("this is an alert")
        self.section.add(alrt)
        self.report.add(self.section)

        self.assertEquals("plugin\n" + self.div + "\n-  alerts:\n  ! this is an alert",
                PlainTextReport(self.report).unicode())
Esempio n. 4
0
    def test_created_file(self):
        crf = CreatedFile(name="sample.txt")
        self.section.add(crf)
        self.report.add(self.section)

        self.assertEquals("plugin\n" + self.div + "\n-  files created:\n  * sample.txt",
                PlainTextReport(self.report).unicode())
Esempio n. 5
0
    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)))
Esempio n. 6
0
    def test_copied_file(self):
        cf = CopiedFile(name="/etc/hosts", href="etc/hosts")
        self.section.add(cf)
        self.report.add(self.section)

        self.assertEquals(
            u''.join([self.defaultheader, "-  files copied:\n  * /etc/hosts"]),
            PlainTextReport(self.report).unicode())
Esempio n. 7
0
    def test_alert(self):
        alrt = Alert("this is an alert")
        self.section.add(alrt)
        self.report.add(self.section)

        self.assertEquals(
            u''.join([self.defaultheader, "-  alerts:\n  ! this is an alert"]),
            PlainTextReport(self.report).unicode())
Esempio n. 8
0
    def test_command(self):
        cmd = Command(name="ls -al /foo/bar/baz",
                      return_code=0,
                      href="sos_commands/plugin/ls_-al_foo.bar.baz")
        self.section.add(cmd)
        self.report.add(self.section)

        self.assertEquals("plugin\n" + self.div + "\n-  commands executed:\n  * ls -al /foo/bar/baz",
                PlainTextReport(self.report).unicode())
Esempio n. 9
0
    def test_created_file(self):
        crf = CreatedFile(name="sample.txt",
                          href="../sos_strings/sample/sample.txt")
        self.section.add(crf)
        self.report.add(self.section)

        self.assertEquals(
            u''.join([self.defaultheader,
                      "-  files created:\n  * sample.txt"]),
            PlainTextReport(self.report).unicode())
Esempio n. 10
0
    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())
Esempio n. 11
0
    def test_command(self):
        cmd = Command(name="ls -al /foo/bar/baz",
                      return_code=0,
                      href="sos_commands/plugin/ls_-al_foo.bar.baz")
        self.section.add(cmd)
        self.report.add(self.section)

        self.assertEquals(u''.join([
                            self.defaultheader,
                            "-  commands executed:\n  * ls -al /foo/bar/baz"
                        ]),
                        PlainTextReport(self.report).unicode())
Esempio n. 12
0
    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)
Esempio n. 13
0
    def test_one_section(self):
        self.report.add(self.section)

        self.assertEquals("plugin\n" + self.div,
                          str(PlainTextReport(self.report)))
Esempio n. 14
0
 def test_basic(self):
     self.assertEquals("", str(PlainTextReport(self.report)))
Esempio n. 15
0
 def test_basic(self):
     self.assertEquals("", PlainTextReport(self.report).unicode())
Esempio n. 16
0
    def test_one_section(self):
        self.report.add(self.section)

        self.assertEquals(self.defaultheader,
                          PlainTextReport(self.report).unicode() + '\n')
Esempio n. 17
0
 def test_basic(self):
     self.assertEquals(self.pluglist.format(pluglist=""),
                       PlainTextReport(self.report).unicode())