Esempio n. 1
0
    def test_info(self):
        """Test info messages. """
        checker = StorageChecker()

        def error_check(storage, constraints, report_error, report_warning):
            report_error("error")

        def warning_check(storage, constraints, report_error, report_warning):
            report_warning("warning")

        def skipped_check(storage, constraints, report_error, report_warning):
            report_warning("skipped")

        checker.add_constraint("x", None)
        checker.add_check(error_check)
        checker.add_check(warning_check)
        checker.add_check(skipped_check)

        report = checker.check(None, skip=(skipped_check,))
        self.assertListEqual(report.info, [
            "Storage check started with constraints {'x': None}.",
            "Run sanity check error_check.",
            "Found sanity error: error",
            "Run sanity check warning_check.",
            "Found sanity warning: warning",
            "Skipped sanity check skipped_check.",
            "Storage check finished with failure(s)."
        ])
Esempio n. 2
0
 def test_simple_info(self):
     """Test simple info messages. """
     checker = StorageChecker()
     report = checker.check(None)
     self.assertListEqual(report.info, [
         "Storage check started with constraints {}.",
         "Storage check finished with success."
     ])
Esempio n. 3
0
    def test_nocheck(self):
        """Test a check with no checks."""
        checker = StorageChecker()
        report = checker.check(None)

        self.assertEqual(report.success, True)
        self.assertEqual(report.failure, False)
        self.assertListEqual(report.errors, [])
        self.assertListEqual(report.warnings, [])
Esempio n. 4
0
    def test_check_constraints(self):
        """Test constraints checking."""
        checker = StorageChecker()

        def check(storage, constraints, report_error, report_warning):
            report_warning("%s" % constraints)

        checker.add_check(check)
        report = checker.check(None)
        self.assertListEqual(report.warnings, ["{}"])

        checker.add_constraint("x", 1)
        report = checker.check(None)
        self.assertListEqual(report.warnings, ["{'x': 1}"])

        checker.set_constraint("x", 0)
        report = checker.check(None)
        self.assertListEqual(report.warnings, ["{'x': 0}"])
    def test_nocheck(self):
        """Test a check with no checks."""
        checker = StorageChecker()
        report = checker.check(None)

        assert report.success is True
        assert report.failure is False
        assert report.errors == []
        assert report.warnings == []
Esempio n. 6
0
    def test_simple_warning(self):
        """Test an simple warning report."""
        checker = StorageChecker()

        def check(storage, constraints, report_error, report_warning):
            report_warning("warning")

        checker.add_check(check)
        report = checker.check(None)
        self.assertEqual(report.success, False)
        self.assertListEqual(report.errors, [])
        self.assertListEqual(report.warnings, ["warning"])
    def test_simple_warning(self):
        """Test an simple warning report."""
        checker = StorageChecker()

        def check(storage, constraints, report_error, report_warning):
            report_warning("warning")

        checker.add_check(check)
        report = checker.check(None)
        assert report.success is False
        assert report.errors == []
        assert report.warnings == ["warning"]
Esempio n. 8
0
    def test_complicated(self):
        """Run a complicated check."""
        checker = StorageChecker()

        # Set the checks,
        def check_x(storage, constraints, report_error, report_warning):
            if constraints["x"] != 1:
                report_error("x is not equal to 1")

        def check_y(storage, constraints, report_error, report_warning):
            if constraints["y"] != 2:
                report_error("y is not equal to 2")

        def check_z(storage, constraints, report_error, report_warning):
            if constraints["z"] != 3:
                report_error("z is not equal to 3")

        checker.add_check(check_x)
        checker.add_check(check_y)
        checker.add_check(check_z)

        # Set the constraints.
        checker.add_constraint("x", 1)
        checker.add_constraint("y", 2)
        checker.add_constraint("z", 3)

        # Run the checker. OK
        report = checker.check(None)
        self.assertEqual(report.success, True)
        self.assertListEqual(report.errors, [])
        self.assertListEqual(report.warnings, [])

        # Set constraints to different values.
        checker.set_constraint("x", 0)
        checker.set_constraint("y", 1)
        checker.set_constraint("z", 2)

        # Run the checker. FAIL
        report = checker.check(None)
        self.assertEqual(report.success, False)
        self.assertListEqual(report.errors, [
            "x is not equal to 1",
            "y is not equal to 2",
            "z is not equal to 3"
        ])
        self.assertListEqual(report.warnings, [])

        # Run the checker. Test SKIP.
        report = checker.check(None, skip=(check_y,))
        self.assertEqual(report.success, False)
        self.assertListEqual(report.errors, [
            "x is not equal to 1",
            "z is not equal to 3"
        ])
        self.assertListEqual(report.warnings, [])

        # Run the checker. Test CONSTRAINTS.
        constraints = {"x": 1, "y": 2, "z": 3}
        report = checker.check(None, constraints=constraints)
        self.assertEqual(report.success, True)
        self.assertListEqual(report.errors, [])
        self.assertListEqual(report.warnings, [])

        # Remove checks.
        checker.remove_check(check_x)
        checker.remove_check(check_y)
        checker.remove_check(check_z)

        report = checker.check(None)
        self.assertEqual(report.success, True)
        self.assertListEqual(report.errors, [])
        self.assertListEqual(report.warnings, [])