def test_delete_app_throws_exception(self): app_id = 'example--service.main.git93340779.configddb38a65' client = self.fake_marathon_client with contextlib.nested( mock.patch( 'paasta_tools.cleanup_marathon_jobs.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.bounce_lib.bounce_lock_zookeeper', autospec=True), mock.patch('paasta_tools.bounce_lib.delete_marathon_app', side_effect=ValueError('foo')), mock.patch('paasta_tools.cleanup_marathon_jobs._log', autospec=True), ) as ( mock_load_system_paasta_config, mock_bounce_lock_zookeeper, mock_delete_marathon_app, mock_log, ): with raises(ValueError): cleanup_marathon_jobs.delete_app(app_id, client, 'fake_soa_dir') assert 'example_service' in mock_log.mock_calls[0][2]["line"] assert 'Traceback' in mock_log.mock_calls[1][2]["line"]
def test_delete_app(self): app_id = 'example--service.main.git93340779.configddb38a65' client = self.fake_marathon_client with contextlib.nested( mock.patch('paasta_tools.cleanup_marathon_jobs.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.bounce_lib.bounce_lock_zookeeper', autospec=True), mock.patch('paasta_tools.bounce_lib.delete_marathon_app', autospec=True), mock.patch('paasta_tools.cleanup_marathon_jobs._log', autospec=True), mock.patch('paasta_tools.cleanup_marathon_jobs.send_event', autospec=True) ) as ( mock_load_system_paasta_config, mock_bounce_lock_zookeeper, mock_delete_marathon_app, mock_log, mock_send_sensu_event, ): mock_load_system_paasta_config.return_value.get_cluster = mock.Mock(return_value='fake_cluster') cleanup_marathon_jobs.delete_app(app_id, client, 'fake_soa_dir') mock_delete_marathon_app.assert_called_once_with(app_id, client) mock_load_system_paasta_config.return_value.get_cluster.assert_called_once_with() expected_log_line = ( 'Deleted stale marathon job that looks lost: ' + app_id ) mock_log.assert_called_once_with( instance='main', service='example_service', level='event', component='deploy', cluster='fake_cluster', line=expected_log_line, ) assert mock_send_sensu_event.call_count == 3
def test_delete_app(self): app_id = "example--service.main.git93340779.configddb38a65" client = self.fake_marathon_client with mock.patch( "paasta_tools.cleanup_marathon_jobs.load_system_paasta_config", autospec=True, ) as mock_load_system_paasta_config, mock.patch( "paasta_tools.bounce_lib.bounce_lock_zookeeper", autospec=True), mock.patch( "paasta_tools.bounce_lib.delete_marathon_app", autospec=True) as mock_delete_marathon_app, mock.patch( "paasta_tools.cleanup_marathon_jobs._log", autospec=True) as mock_log, mock.patch( "paasta_tools.cleanup_marathon_jobs.send_event", autospec=True) as mock_send_sensu_event: mock_load_system_paasta_config.return_value.get_cluster = mock.Mock( return_value="fake_cluster") cleanup_marathon_jobs.delete_app(app_id, client, "fake_soa_dir") mock_delete_marathon_app.assert_called_once_with(app_id, client) mock_load_system_paasta_config.return_value.get_cluster.assert_called_once_with( ) expected_log_line = "Deleted stale marathon job that looks lost: " + app_id mock_log.assert_called_once_with( instance="main", service="example_service", level="event", component="deploy", cluster="fake_cluster", line=expected_log_line, ) assert mock_send_sensu_event.call_count == 2
def test_delete_app_throws_exception(self): app_id = 'example--service.main.git93340779.configddb38a65' client = self.fake_marathon_client with contextlib.nested( mock.patch('paasta_tools.cleanup_marathon_jobs.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.bounce_lib.bounce_lock_zookeeper', autospec=True), mock.patch('paasta_tools.bounce_lib.delete_marathon_app', side_effect=ValueError('foo')), mock.patch('paasta_tools.cleanup_marathon_jobs._log', autospec=True), ) as ( mock_load_system_paasta_config, mock_bounce_lock_zookeeper, mock_delete_marathon_app, mock_log, ): with raises(ValueError): cleanup_marathon_jobs.delete_app(app_id, client, 'fake_soa_dir') assert 'example_service' in mock_log.mock_calls[0][2]["line"] assert 'Traceback' in mock_log.mock_calls[1][2]["line"]
def test_delete_app_throws_exception(self): app_id = "example--service.main.git93340779.configddb38a65" client = self.fake_marathon_client with mock.patch( "paasta_tools.cleanup_marathon_jobs.load_system_paasta_config", autospec=True, ), mock.patch("paasta_tools.bounce_lib.bounce_lock_zookeeper", autospec=True), mock.patch( "paasta_tools.bounce_lib.delete_marathon_app", side_effect=ValueError("foo"), autospec=True, ), mock.patch("paasta_tools.cleanup_marathon_jobs._log", autospec=True) as mock_log: with raises(ValueError): cleanup_marathon_jobs.delete_app(app_id, client, "fake_soa_dir") assert "example_service" in mock_log.mock_calls[0][2]["line"] assert "Traceback" in mock_log.mock_calls[1][2]["line"]