Example #1
0
def test_do_replication_check():
    base_module = 'paasta_tools.monitoring'
    check_classic_module = base_module + '.check_classic_service_replication'

    check_method = check_classic_module + '.check_replication'
    read_key_method = check_classic_module + '.read_key'

    mock_keys = [
        'team', 'notification_email', 'runbook', 'tip', 'page', 'alert_after',
        'realert_every'
    ]

    mock_default_data = dict([(key, None) for key in mock_keys])
    mock_default_data['team'] = 'test_team'

    mock_specific_data = dict([(key, "test_{0}".format(key))
                               for key in mock_keys])
    mock_specific_data['extra'] = {
        'replication': {
            'key': 'test_key',
            'default': 'test_default',
            'map': 'test_map'
        }
    }

    with nested(
            mock.patch(check_method, return_value=(-1, 'bar'), autospec=True),
            mock.patch(read_key_method, return_value=-2, autospec=True),
    ):
        expected = {
            'name': 'replication_test_service',
            'status': -1,
            'output': 'bar',
            'team': 'test_team',
            'notification_email': None,
            'runbook': 'no runbook',
            'tip': 'no tip',
            'page': False,
            'check_every': '1m',
            'alert_after': '0s',
            'realert_every': -1
        }
        results = do_replication_check('test_service', mock_default_data, 3)
        assert expected == results

        expected = {
            'name': 'replication_test_service',
            'status': -1,
            'output': 'bar',
            'team': 'test_team',
            'notification_email': 'test_notification_email',
            'runbook': 'test_runbook',
            'tip': 'test_tip',
            'page': 'test_page',
            'check_every': '1m',
            'alert_after': 'test_alert_after',
            'realert_every': 'test_realert_every'
        }
        results = do_replication_check('test_service', mock_specific_data, 3)
        assert expected == results
def test_do_replication_check():
    base_module = 'paasta_tools.monitoring'
    check_classic_module = base_module + '.check_classic_service_replication'

    check_method = check_classic_module + '.check_replication'
    read_key_method = check_classic_module + '.read_key'

    mock_keys = ['team', 'notification_email', 'runbook', 'tip', 'page',
                 'alert_after', 'realert_every']

    mock_default_data = dict([(key, None) for key in mock_keys])
    mock_default_data['team'] = 'test_team'

    mock_specific_data = dict(
        [(key, "test_{0}".format(key)) for key in mock_keys]
    )
    mock_specific_data['extra'] = {
        'replication': {
            'key': 'test_key',
            'default': 'test_default',
            'map': 'test_map'
        }
    }

    with nested(
            mock.patch(check_method, return_value=(-1, 'bar')),
            mock.patch(read_key_method, return_value=-2)):
        expected = {
            'name': 'replication_test_service',
            'status': -1,
            'output': 'bar',
            'team': 'test_team',
            'notification_email': None,
            'runbook': 'no runbook',
            'tip': 'no tip',
            'page': False,
            'check_every': '1m',
            'alert_after': '0s',
            'realert_every': -1
        }
        results = do_replication_check('test_service', mock_default_data,
                                       3)
        assert expected == results

        expected = {
            'name': 'replication_test_service',
            'status': -1,
            'output': 'bar',
            'team': 'test_team',
            'notification_email': 'test_notification_email',
            'runbook': 'test_runbook',
            'tip': 'test_tip',
            'page': 'test_page',
            'check_every': '1m',
            'alert_after': 'test_alert_after',
            'realert_every': 'test_realert_every'
        }
        results = do_replication_check('test_service', mock_specific_data,
                                       3)
        assert expected == results