コード例 #1
0
def test_generate_configuration_healthcheck_mode():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with mock.patch(
        'nerve_tools.configure_nerve.get_ip_address',
        return_value='ip_address'
    ), mock.patch(
        'nerve_tools.configure_nerve.get_hostname',
        return_value='my_host'
    ), mock.patch(
        'nerve_tools.configure_nerve.generate_subconfiguration',
        return_value={'foo': 17}
    ) as mock_generate_subconfiguration:

        mock_service_info = {
            'port': 1234,
            'routes': [('remote_location', 'local_location')],
            'healthcheck_timeout_s': 2.0,
            'healthcheck_mode': 'tcp',
            'healthcheck_port': 7890,
            'advertise': ['region'],
            'extra_advertise': [('habitat:my_habitat', 'region:another_region')],
        }

        actual_config = configure_nerve.generate_configuration(
            paasta_services=[(
                'test_service',
                mock_service_info,
            )],
            puppet_services=[],
            heartbeat_path='test',
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
            labels_dir='/dev/null',
            envoy_listeners={},
        )

        mock_generate_subconfiguration.assert_called_once_with(
            service_name='test_service',
            service_info=mock_service_info,
            ip_address='ip_address',
            hacheck_port=6666,
            weight=10,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
            labels_dir='/dev/null',
            envoy_service_info=None,
        )

    assert expected_config == actual_config
コード例 #2
0
def test_generate_configuration_empty():
    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host')):

        configuration = configure_nerve.generate_configuration([], "")
        assert configuration == {'instance_id': 'my_host', 'services': {}, 'heartbeat_path': ''}
コード例 #3
0
def test_generate_configuration_healthcheck_mode():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host'),
        mock.patch('nerve_tools.configure_nerve.generate_subconfiguration',
                   return_value={'foo': 17})) as (
            _, _, mock_generate_subconfiguration):

        actual_config = configure_nerve.generate_configuration(
            services=[(
                'test_service',
                {
                    'port': 1234,
                    'routes': [('remote_location', 'local_location')],
                    'healthcheck_timeout_s': 2.0,
                    'healthcheck_mode': 'tcp',
                    'healthcheck_port': 7890,
                    'advertise': ['region'],
                    'extra_advertise': [('habitat:my_habitat', 'region:another_region')],
                }
            )],
            heartbeat_path='test',
            hacheck_port=6666,
            weight=1,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )

        mock_generate_subconfiguration.assert_called_once_with(
            service_name='test_service',
            advertise=['region'],
            extra_advertise=[('habitat:my_habitat', 'region:another_region')],
            port=1234,
            ip_address='ip_address',
            healthcheck_timeout_s=2.0,
            hacheck_uri='/tcp/test_service/7890/status',
            healthcheck_headers={},
            hacheck_port=6666,
            weight=1,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )

    assert expected_config == actual_config
コード例 #4
0
def test_generate_configuration_healthcheck_mode():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host'),
        mock.patch('nerve_tools.configure_nerve.generate_subconfiguration',
                   return_value={'foo': 17})) as (
            _, _, mock_generate_subconfiguration):

        mock_service_info = {
            'port': 1234,
            'routes': [('remote_location', 'local_location')],
            'healthcheck_timeout_s': 2.0,
            'healthcheck_mode': 'tcp',
            'healthcheck_port': 7890,
            'advertise': ['region'],
            'extra_advertise': [('habitat:my_habitat', 'region:another_region')],
        }

        actual_config = configure_nerve.generate_configuration(
            classic_services=[(
                'test_service',
                mock_service_info,
            )],
            paasta_services=[],
            heartbeat_path='test',
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )

        mock_generate_subconfiguration.assert_called_once_with(
            service_name='test_service',
            service_info=mock_service_info,
            ip_address='ip_address',
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )

    assert expected_config == actual_config
コード例 #5
0
def test_generate_configuration_empty():
    with contextlib.nested(
            mock.patch('nerve_tools.configure_nerve.get_ip_address',
                       return_value='ip_address'),
            mock.patch('nerve_tools.configure_nerve.get_hostname',
                       return_value='my_host')):

        configuration = configure_nerve.generate_configuration([], "")
        assert configuration == {
            'instance_id': 'my_host',
            'services': {},
            'heartbeat_path': ''
        }
コード例 #6
0
def test_generate_configuration_empty():
    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host')):

        configuration = configure_nerve.generate_configuration(
            services=[],
            heartbeat_path="",
            hacheck_port=6666,
            weight=1,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )
        assert configuration == {'instance_id': 'my_host', 'services': {}, 'heartbeat_path': ''}
コード例 #7
0
def test_generate_configuration_empty():
    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host')):

        configuration = configure_nerve.generate_configuration(
            classic_services=[],
            paasta_services=[],
            heartbeat_path="",
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
        )
        assert configuration == {'instance_id': 'my_host', 'services': {}, 'heartbeat_path': ''}
