def test_exceptions_logged_with_debug(): with mock.patch( 'paasta_tools.list_marathon_service_instances.get_services_for_cluster', autospec=True, ) as mock_get_services_for_cluster, mock.patch( 'paasta_tools.list_marathon_service_instances.load_marathon_service_config', autospec=True, ) as mock_load_marathon_service_config, mock.patch( 'paasta_tools.list_marathon_service_instances.load_system_paasta_config', autospec=True, ), mock.patch( 'paasta_tools.list_marathon_service_instances._log', autospec=True, ) as mock_log: mock_app = mock.MagicMock( format_marathon_app_dict=mock.MagicMock(side_effect=[Exception]), ) mock_get_services_for_cluster.return_value = [('service', 'broken_instance')] mock_load_marathon_service_config.side_effect = [mock_app] list_marathon_service_instances.get_desired_marathon_configs( '/fake/soa/dir') mock_log.assert_called_once_with( service='service', line=mock.ANY, component='deploy', level='debug', cluster=mock.ANY, instance='broken_instance', )
def test_exceptions_logged_with_debug(): with mock.patch( "paasta_tools.list_marathon_service_instances.get_services_for_cluster", autospec=True, ) as mock_get_services_for_cluster, mock.patch( "paasta_tools.list_marathon_service_instances.load_marathon_service_config", autospec=True, ) as mock_load_marathon_service_config, mock.patch( "paasta_tools.list_marathon_service_instances.load_system_paasta_config", autospec=True, ), mock.patch("paasta_tools.list_marathon_service_instances._log", autospec=True) as mock_log: mock_app = mock.MagicMock(format_marathon_app_dict=mock.MagicMock( side_effect=[Exception])) mock_get_services_for_cluster.return_value = [("service", "broken_instance")] mock_load_marathon_service_config.side_effect = [mock_app] list_marathon_service_instances.get_desired_marathon_configs( "/fake/soa/dir") mock_log.assert_called_once_with( service="service", line=mock.ANY, component="deploy", level="debug", cluster=mock.ANY, instance="broken_instance", )
def test_get_desired_marathon_configs(): with mock.patch( 'paasta_tools.list_marathon_service_instances.get_services_for_cluster', autospec=True, ) as mock_get_services_for_cluster, mock.patch( 'paasta_tools.list_marathon_service_instances.load_marathon_service_config', autospec=True, ) as mock_load_marathon_service_config, mock.patch( 'paasta_tools.list_marathon_service_instances.load_system_paasta_config', autospec=True, ), mock.patch( 'paasta_tools.list_marathon_service_instances._log', autospec=True, ): mock_app_dict = {'id': '/service.instance.git.configs'} mock_app = mock.MagicMock(format_marathon_app_dict=mock.MagicMock( return_value=mock_app_dict), ) mock_app_2 = mock.MagicMock( format_marathon_app_dict=mock.MagicMock(side_effect=[Exception]), ) mock_get_services_for_cluster.return_value = [('service', 'instance'), ('service', 'broken_instance')] mock_load_marathon_service_config.side_effect = [mock_app, mock_app_2] assert list_marathon_service_instances.get_desired_marathon_configs( '/fake/soa/dir', ) == ( { 'service.instance.git.configs': mock_app_dict }, { 'service.instance.git.configs': mock_app }, )
def test_get_desired_marathon_configs(): with contextlib.nested( mock.patch( 'paasta_tools.list_marathon_service_instances.get_services_for_cluster', autospec=True), mock.patch( 'paasta_tools.list_marathon_service_instances.load_marathon_service_config', autospec=True), mock.patch( 'paasta_tools.list_marathon_service_instances.load_system_paasta_config', autospec=True), ) as ( mock_get_services_for_cluster, mock_load_marathon_service_config, _, ): mock_app_dict = {'id': '/service.instance.git.configs'} mock_get_services_for_cluster.return_value = [('service', 'instance')] mock_load_marathon_service_config.return_value = mock.MagicMock( format_marathon_app_dict=mock.MagicMock( return_value=mock_app_dict), ) assert list_marathon_service_instances.get_desired_marathon_configs( '/fake/soa/dir') == { 'service.instance.git.configs': mock_app_dict }
def test_get_desired_marathon_configs(): with mock.patch( "paasta_tools.list_marathon_service_instances.get_services_for_cluster", autospec=True, ) as mock_get_services_for_cluster, mock.patch( "paasta_tools.list_marathon_service_instances.load_marathon_service_config", autospec=True, ) as mock_load_marathon_service_config, mock.patch( "paasta_tools.list_marathon_service_instances.load_system_paasta_config", autospec=True, ), mock.patch("paasta_tools.list_marathon_service_instances._log", autospec=True): mock_app_dict = {"id": "/service.instance.git.configs"} mock_app = mock.MagicMock(format_marathon_app_dict=mock.MagicMock( return_value=mock_app_dict)) mock_app_2 = mock.MagicMock(format_marathon_app_dict=mock.MagicMock( side_effect=[Exception])) mock_get_services_for_cluster.return_value = [ ("service", "instance"), ("service", "broken_instance"), ] mock_load_marathon_service_config.side_effect = [mock_app, mock_app_2] assert list_marathon_service_instances.get_desired_marathon_configs( "/fake/soa/dir") == ( { "service.instance.git.configs": mock_app_dict }, { "service.instance.git.configs": mock_app }, )
def test_get_desired_marathon_configs_handles_no_slaves(): with mock.patch( 'paasta_tools.list_marathon_service_instances.get_services_for_cluster', autospec=True, ), mock.patch( 'paasta_tools.list_marathon_service_instances.load_marathon_service_config', autospec=True, ), mock.patch( 'paasta_tools.list_marathon_service_instances.load_system_paasta_config', autospec=True, ) as mock_load_marathon_service_config: mock_load_marathon_service_config.return_value = mock.MagicMock( format_marathon_app_dict=mock.MagicMock( side_effect=NoSlavesAvailableError()), ) assert list_marathon_service_instances.get_desired_marathon_configs( '/fake/soadir/', ) == ({}, {})
def test_get_desired_marathon_configs(): with contextlib.nested( mock.patch('paasta_tools.list_marathon_service_instances.get_services_for_cluster', autospec=True), mock.patch('paasta_tools.list_marathon_service_instances.load_marathon_service_config', autospec=True), mock.patch('paasta_tools.list_marathon_service_instances.load_system_paasta_config', autospec=True), ) as ( mock_get_services_for_cluster, mock_load_marathon_service_config, _, ): mock_app_dict = {'id': '/service.instance.git.configs'} mock_get_services_for_cluster.return_value = [('service', 'instance')] mock_load_marathon_service_config.return_value = mock.MagicMock( format_marathon_app_dict=mock.MagicMock(return_value=mock_app_dict), ) assert list_marathon_service_instances.get_desired_marathon_configs( '/fake/soa/dir') == {'service.instance.git.configs': mock_app_dict}