Example #1
0
    def test_recon_fail(self):
        mock_json = Mock()
        mock_json.side_effect = ValueError('error')
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = True

        with patch(BUILTIN_OPEN):
            with patch('json.load', mock_json):
                actual = replication._recon_check(mock_server_type)

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

        expected1 = replication.BASE_RESULT.child(
            'servertype.last_replication')
        expected1.value = 0

        self.assertIn(expected1.metric(), actual)
        actual.remove(expected1.metric())

        expected2 = CheckFailure.child(dimensions={
            'check': expected1.name,
            'error': 'error',
        })
        expected2.value = Severity.fail

        pprint.pprint(expected2.metric())
        pprint.pprint(actual)
        self.assertIn(expected2.metric(), actual)
        actual.remove(expected2.metric())
Example #2
0
    def test_recon_ok(self):
        mock_json = Mock()
        mock_json.return_value = {
            'replication_last': '1222'
        }
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = True

        with patch(BUILTIN_OPEN):
            with patch('json.load', mock_json):
                actual = replication._recon_check(mock_server_type)

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 1)
        r = actual[0]
        expected = replication.BASE_RESULT.child('servertype.last_replication',
                                                 dimensions={'component':
                                                             'servertype'
                                                             '-replicator'})

        # mocked timestamp - object_last_replication
        expected.value = 123456 - 1222

        self.assertDictEqual(expected.metric(), r.metric())
Example #3
0
    def test_recon_fail(self):
        mock_json = Mock()
        mock_json.side_effect = ValueError('error')
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = True

        with patch(BUILTIN_OPEN):
            with patch('json.load', mock_json):
                actual = replication._recon_check(mock_server_type)

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

        expected1 = replication.BASE_RESULT.child(
            'servertype.last_replication')
        expected1.value = 0

        self.assertIn(expected1.metric(), actual)
        actual.remove(expected1.metric())

        expected2 = CheckFailure.child(dimensions={
            'check': expected1.name,
            'error': 'error',
        })
        expected2.value = Severity.fail

        pprint.pprint(expected2.metric())
        pprint.pprint(actual)
        self.assertIn(expected2.metric(), actual)
        actual.remove(expected2.metric())
Example #4
0
    def test_recon_server_type(self):
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = False

        actual = replication._recon_check(mock_server_type)

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 0)
Example #5
0
    def test_recon_server_type(self):
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = False

        actual = replication._recon_check(mock_server_type)

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 0)
Example #6
0
    def test_recon_ok(self):
        mock_json = Mock()
        mock_json.return_value = {
            'replication_last': '1222'
        }
        mock_server_type = Mock(spec=ServerType)
        mock_server_type.name = 'servertype'
        mock_server_type.is_instance = True

        with patch(BUILTIN_OPEN):
            with patch('json.load', mock_json):
                actual = replication._recon_check(mock_server_type)

        self.assertIsInstance(actual, list)
        self.assertEqual(len(actual), 1)
        r = actual[0]
        expected = replication.BASE_RESULT.child('servertype.last_replication')
        # mocked timestamp - object_last_replication
        expected.value = 123456 - 1222

        self.assertDictEqual(expected.metric(), r.metric())