コード例 #8
0
def test_generate_configuration_healthcheck_mode():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with contextlib.nested(
        mock.patch('nerve_tools.configure_nerve.get_ip_address',
                   return_value='ip_address'),
        mock.patch('nerve_tools.configure_nerve.get_hostname',
                   return_value='my_host'),
        mock.patch('nerve_tools.configure_nerve.generate_subconfiguration',
                   return_value={'foo': 17})) as (
            _, _, mock_generate_subconfiguration):

        actual_config = configure_nerve.generate_configuration([(
            'test_service',
            {
                'port': 1234,
                'routes': [('remote_location', 'local_location')],
                'healthcheck_timeout_s': 2.0,
                'healthcheck_mode': 'tcp',
                'healthcheck_port': 7890,
                'advertise': ['region'],
                'extra_advertise': [('habitat:my_habitat', 'region:another_region')],
            }
        )], 'test')

        mock_generate_subconfiguration.assert_called_once_with(
            service_name='test_service',
            advertise=['region'],
            extra_advertise=[('habitat:my_habitat', 'region:another_region')],
            port=1234,
            ip_address='ip_address',
            healthcheck_timeout_s=2.0,
            hacheck_uri='/tcp/test_service/7890/status',
            healthcheck_headers={},
        )

    assert expected_config == actual_config
コード例 #9
0
def test_generate_configuration():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with contextlib.nested(
            mock.patch('nerve_tools.configure_nerve.get_ip_address',
                       return_value='ip_address'),
            mock.patch('nerve_tools.configure_nerve.get_hostname',
                       return_value='my_host'),
            mock.patch('nerve_tools.configure_nerve.generate_subconfiguration',
                       return_value={'foo':
                                     17})) as (_, _,
                                               mock_generate_subconfiguration):

        actual_config = configure_nerve.generate_configuration(
            [('test_service', {
                'port':
                1234,
                'healthcheck_timeout_s':
                2.0,
                'advertise': ['region'],
                'extra_advertise':
                [('habitat:my_habitat', 'region:another_region')],
            })], 'test')

        mock_generate_subconfiguration.assert_called_once_with(
            service_name='test_service',
            advertise=['region'],
            extra_advertise=[('habitat:my_habitat', 'region:another_region')],
            port=1234,
            ip_address='ip_address',
            healthcheck_timeout_s=2.0,
            hacheck_uri='/http/test_service/1234/status',
            healthcheck_headers={},
        )

    assert expected_config == actual_config
コード例 #10
0
def test_generate_configuration_empty():
    with mock.patch(
        'nerve_tools.configure_nerve.get_ip_address',
        return_value='ip_address'
    ), mock.patch(
        'nerve_tools.configure_nerve.get_hostname',
        return_value='my_host'
    ):

        configuration = configure_nerve.generate_configuration(
            paasta_services=[],
            puppet_services=[],
            heartbeat_path="",
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
            labels_dir='/dev/null',
            envoy_listeners={},
        )
        assert configuration == {'instance_id': 'my_host', 'services': {}, 'heartbeat_path': ''}
コード例 #11
0
def test_generate_configuration_paasta_service_with_envoy_listeners():
    expected_config = {
        'instance_id': 'my_host',
        'services': {
            'foo': 17,
        },
        'heartbeat_path': 'test'
    }

    with mock.patch(
        'nerve_tools.configure_nerve.get_ip_address',
        return_value='ip_address'
    ), mock.patch(
        'nerve_tools.configure_nerve.get_hostname',
        return_value='my_host'
    ), mock.patch(
        'nerve_tools.configure_nerve.generate_subconfiguration',
        return_value={'foo': 17}
    ) as mock_generate_subconfiguration:

        mock_service_info = {
            'port': 1234,
            'healthcheck_timeout_s': 2.0,
            'advertise': ['region'],
            'extra_advertise': [('habitat:my_habitat', 'region:another_region')],
        }

        envoy_listeners = {1234: 35001}
        mock_envoy_service_main_info = copy.deepcopy(mock_service_info)
        mock_envoy_service_main_info.update({
            'port': 35001,
            'healthcheck_port': 35001,
            'extra_healthcheck_headers': {'Host': 'test_service.main'},
        })
        mock_envoy_service_alt_info = copy.deepcopy(mock_service_info)
        mock_envoy_service_alt_info.update({
            'port': 35001,
            'healthcheck_port': 35001,
            'extra_healthcheck_headers': {'Host': 'test_service.alt'},
        })

        actual_config = configure_nerve.generate_configuration(
            paasta_services=[
                (
                    'test_service.main',
                    mock_service_info,
                ),
                (
                    'test_service.alt',
                    mock_service_info,
                )
            ],
            puppet_services=[],
            heartbeat_path='test',
            hacheck_port=6666,
            weight=mock.sentinel.classic_weight,
            zk_topology_dir='/fake/path',
            zk_location_type='fake_zk_location_type',
            zk_cluster_type='fake_cluster_type',
            labels_dir='/dev/null',
            envoy_listeners=envoy_listeners,
        )

        mock_generate_subconfiguration.assert_has_calls([
            mock.call(
                service_name='test_service.main',
                service_info=mock_service_info,
                ip_address='ip_address',
                hacheck_port=6666,
                weight=10,
                zk_topology_dir='/fake/path',
                zk_location_type='fake_zk_location_type',
                zk_cluster_type='fake_cluster_type',
                labels_dir='/dev/null',
                envoy_service_info=mock_envoy_service_main_info,
            ),
            mock.call(
                service_name='test_service.alt',
                service_info=mock_service_info,
                ip_address='ip_address',
                hacheck_port=6666,
                weight=10,
                zk_topology_dir='/fake/path',
                zk_location_type='fake_zk_location_type',
                zk_cluster_type='fake_cluster_type',
                labels_dir='/dev/null',
                envoy_service_info=mock_envoy_service_alt_info,
            )
        ])

    assert expected_config == actual_config