Esempio n. 1
0
    def test_status_ok(self):
        mock_command = Mock()
        mock_command.return_value = CommandResult(0, '')

        with patch('swiftlm.systems.ntp.run_cmd', mock_command):
            with patch('swiftlm.systems.ntp.check_details', lambda: []):
                actual = ntp.main()

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 1)
        r = actual[0]
        self.assertIsInstance(r, MetricData)

        expected = MetricData.single(ntp.__name__, Severity.ok,
                                     ntp.BASE_RESULT.messages['ok'])
        self.assertEqual(r, expected)
Esempio n. 2
0
    def test_details_ok(self):
        mock_command = Mock()
        mock_command.return_value = CommandResult(0, 'stratum=1,offset=2,')

        with patch('swiftlm.systems.ntp.run_cmd', mock_command):
            with patch('swiftlm.systems.ntp.check_status', lambda: []):
                actual = ntp.main()

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 2)
        actual = [a.metric() for a in actual]

        expected = [
            MetricData.single(ntp.__name__+'.stratum', '1', ''),
            MetricData.single(ntp.__name__+'.offset', '2', '')
        ]

        for e in expected:
            self.assertIn(e.metric(), actual)
Esempio n. 3
0
    def test_details_fail(self):
        mock_command = Mock()
        mock_command.return_value = CommandResult(0, 'stratum=1,')

        with patch('swiftlm.systems.ntp.run_cmd', mock_command):
            with patch('swiftlm.systems.ntp.check_status', lambda: []):
                actual = ntp.main()

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 2)
        actual = [a.metric() for a in actual]

        failed = CheckFailure.child()
        failed.value = Severity.fail
        failed['check'] = ntp.__name__ + '.offset'
        failed['error'] = 'Output does not contain "offset"'

        expected = [
            failed,
            MetricData.single(ntp.__name__+'.stratum', '1', ''),
        ]

        for e in expected:
            self.assertIn(e.metric(), actual)
Esempio n. 4
0
    def test_main(self):
        with patch('swiftlm.systems.ntp.check_status', lambda: ['a']):
            with patch('swiftlm.systems.ntp.check_details', lambda: ['b']):
                actual = ntp.main()

        self.assertListEqual(['a', 'b'], actual)