diff --git a/cloudkitty/api/app.py b/cloudkitty/api/app.py index 0290eb40..52e9bbf9 100644 --- a/cloudkitty/api/app.py +++ b/cloudkitty/api/app.py @@ -93,6 +93,7 @@ def load_app(): def build_wsgi_app(argv=None): service.prepare_service() + CONF.log_opt_values(LOG, log.DEBUG) return load_app() diff --git a/cloudkitty/cli/processor.py b/cloudkitty/cli/processor.py index cace2fdf..142fb202 100644 --- a/cloudkitty/cli/processor.py +++ b/cloudkitty/cli/processor.py @@ -13,11 +13,22 @@ # License for the specific language governing permissions and limitations # under the License. # +import cotyledon +from cotyledon import oslo_config_glue +from oslo_config import cfg +from oslo_log import log + from cloudkitty import service +CONF = cfg.CONF +LOG = log.getLogger(__name__) + + def main(): + sm = cotyledon.ServiceManager() service.prepare_service() + oslo_config_glue.setup(sm, CONF) # NOTE(mc): This import is done here to ensure that the prepare_service() # function is called before any cfg option. By importing the orchestrator @@ -25,7 +36,22 @@ def main(): # before the prepare_service(), making cfg.CONF returning default values # systematically. from cloudkitty import orchestrator - orchestrator.CloudKittyServiceManager().run() + + if CONF.orchestrator.max_workers: + sm.add( + orchestrator.CloudKittyProcessor, + workers=CONF.orchestrator.max_workers) + else: + LOG.info("No worker configured for CloudKitty processing.") + + if CONF.orchestrator.max_workers_reprocessing: + sm.add( + orchestrator.CloudKittyReprocessor, + workers=CONF.orchestrator.max_workers_reprocessing) + else: + LOG.info("No worker configured for CloudKitty reprocessing.") + + sm.run() if __name__ == '__main__': diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index 38e1e482..1398a0cc 100644 --- a/cloudkitty/orchestrator.py +++ b/cloudkitty/orchestrator.py @@ -741,21 +741,3 @@ class CloudKittyReprocessor(CloudKittyProcessor): scope.identifier, scope.start_reprocess_time, scope.end_reprocess_time) - - -class CloudKittyServiceManager(cotyledon.ServiceManager): - - def __init__(self): - super(CloudKittyServiceManager, self).__init__() - if CONF.orchestrator.max_workers: - self.cloudkitty_processor_service_id = self.add( - CloudKittyProcessor, workers=CONF.orchestrator.max_workers) - else: - LOG.info("No worker configured for CloudKitty processing.") - - if CONF.orchestrator.max_workers_reprocessing: - self.cloudkitty_reprocessor_service_id = self.add( - CloudKittyReprocessor, - workers=CONF.orchestrator.max_workers_reprocessing) - else: - LOG.info("No worker configured for CloudKitty reprocessing.") diff --git a/cloudkitty/tests/test_orchestrator.py b/cloudkitty/tests/test_orchestrator.py index 73f6573f..c3773996 100644 --- a/cloudkitty/tests/test_orchestrator.py +++ b/cloudkitty/tests/test_orchestrator.py @@ -170,66 +170,6 @@ class OrchestratorTest(tests.TestCase): self.assertEqual('fake2', worker._processors[2].name) self.assertEqual(1, worker._processors[2].obj.priority) - @mock.patch("cotyledon.ServiceManager.add") - @mock.patch("cotyledon._service_manager.ServiceManager.__init__") - def test_cloudkitty_service_manager_only_processing( - self, service_manager_init_mock, cotyledon_add_mock): - - OrchestratorTest.execute_cloudkitty_service_manager_test( - cotyledon_add_mock=cotyledon_add_mock, max_workers_reprocessing=0, - max_workers=1) - - self.assertTrue(service_manager_init_mock.called) - - @mock.patch("cotyledon.ServiceManager.add") - @mock.patch("cotyledon._service_manager.ServiceManager.__init__") - def test_cloudkitty_service_manager_only_reprocessing( - self, service_manager_init_mock, cotyledon_add_mock): - OrchestratorTest.execute_cloudkitty_service_manager_test( - cotyledon_add_mock=cotyledon_add_mock, max_workers_reprocessing=1, - max_workers=0) - - self.assertTrue(service_manager_init_mock.called) - - @mock.patch("cotyledon.ServiceManager.add") - @mock.patch("cotyledon._service_manager.ServiceManager.__init__") - def test_cloudkitty_service_manager_both_processings( - self, service_manager_init_mock, cotyledon_add_mock): - OrchestratorTest.execute_cloudkitty_service_manager_test( - cotyledon_add_mock=cotyledon_add_mock) - - self.assertTrue(service_manager_init_mock.called) - - @staticmethod - def execute_cloudkitty_service_manager_test(cotyledon_add_mock=None, - max_workers=1, - max_workers_reprocessing=1): - - original_conf = orchestrator.CONF - try: - orchestrator.CONF = mock.Mock() - orchestrator.CONF.orchestrator = mock.Mock() - orchestrator.CONF.orchestrator.max_workers = max_workers - orchestrator.CONF.orchestrator.max_workers_reprocessing = \ - max_workers_reprocessing - - orchestrator.CloudKittyServiceManager() - - expected_calls = [] - if max_workers: - expected_calls.append( - mock.call(orchestrator.CloudKittyProcessor, - workers=max_workers)) - - if max_workers_reprocessing: - expected_calls.append( - mock.call(orchestrator.CloudKittyReprocessor, - workers=max_workers_reprocessing)) - - cotyledon_add_mock.assert_has_calls(expected_calls) - finally: - orchestrator.CONF = original_conf - class WorkerTest(tests.TestCase): diff --git a/etc/oslo-config-generator/cloudkitty.conf b/etc/oslo-config-generator/cloudkitty.conf index bde81446..4857f9c3 100644 --- a/etc/oslo-config-generator/cloudkitty.conf +++ b/etc/oslo-config-generator/cloudkitty.conf @@ -1,6 +1,7 @@ [DEFAULT] output_file = etc/cloudkitty/cloudkitty.conf.sample namespace = cloudkitty.common.config +namespace = cotyledon namespace = oslo.concurrency namespace = oslo.db namespace = oslo.log @@ -8,4 +9,4 @@ namespace = oslo.messaging namespace = oslo.middleware.http_proxy_to_wsgi namespace = oslo.middleware.cors namespace = oslo.policy -namespace = keystonemiddleware.auth_token \ No newline at end of file +namespace = keystonemiddleware.auth_token