You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by av...@apache.org on 2017/04/06 14:30:15 UTC
[01/10] incubator-ariatosca git commit: fixed operation logging
issues in tests [Forced Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/cli-tests 479a3b10c -> e898e1064 (forced update)
fixed operation logging issues in 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/4275d215
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/4275d215
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/4275d215
Branch: refs/heads/cli-tests
Commit: 4275d2150e32968d45d1419ff0236f8c203f0fe7
Parents: e04ba1f
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 16:13:09 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 16:13:09 2017 +0300
----------------------------------------------------------------------
aria/orchestrator/context/common.py | 5 ++++-
tests/conftest.py | 9 ++-------
2 files changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4275d215/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 4cb7bce..61ef9c0 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -32,6 +32,9 @@ from aria.storage import exceptions
from ...utils.uuid import generate_uuid
+TASK_LOGGER_NAME = 'aria.executions.task'
+
+
class BaseContext(object):
"""
Base context object for workflow and operation
@@ -69,7 +72,7 @@ class BaseContext(object):
def _register_logger(self, level=None, task_id=None):
self.logger = self.PrefixedLogger(
- logging.getLogger('aria.executions.task'), self.logging_id, task_id=task_id)
+ logging.getLogger(TASK_LOGGER_NAME), self.logging_id, task_id=task_id)
self.logger.setLevel(level or logging.DEBUG)
if not self.logger.handlers:
self.logger.addHandler(aria_logger.create_console_log_handler())
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4275d215/tests/conftest.py
----------------------------------------------------------------------
diff --git a/tests/conftest.py b/tests/conftest.py
index c501eeb..e604eb8 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -18,6 +18,7 @@ import logging
import pytest
import aria
+from aria.orchestrator.context import common
@pytest.fixture(scope='session', autouse=True)
@@ -37,11 +38,5 @@ def logging_handler_cleanup(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 = []
+ logging.getLogger(common.TASK_LOGGER_NAME).handlers = []
request.addfinalizer(clear_logging_handlers)
[09/10] incubator-ariatosca git commit: Add tests for
service-templates delete
Posted by av...@apache.org.
Add tests for service-templates delete
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/81f8894e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/81f8894e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/81f8894e
Branch: refs/heads/cli-tests
Commit: 81f8894ebca689950f1de13b124f481891223862
Parents: d54b397
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 14:02:56 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/81f8894e/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d0daf59..9d210c1 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -141,3 +141,25 @@ class TestServiceTemplatesStore(TestCliBase):
expected_exception=AriaCliError,
expected_msg='Could not store service template `test_st`\n'
'There already a exists a service template with the same name')
+
+
+class TestServiceTemplatesDelete(TestCliBase):
+
+ def test_delete_no_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ monkeypatch.setattr(Core, 'delete_service_template', mock_object)
+ self.invoke('service_templates delete test_st')
+ assert 'Service template test_st deleted' in self.logger_output_string
+
+ def test_delete_raises_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ monkeypatch.setattr(Core,
+ 'delete_service_template',
+ raise_exception(storage_exceptions.NotFoundError))
+
+ assert_exception_raised(
+ self.invoke('service_templates delete test_st'),
+ expected_exception=AriaCliError,
+ expected_msg='')
[06/10] incubator-ariatosca git commit: Create testing framework for
the CLI, and add some tests
Posted by av...@apache.org.
Create testing framework for the CLI, and add some tests
The tests are of:
service-templates show
service-templates list
service-templates store
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/d54b3971
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d54b3971
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d54b3971
Branch: refs/heads/cli-tests
Commit: d54b3971f405e43d66a96ff2f710ae98f46030cb
Parents: 97b865f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:28:11 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/__init__.py | 1 -
aria/cli/commands/service_templates.py | 5 +-
tests/cli/base_test.py | 29 +++++-
tests/cli/runner.py | 10 +-
tests/cli/test_service_templates.py | 136 ++++++++++++++++++++++++++--
5 files changed, 160 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index 5da374b..7777791 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -17,7 +17,6 @@ from . import (
executions,
logs,
node_templates,
- node_templates,
nodes,
plugins,
service_templates,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index a0e651f..5fcc973 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -15,7 +15,6 @@
import os
-import json
from .. import utils
from .. import csar
@@ -66,7 +65,7 @@ def show(service_template_id, model_storage, logger):
logger.info('{0}\n'.format(service_template_dict['description'].encode('UTF-8') or ''))
logger.info('Existing services:')
- logger.info('{0}\n'.format(json.dumps([d['name'] for d in services])))
+ logger.info('{0}\n'.format([s['name'] for s in services]))
@service_templates.command(name='list',
@@ -122,7 +121,7 @@ def store(service_template_path, service_template_name, model_storage, resource_
service_template_name)
except storage_exceptions.StorageError as e:
handle_storage_exception(e, 'service template', service_template_name)
- logger.info('Service template stored')
+ logger.info('Service template {0} stored'.format(service_template_name))
@service_templates.command(name='delete',
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index c8c574b..d5db9c2 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,8 +6,33 @@ from utils import setup_logger
class TestCliBase(object):
- logger_output = StringIO()
- setup_logger(logger_name='aria.cli.main', output_stream=logger_output)
+ _logger_output = StringIO()
+ setup_logger(logger_name='aria.cli.main', output_stream=_logger_output)
def invoke(self, command):
+ self._logger_output.truncate(0)
return runner.invoke(command)
+
+ @property
+ def logger_output_string(self):
+ return self._logger_output.getvalue()
+
+
+def assert_exception_raised(outcome, expected_exception, expected_msg):
+ assert isinstance(outcome.exception, expected_exception)
+ assert expected_msg == str(outcome.exception)
+
+
+# This exists as I wanted to mocked a function using monkeypatch to return a function that raises an
+# exception. I tried doing that using a lambda in-place, but this can't be accomplished in a trivial
+# way it seems. So I wrote this silly function instead
+def raise_exception(exception, msg=''):
+
+ def inner(*args, **kwargs):
+ raise exception(msg)
+
+ return inner
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index 26af20a..8b4294a 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -2,11 +2,11 @@ import aria.cli.commands as commands
import click.testing
-def invoke(command):
- # TODO handle verbosity later
- command_string = ['service_templates', 'show', '1']
- command, sub, args = command_string[0], command_string[1], command_string[2:]
+def invoke(command_string):
+ # TODO handle verbosity and co. later
+ command_list = command_string.split()
+ command, sub, args = command_list[0], command_list[1], command_list[2:]
runner = click.testing.CliRunner()
outcome = runner.invoke(getattr(
getattr(commands, command), sub), args)
- return outcome
\ No newline at end of file
+ return outcome
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 8e1fa65..d0daf59 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,27 +1,143 @@
+from aria.cli import service_template_utils
from aria.cli.env import Environment
-from base_test import TestCliBase
-from aria.modeling.models import ServiceTemplate
+from aria.cli.exceptions import AriaCliError
+from aria.core import Core
+from aria.storage import exceptions as storage_exceptions
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception
+from tests.mock import models
+
+import pytest
+
+
+@pytest.fixture
+def mock_object(mocker):
+ return mocker.MagicMock()
class MockStorage(object):
def __init__(self):
- self.service_template = MockServiceTemplateStorage()
+ self.service_template = MockServiceTemplateStorage
class MockServiceTemplateStorage(object):
- def get(self, id_):
- if id_ == '1': # a service-template with no description and no services.
- st = ServiceTemplate()
- st.name = 'test_st'
+ @staticmethod
+ def list(**_):
+ return [models.create_service_template('test_st'),
+ models.create_service_template('test_st2')]
+
+ @staticmethod
+ def get(id):
+ st = models.create_service_template('test_st')
+ if id == '1': # no services and no description.
+ st.services = []
+ if id == '2': # no services, but an description
+ st.description = 'test_description'
st.services = []
- return st
+ if id == '3': # one service, and a description
+ service = models.create_service(st, 'test_s')
+ st.description = 'test_description'
+ st.services = [service]
+ if id == '4': # one service, and a description
+ service = models.create_service(st, 'test_s')
+ st.services = [service]
+ return st
class TestServiceTemplatesShow(TestCliBase):
def test_show_no_services_no_description(self, monkeypatch):
- # reroute the logger to a special location, and check it's content.
+
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates show 1')
+
+ assert 'Description:' not in self.logger_output_string
+ assert 'Existing services:\n[]' in self.logger_output_string
+
+ def test_show_no_services_yes_description(self, monkeypatch):
+
monkeypatch.setattr(Environment, 'model_storage', MockStorage())
- outcome = self.invoke('service_templates show 1')
+ self.invoke('service_templates show 2')
+
+ assert 'Description:\ntest_description' in self.logger_output_string
+ assert 'Existing services:\n[]' in self.logger_output_string
+
+ def test_show_one_service_yes_description(self, monkeypatch):
+
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates show 3')
+
+ assert 'Description:\ntest_description' in self.logger_output_string
+ assert "Existing services:\n['test_s']" in self.logger_output_string
+
+ def test_show_one_service_no_description(self, monkeypatch):
+
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates show 4')
+
+ assert 'Description:' not in self.logger_output_string
+ assert "Existing services:\n['test_s']" in self.logger_output_string
+
+ def test_show_exception_raise_when_no_service_template_with_given_id(self):
+
+ # TODO consider removing as it does not seem to test the cli but rather the message received
+ # from the storage
+ outcome = self.invoke('service_templates show 5')
+ assert_exception_raised(
+ outcome,
+ expected_exception=storage_exceptions.NotFoundError,
+ expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
+
+
+class TestServiceTemplatesList(TestCliBase):
+
+ def test_list_one_service_template(self, monkeypatch):
+
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates list')
+ assert 'test_st' in self.logger_output_string
+ assert 'test_st2' in self.logger_output_string
+
+ def test_list_ascending(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ self.invoke('service_templates list --sort-by name')
+ mock_object.service_template.list.assert_called_with(sort={'name': 'asc'})
+
+ def test_list_descending(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ self.invoke('service_templates list --sort-by name --descending')
+ mock_object.service_template.list.assert_called_with(sort={'name': 'desc'})
+
+ def test_list_default_sorting(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ self.invoke('service_templates list')
+ mock_object.service_template.list.assert_called_with(sort={'created_at': 'asc'})
+
+
+class TestServiceTemplatesStore(TestCliBase):
+
+ def test_store_no_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Core, 'create_service_template', mock_object)
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ self.invoke('service_templates store stubpath test_st')
+ assert 'Service template test_st stored' in self.logger_output_string
+
+ def test_store_raises_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ monkeypatch.setattr(Core,
+ 'create_service_template',
+ raise_exception(storage_exceptions.NotFoundError,
+ msg='UNIQUE constraint failed'))
+
+ outcome = self.invoke('service_templates store stubpath test_st')
+ assert_exception_raised(
+ outcome,
+ expected_exception=AriaCliError,
+ expected_msg='Could not store service template `test_st`\n'
+ 'There already a exists a service template with the same name')
[05/10] incubator-ariatosca git commit: Clean up the code a bit
Posted by av...@apache.org.
Clean up the code a bit
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e898e106
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e898e106
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e898e106
Branch: refs/heads/cli-tests
Commit: e898e1064fa51661c3ba39c711208dd58f856b3a
Parents: 314f09e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 16:25:47 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e898e106/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index f79b22e..d357fad 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -94,9 +94,8 @@ class TestServiceTemplatesShow(TestCliBase):
# TODO consider removing as it does not seem to test the cli but rather the message received
# from the storage
- outcome = self.invoke('service_templates show 5')
assert_exception_raised(
- outcome,
+ self.invoke('service_templates show 5'),
expected_exception=storage_exceptions.NotFoundError,
expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
@@ -146,9 +145,8 @@ class TestServiceTemplatesStore(TestCliBase):
raise_exception(storage_exceptions.NotFoundError,
msg='UNIQUE constraint failed'))
- outcome = self.invoke('service_templates store stubpath test_st')
assert_exception_raised(
- outcome,
+ self.invoke('service_templates store stubpath test_st'),
expected_exception=AriaCliError,
expected_msg='Could not store service template `test_st`\n'
'There already a exists a service template with the same name')
@@ -160,9 +158,8 @@ class TestServiceTemplatesStore(TestCliBase):
'create_service_template',
raise_exception(storage_exceptions.NotFoundError))
- outcome = self.invoke('service_templates store stubpath test_st')
assert_exception_raised(
- outcome,
+ self.invoke('service_templates store stubpath test_st'),
expected_exception=AriaCliError)
[03/10] incubator-ariatosca git commit: fixed a test
Posted by av...@apache.org.
fixed a test
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/eb75d85e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/eb75d85e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/eb75d85e
Branch: refs/heads/cli-tests
Commit: eb75d85ec66661f53325eb4761ada8168c08e1c2
Parents: 2ab146e
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 16:30:39 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 16:30:39 2017 +0300
----------------------------------------------------------------------
tests/modeling/test_models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb75d85e/tests/modeling/test_models.py
----------------------------------------------------------------------
diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py
index e459821..48793c3 100644
--- a/tests/modeling/test_models.py
+++ b/tests/modeling/test_models.py
@@ -180,7 +180,7 @@ class TestServiceTemplate(object):
@pytest.mark.parametrize(
'is_valid, description, created_at, updated_at, main_file_name',
[
- (False, {}, now, now, '/path'),
+ (False, [], now, now, '/path'),
(False, 'description', 'error', now, '/path'),
(False, 'description', now, 'error', '/path'),
(False, 'description', now, now, {}),
[08/10] incubator-ariatosca git commit: Add tests for
service-templates validate
Posted by av...@apache.org.
Add tests for service-templates validate
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/314f09e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/314f09e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/314f09e7
Branch: refs/heads/cli-tests
Commit: 314f09e736cd6824da4f4839ff260ba87699bfa2
Parents: 54f3f52
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 16:23:02 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/service_templates.py | 3 +--
tests/cli/test_service_templates.py | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/314f09e7/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 5fcc973..e2e21c7 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -169,8 +169,7 @@ def inputs(service_template_name, model_storage, logger):
@aria.pass_resource_storage
@aria.pass_plugin_manager
@aria.pass_logger
-def validate_service_template(service_template, model_storage, resource_storage, plugin_manager,
- logger):
+def validate(service_template, model_storage, resource_storage, plugin_manager, logger):
"""Validate a service template
`SERVICE_TEMPLATE` is the path or url of the service template or archive to validate.
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/314f09e7/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 3d5a8fb..f79b22e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -2,6 +2,7 @@ from aria.cli import service_template_utils
from aria.cli.env import Environment
from aria.cli.exceptions import AriaCliError
from aria.core import Core
+from aria.exceptions import AriaException
from aria.storage import exceptions as storage_exceptions
from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception
from tests.mock import models
@@ -198,3 +199,19 @@ class TestServiceTemplatesInputs(TestCliBase):
monkeypatch.setattr(Environment, 'model_storage', MockStorage())
self.invoke('service_templates inputs without_inputs')
assert 'No inputs' in self.logger_output_string
+
+
+class TestServiceTemplatesValidate(TestCliBase):
+
+ def test_validate_no_exception(self, monkeypatch, mock_object):
+ monkeypatch.setattr(Core, 'validate_service_template', mock_object)
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ self.invoke('service_templates validate stubpath')
+ assert 'Service template validated successfully' in self.logger_output_string
+
+ def test_validate_raises_exception(self, monkeypatch, mock_object):
+ monkeypatch.setattr(Core, 'validate_service_template', raise_exception(AriaException))
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ assert_exception_raised(
+ self.invoke('service_templates validate stubpath'),
+ expected_exception=AriaCliError)
[02/10] incubator-ariatosca git commit: moved TASK_LOG_NAME
Posted by av...@apache.org.
moved TASK_LOG_NAME
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/2ab146e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2ab146e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2ab146e3
Branch: refs/heads/cli-tests
Commit: 2ab146e394b2cae207e6db06a86e070660d0396f
Parents: 4275d21
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 16:18:07 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 16:18:07 2017 +0300
----------------------------------------------------------------------
aria/logger.py | 3 +++
aria/orchestrator/context/common.py | 6 ++----
tests/conftest.py | 4 ++--
3 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2ab146e3/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index e3039f5..bbb6c7a 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -21,6 +21,9 @@ import logging
from logging import handlers as logging_handlers
from datetime import datetime
+TASK_LOGGER_NAME = 'aria.executions.task'
+
+
_base_logger = logging.getLogger('aria')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2ab146e3/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 61ef9c0..11b5eb9 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -29,12 +29,10 @@ from aria import (
)
from aria.storage import exceptions
+from ... import logger
from ...utils.uuid import generate_uuid
-TASK_LOGGER_NAME = 'aria.executions.task'
-
-
class BaseContext(object):
"""
Base context object for workflow and operation
@@ -72,7 +70,7 @@ class BaseContext(object):
def _register_logger(self, level=None, task_id=None):
self.logger = self.PrefixedLogger(
- logging.getLogger(TASK_LOGGER_NAME), self.logging_id, task_id=task_id)
+ logging.getLogger(logger.TASK_LOGGER_NAME), self.logging_id, task_id=task_id)
self.logger.setLevel(level or logging.DEBUG)
if not self.logger.handlers:
self.logger.addHandler(aria_logger.create_console_log_handler())
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2ab146e3/tests/conftest.py
----------------------------------------------------------------------
diff --git a/tests/conftest.py b/tests/conftest.py
index e604eb8..312ee0b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -18,7 +18,7 @@ import logging
import pytest
import aria
-from aria.orchestrator.context import common
+from aria import logger
@pytest.fixture(scope='session', autouse=True)
@@ -38,5 +38,5 @@ def logging_handler_cleanup(request):
:return:
"""
def clear_logging_handlers():
- logging.getLogger(common.TASK_LOGGER_NAME).handlers = []
+ logging.getLogger(logger.TASK_LOGGER_NAME).handlers = []
request.addfinalizer(clear_logging_handlers)
[04/10] incubator-ariatosca git commit: fixed debugging issue in cli
Posted by av...@apache.org.
fixed debugging issue in cli
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/97b865f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/97b865f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/97b865f8
Branch: refs/heads/cli-tests
Commit: 97b865f8ec7f9c4f176afa00d284d31657aa61c7
Parents: eb75d85
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 16:52:45 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 16:52:45 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/__init__.py | 12 ++++++++++++
aria/cli/main.py | 35 +++++++++++------------------------
2 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/97b865f8/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index ae1e83e..5da374b 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -12,3 +12,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
+from . import (
+ executions,
+ logs,
+ node_templates,
+ node_templates,
+ nodes,
+ plugins,
+ service_templates,
+ services,
+ workflows
+)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/97b865f8/aria/cli/main.py
----------------------------------------------------------------------
diff --git a/aria/cli/main.py b/aria/cli/main.py
index 966096c..d06ad8a 100644
--- a/aria/cli/main.py
+++ b/aria/cli/main.py
@@ -13,22 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# TODO handle
-if __name__ == '__main__' and __package__ is None:
- import aria.cli
- __package__ = 'aria.cli'
-
-# from . import env
-from .cli import aria
-from .commands import service_templates
-from .commands import node_templates
-from .commands import services
-from .commands import nodes
-from .commands import workflows
-from .commands import executions
-from .commands import plugins
-from .commands import logs
-from .. import install_aria_extensions
+from aria import install_aria_extensions
+from aria.cli import commands
+from aria.cli.cli import aria
@aria.group(name='aria')
@@ -50,14 +37,14 @@ def _register_commands():
Register the CLI's commands.
"""
- _aria.add_command(service_templates.service_templates)
- _aria.add_command(node_templates.node_templates)
- _aria.add_command(services.services)
- _aria.add_command(nodes.nodes)
- _aria.add_command(workflows.workflows)
- _aria.add_command(executions.executions)
- _aria.add_command(plugins.plugins)
- _aria.add_command(logs.logs)
+ _aria.add_command(commands.service_templates.service_templates)
+ _aria.add_command(commands.node_templates.node_templates)
+ _aria.add_command(commands.services.services)
+ _aria.add_command(commands.nodes.nodes)
+ _aria.add_command(commands.workflows.workflows)
+ _aria.add_command(commands.executions.executions)
+ _aria.add_command(commands.plugins.plugins)
+ _aria.add_command(commands.logs.logs)
_register_commands()
[10/10] incubator-ariatosca git commit: Add test for non `unique
name` exception from service-templates store
Posted by av...@apache.org.
Add test for non `unique name` exception from service-templates store
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/fe6ee154
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/fe6ee154
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/fe6ee154
Branch: refs/heads/cli-tests
Commit: fe6ee154be942b51eec7d86e5e849290846848cb
Parents: 81f8894
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:02:18 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
aria/cli/utils.py | 2 +-
tests/cli/base_test.py | 2 +-
tests/cli/test_service_templates.py | 14 +++++++++++++-
3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/aria/cli/utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/utils.py b/aria/cli/utils.py
index 99315c4..44358ec 100644
--- a/aria/cli/utils.py
+++ b/aria/cli/utils.py
@@ -158,4 +158,4 @@ def handle_storage_exception(e, model_class, name):
'There already a exists a {model_class} with the same name' \
.format(model_class=model_class, name=name)
raise AriaCliError(msg)
- raise
+ raise AriaCliError()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index d5db9c2..1dae957 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -18,7 +18,7 @@ class TestCliBase(object):
return self._logger_output.getvalue()
-def assert_exception_raised(outcome, expected_exception, expected_msg):
+def assert_exception_raised(outcome, expected_exception, expected_msg=''):
assert isinstance(outcome.exception, expected_exception)
assert expected_msg == str(outcome.exception)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 9d210c1..c98bc7e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -127,7 +127,7 @@ class TestServiceTemplatesStore(TestCliBase):
self.invoke('service_templates store stubpath test_st')
assert 'Service template test_st stored' in self.logger_output_string
- def test_store_raises_exception(self, monkeypatch, mock_object):
+ def test_store_raises_exception_resulting_from_name_uniqueness(self, monkeypatch, mock_object):
monkeypatch.setattr(service_template_utils, 'get', mock_object)
monkeypatch.setattr(Core,
@@ -142,6 +142,18 @@ class TestServiceTemplatesStore(TestCliBase):
expected_msg='Could not store service template `test_st`\n'
'There already a exists a service template with the same name')
+ def test_store_raises_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ monkeypatch.setattr(Core,
+ 'create_service_template',
+ raise_exception(storage_exceptions.NotFoundError))
+
+ outcome = self.invoke('service_templates store stubpath test_st')
+ assert_exception_raised(
+ outcome,
+ expected_exception=AriaCliError)
+
class TestServiceTemplatesDelete(TestCliBase):
[07/10] incubator-ariatosca git commit: Add tests for
service-templates inputs
Posted by av...@apache.org.
Add tests for service-templates inputs
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/54f3f52c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/54f3f52c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/54f3f52c
Branch: refs/heads/cli-tests
Commit: 54f3f52cab9688df1b9eb7df3bab0de159ee2d22
Parents: fe6ee15
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:54:26 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 23 +++++++++++++++++++++++
tests/mock/models.py | 5 +++++
2 files changed, 28 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54f3f52c/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index c98bc7e..3d5a8fb 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -44,6 +44,16 @@ class MockServiceTemplateStorage(object):
st.services = [service]
return st
+ @staticmethod
+ def get_by_name(name):
+ st = models.create_service_template('test_st')
+ if name == 'with_inputs':
+ input = models.create_input(name='input1', value='value1')
+ st.inputs = {'input1': input}
+ if name == 'without_inputs':
+ st.inputs = {}
+ return st
+
class TestServiceTemplatesShow(TestCliBase):
@@ -175,3 +185,16 @@ class TestServiceTemplatesDelete(TestCliBase):
self.invoke('service_templates delete test_st'),
expected_exception=AriaCliError,
expected_msg='')
+
+
+class TestServiceTemplatesInputs(TestCliBase):
+
+ def test_inputs_existing_inputs(self, monkeypatch):
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates inputs with_inputs')
+ assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+ def test_inputs_no_inputs(self, monkeypatch):
+ monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ self.invoke('service_templates inputs without_inputs')
+ assert 'No inputs' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54f3f52c/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 6b7f810..9771fe2 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -221,6 +221,11 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
)
+def create_input(name, value):
+ p = models.Parameter()
+ return p.wrap(name, value)
+
+
def _dictify(item):
return dict(((item.name, item),))