def test_loaded_module_no_device(self):
        """Loaded module with no device entry should be skipped."""
        # We can hit this case fairly readily simply by unmounting
        # targets and leaving modules loaded.  We can simulate it
        # by creating a /proc/modules file with one of our Audit
        # classes' modules in it and an empty devices
        # file.
        os.makedirs(os.path.join(self.test_root, "sys/kernel/debug/lustre"))

        # Create a modules file with...  I dunno, lnet and mgs entries.
        f = open(os.path.join(self.test_root, "proc/modules"), "w+")
        f.write("""
lnet 233888 3 ptlrpc,ksocklnd,obdclass, Live 0xffffffffa076e000
exportfs 4202 1 fsfilt_ldiskfs, Live 0xffffffffa0d22000
mgs 153919 1 - Live 0xffffffffa0cfa000
mgc 50620 2 mgs, Live 0xffffffffa0a90000
        """)
        f.close()

        # Create an empty devices file
        open(os.path.join(self.test_root, "sys/kernel/debug/lustre/devices"), "w+").close()

        # Ideally, our audit aggregator should never instantiate the
        # audit in the first place.
        audit = LocalAudit()
        assert MgsAudit not in audit.audit_classes()

        # On the other hand, some modules don't have a corresponding
        # device entry, and therefore the audit should be instantiated.
        audit = LocalAudit()
        assert LnetAudit in audit.audit_classes()
    def test_loaded_module_no_stats(self):
        """Loaded modules with no stats files should be skipped."""
        # An easily-repeatable example of when this happens is when
        # lnet.ko is loaded but LNet is stopped.
        os.makedirs(os.path.join(self.test_root, "proc/sys/lnet"))

        f = open(os.path.join(self.test_root, "proc/modules"), "w+")
        f.write("""
lnet 233888 3 ptlrpc,ksocklnd,obdclass, Live 0xffffffffa076e000
        """)
        f.close()

        # Create dummy nodestats files
        f = open(os.path.join(self.test_root, "proc/meminfo"), "w")
        f.write("MemTotal:        3991680 kB\n")
        f.close()
        f = open(os.path.join(self.test_root, "proc/stat"), "w")
        f.write("cpu  24601 2 33757 3471279 10892 6 676 0 0\n")
        f.close()

        audit = LocalAudit()
        assert LnetAudit in audit.audit_classes()

        # this shouldn't raise a runtime error
        audit.metrics()
    def test_missing_brw_stats(self):
        """Catch a race where brw_stats hasn't been created yet."""
        os.makedirs(os.path.join(self.test_root, "sys/kernel/debug/lustre"))

        f = open(os.path.join(self.test_root, "proc/modules"), "w+")
        f.write("obdfilter 265823 4 - Live 0xffffffffa06b5000")
        f.close()

        f = open(os.path.join(self.test_root, "sys/kernel/debug/lustre/devices"), "w+")
        f.write("  2 UP obdfilter test-OST0000 test-OST0000_UUID 5")
        f.close()

        # Create dummy nodestats files
        f = open(os.path.join(self.test_root, "proc/meminfo"), "w")
        f.write("MemTotal:        3991680 kB\n")
        f.close()
        f = open(os.path.join(self.test_root, "proc/stat"), "w")
        f.write("cpu  24601 2 33757 3471279 10892 6 676 0 0\n")
        f.close()

        audit = LocalAudit()
        assert ObdfilterAudit in audit.audit_classes()

        # this shouldn't raise a runtime error
        audit.metrics()
Пример #4
0
class TestLocalAudit(PatchedContextTestCase):
    def setUp(self):
        tests = os.path.join(os.path.dirname(__file__), '..')
        self.test_root = os.path.join(tests,
                                      "data/lustre_versions/2.0.66/mds_mgs")
        super(TestLocalAudit, self).setUp()
        self.audit = LocalAudit()

    def test_localaudit_audit_classes(self):
        """LocalAudit.audit_classes() should return a list of classes."""
        self.assertEqual(self.audit.audit_classes(),
                         [LnetAudit, MdtAudit, MgsAudit, NodeAudit])