Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-106-Create-sqla-logging-handler ad0c52749 -> 248f1b11b
added logger handlers cleanup, and fixed some mock tests Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/248f1b11 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/248f1b11 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/248f1b11 Branch: refs/heads/ARIA-106-Create-sqla-logging-handler Commit: 248f1b11b80b0d3325a2e91b4ab2c838e07ec6fe Parents: ad0c527 Author: mxmrlv <[email protected]> Authored: Tue Feb 21 23:59:21 2017 +0200 Committer: mxmrlv <[email protected]> Committed: Tue Feb 21 23:59:21 2017 +0200 ---------------------------------------------------------------------- aria/orchestrator/workflows/executor/process.py | 1 - tests/conftest.py | 24 ++++++++++++++++++++ tests/orchestrator/execution_plugin/test_ssh.py | 7 ++++++ .../workflows/executor/test_process_executor.py | 3 +-- 4 files changed, 32 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/248f1b11/aria/orchestrator/workflows/executor/process.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index ecc8ca4..d999b37 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -362,7 +362,6 @@ def _patch_session(ctx, messenger, instrument): def _main(): - arguments_json_path = sys.argv[1] with open(arguments_json_path) as f: arguments = pickle.loads(f.read()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/248f1b11/tests/conftest.py ---------------------------------------------------------------------- diff --git a/tests/conftest.py b/tests/conftest.py index 4b24f18..c501eeb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging + import pytest import aria @@ -21,3 +23,25 @@ import aria @pytest.fixture(scope='session', autouse=True) def install_aria_extensions(): aria.install_aria_extensions() + + [email protected](autouse=True) +def logging_handler_cleanup(request): + """ + Each time a test runs, the loggers do not clear. we need to manually clear them or we'd have + logging overload. + + Since every type of logger (node/relationship/workflow) share the same name, we should + clear the logger each test. This should not happen in real world use. + :param request: + :return: + """ + def clear_logging_handlers(): + logged_ctx_names = [ + aria.orchestrator.context.workflow.WorkflowContext.__name__, + aria.orchestrator.context.operation.NodeOperationContext.__name__, + aria.orchestrator.context.operation.RelationshipOperationContext.__name__ + ] + for logger_name in logged_ctx_names: + logging.getLogger(logger_name).handlers = [] + request.addfinalizer(clear_logging_handlers) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/248f1b11/tests/orchestrator/execution_plugin/test_ssh.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/execution_plugin/test_ssh.py b/tests/orchestrator/execution_plugin/test_ssh.py index 0981b61..ad577f0 100644 --- a/tests/orchestrator/execution_plugin/test_ssh.py +++ b/tests/orchestrator/execution_plugin/test_ssh.py @@ -413,6 +413,13 @@ class TestFabricEnvHideGroupsAndRunCommands(object): task.runs_on = Stub logger = logging.getLogger() + @staticmethod + @contextlib.contextmanager + def _mock_self_logging(*args, **kwargs): + yield + _Ctx.logging_handlers = _mock_self_logging + + @pytest.fixture(autouse=True) def _setup(self, mocker): self.default_fabric_env = { http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/248f1b11/tests/orchestrator/workflows/executor/test_process_executor.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py index 1bdc1e4..2d43261 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor.py +++ b/tests/orchestrator/workflows/executor/test_process_executor.py @@ -112,7 +112,7 @@ def mock_plugin(plugin_manager, tmpdir): class MockContext(object): def __init__(self, *args, **kwargs): - pass + self.logger = logging.getLogger('mock_logger') def __getattr__(self, item): if item == 'serialization_dict': @@ -124,7 +124,6 @@ class MockContext(object): def deserialize_from_dict(cls, **kwargs): return cls() - class MockTask(object): INFINITE_RETRIES = aria_model.Task.INFINITE_RETRIES
