diff --git a/masakari/cmd/api.py b/masakari/cmd/api.py index 7f0b014a..6c0b42db 100644 --- a/masakari/cmd/api.py +++ b/masakari/cmd/api.py @@ -53,18 +53,12 @@ def main(): objects.register_all() launcher = service.process_launcher() - started = 0 try: server = service.WSGIService("masakari_api", use_ssl=CONF.use_ssl) launcher.launch_service(server, workers=server.workers or 1) - started += 1 except exception.PasteAppNotFound as ex: - log.warning("%s. ``enabled_apis`` includes bad values. " - "Fix to remove this warning.", six.text_type(ex)) - - if started == 0: - log.error('No APIs were started. ' - 'Check the enabled_apis config option.') + log.error("Failed to start ``masakari_api`` service. Error: %s", + six.text_type(ex)) sys.exit(1) launcher.wait() diff --git a/masakari/tests/unit/cmd/__init__.py b/masakari/tests/unit/cmd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/masakari/tests/unit/cmd/test_masakari_api.py b/masakari/tests/unit/cmd/test_masakari_api.py index f5d4ef13..6f573d20 100644 --- a/masakari/tests/unit/cmd/test_masakari_api.py +++ b/masakari/tests/unit/cmd/test_masakari_api.py @@ -22,52 +22,32 @@ from masakari import test @mock.patch.object(config, 'parse_args', new=lambda *args, **kwargs: None) class TestMasakariAPI(test.NoDBTestCase): - def test_continues_on_failure(self, version_cache): - count = [1, 2] + def test_continues_without_failure(self): fake_server = mock.MagicMock() fake_server.workers = 123 def fake_service(api, **kw): - while count: - count.pop() - raise exception.PasteAppNotFound(name=api, path='/') return fake_server - self.flags(enabled_apis=['foo', 'bar', 'baz']) with mock.patch.object(api, 'service') as mock_service: mock_service.WSGIService.side_effect = fake_service api.main() mock_service.WSGIService.assert_has_calls([ - mock.call('foo', use_ssl=False), - mock.call('bar', use_ssl=False), - mock.call('baz', use_ssl=False), + mock.call('masakari_api', use_ssl=False), ]) launcher = mock_service.process_launcher.return_value launcher.launch_service.assert_called_once_with( fake_server, workers=123) - self.assertFalse(version_cache.called) + self.assertTrue(launcher.wait.called) @mock.patch('sys.exit') - def test_fails_if_none_started(self, mock_exit, version_cache): - mock_exit.side_effect = test.TestingException - self.flags(enabled_apis=[]) - with mock.patch.object(api, 'service') as mock_service: - self.assertRaises(test.TestingException, api.main) - mock_exit.assert_called_once_with(1) - launcher = mock_service.process_launcher.return_value - self.assertFalse(launcher.wait.called) - self.assertFalse(version_cache.called) - - @mock.patch('sys.exit') - def test_fails_if_all_failed(self, mock_exit, version_cache): - mock_exit.side_effect = test.TestingException - self.flags(enabled_apis=['foo', 'bar']) + def test_fails_if_all_failed(self, mock_exit): + mock_exit.side_effect = exception.MasakariException with mock.patch.object(api, 'service') as mock_service: mock_service.WSGIService.side_effect = exception.PasteAppNotFound( - name='foo', path='/') - self.assertRaises(test.TestingException, api.main) + name='masakari_api', path='/') + self.assertRaises(exception.MasakariException, api.main) mock_exit.assert_called_once_with(1) launcher = mock_service.process_launcher.return_value self.assertFalse(launcher.wait.called) - self.assertFalse(version_cache.called)