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/13 14:16:10 UTC
[01/14] incubator-ariatosca git commit: fixed ssh tests [Forced
Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/cli-tests dfcab849a -> b0e15483d (forced update)
fixed ssh 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/402eeb45
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/402eeb45
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/402eeb45
Branch: refs/heads/cli-tests
Commit: 402eeb45113b5ee873262dabe9e6f5812d5cac2d
Parents: e1b682b
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 13 11:39:16 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 13 11:39:16 2017 +0300
----------------------------------------------------------------------
tests/orchestrator/execution_plugin/test_ssh.py | 44 ++++++++++++--------
1 file changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/402eeb45/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 d17def1..5305d00 100644
--- a/tests/orchestrator/execution_plugin/test_ssh.py
+++ b/tests/orchestrator/execution_plugin/test_ssh.py
@@ -217,29 +217,39 @@ class TestWithActualSSHServer(object):
@workflow
def mock_workflow(ctx, graph):
node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
+ inputs = {
+ 'script_path': script_path,
+ 'fabric_env': _FABRIC_ENV,
+ 'process': process,
+ 'use_sudo': use_sudo,
+ 'hide_output': hide_output,
+ 'custom_env_var': custom_input,
+ 'test_operation': '',
+ 'commands': commands
+ }
interface = mock.models.create_interface(
node.service,
'test',
'op',
- operation_kwargs=dict(implementation='{0}.{1}'.format(
- operations.__name__,
- operation.__name__))
+ operation_kwargs=dict(
+ implementation='{0}.{1}'.format(
+ operations.__name__,
+ operation.__name__),
+ inputs=inputs)
)
node.interfaces[interface.name] = interface
- graph.sequence(*[api.task.OperationTask.for_node(
- node=node,
- interface_name='test',
- operation_name='op',
- inputs={
- 'script_path': script_path,
- 'fabric_env': _FABRIC_ENV,
- 'process': process,
- 'use_sudo': use_sudo,
- 'hide_output': hide_output,
- 'custom_env_var': custom_input,
- 'test_operation': test_operation,
- 'commands': commands
- }) for test_operation in test_operations])
+
+ ops = []
+ for test_operation in test_operations:
+ op_inputs = inputs.copy()
+ op_inputs['test_operation'] = test_operation
+ ops.append(api.task.OperationTask.for_node(
+ node=node,
+ interface_name='test',
+ operation_name='op',
+ inputs=op_inputs))
+
+ graph.sequence(*ops)
return graph
tasks_graph = mock_workflow(ctx=self._workflow_context) # pylint: disable=no-value-for-parameter
eng = engine.Engine(
[02/14] incubator-ariatosca git commit: fixed pylint issues
Posted by av...@apache.org.
fixed pylint issues
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7b8a4187
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7b8a4187
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7b8a4187
Branch: refs/heads/cli-tests
Commit: 7b8a4187948683a63355d652636254de7abc3b1a
Parents: 402eeb4
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 13 12:23:26 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 13 12:23:26 2017 +0300
----------------------------------------------------------------------
aria/.pylintrc | 2 +-
aria/modeling/utils.py | 4 ++--
aria/orchestrator/context/common.py | 5 +++--
aria/orchestrator/context/operation.py | 2 --
aria/orchestrator/context/workflow.py | 4 +---
aria/utils/threading.py | 4 ++--
aria/utils/type.py | 2 +-
tests/.pylintrc | 2 +-
8 files changed, 11 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/.pylintrc
----------------------------------------------------------------------
diff --git a/aria/.pylintrc b/aria/.pylintrc
index 7222605..7da8c56 100644
--- a/aria/.pylintrc
+++ b/aria/.pylintrc
@@ -77,7 +77,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
-disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,redefined-builtin,logging-format-interpolation,import-error,redefined-variable-type,broad-except,protected-access,global-statement,no-member
+disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,redefined-builtin,logging-format-interpolation,import-error,redefined-variable-type,broad-except,protected-access,global-statement,no-member,u
nused-argument
[REPORTS]
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index acae065..917f495 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -26,7 +26,7 @@ from ..utils.type import validate_value_type
class ModelJSONEncoder(JSONEncoder):
- def default(self, o):
+ def default(self, o): # pylint: disable=method-hidden
from .mixins import ModelMixin
if isinstance(o, ModelMixin):
if hasattr(o, 'value'):
@@ -56,7 +56,7 @@ def create_inputs(inputs, template_inputs):
value=input_val)
input_models.append(parameter)
- return {input.name: input for input in input_models}
+ return dict((inp.name, inp) for inp in input_models)
def _merge_and_validate_inputs(inputs, template_inputs):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 11b5eb9..15843db 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -29,7 +29,6 @@ from aria import (
)
from aria.storage import exceptions
-from ... import logger
from ...utils.uuid import generate_uuid
@@ -55,6 +54,7 @@ class BaseContext(object):
self,
name,
service_id,
+ execution_id,
model_storage,
resource_storage,
workdir=None,
@@ -65,12 +65,13 @@ class BaseContext(object):
self._model = model_storage
self._resource = resource_storage
self._service_id = service_id
+ self._execution_id = execution_id
self._workdir = workdir
self.logger = None
def _register_logger(self, level=None, task_id=None):
self.logger = self.PrefixedLogger(
- logging.getLogger(logger.TASK_LOGGER_NAME), self.logging_id, task_id=task_id)
+ logging.getLogger(aria_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/7b8a4187/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py
index cbd186c..c7d8246 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -36,7 +36,6 @@ class BaseOperationContext(BaseContext):
service_id,
task_id,
actor_id,
- execution_id,
**kwargs):
super(BaseOperationContext, self).__init__(
name=name,
@@ -47,7 +46,6 @@ class BaseOperationContext(BaseContext):
self._task_id = task_id
self._actor_id = actor_id
self._thread_local = threading.local()
- self._execution_id = execution_id
self._register_logger(task_id=self.task.id)
def __repr__(self):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/orchestrator/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/workflow.py b/aria/orchestrator/context/workflow.py
index ad4a2ff..667d22f 100644
--- a/aria/orchestrator/context/workflow.py
+++ b/aria/orchestrator/context/workflow.py
@@ -30,7 +30,6 @@ class WorkflowContext(BaseContext):
"""
def __init__(self,
workflow_name,
- execution_id,
parameters=None,
task_max_attempts=1,
task_retry_interval=0,
@@ -38,11 +37,10 @@ class WorkflowContext(BaseContext):
*args, **kwargs):
super(WorkflowContext, self).__init__(*args, **kwargs)
self._workflow_name = workflow_name
- self.parameters = parameters or {}
+ self._parameters = parameters or {}
self._task_max_attempts = task_max_attempts
self._task_retry_interval = task_retry_interval
self._task_ignore_failure = task_ignore_failure
- self._execution_id = execution_id
self._register_logger()
def __repr__(self):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/utils/threading.py
----------------------------------------------------------------------
diff --git a/aria/utils/threading.py b/aria/utils/threading.py
index 06c48bc..bfd30f5 100644
--- a/aria/utils/threading.py
+++ b/aria/utils/threading.py
@@ -277,5 +277,5 @@ class ExceptionThread(Thread):
def raise_error_if_exists(self):
if self.is_error():
- type_, value, tb = self.exception
- raise type_, value, tb
+ type_, value, trace = self.exception
+ raise type_, value, trace
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index fff0f2a..dad5427 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -40,7 +40,7 @@ def validate_value_type(value, type_name):
if type_ is None:
raise RuntimeError('No supported type_name was provided')
- if type(value) != type_:
+ if not isinstance(value, type_):
raise ValueError('Value {0} is not of type {1}'.format(value, type_name))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b8a4187/tests/.pylintrc
----------------------------------------------------------------------
diff --git a/tests/.pylintrc b/tests/.pylintrc
index 06409e9..eead6e8 100644
--- a/tests/.pylintrc
+++ b/tests/.pylintrc
@@ -77,7 +77,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
-disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,redefined-builtin,no-self-use,missing-docstring,attribute-defined-outside-init,redefined-outer-name,import-error,redefined-variable-type,broad
-except,protected-access,global-statement,too-many-locals,abstract-method,no-member
+disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,redefined-builtin,no-self-use,missing-docstring,attribute-defined-outside-init,redefined-outer-name,import-error,redefined-variable-type,broad
-except,protected-access,global-statement,too-many-locals,abstract-method,no-member,unused-argument
[REPORTS]
[07/14] incubator-ariatosca git commit: Add tests for node-templates
show
Posted by av...@apache.org.
Add tests for node-templates show
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/043374ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/043374ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/043374ad
Branch: refs/heads/cli-tests
Commit: 043374ade1840b0e787d215bb4142c1e60fb77b2
Parents: a948850
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 15:05:10 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/base_test.py | 5 ++--
tests/cli/test_node_templates.py | 49 +++++++++++++++++++++++++++++++++++
tests/cli/utils.py | 44 +++++++++++++++++++++++--------
tests/mock/models.py | 2 +-
4 files changed, 86 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/043374ad/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index a1a1acd..9268f71 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -1,10 +1,11 @@
from StringIO import StringIO
import logging
-import runner
-from utils import setup_logger, MockStorage
import pytest
+import tests.cli.runner as runner
+from tests.cli.utils import setup_logger, MockStorage
+
@pytest.fixture
def mock_storage():
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/043374ad/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
new file mode 100644
index 0000000..4fb2b9d
--- /dev/null
+++ b/tests/cli/test_node_templates.py
@@ -0,0 +1,49 @@
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodeTemplatesShow(TestCliBase):
+
+ def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 1')
+ assert 'Showing node template 1' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' in self.logger_output_string
+ assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+ assert 'No nodes' in self.logger_output_string
+ assert 'node1' not in self.logger_output_string
+
+ def test_one_property_no_nodes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 2')
+ assert 'Showing node template 2' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' not in self.logger_output_string
+ assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'No nodes' in self.logger_output_string
+ assert 'node1' not in self.logger_output_string
+
+ def test_no_properties_one_node(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 3')
+ assert 'Showing node template 3' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' in self.logger_output_string
+ assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+ assert 'No nodes' not in self.logger_output_string
+ assert 'node1' in self.logger_output_string
+
+ def test_one_property_one_node(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 4')
+ assert 'Showing node template 4' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' not in self.logger_output_string
+ assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'No nodes' not in self.logger_output_string
+ assert 'node1' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/043374ad/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 21047c9..a9ea44b 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -49,6 +49,7 @@ class MockStorage(object):
def __init__(self):
self.service_template = MockServiceTemplateStorage
self.service = MockServiceStorage()
+ self.node_template = MockNodeTemplateStorage
class MockServiceTemplateStorage(object):
@@ -63,14 +64,14 @@ class MockServiceTemplateStorage(object):
st = mock_models.create_service_template('test_st')
if id == '1': # no services and no description.
st.services = []
- if id == '2': # no services, but an description
+ elif id == '2': # no services, but an description
st.description = 'test_description'
st.services = []
- if id == '3': # one service, and a description
+ elif id == '3': # one service, and a description
service = mock_models.create_service(st, 'test_s')
st.description = 'test_description'
st.services = [service]
- if id == '4': # one service, and a description
+ elif id == '4': # one service, and a description
service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@@ -79,11 +80,11 @@ class MockServiceTemplateStorage(object):
def get_by_name(name):
st = mock_models.create_service_template('test_st')
if name == 'with_inputs':
- input = mock_models.create_input(name='input1', value='value1')
+ input = mock_models.create_parameter(name='input1', value='value1')
st.inputs = {'input1': input}
- if name == 'without_inputs':
+ elif name == 'without_inputs':
st.inputs = {}
- if name == 'one_service':
+ elif name == 'one_service':
service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@@ -104,7 +105,7 @@ class MockServiceStorage(object):
execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
execution.id = '1'
test_s.executions = [execution]
- if id == '2':
+ elif id == '2':
test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
node_template = mock_models.create_node_template(service_template=test_st)
node = mock_models.create_node(name='test_node',
@@ -121,15 +122,36 @@ class MockServiceStorage(object):
m = MagicMock()
m.id = '1'
return m
- if name == 'service_with_available_nodes':
+ elif name == 'service_with_available_nodes':
m = MagicMock()
m.id = '2'
return m
- if name == 'service_with_no_inputs':
+ elif name == 'service_with_no_inputs':
test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
- if name == 'service_with_one_input':
+ elif name == 'service_with_one_input':
test_s = mock_models.create_service(test_st, 'service_with_one_input')
- input = mock_models.create_input(name='input1', value='value1')
+ input = mock_models.create_parameter(name='input1', value='value1')
test_s.inputs = {'input1': input}
return test_s
+
+
+class MockNodeTemplateStorage(object):
+
+ @staticmethod
+ def get(id):
+ st = mock_models.create_service_template('test_st')
+ s = mock_models.create_service(st, 'test_s')
+ nt = mock_models.create_node_template(service_template=st, name='test_nt')
+ if id == '1':
+ pass
+ elif id == '2':
+ prop1 = mock_models.create_parameter('prop1', 'value1')
+ nt.properties = {'prop1': prop1}
+ elif id == '3':
+ mock_models.create_node('node1', nt, s)
+ elif id == '4':
+ prop1 = mock_models.create_parameter('prop1', 'value1')
+ nt.properties = {'prop1': prop1}
+ mock_models.create_node('node1', nt, s)
+ return nt
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/043374ad/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 84e452a..d2edb70 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -239,7 +239,7 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
)
-def create_input(name, value):
+def create_parameter(name, value):
p = models.Parameter()
return p.wrap(name, value)
[06/14] incubator-ariatosca git commit: Add tests for services list
Posted by av...@apache.org.
Add tests for services list
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/785b0b55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/785b0b55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/785b0b55
Branch: refs/heads/cli-tests
Commit: 785b0b555165a769d8a7d1569fc2f5e43c4fec4f
Parents: d209577
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 15:58:32 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/services.py | 4 +--
tests/cli/base_test.py | 2 +-
tests/cli/test_services.py | 57 ++++++++++++++++++++++++++++++++
tests/cli/utils.py | 15 ++++++++-
tests/storage/test_model_storage.py | 2 +-
5 files changed, 75 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/785b0b55/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 1059e10..b785006 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -58,10 +58,10 @@ def list(service_template_name,
if service_template_name:
logger.info('Listing services for service template {0}...'.format(
service_template_name))
- service_template = model_storage.service_template.get(service_template_name)
+ service_template = model_storage.service_template.get_by_name(service_template_name)
filters = dict(service_template=service_template)
else:
- logger.info('Listing all service...')
+ logger.info('Listing all services...')
filters = {}
services_list = [d.to_dict() for d in model_storage.service.list(
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/785b0b55/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 430781a..a1a1acd 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,7 +6,7 @@ from utils import setup_logger, MockStorage
import pytest
-@pytest.fixture()
+@pytest.fixture
def mock_storage():
return MockStorage()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/785b0b55/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
new file mode 100644
index 0000000..4f7b98b
--- /dev/null
+++ b/tests/cli/test_services.py
@@ -0,0 +1,57 @@
+import pytest
+from mock import ANY
+
+from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.env import Environment
+
+
+class TestServicesList(TestCliBase):
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'created_at', 'asc'),
+ ('', ' --descending', 'created_at', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_services_list_specified_service_template(self, monkeypatch, mock_storage, sort_by,
+ order, sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing services for service template test_st...' in self.logger_output_string
+ assert 'Listing all services...' not in self.logger_output_string
+
+ services_list = mock_storage.service.list
+ services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={'service_template': ANY})
+ assert 'Services:' in self.logger_output_string
+ assert 'test_st' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'created_at', 'asc'),
+ ('', ' --descending', 'created_at', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_services_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by,
+ order, sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing all services...' in self.logger_output_string
+ assert 'Listing services for service template' not in self.logger_output_string
+
+ services_list = mock_storage.service.list
+ services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output}, filters={})
+ assert 'Services:' in self.logger_output_string
+ assert 'test_st' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/785b0b55/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index c046ed3..97f6a67 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,7 @@
import logging
+from mock import MagicMock
+
from tests.mock import models
@@ -46,6 +48,7 @@ class MockStorage(object):
def __init__(self):
self.service_template = MockServiceTemplateStorage
+ self.service = MockServiceStorage()
class MockServiceTemplateStorage(object):
@@ -80,4 +83,14 @@ class MockServiceTemplateStorage(object):
st.inputs = {'input1': input}
if name == 'without_inputs':
st.inputs = {}
- return st
\ No newline at end of file
+ if name == 'one_service':
+ service = models.create_service(st, 'test_s')
+ st.services = [service]
+ return st
+
+
+class MockServiceStorage(object):
+
+ def __init__(self):
+ st = models.create_service_template('test_st')
+ self.list = MagicMock(return_value=[models.create_service(st, 'test_s')])
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/785b0b55/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 4dabfaf..8dd781b 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -167,7 +167,7 @@ class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixi
class TestFilterOperands(object):
- @pytest.fixture()
+ @pytest.fixture
def storage(self):
model_storage = application_model_storage(
sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)
[12/14] incubator-ariatosca git commit: Add tests for services delete
Posted by av...@apache.org.
Add tests for services 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/d9c520ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d9c520ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d9c520ee
Branch: refs/heads/cli-tests
Commit: d9c520eefd65555f20c280868bc4a9edcb300323
Parents: 60225a2
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 00:37:08 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_services.py | 50 ++++++++++++++++++++++++++++++----
tests/cli/utils.py | 53 +++++++++++++++++++++++++++---------
tests/mock/models.py | 60 ++++++++++++++++++++++++++---------------
3 files changed, 125 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d9c520ee/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 0c89b14..af10a45 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -3,7 +3,8 @@ from mock import ANY
from aria.cli.exceptions import AriaCliError
from aria.cli.env import Environment
from aria.core import Core
-from aria.exceptions import AriaException
+from aria.exceptions import (AriaException, DependentActiveExecutionsError,
+ DependentAvailableNodesError)
from aria.storage import exceptions as storage_exceptions
from tests.cli.base_test import TestCliBase, mock_storage, raise_exception, assert_exception_raised
from tests.mock.models import create_service, create_service_template
@@ -17,8 +18,8 @@ class TestServicesList(TestCliBase):
(' --sort-by name', '', 'name', 'asc'),
(' --sort-by name', ' --descending', 'name', 'desc')
])
- def test_services_list_specified_service_template(self, monkeypatch, mock_storage, sort_by,
- order, sort_by_in_output, order_in_output):
+ def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
monkeypatch.setattr(Environment, 'model_storage', mock_storage)
self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
@@ -39,8 +40,8 @@ class TestServicesList(TestCliBase):
(' --sort-by name', '', 'name', 'asc'),
(' --sort-by name', ' --descending', 'name', 'desc')
])
- def test_services_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by,
- order, sort_by_in_output, order_in_output):
+ def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
monkeypatch.setattr(Environment, 'model_storage', mock_storage)
self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
@@ -113,3 +114,42 @@ class TestServicesCreate(TestCliBase):
assert 'error creating service `test_s`' in self.logger_output_string
assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+
+class TestServicesDelete(TestCliBase):
+
+ def test_delete_no_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ monkeypatch.setattr(Core, 'delete_service', mock_object)
+ self.invoke('services delete test_s')
+ assert 'Deleting service test_s...' in self.logger_output_string
+ assert 'Service test_s deleted' in self.logger_output_string
+
+ def test_delete_active_execution_error(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ assert_exception_raised(
+ self.invoke('services delete service_with_active_executions'),
+ expected_exception=DependentActiveExecutionsError,
+ expected_msg="Can't delete service service_with_active_executions - there is an active "
+ "execution for this service. Active execution id: 1"
+ )
+ assert 'Deleting service service_with_active_executions...' in self.logger_output_string
+
+ def test_delete_available_nodes_error(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ assert_exception_raised(
+ self.invoke('services delete service_with_available_nodes'),
+ expected_exception=DependentAvailableNodesError,
+ expected_msg="Can't delete service service_with_active_executions - "
+ "there are available nodes for this service. Available node ids: 1"
+ )
+ assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
+
+ def test_delete_available_nodes_error_with_force(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('services delete service_with_available_nodes --force')
+
+ assert mock_storage.service.delete.call_count == 1
+ assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
+ assert 'Service service_with_available_nodes deleted' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d9c520ee/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 97f6a67..222a225 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,8 +1,8 @@
import logging
-
+from aria.modeling import models
from mock import MagicMock
-from tests.mock import models
+from tests.mock import models as mock_models
def setup_logger(logger_name,
@@ -55,36 +55,36 @@ class MockServiceTemplateStorage(object):
@staticmethod
def list(**_):
- return [models.create_service_template('test_st'),
- models.create_service_template('test_st2')]
+ return [mock_models.create_service_template('test_st'),
+ mock_models.create_service_template('test_st2')]
@staticmethod
def get(id):
- st = models.create_service_template('test_st')
+ st = mock_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 = []
if id == '3': # one service, and a description
- service = models.create_service(st, 'test_s')
+ service = mock_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')
+ service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@staticmethod
def get_by_name(name):
- st = models.create_service_template('test_st')
+ st = mock_models.create_service_template('test_st')
if name == 'with_inputs':
- input = models.create_input(name='input1', value='value1')
+ input = mock_models.create_input(name='input1', value='value1')
st.inputs = {'input1': input}
if name == 'without_inputs':
st.inputs = {}
if name == 'one_service':
- service = models.create_service(st, 'test_s')
+ service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@@ -92,5 +92,34 @@ class MockServiceTemplateStorage(object):
class MockServiceStorage(object):
def __init__(self):
- st = models.create_service_template('test_st')
- self.list = MagicMock(return_value=[models.create_service(st, 'test_s')])
+ self.st = mock_models.create_service_template('test_st')
+ self.list = MagicMock(return_value=[mock_models.create_service(self.st, 'test_s')])
+ self.delete = MagicMock()
+
+ @staticmethod
+ def get(id):
+ test_st = mock_models.create_service_template('test_st')
+ test_s = mock_models.create_service(test_st, 'service_with_active_executions')
+ if id == '1':
+ execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
+ execution.id = '1'
+ test_s.executions = [execution]
+ if id == '2':
+ node_template = mock_models.create_node_template(service_template=test_st)
+ node = mock_models.create_node(name='test_node',
+ dependency_node_template=node_template,
+ service=test_s,
+ state=models.Node.STARTED)
+ node.id = '1'
+ return test_s
+
+ @staticmethod
+ def get_by_name(name):
+ if name == 'service_with_active_executions':
+ m = MagicMock()
+ m.id = '1'
+ return m
+ if name == 'service_with_available_nodes':
+ m = MagicMock()
+ m.id = '2'
+ return m
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d9c520ee/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 9771fe2..84e452a 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -39,6 +39,7 @@ from aria.orchestrator.workflows.builtin.workflows import (
SERVICE_NAME = 'test_service_name'
SERVICE_TEMPLATE_NAME = 'test_service_template_name'
+NODE_TEMPLATE_NAME = 'test_node_template'
WORKFLOW_NAME = 'test_workflow_name'
TASK_RETRY_INTERVAL = 1
TASK_MAX_ATTEMPTS = 1
@@ -80,6 +81,33 @@ def create_service(service_template, name=SERVICE_NAME):
)
+def create_node_template(service_template,
+ name=NODE_TEMPLATE_NAME,
+ type=models.Type(variant='node', name='test_node_type'),
+ capability_templates=None,
+ requirement_templates=None,
+ interface_templates=None,
+ default_instances=1,
+ min_instances=1,
+ max_instances=1):
+ capability_templates = capability_templates or {}
+ requirement_templates = requirement_templates or []
+ interface_templates = interface_templates or {}
+ node_template = models.NodeTemplate(
+ name=name,
+ type=type,
+ capability_templates=capability_templates,
+ requirement_templates=requirement_templates,
+ interface_templates=interface_templates,
+ default_instances=default_instances,
+ min_instances=min_instances,
+ max_instances=max_instances,
+ service_template=service_template)
+
+ service_template.node_templates[node_template.name] = node_template
+ return node_template
+
+
def create_dependency_node_template(service_template, name=DEPENDENCY_NODE_TEMPLATE_NAME):
node_type = service_template.node_types.get_descendant('test_node_type')
capability_type = service_template.capability_types.get_descendant('test_capability_type')
@@ -88,18 +116,12 @@ def create_dependency_node_template(service_template, name=DEPENDENCY_NODE_TEMPL
name='capability',
type=capability_type
)
-
- node_template = models.NodeTemplate(
+ return create_node_template(
+ service_template=service_template,
name=name,
type=node_type,
- capability_templates=_dictify(capability_template),
- default_instances=1,
- min_instances=1,
- max_instances=1,
- service_template=service_template
+ capability_templates=_dictify(capability_template)
)
- service_template.node_templates[node_template.name] = node_template
- return node_template
def create_dependent_node_template(
@@ -110,29 +132,25 @@ def create_dependent_node_template(
name='requirement',
target_node_template=dependency_node_template
)
-
- node_template = models.NodeTemplate(
+ return create_node_template(
+ service_template=service_template,
name=name,
type=the_type,
- default_instances=1,
- min_instances=1,
- max_instances=1,
interface_templates=_dictify(get_standard_interface_template(service_template)),
requirement_templates=[requirement_template],
- service_template=service_template
)
- service_template.node_templates[node_template.name] = node_template
- return node_template
-def create_node(name, dependency_node_template, service):
+def create_node(name, dependency_node_template, service,
+ interfaces=None, state=models.Node.INITIAL):
+
node = models.Node(
name=name,
type=dependency_node_template.type,
runtime_properties={'ip': '1.1.1.1'},
version=None,
node_template=dependency_node_template,
- state=models.Node.INITIAL,
+ state=state,
scaling_groups=[],
service=service,
interfaces=get_standard_interface(service),
@@ -186,10 +204,10 @@ def create_interface(service, interface_name, operation_name, operation_kwargs=N
)
-def create_execution(service):
+def create_execution(service, status=models.Execution.PENDING):
return models.Execution(
service=service,
- status=models.Execution.PENDING,
+ status=status,
workflow_name=WORKFLOW_NAME,
created_at=datetime.utcnow(),
started_at=datetime.utcnow(),
[13/14] incubator-ariatosca git commit: Add tests for nodes show and
nodes list
Posted by av...@apache.org.
Add tests for nodes show and nodes list
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/b0e15483
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/b0e15483
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/b0e15483
Branch: refs/heads/cli-tests
Commit: b0e15483d7f2d72f08107e2c1c5bf5f00a99d7a9
Parents: e08a68d
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 17:13:04 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_nodes.py | 75 ++++++++++++++++++++++++++++++++++++++++++++
tests/cli/utils.py | 26 +++++++++++++--
tests/mock/models.py | 9 +++---
3 files changed, 104 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
new file mode 100644
index 0000000..7817e86
--- /dev/null
+++ b/tests/cli/test_nodes.py
@@ -0,0 +1,75 @@
+import pytest
+from mock import ANY
+
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodesShow(TestCliBase):
+
+ def test_no_attributes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes show 1')
+ assert 'Showing node 1' in self.logger_output_string
+ assert 'Node:' in self.logger_output_string
+ assert 'Node attributes:' in self.logger_output_string
+ assert 'No attributes' in self.logger_output_string
+ assert 'attribute1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+
+ def test_one_attribute(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes show 2')
+ assert 'Showing node 2' in self.logger_output_string
+ assert 'Node:' in self.logger_output_string
+ assert 'Node attributes:' in self.logger_output_string
+ assert 'No attributes' not in self.logger_output_string
+ assert 'attribute1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+
+class TestNodesList(TestCliBase):
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_name', 'asc'),
+ ('', ' --descending', 'service_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing nodes for service test_s...' in self.logger_output_string
+ assert 'Listing all nodes...' not in self.logger_output_string
+
+ nodes_list = mock_storage.node.list
+ nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={'service': ANY})
+ assert 'Nodes:' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+ assert 'test_n' in self.logger_output_string
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_name', 'asc'),
+ ('', ' --descending', 'service_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing nodes for service test_s...' not in self.logger_output_string
+ assert 'Listing all nodes...' in self.logger_output_string
+
+ nodes_list = mock_storage.node.list
+ nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={})
+ assert 'Nodes:' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+ assert 'test_n' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index b538826..a3868ab 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -50,6 +50,7 @@ class MockStorage(object):
self.service_template = MockServiceTemplateStorage
self.service = MockServiceStorage()
self.node_template = MockNodeTemplateStorage()
+ self.node = MockNodeStorage()
class MockServiceTemplateStorage(object):
@@ -118,6 +119,7 @@ class MockServiceStorage(object):
@staticmethod
def get_by_name(name):
test_st = mock_models.create_service_template('test_st')
+ test_s = mock_models.create_service(test_st, 'test_s')
if name == 'service_with_active_executions':
m = MagicMock()
m.id = '1'
@@ -127,9 +129,9 @@ class MockServiceStorage(object):
m.id = '2'
return m
elif name == 'service_with_no_inputs':
- test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
+ test_s. name = 'service_with_no_inputs'
elif name == 'service_with_one_input':
- test_s = mock_models.create_service(test_st, 'service_with_one_input')
+ test_s.name = 'service_with_one_input'
input = mock_models.create_parameter(name='input1', value='value1')
test_s.inputs = {'input1': input}
@@ -160,3 +162,23 @@ class MockNodeTemplateStorage(object):
nt.properties = {'prop1': prop1}
mock_models.create_node('node1', nt, s)
return nt
+
+class MockNodeStorage(object):
+
+ def __init__(self):
+ self.st = mock_models.create_service_template('test_st')
+ self.s = mock_models.create_service(self.st, 'test_s')
+ self.nt = mock_models.create_node_template(service_template=self.st, name='test_nt')
+ self.list = MagicMock(return_value=[mock_models.create_node('test_n', self.nt, self.s)])
+
+ @staticmethod
+ def get(id):
+ st = mock_models.create_service_template('test_st')
+ s = mock_models.create_service(st, 'test_s')
+ nt = mock_models.create_node_template(service_template=st, name='test_nt')
+ n = mock_models.create_node('test_n', nt, s)
+ if id == '1':
+ pass
+ elif id == '2':
+ n.runtime_properties = {'attribute1': 'value1'}
+ return n
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index d2edb70..2f641ad 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -141,13 +141,14 @@ def create_dependent_node_template(
)
-def create_node(name, dependency_node_template, service,
- interfaces=None, state=models.Node.INITIAL):
-
+def create_node(name, dependency_node_template, service, state=models.Node.INITIAL,
+ runtime_properties=None):
+ runtime_properties = runtime_properties or {}
+ tmp_runtime_properties = {'ip': '1.1.1.1'}
node = models.Node(
name=name,
type=dependency_node_template.type,
- runtime_properties={'ip': '1.1.1.1'},
+ runtime_properties=runtime_properties,
version=None,
node_template=dependency_node_template,
state=state,
[05/14] incubator-ariatosca git commit: added default NullHandler
support for py26
Posted by av...@apache.org.
added default NullHandler support for py26
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/d6458c03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d6458c03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d6458c03
Branch: refs/heads/cli-tests
Commit: d6458c0391877f531471fec5764ee2d2dec21ec8
Parents: 207cc09
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 13 17:05:57 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Apr 13 17:05:57 2017 +0300
----------------------------------------------------------------------
aria/logger.py | 9 +++++++++
aria/storage/core.py | 5 ++---
2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d6458c03/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index bbb6c7a..41e1ac8 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -21,6 +21,15 @@ import logging
from logging import handlers as logging_handlers
from datetime import datetime
+# NullHandler doesn't exist in < 27. this workaround is from
+# http://docs.python.org/release/2.6/library/logging.html#configuring-logging-for-a-library
+try:
+ from logging import NullHandler
+except ImportError:
+ class NullHandler(logging.Handler):
+ def emit(self, record):
+ pass
+
TASK_LOGGER_NAME = 'aria.executions.task'
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d6458c03/aria/storage/core.py
----------------------------------------------------------------------
diff --git a/aria/storage/core.py b/aria/storage/core.py
index 0e900bb..8caca66 100644
--- a/aria/storage/core.py
+++ b/aria/storage/core.py
@@ -37,9 +37,8 @@ API:
* drivers - module, a pool of ARIA standard drivers.
* StorageDriver - class, abstract model implementation.
"""
-import logging
-from aria.logger import LoggerMixin
+from aria.logger import LoggerMixin, NullHandler
from . import sql_mapi
__all__ = (
@@ -75,7 +74,7 @@ class Storage(LoggerMixin):
# Set the logger handler of any storage object to NullHandler.
# This is since the absence of a handler shows up while using the CLI in the form of:
# `No handlers could be found for logger "aria.ResourceStorage"`.
- self.logger.addHandler(logging.NullHandler())
+ self.logger.addHandler(NullHandler())
self.api = api_cls
self.registered = {}
self._initiator = initiator
[10/14] incubator-ariatosca git commit: Add tests for services create
Posted by av...@apache.org.
Add tests for services create
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/60225a2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/60225a2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/60225a2e
Branch: refs/heads/cli-tests
Commit: 60225a2e3e2b8cfecfffada56d691a3c71e5d458
Parents: 785b0b5
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 17:36:03 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_services.py | 62 ++++++++++++++++++++++++++++++--
tests/storage/test_model_storage.py | 2 +-
2 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60225a2e/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 4f7b98b..0c89b14 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,8 +1,12 @@
import pytest
from mock import ANY
-
-from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.exceptions import AriaCliError
from aria.cli.env import Environment
+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, mock_storage, raise_exception, assert_exception_raised
+from tests.mock.models import create_service, create_service_template
class TestServicesList(TestCliBase):
@@ -51,7 +55,61 @@ class TestServicesList(TestCliBase):
assert 'test_s' in self.logger_output_string
+class TestServicesCreate(TestCliBase):
+
+ def test_create_no_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+
+ test_st = create_service_template('test_st')
+ mock_object.return_value = create_service(test_st, 'test_s')
+ monkeypatch.setattr(Core, 'create_service', mock_object)
+ self.invoke('services create -t test_st test_s')
+
+ assert 'Creating new service from service template test_st...' in self.logger_output_string
+ assert "Service created. The service's name is test_s" in self.logger_output_string
+ def test_store_raises_storage_error_resulting_from_name_uniqueness(self, monkeypatch,
+ mock_object):
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ monkeypatch.setattr(Core,
+ 'create_service',
+ raise_exception(storage_exceptions.NotFoundError,
+ msg='UNIQUE constraint failed'))
+ assert_exception_raised(
+ self.invoke('services create -t test_st test_s'),
+ expected_exception=AriaCliError,
+ expected_msg='Could not store service `test_s`\n'
+ 'There already a exists a service with the same name')
+ assert 'Creating new service from service template test_st...' in self.logger_output_string
+ assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+ def test_store_raises_other_storage_error(self, monkeypatch, mock_object):
+ monkeypatch.setattr(Environment, 'model_storage', mock_object)
+ monkeypatch.setattr(Core,
+ 'create_service',
+ raise_exception(storage_exceptions.NotFoundError))
+
+ assert_exception_raised(
+ self.invoke('services create -t test_st test_s'),
+ expected_exception=AriaCliError)
+
+ assert 'Creating new service from service template test_st...' in self.logger_output_string
+ assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+ def test_store_raises_aria_exception(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ monkeypatch.setattr(Core,
+ 'create_service',
+ raise_exception(AriaException, msg='error creating service `test_s`'))
+ assert_exception_raised(
+ self.invoke('services create -t with_inputs test_s'),
+ expected_exception=AriaCliError,
+ expected_msg='error creating service `test_s`')
+ assert 'Creating new service from service template with_inputs...' in self.logger_output_string
+ assert 'error creating service `test_s`' in self.logger_output_string
+ assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert "Service created. The service's name is test_s" not in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/60225a2e/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 8dd781b..4dabfaf 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -167,7 +167,7 @@ class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixi
class TestFilterOperands(object):
- @pytest.fixture
+ @pytest.fixture()
def storage(self):
model_storage = application_model_storage(
sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)
[14/14] incubator-ariatosca git commit: Add tests for services inputs
Posted by av...@apache.org.
Add tests for services 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/a9488507
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/a9488507
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/a9488507
Branch: refs/heads/cli-tests
Commit: a948850791b2660d4ecfd2ac1803e1518289b382
Parents: d9c520e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 12:12:22 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 2 +-
tests/cli/test_services.py | 26 +++++++++++++++++++++++++-
tests/cli/utils.py | 12 +++++++++++-
3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9488507/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 46ba2ac..500124c 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -53,7 +53,7 @@ class TestServiceTemplatesShow(TestCliBase):
class TestServiceTemplatesList(TestCliBase):
- def test_list_one_service_template(self, monkeypatch, mock_storage):
+ def test_list_two_service_templates(self, monkeypatch, mock_storage):
monkeypatch.setattr(Environment, 'model_storage', mock_storage)
self.invoke('service_templates list')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9488507/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index af10a45..7538512 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -141,7 +141,7 @@ class TestServicesDelete(TestCliBase):
assert_exception_raised(
self.invoke('services delete service_with_available_nodes'),
expected_exception=DependentAvailableNodesError,
- expected_msg="Can't delete service service_with_active_executions - "
+ expected_msg="Can't delete service service_with_available_nodes - "
"there are available nodes for this service. Available node ids: 1"
)
assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
@@ -153,3 +153,27 @@ class TestServicesDelete(TestCliBase):
assert mock_storage.service.delete.call_count == 1
assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
assert 'Service service_with_available_nodes deleted' in self.logger_output_string
+
+class TestServicesOutputs(TestCliBase):
+ # TODO implement this after the `services outputs` command will work
+ pass
+
+
+class TestServicesInputs(TestCliBase):
+
+ def test_inputs_no_inputs(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('services inputs service_with_no_inputs')
+
+ assert 'Showing inputs for service service_with_no_inputs...' in self.logger_output_string
+ assert 'No inputs' in self.logger_output_string
+ assert 'input1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+
+ def test_inputs_one_input(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('services inputs service_with_one_input')
+
+ assert 'Showing inputs for service service_with_one_input...' in self.logger_output_string
+ assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'No inputs' not in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a9488507/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 222a225..21047c9 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -99,12 +99,13 @@ class MockServiceStorage(object):
@staticmethod
def get(id):
test_st = mock_models.create_service_template('test_st')
- test_s = mock_models.create_service(test_st, 'service_with_active_executions')
if id == '1':
+ test_s = mock_models.create_service(test_st, 'service_with_active_executions')
execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
execution.id = '1'
test_s.executions = [execution]
if id == '2':
+ test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
node_template = mock_models.create_node_template(service_template=test_st)
node = mock_models.create_node(name='test_node',
dependency_node_template=node_template,
@@ -115,6 +116,7 @@ class MockServiceStorage(object):
@staticmethod
def get_by_name(name):
+ test_st = mock_models.create_service_template('test_st')
if name == 'service_with_active_executions':
m = MagicMock()
m.id = '1'
@@ -123,3 +125,11 @@ class MockServiceStorage(object):
m = MagicMock()
m.id = '2'
return m
+ if name == 'service_with_no_inputs':
+ test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
+ if name == 'service_with_one_input':
+ test_s = mock_models.create_service(test_st, 'service_with_one_input')
+ input = mock_models.create_input(name='input1', value='value1')
+ test_s.inputs = {'input1': input}
+
+ return test_s
[11/14] incubator-ariatosca git commit: Add test for
service-templates create-archive
Posted by av...@apache.org.
Add test for service-templates create-archive
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/d2095770
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d2095770
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d2095770
Branch: refs/heads/cli-tests
Commit: d20957709d0ff723e6baa857bed8c0829e9b36a2
Parents: 9625e2d
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 11:35:40 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d2095770/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 48ffa30..46ba2ac 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,4 +1,4 @@
-from aria.cli import service_template_utils
+from aria.cli import service_template_utils, csar
from aria.cli.env import Environment
from aria.cli.exceptions import AriaCliError
from aria.core import Core
@@ -163,3 +163,11 @@ class TestServiceTemplatesValidate(TestCliBase):
assert_exception_raised(
self.invoke('service_templates validate stubpath'),
expected_exception=AriaCliError)
+
+
+class TestServiceTemplatesCreateArchive(TestCliBase):
+
+ def test_create_archive_successful(self, monkeypatch, mock_object):
+ monkeypatch.setattr(csar, 'write', mock_object)
+ self.invoke('service_templates create_archive stubpath stubdest')
+ assert 'Csar archive created at stubdest' in self.logger_output_string
[08/14] incubator-ariatosca git commit: Add tests for node-templates
list
Posted by av...@apache.org.
Add tests for node-templates list
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e08a68dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e08a68dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e08a68dd
Branch: refs/heads/cli-tests
Commit: e08a68dde0cd866322fc07d290817e47de28e8dc
Parents: 043374a
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 15:40:41 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_node_templates.py | 49 +++++++++++++++++++++++++++++++++++
tests/cli/test_services.py | 6 ++---
tests/cli/utils.py | 9 +++++--
3 files changed, 58 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e08a68dd/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index 4fb2b9d..aa202d4 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -1,3 +1,6 @@
+from mock import ANY
+import pytest
+
from aria.cli.env import Environment
from tests.cli.base_test import TestCliBase, mock_storage
@@ -47,3 +50,49 @@ class TestNodeTemplatesShow(TestCliBase):
assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
assert 'No nodes' not in self.logger_output_string
assert 'node1' in self.logger_output_string
+
+
+class TestNodeTemplatesList(TestCliBase):
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_template_name', 'asc'),
+ ('', ' --descending', 'service_template_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing node templates for service template test_st...' in self.logger_output_string
+ assert 'Listing all node templates...' not in self.logger_output_string
+
+ node_templates_list = mock_storage.node_template.list
+ node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={'service_template': ANY})
+ assert 'Node templates:' in self.logger_output_string
+ assert 'test_st' in self.logger_output_string
+ assert 'test_nt' in self.logger_output_string
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_template_name', 'asc'),
+ ('', ' --descending', 'service_template_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
+ assert 'Listing all node templates...' in self.logger_output_string
+ assert 'Listing node templates for service template test_st...' not in self.logger_output_string
+
+ node_templates_list = mock_storage.node_template.list
+ node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={})
+ assert 'Node templates:' in self.logger_output_string
+ assert 'test_st' in self.logger_output_string
+ assert 'test_nt' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e08a68dd/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 7538512..e23848b 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -22,8 +22,7 @@ class TestServicesList(TestCliBase):
sort_by_in_output, order_in_output):
monkeypatch.setattr(Environment, 'model_storage', mock_storage)
- self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
- order=order))
+ self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by, order=order))
assert 'Listing services for service template test_st...' in self.logger_output_string
assert 'Listing all services...' not in self.logger_output_string
@@ -44,8 +43,7 @@ class TestServicesList(TestCliBase):
sort_by_in_output, order_in_output):
monkeypatch.setattr(Environment, 'model_storage', mock_storage)
- self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
- order=order))
+ self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by, order=order))
assert 'Listing all services...' in self.logger_output_string
assert 'Listing services for service template' not in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e08a68dd/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index a9ea44b..b538826 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -49,7 +49,7 @@ class MockStorage(object):
def __init__(self):
self.service_template = MockServiceTemplateStorage
self.service = MockServiceStorage()
- self.node_template = MockNodeTemplateStorage
+ self.node_template = MockNodeTemplateStorage()
class MockServiceTemplateStorage(object):
@@ -138,6 +138,11 @@ class MockServiceStorage(object):
class MockNodeTemplateStorage(object):
+ def __init__(self):
+ self.st = mock_models.create_service_template('test_st')
+ self.list = MagicMock(return_value=[mock_models.create_node_template(self.st, 'test_nt')])
+
+
@staticmethod
def get(id):
st = mock_models.create_service_template('test_st')
@@ -154,4 +159,4 @@ class MockNodeTemplateStorage(object):
prop1 = mock_models.create_parameter('prop1', 'value1')
nt.properties = {'prop1': prop1}
mock_models.create_node('node1', nt, s)
- return nt
\ No newline at end of file
+ return nt
[04/14] incubator-ariatosca git commit: fixed pylint issues in tests
Posted by av...@apache.org.
fixed pylint 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/207cc093
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/207cc093
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/207cc093
Branch: refs/heads/cli-tests
Commit: 207cc093c6fe66fd9b1692a91f365fce1c72154a
Parents: 7f81c42
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 13 14:47:18 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 13 14:47:18 2017 +0300
----------------------------------------------------------------------
tests/cli/__init__.py | 2 +-
tests/cli/base_test.py | 1 -
tests/orchestrator/test_workflow_runner.py | 3 +--
3 files changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/207cc093/tests/cli/__init__.py
----------------------------------------------------------------------
diff --git a/tests/cli/__init__.py b/tests/cli/__init__.py
index 13878a1..ae1e83e 100644
--- a/tests/cli/__init__.py
+++ b/tests/cli/__init__.py
@@ -11,4 +11,4 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
\ No newline at end of file
+# limitations under the License.
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/207cc093/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 783631b..55da476 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -55,4 +55,3 @@ def get_default_logger_config():
_default_logger_config = get_default_logger_config()
-
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/207cc093/tests/orchestrator/test_workflow_runner.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/test_workflow_runner.py b/tests/orchestrator/test_workflow_runner.py
index aa89ac5..54e940f 100644
--- a/tests/orchestrator/test_workflow_runner.py
+++ b/tests/orchestrator/test_workflow_runner.py
@@ -174,11 +174,10 @@ def test_execution_inputs_override_workflow_inputs(request):
inputs=dict((name, models.Parameter.wrap(name, val)) for name, val
in wf_inputs.iteritems()))
- with mock.patch('aria.orchestrator.workflow_runner.Engine') as mock_engine_cls:
+ with mock.patch('aria.orchestrator.workflow_runner.Engine'):
workflow_runner = _create_workflow_runner(
request, mock_workflow, inputs={'input2': 'overriding-value2', 'input3': 7})
- _, engine_kwargs = mock_engine_cls.call_args
assert len(workflow_runner.execution.inputs) == 3
# did not override input1 - expecting the default value from the workflow inputs
assert workflow_runner.execution.inputs['input1'].value == 'value1'
[03/14] incubator-ariatosca git commit: add logutils to support
configuring logging via dict
Posted by av...@apache.org.
add logutils to support configuring logging via dict
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7f81c423
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7f81c423
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7f81c423
Branch: refs/heads/cli-tests
Commit: 7f81c4236ff3518fc4918e5d4715149b057ccf05
Parents: 7b8a418
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 13 14:39:34 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Apr 13 14:43:30 2017 +0300
----------------------------------------------------------------------
aria/cli/logger.py | 4 ++--
requirements.in | 4 ++++
requirements.txt | 17 ++++++++---------
3 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7f81c423/aria/cli/logger.py
----------------------------------------------------------------------
diff --git a/aria/cli/logger.py b/aria/cli/logger.py
index cbb916d..2f012d9 100644
--- a/aria/cli/logger.py
+++ b/aria/cli/logger.py
@@ -17,7 +17,7 @@
import os
import copy
import logging
-import logging.config
+from logutils import dictconfig
HIGH_VERBOSE = 3
@@ -111,4 +111,4 @@ class Logging(object):
log.setLevel(level)
self._all_loggers.append(logger_name)
- logging.config.dictConfig(logger_dict)
+ dictconfig.dictConfig(logger_dict)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7f81c423/requirements.in
----------------------------------------------------------------------
diff --git a/requirements.in b/requirements.in
index 32e2d04..3950140 100644
--- a/requirements.in
+++ b/requirements.in
@@ -10,6 +10,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# In order to create the requirements.txt file, execute
+# pip-compile --output-file requirements.txt requirements.in (pip-tools package is needed).
+
PyYAML<3.13
requests>=2.3.0, <2.14.0
networkx>=1.9, <1.10 # version 1.10 dropped support of python 2.6
@@ -30,6 +33,7 @@ colorama>=0.3.3, < 0.3.5
PrettyTable>=0.7,<0.8
click_didyoumean==0.0.3
backports.shutil_get_terminal_size==1.0.0
+logutils==0.3.4.1
# Since the tool we are using to generate our requirements.txt, `pip-tools`,
# does not currently support conditional dependencies (;), we're adding our original
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7f81c423/requirements.txt
----------------------------------------------------------------------
diff --git a/requirements.txt b/requirements.txt
index aba6aa7..3accaa3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,21 +4,19 @@
#
# pip-compile --output-file requirements.txt requirements.in
#
-
-# ----------------------------------------------------------------------------------
# Since the tool we are using to generate our requirements.txt, `pip-tools`,
# does not currently support conditional dependencies (;), we're adding our original
-# conditional dependencies here manually.
+# conditional dependencies here as comments, and manually adding them to our
+# generated requirements.txt file.
# The relevant pip-tools issue: https://github.com/jazzband/pip-tools/issues/435
-importlib==1.0.4 ; python_version < '2.7'
-ordereddict==1.1 ; python_version < '2.7'
-total-ordering==0.1.0 ; python_version < '2.7'
+importlib ; python_version < '2.7'
+ordereddict ; python_version < '2.7'
+total-ordering ; python_version < '2.7' # only one version on pypi
# Fabric makes use of this library, but doesn't bring it :(
pypiwin32==219 ; sys_platform == 'win32'
# ----------------------------------------------------------------------------------
-appdirs==1.4.3 # via setuptools
args==0.1.0 # via clint
asn1crypto==0.22.0 # via cryptography
backports.shutil_get_terminal_size==1.0.0
@@ -39,10 +37,11 @@ ipaddress==1.0.18 # via cryptography
jinja2==2.8.1
jsonpickle==0.9.4
lockfile==0.12.2 # via cachecontrol
+logutils==0.3.4.1
markupsafe==1.0 # via jinja2
msgpack-python==0.4.8 # via cachecontrol
networkx==1.9.1
-packaging==16.8 # via cryptography, setuptools
+packaging==16.8 # via cryptography
paramiko==2.1.2 # via fabric
prettytable==0.7.2
pyasn1==0.2.3 # via paramiko
@@ -54,7 +53,7 @@ retrying==1.3.3
ruamel.ordereddict==0.4.9 # via ruamel.yaml
ruamel.yaml==0.11.15
shortuuid==0.5.0
-six==1.10.0 # via cryptography, packaging, retrying, setuptools
+six==1.10.0 # via cryptography, packaging, retrying
sqlalchemy==1.1.6
wagon==0.6.0
wheel==0.29.0 # via wagon
[09/14] incubator-ariatosca git commit: Refactor basetest and fixtures
Posted by av...@apache.org.
Refactor basetest and fixtures
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/9625e2d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/9625e2d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/9625e2d6
Branch: refs/heads/cli-tests
Commit: 9625e2d6a6d9b75bfaffb33450efbbc8053adcc2
Parents: d6458c0
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 11 18:48:42 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/base_test.py | 10 ++--
tests/cli/test_service_templates.py | 79 ++++++--------------------------
tests/cli/utils.py | 43 +++++++++++++++++
tests/conftest.py | 5 ++
4 files changed, 70 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9625e2d6/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 55da476..430781a 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -1,11 +1,16 @@
from StringIO import StringIO
import logging
-#
+
import runner
-from utils import setup_logger
+from utils import setup_logger, MockStorage
import pytest
+@pytest.fixture()
+def mock_storage():
+ return MockStorage()
+
+
@pytest.mark.usefixtures("redirect_logger")
class TestCliBase(object):
@@ -54,4 +59,3 @@ def get_default_logger_config():
'level': logger.level}
_default_logger_config = get_default_logger_config()
-
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9625e2d6/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d357fad..48ffa30 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -4,87 +4,38 @@ 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
-
-import pytest
-
-
-@pytest.fixture
-def mock_object(mocker):
- return mocker.MagicMock()
-
-
-class MockStorage(object):
-
- def __init__(self):
- self.service_template = MockServiceTemplateStorage
-
-
-class MockServiceTemplateStorage(object):
-
- @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 = []
- 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
-
- @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
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception, mock_storage
class TestServiceTemplatesShow(TestCliBase):
- def test_show_no_services_no_description(self, monkeypatch):
+ def test_show_no_services_no_description(self, monkeypatch, mock_storage):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
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):
+ def test_show_no_services_yes_description(self, monkeypatch, mock_storage):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
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):
+ def test_show_one_service_yes_description(self, monkeypatch, mock_storage):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
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):
+ def test_show_one_service_no_description(self, monkeypatch, mock_storage):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
self.invoke('service_templates show 4')
assert 'Description:' not in self.logger_output_string
@@ -102,9 +53,9 @@ class TestServiceTemplatesShow(TestCliBase):
class TestServiceTemplatesList(TestCliBase):
- def test_list_one_service_template(self, monkeypatch):
+ def test_list_one_service_template(self, monkeypatch, mock_storage):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
self.invoke('service_templates list')
assert 'test_st' in self.logger_output_string
assert 'test_st2' in self.logger_output_string
@@ -187,13 +138,13 @@ class TestServiceTemplatesDelete(TestCliBase):
class TestServiceTemplatesInputs(TestCliBase):
- def test_inputs_existing_inputs(self, monkeypatch):
- monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+ def test_inputs_existing_inputs(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
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())
+ def test_inputs_no_inputs(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
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/9625e2d6/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 7093e34..c046ed3 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,7 @@
import logging
+from tests.mock import models
+
def setup_logger(logger_name,
level=logging.INFO,
@@ -38,3 +40,44 @@ def setup_logger(logger_name,
logger.propagate = False
return logger
+
+
+class MockStorage(object):
+
+ def __init__(self):
+ self.service_template = MockServiceTemplateStorage
+
+
+class MockServiceTemplateStorage(object):
+
+ @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 = []
+ 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
+
+ @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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9625e2d6/tests/conftest.py
----------------------------------------------------------------------
diff --git a/tests/conftest.py b/tests/conftest.py
index 312ee0b..8f2c273 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -40,3 +40,8 @@ def logging_handler_cleanup(request):
def clear_logging_handlers():
logging.getLogger(logger.TASK_LOGGER_NAME).handlers = []
request.addfinalizer(clear_logging_handlers)
+
+
+@pytest.fixture
+def mock_object(mocker):
+ return mocker.MagicMock()