From f55f34c9c4bdd3cc6b35e61df12b47b388d154bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Tr=C4=99bski?= Date: Thu, 20 Jul 2017 07:00:32 +0200 Subject: [PATCH] Refactor project tree Old project tree had everything mixed up in different locations. Not to mention that actual REST controllers resided in package that's name did not reflect the content. Reorganized the tree to be more predictable and easier to maintain. Change-Id: Ic9acc80a4cf7416394702d43141c96953c03beea --- etc/monasca/log-api-logging.conf | 2 +- monasca_log_api/app/api.py | 12 ++--- monasca_log_api/{api => app/base}/__init__.py | 0 .../common => app/base}/error_handlers.py | 2 +- .../{api => app/base}/exceptions.py | 0 .../common => app/base}/log_publisher.py | 2 +- .../{reference/common => app/base}/model.py | 0 .../{api/core => app/base}/request.py | 2 +- .../common => app/base}/validation.py | 2 +- .../{api/core => app/controller}/__init__.py | 0 .../controller/api}/__init__.py | 0 .../{ => app/controller}/api/headers.py | 0 .../controller}/api/healthcheck_api.py | 0 .../{ => app/controller}/api/logs_api.py | 0 .../{ => app/controller}/api/versions_api.py | 0 .../controller}/healthchecks.py | 3 +- .../common => app/controller/v2}/__init__.py | 0 .../v2 => app/controller/v2/aid}/__init__.py | 0 .../controller/v2/aid}/service.py | 6 +-- .../{reference => app/controller}/v2/logs.py | 8 +-- .../common => app/controller/v3}/__init__.py | 0 .../v3 => app/controller/v3/aid}/__init__.py | 0 .../controller/v3/aid}/bulk_processor.py | 8 +-- .../controller/v3/aid}/helpers.py | 4 +- .../{reference => app/controller}/v3/logs.py | 10 ++-- .../{reference => app/controller}/versions.py | 2 +- monasca_log_api/conf/__init__.py | 20 ++----- .../reference/v3/common/__init__.py | 0 monasca_log_api/tests/base.py | 2 +- monasca_log_api/tests/test_healthchecks.py | 2 +- monasca_log_api/tests/test_log_publisher.py | 18 +++---- monasca_log_api/tests/test_logs.py | 52 +++++++++---------- monasca_log_api/tests/test_logs_v3.py | 23 ++++---- monasca_log_api/tests/test_request.py | 4 +- monasca_log_api/tests/test_service.py | 30 +++++------ monasca_log_api/tests/test_v2_v3_compare.py | 10 ++-- monasca_log_api/tests/test_versions.py | 2 +- .../notes/project_tree-3a041cbffc83595a.yaml | 6 +++ 38 files changed, 111 insertions(+), 121 deletions(-) rename monasca_log_api/{api => app/base}/__init__.py (100%) rename monasca_log_api/{reference/common => app/base}/error_handlers.py (94%) rename monasca_log_api/{api => app/base}/exceptions.py (100%) rename monasca_log_api/{reference/common => app/base}/log_publisher.py (99%) rename monasca_log_api/{reference/common => app/base}/model.py (100%) rename monasca_log_api/{api/core => app/base}/request.py (98%) rename monasca_log_api/{reference/common => app/base}/validation.py (99%) rename monasca_log_api/{api/core => app/controller}/__init__.py (100%) rename monasca_log_api/{reference => app/controller/api}/__init__.py (100%) rename monasca_log_api/{ => app/controller}/api/headers.py (100%) rename monasca_log_api/{ => app/controller}/api/healthcheck_api.py (100%) rename monasca_log_api/{ => app/controller}/api/logs_api.py (100%) rename monasca_log_api/{ => app/controller}/api/versions_api.py (100%) rename monasca_log_api/{reference => app/controller}/healthchecks.py (96%) rename monasca_log_api/{reference/common => app/controller/v2}/__init__.py (100%) rename monasca_log_api/{reference/v2 => app/controller/v2/aid}/__init__.py (100%) rename monasca_log_api/{reference/v2/common => app/controller/v2/aid}/service.py (96%) rename monasca_log_api/{reference => app/controller}/v2/logs.py (93%) rename monasca_log_api/{reference/v2/common => app/controller/v3}/__init__.py (100%) rename monasca_log_api/{reference/v3 => app/controller/v3/aid}/__init__.py (100%) rename monasca_log_api/{reference/v3/common => app/controller/v3/aid}/bulk_processor.py (95%) rename monasca_log_api/{reference/v3/common => app/controller/v3/aid}/helpers.py (94%) rename monasca_log_api/{reference => app/controller}/v3/logs.py (91%) rename monasca_log_api/{reference => app/controller}/versions.py (98%) delete mode 100644 monasca_log_api/reference/v3/common/__init__.py create mode 100644 releasenotes/notes/project_tree-3a041cbffc83595a.yaml diff --git a/etc/monasca/log-api-logging.conf b/etc/monasca/log-api-logging.conf index 638ffa2e..234217b0 100644 --- a/etc/monasca/log-api-logging.conf +++ b/etc/monasca/log-api-logging.conf @@ -13,7 +13,7 @@ handlers = console, file [logger_kafka] qualname = kafka -level = DEBUG +level = INFO handlers = console, file propagate = 0 diff --git a/monasca_log_api/app/api.py b/monasca_log_api/app/api.py index 2eef4531..53d278ce 100644 --- a/monasca_log_api/app/api.py +++ b/monasca_log_api/app/api.py @@ -22,13 +22,13 @@ import six import falcon from oslo_log import log -from monasca_log_api.api.core import request +from monasca_log_api.app.base import error_handlers +from monasca_log_api.app.base import request +from monasca_log_api.app.controller import healthchecks +from monasca_log_api.app.controller.v2 import logs as v2_logs +from monasca_log_api.app.controller.v3 import logs as v3_logs +from monasca_log_api.app.controller import versions from monasca_log_api import config -from monasca_log_api.reference.common import error_handlers -from monasca_log_api.reference import healthchecks -from monasca_log_api.reference.v2 import logs as v2_logs -from monasca_log_api.reference.v3 import logs as v3_logs -from monasca_log_api.reference import versions def error_trap(app_name): diff --git a/monasca_log_api/api/__init__.py b/monasca_log_api/app/base/__init__.py similarity index 100% rename from monasca_log_api/api/__init__.py rename to monasca_log_api/app/base/__init__.py diff --git a/monasca_log_api/reference/common/error_handlers.py b/monasca_log_api/app/base/error_handlers.py similarity index 94% rename from monasca_log_api/reference/common/error_handlers.py rename to monasca_log_api/app/base/error_handlers.py index 4c6052da..db986511 100644 --- a/monasca_log_api/reference/common/error_handlers.py +++ b/monasca_log_api/app/base/error_handlers.py @@ -14,7 +14,7 @@ import falcon -from monasca_log_api.reference.common import model +from monasca_log_api.app.base import model def log_envelope_exception_handler(ex, req, resp, params): diff --git a/monasca_log_api/api/exceptions.py b/monasca_log_api/app/base/exceptions.py similarity index 100% rename from monasca_log_api/api/exceptions.py rename to monasca_log_api/app/base/exceptions.py diff --git a/monasca_log_api/reference/common/log_publisher.py b/monasca_log_api/app/base/log_publisher.py similarity index 99% rename from monasca_log_api/reference/common/log_publisher.py rename to monasca_log_api/app/base/log_publisher.py index 292fb055..4cdaf80d 100644 --- a/monasca_log_api/reference/common/log_publisher.py +++ b/monasca_log_api/app/base/log_publisher.py @@ -20,10 +20,10 @@ from monasca_common.kafka import producer from monasca_common.rest import utils as rest_utils from oslo_log import log +from monasca_log_api.app.base import model from monasca_log_api import conf from monasca_log_api.monitoring import client from monasca_log_api.monitoring import metrics -from monasca_log_api.reference.common import model LOG = log.getLogger(__name__) CONF = conf.CONF diff --git a/monasca_log_api/reference/common/model.py b/monasca_log_api/app/base/model.py similarity index 100% rename from monasca_log_api/reference/common/model.py rename to monasca_log_api/app/base/model.py diff --git a/monasca_log_api/api/core/request.py b/monasca_log_api/app/base/request.py similarity index 98% rename from monasca_log_api/api/core/request.py rename to monasca_log_api/app/base/request.py index ed214b27..319caed6 100644 --- a/monasca_log_api/api/core/request.py +++ b/monasca_log_api/app/base/request.py @@ -16,7 +16,7 @@ import falcon from oslo_context import context -from monasca_log_api.reference.common import validation +from monasca_log_api.app.base import validation _TENANT_ID_PARAM = 'tenant_id' """Name of the query-param pointing at project-id (tenant-id)""" diff --git a/monasca_log_api/reference/common/validation.py b/monasca_log_api/app/base/validation.py similarity index 99% rename from monasca_log_api/reference/common/validation.py rename to monasca_log_api/app/base/validation.py index afe27455..6ec033cd 100644 --- a/monasca_log_api/reference/common/validation.py +++ b/monasca_log_api/app/base/validation.py @@ -18,7 +18,7 @@ import falcon from oslo_log import log import six -from monasca_log_api.api import exceptions +from monasca_log_api.app.base import exceptions from monasca_log_api import conf LOG = log.getLogger(__name__) diff --git a/monasca_log_api/api/core/__init__.py b/monasca_log_api/app/controller/__init__.py similarity index 100% rename from monasca_log_api/api/core/__init__.py rename to monasca_log_api/app/controller/__init__.py diff --git a/monasca_log_api/reference/__init__.py b/monasca_log_api/app/controller/api/__init__.py similarity index 100% rename from monasca_log_api/reference/__init__.py rename to monasca_log_api/app/controller/api/__init__.py diff --git a/monasca_log_api/api/headers.py b/monasca_log_api/app/controller/api/headers.py similarity index 100% rename from monasca_log_api/api/headers.py rename to monasca_log_api/app/controller/api/headers.py diff --git a/monasca_log_api/api/healthcheck_api.py b/monasca_log_api/app/controller/api/healthcheck_api.py similarity index 100% rename from monasca_log_api/api/healthcheck_api.py rename to monasca_log_api/app/controller/api/healthcheck_api.py diff --git a/monasca_log_api/api/logs_api.py b/monasca_log_api/app/controller/api/logs_api.py similarity index 100% rename from monasca_log_api/api/logs_api.py rename to monasca_log_api/app/controller/api/logs_api.py diff --git a/monasca_log_api/api/versions_api.py b/monasca_log_api/app/controller/api/versions_api.py similarity index 100% rename from monasca_log_api/api/versions_api.py rename to monasca_log_api/app/controller/api/versions_api.py diff --git a/monasca_log_api/reference/healthchecks.py b/monasca_log_api/app/controller/healthchecks.py similarity index 96% rename from monasca_log_api/reference/healthchecks.py rename to monasca_log_api/app/controller/healthchecks.py index a77f7356..a29ebf18 100644 --- a/monasca_log_api/reference/healthchecks.py +++ b/monasca_log_api/app/controller/healthchecks.py @@ -13,10 +13,9 @@ # under the License. import falcon - from monasca_common.rest import utils as rest_utils -from monasca_log_api.api import healthcheck_api +from monasca_log_api.app.controller.api import healthcheck_api from monasca_log_api.healthcheck import kafka_check diff --git a/monasca_log_api/reference/common/__init__.py b/monasca_log_api/app/controller/v2/__init__.py similarity index 100% rename from monasca_log_api/reference/common/__init__.py rename to monasca_log_api/app/controller/v2/__init__.py diff --git a/monasca_log_api/reference/v2/__init__.py b/monasca_log_api/app/controller/v2/aid/__init__.py similarity index 100% rename from monasca_log_api/reference/v2/__init__.py rename to monasca_log_api/app/controller/v2/aid/__init__.py diff --git a/monasca_log_api/reference/v2/common/service.py b/monasca_log_api/app/controller/v2/aid/service.py similarity index 96% rename from monasca_log_api/reference/v2/common/service.py rename to monasca_log_api/app/controller/v2/aid/service.py index ecd9ac00..d2a393b6 100644 --- a/monasca_log_api/reference/v2/common/service.py +++ b/monasca_log_api/app/controller/v2/aid/service.py @@ -19,10 +19,10 @@ from monasca_common.rest import utils as rest_utils from oslo_config import cfg from oslo_log import log -from monasca_log_api.api import exceptions +from monasca_log_api.app.base import exceptions +from monasca_log_api.app.base import model +from monasca_log_api.app.base import validation from monasca_log_api import conf -from monasca_log_api.reference.common import model -from monasca_log_api.reference.common import validation LOG = log.getLogger(__name__) CONF = conf.CONF diff --git a/monasca_log_api/reference/v2/logs.py b/monasca_log_api/app/controller/v2/logs.py similarity index 93% rename from monasca_log_api/reference/v2/logs.py rename to monasca_log_api/app/controller/v2/logs.py index fd56666e..39ef7cf4 100644 --- a/monasca_log_api/reference/v2/logs.py +++ b/monasca_log_api/app/controller/v2/logs.py @@ -16,10 +16,10 @@ import falcon import six -from monasca_log_api.api import headers -from monasca_log_api.api import logs_api -from monasca_log_api.reference.common import log_publisher -from monasca_log_api.reference.v2.common import service +from monasca_log_api.app.base import log_publisher +from monasca_log_api.app.controller.api import headers +from monasca_log_api.app.controller.api import logs_api +from monasca_log_api.app.controller.v2.aid import service _DEPRECATED_INFO = ('/v2.0/log/single has been deprecated. ' 'Please use /v3.0/logs') diff --git a/monasca_log_api/reference/v2/common/__init__.py b/monasca_log_api/app/controller/v3/__init__.py similarity index 100% rename from monasca_log_api/reference/v2/common/__init__.py rename to monasca_log_api/app/controller/v3/__init__.py diff --git a/monasca_log_api/reference/v3/__init__.py b/monasca_log_api/app/controller/v3/aid/__init__.py similarity index 100% rename from monasca_log_api/reference/v3/__init__.py rename to monasca_log_api/app/controller/v3/aid/__init__.py diff --git a/monasca_log_api/reference/v3/common/bulk_processor.py b/monasca_log_api/app/controller/v3/aid/bulk_processor.py similarity index 95% rename from monasca_log_api/reference/v3/common/bulk_processor.py rename to monasca_log_api/app/controller/v3/aid/bulk_processor.py index 1a04ca59..1afa2e89 100644 --- a/monasca_log_api/reference/v3/common/bulk_processor.py +++ b/monasca_log_api/app/controller/v3/aid/bulk_processor.py @@ -14,10 +14,10 @@ from oslo_log import log +from monasca_log_api.app.base import log_publisher +from monasca_log_api.app.base import model +from monasca_log_api.app.base import validation from monasca_log_api import conf -from monasca_log_api.reference.common import log_publisher -from monasca_log_api.reference.common import model -from monasca_log_api.reference.common import validation LOG = log.getLogger(__name__) CONF = conf.CONF @@ -27,7 +27,7 @@ class BulkProcessor(log_publisher.LogPublisher): """BulkProcessor for effective log processing and publishing. BulkProcessor is customized version of - :py:class:`monasca_log_api.reference.common.log_publisher.LogPublisher` + :py:class:`monasca_log_api.app.base.log_publisher.LogPublisher` that utilizes processing of bulk request inside single loop. """ diff --git a/monasca_log_api/reference/v3/common/helpers.py b/monasca_log_api/app/controller/v3/aid/helpers.py similarity index 94% rename from monasca_log_api/reference/v3/common/helpers.py rename to monasca_log_api/app/controller/v3/aid/helpers.py index de4d99fe..228622e3 100644 --- a/monasca_log_api/reference/v3/common/helpers.py +++ b/monasca_log_api/app/controller/v3/aid/helpers.py @@ -19,8 +19,8 @@ import falcon from monasca_common.rest import utils as rest_utils from oslo_log import log -from monasca_log_api.api import exceptions -from monasca_log_api.reference.common import validation +from monasca_log_api.app.base import exceptions +from monasca_log_api.app.base import validation LOG = log.getLogger(__name__) diff --git a/monasca_log_api/reference/v3/logs.py b/monasca_log_api/app/controller/v3/logs.py similarity index 91% rename from monasca_log_api/reference/v3/logs.py rename to monasca_log_api/app/controller/v3/logs.py index 81aa8008..7d5654ca 100644 --- a/monasca_log_api/reference/v3/logs.py +++ b/monasca_log_api/app/controller/v3/logs.py @@ -16,12 +16,12 @@ import falcon from oslo_log import log -from monasca_log_api.api import exceptions -from monasca_log_api.api import logs_api +from monasca_log_api.app.base import exceptions +from monasca_log_api.app.base import validation +from monasca_log_api.app.controller.api import logs_api +from monasca_log_api.app.controller.v3.aid import bulk_processor +from monasca_log_api.app.controller.v3.aid import helpers from monasca_log_api.monitoring import metrics -from monasca_log_api.reference.common import validation -from monasca_log_api.reference.v3.common import bulk_processor -from monasca_log_api.reference.v3.common import helpers LOG = log.getLogger(__name__) diff --git a/monasca_log_api/reference/versions.py b/monasca_log_api/app/controller/versions.py similarity index 98% rename from monasca_log_api/reference/versions.py rename to monasca_log_api/app/controller/versions.py index 0590c29f..7cd58332 100644 --- a/monasca_log_api/reference/versions.py +++ b/monasca_log_api/app/controller/versions.py @@ -18,7 +18,7 @@ import six from monasca_common.rest import utils as rest_utils -from monasca_log_api.api import versions_api +from monasca_log_api.app.controller.api import versions_api _VERSIONS_TPL_DICT = { 'v2.0': { diff --git a/monasca_log_api/conf/__init__.py b/monasca_log_api/conf/__init__.py index d4ef831d..7d4dfe8a 100644 --- a/monasca_log_api/conf/__init__.py +++ b/monasca_log_api/conf/__init__.py @@ -33,33 +33,19 @@ def load_conf_modules(): - register_opts (required by :py:currentmodule:) """ - imported_modules = [] for modname in _list_module_names(): mod = importutils.import_module('monasca_log_api.conf.' + modname) required_funcs = ['register_opts', 'list_opts'] for func in required_funcs: - if not hasattr(mod, func): - msg = ("The module 'monasca_log_api.conf.%s' should have a" - " '%s' function which returns" - " the config options." - % (modname, func)) - LOG.warning(msg) - else: - imported_modules.append(mod) - - LOG.debug('Found %d modules that contain configuration', - len(imported_modules)) - - return imported_modules + if hasattr(mod, func): + yield mod def _list_module_names(): - module_names = [] package_path = os.path.dirname(os.path.abspath(__file__)) for _, modname, ispkg in pkgutil.iter_modules(path=[package_path]): if not (modname == "opts" and ispkg): - module_names.append(modname) - return module_names + yield modname def register_opts(): diff --git a/monasca_log_api/reference/v3/common/__init__.py b/monasca_log_api/reference/v3/common/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/monasca_log_api/tests/base.py b/monasca_log_api/tests/base.py index 716bc7cc..6986c86e 100644 --- a/monasca_log_api/tests/base.py +++ b/monasca_log_api/tests/base.py @@ -27,7 +27,7 @@ from oslo_context import fixture as oo_ctx from oslotest import base as oslotest_base import six -from monasca_log_api.api.core import request +from monasca_log_api.app.base import request from monasca_log_api import conf from monasca_log_api import config diff --git a/monasca_log_api/tests/test_healthchecks.py b/monasca_log_api/tests/test_healthchecks.py index 50432cf1..a982be18 100644 --- a/monasca_log_api/tests/test_healthchecks.py +++ b/monasca_log_api/tests/test_healthchecks.py @@ -16,8 +16,8 @@ import falcon import mock import simplejson as json +from monasca_log_api.app.controller import healthchecks from monasca_log_api.healthcheck import kafka_check as healthcheck -from monasca_log_api.reference import healthchecks from monasca_log_api.tests import base ENDPOINT = '/healthcheck' diff --git a/monasca_log_api/tests/test_log_publisher.py b/monasca_log_api/tests/test_log_publisher.py index af3499d9..f1f4ede7 100644 --- a/monasca_log_api/tests/test_log_publisher.py +++ b/monasca_log_api/tests/test_log_publisher.py @@ -24,8 +24,8 @@ from oslo_config import cfg from oslo_log import log import six -from monasca_log_api.reference.common import log_publisher -from monasca_log_api.reference.common import model +from monasca_log_api.app.base import log_publisher +from monasca_log_api.app.base import model from monasca_log_api.tests import base LOG = log.getLogger(__name__) @@ -34,7 +34,7 @@ EPOCH_START = datetime.datetime(1970, 1, 1) class TestSendMessage(base.BaseTestCase): - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_not_send_empty_message(self, _): instance = log_publisher.LogPublisher() @@ -50,7 +50,7 @@ class TestSendMessage(base.BaseTestCase): not_dict_value = 123 instance.send_message(not_dict_value) - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_not_send_message_missing_keys(self, _): # checks every combination of missing keys @@ -74,7 +74,7 @@ class TestSendMessage(base.BaseTestCase): instance.send_message, message) - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_not_send_message_missing_values(self, _): # original message assumes that every property has value @@ -98,7 +98,7 @@ class TestSendMessage(base.BaseTestCase): instance.send_message, tmp_message) - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_send_message(self, kafka_producer): instance = log_publisher.LogPublisher() @@ -133,7 +133,7 @@ class TestSendMessage(base.BaseTestCase): cfg.CONF.log_publisher.topics[0], [ujson.dumps(msg, ensure_ascii=False).encode('utf-8')]) - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_send_message_multiple_topics(self, _): topics = ['logs', 'analyzer', 'tester'] @@ -177,7 +177,7 @@ class TestSendMessage(base.BaseTestCase): topic, [json_msg.encode('utf-8')]) - @mock.patch('monasca_log_api.reference.common.log_publisher.producer' + @mock.patch('monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') def test_should_send_unicode_message(self, kp): instance = log_publisher.LogPublisher() @@ -216,7 +216,7 @@ class TestSendMessage(base.BaseTestCase): @mock.patch( - 'monasca_log_api.reference.common.log_publisher.producer' + 'monasca_log_api.app.base.log_publisher.producer' '.KafkaProducer') class TestTruncation(base.BaseTestCase): EXTRA_CHARS_SIZE = len(bytearray(ujson.dumps({ diff --git a/monasca_log_api/tests/test_logs.py b/monasca_log_api/tests/test_logs.py index 95fb9576..e999b04b 100644 --- a/monasca_log_api/tests/test_logs.py +++ b/monasca_log_api/tests/test_logs.py @@ -16,9 +16,9 @@ import falcon import mock -from monasca_log_api.api import exceptions as log_api_exceptions -from monasca_log_api.api import headers -from monasca_log_api.reference.v2 import logs +from monasca_log_api.app.base import exceptions as log_api_exceptions +from monasca_log_api.app.controller.api import headers +from monasca_log_api.app.controller.v2 import logs from monasca_log_api.tests import base ROLES = 'admin' @@ -31,8 +31,8 @@ def _init_resource(test): class TestApiLogsVersion(base.BaseApiTestCase): - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') def test_should_return_v2_as_version(self, _, __): logs_resource = logs.Logs() self.assertEqual('v2.0', logs_resource.version) @@ -40,8 +40,8 @@ class TestApiLogsVersion(base.BaseApiTestCase): class TestApiLogs(base.BaseApiTestCase): - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') def test_should_contain_deprecated_details_in_successful_response(self, _, __): @@ -62,8 +62,8 @@ class TestApiLogs(base.BaseApiTestCase): self.assertIn('deprecated', self.srmock.headers_dict) self.assertIn('link', self.srmock.headers_dict) - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') def test_should_fail_not_delegate_ok_cross_tenant_id(self, _, __): _init_resource(self) self.simulate_request( @@ -77,8 +77,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_403, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_pass_empty_cross_tenant_id_wrong_role(self, log_creator, kafka_publisher): @@ -102,8 +102,8 @@ class TestApiLogs(base.BaseApiTestCase): self.assertEqual(1, log_creator.new_log.call_count) self.assertEqual(1, log_creator.new_log_envelope.call_count) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_pass_empty_cross_tenant_id_ok_role(self, log_creator, kafka_publisher): @@ -127,8 +127,8 @@ class TestApiLogs(base.BaseApiTestCase): self.assertEqual(1, log_creator.new_log.call_count) self.assertEqual(1, log_creator.new_log_envelope.call_count) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_pass_delegate_cross_tenant_id_ok_role(self, log_creator, log_publisher): @@ -154,7 +154,7 @@ class TestApiLogs(base.BaseApiTestCase): self.assertEqual(1, log_creator.new_log_envelope.call_count) @mock.patch('monasca_common.rest.utils') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_fail_empty_dimensions_delegate(self, _, rest_utils): _init_resource(self) rest_utils.read_body.return_value = True @@ -172,8 +172,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(log_api_exceptions.HTTP_422, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_fail_for_invalid_content_type(self, _, __): _init_resource(self) @@ -189,8 +189,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_415, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_pass_payload_size_not_exceeded(self, _, __): _init_resource(self) @@ -210,8 +210,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_204, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_fail_payload_size_exceeded(self, _, __): _init_resource(self) @@ -231,8 +231,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_413, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_fail_payload_size_equal(self, _, __): _init_resource(self) @@ -252,8 +252,8 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_413, self.srmock.status) - @mock.patch('monasca_log_api.reference.v2.common.service.LogCreator') - @mock.patch('monasca_log_api.reference.common.log_publisher.LogPublisher') + @mock.patch('monasca_log_api.app.controller.v2.aid.service.LogCreator') + @mock.patch('monasca_log_api.app.base.log_publisher.LogPublisher') def test_should_fail_content_length(self, _, __): _init_resource(self) diff --git a/monasca_log_api/tests/test_logs_v3.py b/monasca_log_api/tests/test_logs_v3.py index b45e62ce..729e73e4 100644 --- a/monasca_log_api/tests/test_logs_v3.py +++ b/monasca_log_api/tests/test_logs_v3.py @@ -16,9 +16,9 @@ import falcon import mock import ujson as json -from monasca_log_api.api import exceptions as log_api_exceptions -from monasca_log_api.api import headers -from monasca_log_api.reference.v3 import logs +from monasca_log_api.app.base import exceptions as log_api_exceptions +from monasca_log_api.app.controller.api import headers +from monasca_log_api.app.controller.v3 import logs from monasca_log_api.tests import base ENDPOINT = '/logs' @@ -64,15 +64,14 @@ def _generate_v3_payload(log_count=None, messages=None): class TestApiLogsVersion(base.BaseApiTestCase): - @mock.patch('monasca_log_api.reference.v3.common.' - 'bulk_processor.BulkProcessor') + @mock.patch('monasca_log_api.app.controller.v3.aid' + '.bulk_processor.BulkProcessor') def test_should_return_v3_as_version(self, _): logs_resource = logs.Logs() self.assertEqual('v3.0', logs_resource.version) -@mock.patch('monasca_log_api.reference.common.log_publisher.producer.' - 'KafkaProducer') +@mock.patch('monasca_log_api.app.base.log_publisher.producer.KafkaProducer') @mock.patch('monasca_log_api.monitoring.client.monascastatsd.Connection') class TestApiLogsMonitoring(base.BaseApiTestCase): @@ -203,7 +202,7 @@ class TestApiLogsMonitoring(base.BaseApiTestCase): class TestApiLogs(base.BaseApiTestCase): - @mock.patch('monasca_log_api.reference.v3.common.bulk_processor.' + @mock.patch('monasca_log_api.app.controller.v3.aid.bulk_processor.' 'BulkProcessor') def test_should_pass_cross_tenant_id(self, bulk_processor): logs_resource = _init_resource(self) @@ -229,7 +228,7 @@ class TestApiLogs(base.BaseApiTestCase): global_dimensions=v3_body['dimensions'], log_tenant_id='1') - @mock.patch('monasca_log_api.reference.v3.common.bulk_processor.' + @mock.patch('monasca_log_api.app.controller.v3.aid.bulk_processor.' 'BulkProcessor') def test_should_fail_not_delegate_ok_cross_tenant_id(self, _): _init_resource(self) @@ -244,7 +243,7 @@ class TestApiLogs(base.BaseApiTestCase): ) self.assertEqual(falcon.HTTP_403, self.srmock.status) - @mock.patch('monasca_log_api.reference.v3.common.bulk_processor.' + @mock.patch('monasca_log_api.app.controller.v3.aid.bulk_processor.' 'BulkProcessor') def test_should_pass_empty_cross_tenant_id_wrong_role(self, bulk_processor): @@ -267,7 +266,7 @@ class TestApiLogs(base.BaseApiTestCase): self.assertEqual(falcon.HTTP_204, self.srmock.status) self.assertEqual(1, bulk_processor.send_message.call_count) - @mock.patch('monasca_log_api.reference.v3.common.bulk_processor.' + @mock.patch('monasca_log_api.app.controller.v3.aid.bulk_processor.' 'BulkProcessor') def test_should_pass_empty_cross_tenant_id_ok_role(self, bulk_processor): @@ -293,7 +292,7 @@ class TestApiLogs(base.BaseApiTestCase): class TestUnicodeLogs(base.BaseApiTestCase): - @mock.patch('monasca_log_api.reference.common.log_publisher.producer.' + @mock.patch('monasca_log_api.app.base.log_publisher.producer.' 'KafkaProducer') def test_should_send_unicode_messages(self, _): _init_resource(self) diff --git a/monasca_log_api/tests/test_request.py b/monasca_log_api/tests/test_request.py index ee97c26e..84aa255c 100644 --- a/monasca_log_api/tests/test_request.py +++ b/monasca_log_api/tests/test_request.py @@ -15,8 +15,8 @@ from falcon import testing from mock import mock -from monasca_log_api.api.core import request -from monasca_log_api.reference.common import validation +from monasca_log_api.app.base import request +from monasca_log_api.app.base import validation from monasca_log_api.tests import base diff --git a/monasca_log_api/tests/test_service.py b/monasca_log_api/tests/test_service.py index fc04fb61..7c911a9b 100644 --- a/monasca_log_api/tests/test_service.py +++ b/monasca_log_api/tests/test_service.py @@ -20,9 +20,9 @@ from falcon import errors from falcon import testing import mock -from monasca_log_api.api import exceptions -from monasca_log_api.reference.common import validation -from monasca_log_api.reference.v2.common import service as common_service +from monasca_log_api.app.base import exceptions +from monasca_log_api.app.base import validation +from monasca_log_api.app.controller.v2.aid import service as aid_service from monasca_log_api.tests import base @@ -47,22 +47,22 @@ class IsDelegate(base.BaseTestCase): class ParseDimensions(base.BaseTestCase): def test_should_fail_for_empty_dimensions(self): self.assertRaises(exceptions.HTTPUnprocessableEntity, - common_service.parse_dimensions, + aid_service.parse_dimensions, '') self.assertRaises(exceptions.HTTPUnprocessableEntity, - common_service.parse_dimensions, + aid_service.parse_dimensions, None) def test_should_fail_for_empty_dim_in_dimensions(self): err = self.assertRaises(exceptions.HTTPUnprocessableEntity, - common_service.parse_dimensions, + aid_service.parse_dimensions, ',') self.assertEqual(err.description, 'Dimension cannot be empty') def test_should_fail_for_invalid_dim_in_dimensions(self): invalid_dim = 'a' err = self.assertRaises(exceptions.HTTPUnprocessableEntity, - common_service.parse_dimensions, + aid_service.parse_dimensions, invalid_dim) self.assertEqual(err.description, '%s is not a valid dimension' % invalid_dim) @@ -75,29 +75,29 @@ class ParseDimensions(base.BaseTestCase): } self.assertDictEqual(expected, - common_service.parse_dimensions(dimensions)) + aid_service.parse_dimensions(dimensions)) class ParseApplicationType(base.BaseTestCase): def test_should_return_none_for_none(self): - self.assertIsNone(common_service.parse_application_type(None)) + self.assertIsNone(aid_service.parse_application_type(None)) def test_should_return_none_for_empty(self): - self.assertIsNone(common_service.parse_application_type('')) + self.assertIsNone(aid_service.parse_application_type('')) def test_should_return_none_for_whitespace_filled(self): - self.assertIsNone(common_service.parse_application_type(' ')) + self.assertIsNone(aid_service.parse_application_type(' ')) def test_should_return_value_for_ok_value(self): app_type = 'monasca' self.assertEqual(app_type, - common_service.parse_application_type(app_type)) + aid_service.parse_application_type(app_type)) def test_should_return_value_for_ok_value_with_spaces(self): app_type = ' monasca ' expected = 'monasca' self.assertEqual(expected, - common_service.parse_application_type(app_type)) + aid_service.parse_application_type(app_type)) class ApplicationTypeValidations(base.BaseTestCase): @@ -355,7 +355,7 @@ class LogMessageValidations(base.BaseTestCase): class LogsCreatorNewLog(base.BaseTestCase): def setUp(self): super(LogsCreatorNewLog, self).setUp() - self.instance = common_service.LogCreator() + self.instance = aid_service.LogCreator() @mock.patch('io.IOBase') def test_should_create_log_from_json(self, payload): @@ -409,7 +409,7 @@ class LogsCreatorNewLog(base.BaseTestCase): class LogCreatorNewEnvelope(base.BaseTestCase): def setUp(self): super(LogCreatorNewEnvelope, self).setUp() - self.instance = common_service.LogCreator() + self.instance = aid_service.LogCreator() def test_should_create_envelope(self): msg = u'Hello World' diff --git a/monasca_log_api/tests/test_v2_v3_compare.py b/monasca_log_api/tests/test_v2_v3_compare.py index ac49f316..87972ca4 100644 --- a/monasca_log_api/tests/test_v2_v3_compare.py +++ b/monasca_log_api/tests/test_v2_v3_compare.py @@ -15,17 +15,17 @@ import mock import ujson as json -from monasca_log_api.api import headers -from monasca_log_api.reference.v2 import logs as v2_logs -from monasca_log_api.reference.v3 import logs as v3_logs +from monasca_log_api.app.controller.api import headers +from monasca_log_api.app.controller.v2 import logs as v2_logs +from monasca_log_api.app.controller.v3 import logs as v3_logs from monasca_log_api.tests import base class TestApiSameV2V3Output(base.BaseApiTestCase): # noinspection PyProtectedMember - @mock.patch('monasca_log_api.reference.common.' - 'log_publisher.producer.KafkaProducer') + @mock.patch('monasca_log_api.app.base.log_publisher.' + 'producer.KafkaProducer') def test_send_identical_messages(self, _): # mocks only log publisher, so the last component that actually # sends data to kafka diff --git a/monasca_log_api/tests/test_versions.py b/monasca_log_api/tests/test_versions.py index 07b172b9..25a0b48a 100644 --- a/monasca_log_api/tests/test_versions.py +++ b/monasca_log_api/tests/test_versions.py @@ -15,7 +15,7 @@ import falcon import ujson as json -from monasca_log_api.reference import versions +from monasca_log_api.app.controller import versions from monasca_log_api.tests import base diff --git a/releasenotes/notes/project_tree-3a041cbffc83595a.yaml b/releasenotes/notes/project_tree-3a041cbffc83595a.yaml new file mode 100644 index 00000000..3d3b852a --- /dev/null +++ b/releasenotes/notes/project_tree-3a041cbffc83595a.yaml @@ -0,0 +1,6 @@ +--- +other: + - | + Refactored project tree into more predictable and organized + one. Old tree had everythin mixed up between different locations, + and it was very difficult to follow the code.