You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/04/10 09:51:10 UTC

[01/18] incubator-ariatosca git commit: fixed pylint issues [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/logger_task 93444421b -> 14219f96b (forced update)


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/45f61a0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/45f61a0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/45f61a0f

Branch: refs/heads/logger_task
Commit: 45f61a0f4da4e6d6b069ee1f2067ffdf76917b6c
Parents: 7c567b0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 12:55:26 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 12:55:26 2017 +0300

----------------------------------------------------------------------
 aria/cli/cli/aria.py                            | 12 ++++-----
 aria/cli/commands/executions.py                 |  4 +--
 aria/cli/commands/logs.py                       | 15 +++++------
 aria/cli/commands/node_templates.py             |  4 +--
 aria/cli/commands/nodes.py                      |  4 +--
 aria/cli/commands/plugins.py                    |  6 ++---
 aria/cli/commands/service_templates.py          | 10 ++++----
 aria/cli/commands/services.py                   |  9 ++++---
 aria/cli/commands/workflows.py                  |  5 ++--
 aria/cli/main.py                                |  3 +--
 aria/cli/service_template_utils.py              |  2 +-
 aria/cli/table.py                               | 26 ++++++++++----------
 aria/cli/utils.py                               | 10 ++++----
 aria/modeling/models.py                         |  9 +++----
 aria/modeling/orchestration.py                  |  1 -
 aria/modeling/service_template.py               |  2 +-
 aria/orchestrator/context/common.py             |  3 ++-
 aria/orchestrator/workflows/api/task.py         |  1 -
 .../workflows/builtin/execute_operation.py      |  1 -
 aria/orchestrator/workflows/builtin/utils.py    |  2 +-
 aria/utils/archive.py                           |  8 +++---
 aria/utils/formatting.py                        | 12 ++++-----
 aria/utils/threading.py                         |  4 +--
 aria/utils/type.py                              |  2 +-
 24 files changed, 75 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/cli/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli/aria.py b/aria/cli/cli/aria.py
index 1664ce5..0177134 100644
--- a/aria/cli/cli/aria.py
+++ b/aria/cli/cli/aria.py
@@ -129,17 +129,17 @@ def set_cli_except_hook():
         for solution in possible_solutions:
             logger.info('  - {0}'.format(solution))
 
-    def new_excepthook(tpe, value, tb):
+    def new_excepthook(tpe, value, trace):
         if env.logging.is_high_verbose_level():
             # log error including traceback
-            logger.error(get_exception_as_string(tpe, value, tb))
+            logger.error(get_exception_as_string(tpe, value, trace))
         else:
             # write the full error to the log file
             with open(env.logging.log_file, 'a') as log_file:
                 traceback.print_exception(
                     etype=tpe,
                     value=value,
-                    tb=tb,
+                    tb=trace,
                     file=log_file)
             # print only the error message
             print value
@@ -211,9 +211,9 @@ class AliasedGroup(click.Group):
         super(AliasedGroup, self).__init__(*args, **kwargs)
 
     def get_command(self, ctx, cmd_name):
-        rv = click.Group.get_command(self, ctx, cmd_name)
-        if rv is not None:
-            return rv
+        cmd = click.Group.get_command(self, ctx, cmd_name)
+        if cmd is not None:
+            return cmd
         matches = \
             [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
         if not matches:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index cc8bf6c..396985a 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -90,11 +90,11 @@ def list(service_name,
         logger.info('Listing all executions...')
         filters = {}
 
-    executions = [e.to_dict() for e in model_storage.execution.list(
+    executions_list = [e.to_dict() for e in model_storage.execution.list(
         filters=filters,
         sort=utils.storage_sort_param(sort_by, descending))]
 
-    print_data(EXECUTION_COLUMNS, executions, 'Executions:')
+    print_data(EXECUTION_COLUMNS, executions_list, 'Executions:')
 
 
 @executions.command(name='start',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 3662063..f8873cd 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -28,23 +28,20 @@ def logs():
 @logs.command(name='list',
               short_help='List execution logs')
 @aria.argument('execution-id')
-@aria.options.json_output
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_logger
 def list(execution_id,
-         json_output,
          model_storage,
          logger):
     """Display logs for an execution
     """
     logger.info('Listing logs for execution id {0}'.format(execution_id))
-    # events_logger = get_events_logger(json_output)
-    logs = model_storage.log.list(filters=dict(execution_fk=execution_id),
-                                  sort=utils.storage_sort_param('created_at', False))
+    logs_list = model_storage.log.list(filters=dict(execution_fk=execution_id),
+                                       sort=utils.storage_sort_param('created_at', False))
     # TODO: print logs nicely
-    if logs:
-        for log in logs:
+    if logs_list:
+        for log in logs_list:
             print log
     else:
         logger.info('\tNo logs')
@@ -62,7 +59,7 @@ def delete(execution_id, model_storage, logger):
     `EXECUTION_ID` is the execution logs to delete.
     """
     logger.info('Deleting logs for execution id {0}'.format(execution_id))
-    logs = model_storage.log.list(filters=dict(execution_fk=execution_id))
-    for log in logs:
+    logs_list = model_storage.log.list(filters=dict(execution_fk=execution_id))
+    for log in logs_list:
         model_storage.log.delete(log)
     logger.info('Deleted logs for execution id {0}'.format(execution_id))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/node_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/node_templates.py b/aria/cli/commands/node_templates.py
index b97d4a2..cf50ceb 100644
--- a/aria/cli/commands/node_templates.py
+++ b/aria/cli/commands/node_templates.py
@@ -89,8 +89,8 @@ def list(service_template_name, sort_by, descending, model_storage, logger):
         logger.info('Listing all node templates...')
         filters = {}
 
-    node_templates = [nt.to_dict() for nt in model_storage.node_template.list(
+    node_templates_list = [nt.to_dict() for nt in model_storage.node_template.list(
         filters=filters,
         sort=utils.storage_sort_param(sort_by, descending))]
 
-    print_data(NODE_TEMPLATE_COLUMNS, node_templates, 'Node templates:')
+    print_data(NODE_TEMPLATE_COLUMNS, node_templates_list, 'Node templates:')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/nodes.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/nodes.py b/aria/cli/commands/nodes.py
index 0c9c4e5..fd65e24 100644
--- a/aria/cli/commands/nodes.py
+++ b/aria/cli/commands/nodes.py
@@ -81,8 +81,8 @@ def list(service_name,
         logger.info('Listing all nodes...')
         filters = {}
 
-    nodes = [node.to_dict() for node in model_storage.node.list(
+    nodes_list = [node.to_dict() for node in model_storage.node.list(
         filters=filters,
         sort=utils.storage_sort_param(sort_by, descending))]
 
-    print_data(NODE_COLUMNS, nodes, 'Nodes:')
+    print_data(NODE_COLUMNS, nodes_list, 'Nodes:')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/plugins.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/plugins.py b/aria/cli/commands/plugins.py
index 4d568d7..9e7d449 100644
--- a/aria/cli/commands/plugins.py
+++ b/aria/cli/commands/plugins.py
@@ -95,7 +95,7 @@ def install(ctx, plugin_path, plugin_manager, logger):
 
     `PLUGIN_PATH` is the path to wagon archive to install.
     """
-    # ctx.invoke(validate, plugin_path=plugin_path)
+    ctx.invoke(validate, plugin_path=plugin_path)
     logger.info('Installing plugin {0}...'.format(plugin_path))
     plugin = plugin_manager.install(plugin_path)
     logger.info("Plugin installed. The plugin's id is {0}".format(plugin.id))
@@ -128,6 +128,6 @@ def list(sort_by, descending, model_storage, logger):
     """List all plugins on the manager
     """
     logger.info('Listing all plugins...')
-    plugins = [p.to_dict() for p in model_storage.plugin.list(
+    plugins_list = [p.to_dict() for p in model_storage.plugin.list(
         sort=storage_sort_param(sort_by, descending))]
-    print_data(PLUGIN_COLUMNS, plugins, 'Plugins:')
+    print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index a324131..a0e651f 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -89,9 +89,10 @@ def list(sort_by, descending, model_storage, logger):
         return service_template
 
     logger.info('Listing all service templates...')
-    service_templates = [trim_description(b.to_dict()) for b in model_storage.service_template.list(
-        sort=utils.storage_sort_param(sort_by, descending))]
-    print_data(SERVICE_TEMPLATE_COLUMNS, service_templates, 'Service templates:')
+    service_templates_list = [trim_description(b.to_dict()) for b in
+                              model_storage.service_template.list(
+                                  sort=utils.storage_sort_param(sort_by, descending))]
+    print_data(SERVICE_TEMPLATE_COLUMNS, service_templates_list, 'Service templates:')
 
 
 @service_templates.command(name='store',
@@ -158,7 +159,7 @@ def inputs(service_template_name, model_storage, logger):
     `SERVICE_TEMPLATE_NAME` is the name of the service template to show inputs for.
     """
     logger.info('Showing inputs for service template {0}...'.format(service_template_name))
-    print_service_template_inputs(model_storage, service_template_name)
+    print_service_template_inputs(model_storage, service_template_name, logger)
 
 
 @service_templates.command(name='validate',
@@ -205,7 +206,6 @@ def create_archive(service_template_path, destination, logger):
     logger.info('Csar archive created at {0}'.format(destination))
 
 
-@aria.pass_logger
 def print_service_template_inputs(model_storage, service_template_name, logger):
     service_template = model_storage.service_template.get_by_name(service_template_name)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index e09db21..1059e10 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -64,10 +64,10 @@ def list(service_template_name,
         logger.info('Listing all service...')
         filters = {}
 
-    services = [d.to_dict() for d in model_storage.service.list(
+    services_list = [d.to_dict() for d in model_storage.service.list(
         sort=storage_sort_param(sort_by=sort_by, descending=descending),
         filters=filters)]
-    print_data(SERVICE_COLUMNS, services, 'Services:')
+    print_data(SERVICE_COLUMNS, services_list, 'Services:')
 
 
 @services.command(name='create',
@@ -82,7 +82,7 @@ def list(service_template_name,
 @aria.pass_logger
 def create(service_template_name,
            service_name,
-           inputs,
+           inputs,  # pylint: disable=redefined-outer-name
            model_storage,
            resource_storage,
            plugin_manager,
@@ -103,7 +103,8 @@ def create(service_template_name,
         handle_storage_exception(e, 'service', service_name)
     except AriaException as e:
         logger.info(str(e))
-        service_templates.print_service_template_inputs(model_storage, service_template_name)
+        service_templates.print_service_template_inputs(model_storage, service_template_name,
+                                                        logger)
         raise AriaCliError(str(e))
     logger.info("Service created. The service's name is {0}".format(service.name))
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/commands/workflows.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/workflows.py b/aria/cli/commands/workflows.py
index efa373e..2666675 100644
--- a/aria/cli/commands/workflows.py
+++ b/aria/cli/commands/workflows.py
@@ -93,10 +93,11 @@ def list(service_name, model_storage, logger):
     """
     logger.info('Listing workflows for service {0}...'.format(service_name))
     service = model_storage.service.get_by_name(service_name)
-    workflows = [wf.to_dict() for wf in sorted(service.workflows.values(), key=lambda w: w.name)]
+    workflows_list = [wf.to_dict() for wf in
+                      sorted(service.workflows.values(), key=lambda w: w.name)]
 
     defaults = {
         'service_template_name': service.service_template_name,
         'service_name': service.name
     }
-    print_data(WORKFLOW_COLUMNS, workflows, 'Workflows:', defaults=defaults)
+    print_data(WORKFLOW_COLUMNS, workflows_list, 'Workflows:', defaults=defaults)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/main.py
----------------------------------------------------------------------
diff --git a/aria/cli/main.py b/aria/cli/main.py
index 4544e40..966096c 100644
--- a/aria/cli/main.py
+++ b/aria/cli/main.py
@@ -13,13 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#TODO handle
+# TODO handle
 if __name__ == '__main__' and __package__ is None:
     import aria.cli
     __package__ = 'aria.cli'
 
 # from . import env
-from . import logger
 from .cli import aria
 from .commands import service_templates
 from .commands import node_templates

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/service_template_utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/service_template_utils.py b/aria/cli/service_template_utils.py
index 4ef4ff1..7f79668 100644
--- a/aria/cli/service_template_utils.py
+++ b/aria/cli/service_template_utils.py
@@ -122,7 +122,7 @@ def generate_id(service_template_path, service_template_filename=SAMPLE_SERVICE_
     """
     service_template_id = os.path.split(os.path.dirname(os.path.abspath(
         service_template_path)))[-1]
-    if not service_template_filename == SAMPLE_SERVICE_TEMPLATE_FILENAME:
+    if service_template_filename != SAMPLE_SERVICE_TEMPLATE_FILENAME:
         filename, _ = os.path.splitext(os.path.basename(service_template_filename))
         service_template_id = (service_template_id + '.' + filename)
     return service_template_id.replace('_', '-')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/table.py
----------------------------------------------------------------------
diff --git a/aria/cli/table.py b/aria/cli/table.py
index 9c195f5..36dcbea 100644
--- a/aria/cli/table.py
+++ b/aria/cli/table.py
@@ -16,10 +16,10 @@
 import os
 from datetime import datetime
 
-from .env import logger
-
 from prettytable import PrettyTable
 
+from .env import logger
+
 
 def generate(cols, data, defaults=None):
     """
@@ -63,19 +63,19 @@ def generate(cols, data, defaults=None):
         else:
             return defaults[column]
 
-    pt = PrettyTable([col for col in cols])
+    pretty_table = PrettyTable([col for col in cols])
 
-    for d in data:
+    for datum in data:
         values_row = []
-        for c in cols:
-            values_row.append(get_values_per_column(c, d))
-        pt.add_row(values_row)
+        for col in cols:
+            values_row.append(get_values_per_column(col, datum))
+        pretty_table.add_row(values_row)
 
-    return pt
+    return pretty_table
 
 
-def log(title, tb):
-    logger.info('{0}{1}{0}{2}{0}'.format(os.linesep, title, tb))
+def log(title, table):
+    logger.info('{0}{1}{0}{2}{0}'.format(os.linesep, title, table))
 
 
 def print_data(columns, items, header_text, max_width=None, defaults=None):
@@ -84,7 +84,7 @@ def print_data(columns, items, header_text, max_width=None, defaults=None):
     elif not isinstance(items, list):
         items = [items]
 
-    pt = generate(columns, data=items, defaults=defaults)
+    pretty_table = generate(columns, data=items, defaults=defaults)
     if max_width:
-        pt.max_width = max_width
-    log(header_text, pt)
+        pretty_table.max_width = max_width
+    log(header_text, pretty_table)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/cli/utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/utils.py b/aria/cli/utils.py
index 950c295..99315c4 100644
--- a/aria/cli/utils.py
+++ b/aria/cli/utils.py
@@ -76,11 +76,11 @@ def download_file(url, destination=None):
     :rtype: str
 
     """
-    CHUNK_SIZE = 1024
+    chunk_size = 1024
 
     if not destination:
-        fd, destination = tempfile.mkstemp()
-        os.close(fd)
+        file_descriptor, destination = tempfile.mkstemp()
+        os.close(file_descriptor)
     logger.info('Downloading {0} to {1}...'.format(url, destination))
 
     try:
@@ -95,7 +95,7 @@ def download_file(url, destination=None):
 
     try:
         with open(destination, 'wb') as destination_file:
-            for chunk in response.iter_content(CHUNK_SIZE):
+            for chunk in response.iter_content(chunk_size):
                 destination_file.write(chunk)
     except IOError as ex:
         raise AriaCliError(
@@ -140,7 +140,7 @@ def generate_progress_handler(file_path, action='', max_bar_length=80):
                                                   float(total_bytes))))
         percents = min(100.00, round(
             100.00 * (read_bytes / float(total_bytes)), 2))
-        bar = '#' * filled_length + '-' * (bar_length - filled_length)
+        bar = '#' * filled_length + '-' * (bar_length - filled_length)  # pylint: disable=blacklisted-name
 
         # The \r caret makes sure the cursor moves back to the beginning of
         # the line

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/modeling/models.py
----------------------------------------------------------------------
diff --git a/aria/modeling/models.py b/aria/modeling/models.py
index db9db07..773e3dd 100644
--- a/aria/modeling/models.py
+++ b/aria/modeling/models.py
@@ -16,6 +16,10 @@
 # pylint: disable=abstract-method
 
 from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy import (
+    Column,
+    Text
+)
 
 from . import (
     service_template,
@@ -26,11 +30,6 @@ from . import (
     mixins,
 )
 
-from sqlalchemy import (
-    Column,
-    Text
-)
-
 aria_declarative_base = declarative_base(cls=mixins.ModelIDMixin)
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 3ad6b58..12a56f6 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -39,7 +39,6 @@ from sqlalchemy.ext.associationproxy import association_proxy
 from sqlalchemy.ext.declarative import declared_attr
 
 from ..orchestrator.exceptions import (TaskAbortException, TaskRetryException)
-from .types import Dict
 from .mixins import ModelMixin
 from . import (
     relationship,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 1c6d393..6271bf7 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -279,7 +279,7 @@ class ServiceTemplateBase(TemplateModelMixin):
             ('interface_types', formatting.as_raw(self.interface_types)),
             ('artifact_types', formatting.as_raw(self.artifact_types))))
 
-    def instantiate(self, container, inputs=None):
+    def instantiate(self, container, inputs=None):  # pylint: disable=arguments-differ
         from . import models
         context = ConsumptionContext.get_thread_local()
         now = datetime.now()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 2e33d77..4cb7bce 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -183,7 +183,8 @@ class BaseContext(object):
         try:
             return self.resource.service.read(entry_id=str(self.service.id), path=path)
         except exceptions.StorageError:
-            return self.resource.service_template.read(entry_id=str(self.service_template.id), path=path)
+            return self.resource.service_template.read(entry_id=str(self.service_template.id),
+                                                       path=path)
 
     def get_resource_and_render(self, path=None, variables=None):
         """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index 2ec85b9..099bd64 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -16,7 +16,6 @@
 """
 Provides the tasks to be entered into the task graph
 """
-import copy
 
 from ....modeling import models
 from ....modeling import utils as modeling_utils

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/orchestrator/workflows/builtin/execute_operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/execute_operation.py b/aria/orchestrator/workflows/builtin/execute_operation.py
index 7ee135f..16504ec 100644
--- a/aria/orchestrator/workflows/builtin/execute_operation.py
+++ b/aria/orchestrator/workflows/builtin/execute_operation.py
@@ -18,7 +18,6 @@ Builtin execute_operation workflow
 """
 
 from . import utils
-from ..api.task import OperationTask
 from ... import workflow
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/orchestrator/workflows/builtin/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/utils.py b/aria/orchestrator/workflows/builtin/utils.py
index 8890084..056eb66 100644
--- a/aria/orchestrator/workflows/builtin/utils.py
+++ b/aria/orchestrator/workflows/builtin/utils.py
@@ -137,4 +137,4 @@ def _is_empty_task(actor, interface_name, operation_name):
 
     raise exceptions.OperationNotFoundException(
         'Could not find operation "{0}" on interface "{1}" for {2} "{3}"'
-            .format(operation_name, interface_name, type(actor).__name__.lower(), actor.name))
+        .format(operation_name, interface_name, type(actor).__name__.lower(), actor.name))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/utils/archive.py
----------------------------------------------------------------------
diff --git a/aria/utils/archive.py b/aria/utils/archive.py
index 5077dec..63d9004 100644
--- a/aria/utils/archive.py
+++ b/aria/utils/archive.py
@@ -32,15 +32,15 @@ def extract_archive(source):
 
 
 def tar(source, destination):
-    with closing(tarfile.open(destination, 'w:gz')) as tar:
-        tar.add(source, arcname=os.path.basename(source))
+    with closing(tarfile.open(destination, 'w:gz')) as tar_archive:
+        tar_archive.add(source, arcname=os.path.basename(source))
 
 
 def untar(archive, destination=None):
     if not destination:
         destination = tempfile.mkdtemp()
-    with closing(tarfile.open(name=archive)) as tar:
-        tar.extractall(path=destination, members=tar.getmembers())
+    with closing(tarfile.open(name=archive)) as tar_archive:
+        tar_archive.extractall(path=destination, members=tar_archive.getmembers())
     return destination
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/utils/formatting.py
----------------------------------------------------------------------
diff --git a/aria/utils/formatting.py b/aria/utils/formatting.py
index 698393f..f0ef146 100644
--- a/aria/utils/formatting.py
+++ b/aria/utils/formatting.py
@@ -84,7 +84,7 @@ def full_type_name(value):
 
 
 def decode_list(data):
-    rv = []
+    decoded_list = []
     for item in data:
         if isinstance(item, unicode):
             item = item.encode('utf-8')
@@ -92,12 +92,12 @@ def decode_list(data):
             item = decode_list(item)
         elif isinstance(item, dict):
             item = decode_dict(item)
-        rv.append(item)
-    return rv
+        decoded_list.append(item)
+    return decoded_list
 
 
 def decode_dict(data):
-    rv = {}
+    decoded_dict = {}
     for key, value in data.iteritems():
         if isinstance(key, unicode):
             key = key.encode('utf-8')
@@ -107,8 +107,8 @@ def decode_dict(data):
             value = decode_list(value)
         elif isinstance(value, dict):
             value = decode_dict(value)
-        rv[key] = value
-    return rv
+        decoded_dict[key] = value
+    return decoded_dict
 
 
 def try_convert_from_str(string, target_type):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/utils/threading.py
----------------------------------------------------------------------
diff --git a/aria/utils/threading.py b/aria/utils/threading.py
index f4e9c0e..06c48bc 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():
-            t, v, tb = self.exception
-            raise t, v, tb
+            type_, value, tb = self.exception
+            raise type_, value, tb

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/45f61a0f/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index 494a2c2..292225a 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -38,7 +38,7 @@ def validate_value_type(value, type_name):
     try:
         type(value)
     except ValueError:
-        raise False
+        raise
 
 
 def convert_value_to_type(str_value, type_name):


[06/18] incubator-ariatosca git commit: fixed operation logging issues in tests

Posted by mx...@apache.org.
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/logger_task
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)


[07/18] incubator-ariatosca git commit: moved TASK_LOG_NAME

Posted by mx...@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/logger_task
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)


[15/18] incubator-ariatosca git commit: Create testing framework for the CLI, and add some tests

Posted by mx...@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/logger_task
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/18] incubator-ariatosca git commit: improved type check

Posted by mx...@apache.org.
improved type check


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e04ba1fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e04ba1fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e04ba1fb

Branch: refs/heads/logger_task
Commit: e04ba1fb127484a011f6e6829800b9dcc27ec3b2
Parents: ef3f6a0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:50:46 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:50:46 2017 +0300

----------------------------------------------------------------------
 aria/modeling/utils.py |  9 +++++----
 aria/utils/type.py     | 16 +++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 35ce991..34c2ac7 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -78,12 +78,13 @@ def _merge_and_validate_inputs(inputs, template_inputs):
         else:
             # Validate input type
             try:
-                # TODO: improve type validation; Needs to consider custom data_types as well
-                if input_template.type_name in ('list', 'dict', 'tuple', 'string', 'integer',
-                                                'boolean', 'float'):
-                    validate_value_type(inputs[input_name], input_template.type_name)
+                validate_value_type(inputs[input_name], input_template.type_name)
             except ValueError:
                 wrong_type_inputs[input_name] = input_template.type_name
+            except RuntimeError:
+                # TODO: This error shouldn't be raised (or caught), but right now we lack support
+                # for custom data_types, which will raise this error. Skipping their validation.
+                pass
 
     if missing_inputs:
         raise exceptions.MissingRequiredInputsException(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index 292225a..abcf422 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -15,9 +15,13 @@
 
 
 def validate_value_type(value, type_name):
-    """Supports both python and yaml type names"""
-    #TODO add timestamp type?
+    """
+    Validate a value is of a specific type.
+    A ValueError will be raised on type mismatch.
+    Supports both python and yaml type names.
+    """
 
+    #TODO add timestamp type?
     name_to_type = {
         'list': list,
         'dict': dict,
@@ -34,11 +38,9 @@ def validate_value_type(value, type_name):
 
     type = name_to_type.get(type_name.lower())
     if type is None:
-        raise ValueError('No supported type_name was provided')
-    try:
-        type(value)
-    except ValueError:
-        raise
+        raise RuntimeError('No supported type_name was provided')
+    # validating value type - ValueError will be raised on type mismatch
+    type(value)
 
 
 def convert_value_to_type(str_value, type_name):


[16/18] incubator-ariatosca git commit: added tests for workflow runner

Posted by mx...@apache.org.
added tests for workflow runner


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/5b245b4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/5b245b4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/5b245b4a

Branch: refs/heads/logger_task
Commit: 5b245b4a6ff56f392601aa55ca6c4c5fb311bb38
Parents: e898e10
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Sun Apr 9 17:30:20 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Sun Apr 9 17:30:20 2017 +0300

----------------------------------------------------------------------
 aria/modeling/exceptions.py                |   2 +-
 aria/modeling/utils.py                     |   2 +-
 aria/orchestrator/workflow_runner.py       |  30 +--
 aria/utils/type.py                         |   9 +-
 tests/mock/workflow.py                     |  26 +++
 tests/orchestrator/test_workflow_runner.py | 293 ++++++++++++++++++++++++
 6 files changed, 341 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/aria/modeling/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/modeling/exceptions.py b/aria/modeling/exceptions.py
index f699560..8225f37 100644
--- a/aria/modeling/exceptions.py
+++ b/aria/modeling/exceptions.py
@@ -40,7 +40,7 @@ class MissingRequiredInputsException(ModelingException):
     """
 
 
-class InputOfWrongTypeException(ModelingException):
+class InputsOfWrongTypeException(ModelingException):
     """
     ARIA modeling exception: Inputs of the wrong types have been provided
     """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 34c2ac7..acae065 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -96,7 +96,7 @@ def _merge_and_validate_inputs(inputs, template_inputs):
         for param_name, param_type in wrong_type_inputs.iteritems():
             error_message.write('Input "{0}" must be of type {1}\n'.
                                 format(param_name, param_type))
-        raise exceptions.InputOfWrongTypeException(error_message.getvalue())
+        raise exceptions.InputsOfWrongTypeException(error_message.getvalue())
 
     undeclared_inputs = [input_name for input_name in inputs.keys()
                          if input_name not in template_inputs]

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py
index e2ed3cf..1cdf1de 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -26,8 +26,8 @@ from .context.workflow import WorkflowContext
 from .workflows.builtin import BUILTIN_WORKFLOWS, BUILTIN_WORKFLOWS_PATH_PREFIX
 from .workflows.core.engine import Engine
 from .workflows.executor.process import ProcessExecutor
-from ..modeling import utils as modeling_utils
 from ..modeling import models
+from ..modeling import utils as modeling_utils
 from ..utils.imports import import_fullname
 
 
@@ -100,8 +100,6 @@ class WorkflowRunner(object):
         return self._model_storage.service.get(self._service_id)
 
     def execute(self):
-        #TODO uncomment, commented for testing purposes
-        # self._validate_no_active_executions()
         self._engine.execute()
 
     def cancel(self):
@@ -114,15 +112,16 @@ class WorkflowRunner(object):
             workflow_name=self._workflow_name,
             inputs={})
 
-        # built-in workflows don't have any inputs, and are also
-        # not a part of the service's workflows field
-        if self._workflow_name not in BUILTIN_WORKFLOWS:
-            workflow_inputs = {k: v for k, v in
-                               self.service.workflows[self._workflow_name].inputs
-                               if k not in WORKFLOW_POLICY_INTERNAL_PROPERTIES}
-
-            execution.inputs = modeling_utils.create_inputs(inputs, workflow_inputs)
-
+        if self._workflow_name in BUILTIN_WORKFLOWS:
+            workflow_inputs = dict()  # built-in workflows don't have any inputs
+        else:
+            workflow_inputs = dict((k, v) for k, v in
+                                   self.service.workflows[self._workflow_name].inputs.iteritems()
+                                   if k not in WORKFLOW_POLICY_INTERNAL_PROPERTIES)
+
+        execution.inputs = modeling_utils.create_inputs(inputs, workflow_inputs)
+        # TODO: these two following calls should execute atomically
+        self._validate_no_active_executions(execution)
         self._model_storage.execution.put(execution)
         return execution
 
@@ -133,11 +132,12 @@ class WorkflowRunner(object):
                 'No workflow policy {0} declared in service {1}'
                 .format(self._workflow_name, self.service.name))
 
-    def _validate_no_active_executions(self):
-        active_executions = [e for e in self.service.executions if e.is_active()]
+    def _validate_no_active_executions(self, execution):
+        active_executions = [e for e in self.service.executions
+                             if e.id != execution.id and e.is_active()]
         if active_executions:
             raise exceptions.ActiveExecutionsError(
-                "Can't start execution; Service {0} has a running execution with id {1}"
+                "Can't start execution; Service {0} has an active execution with id {1}"
                 .format(self.service.name, active_executions[0].id))
 
     def _get_workflow_fn(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index abcf422..fff0f2a 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -36,11 +36,12 @@ def validate_value_type(value, type_name):
         'float': float
     }
 
-    type = name_to_type.get(type_name.lower())
-    if type is None:
+    type_ = name_to_type.get(type_name.lower())
+    if type_ is None:
         raise RuntimeError('No supported type_name was provided')
-    # validating value type - ValueError will be raised on type mismatch
-    type(value)
+
+    if type(value) != type_:
+        raise ValueError('Value {0} is not of type {1}'.format(value, type_name))
 
 
 def convert_value_to_type(str_value, type_name):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/tests/mock/workflow.py
----------------------------------------------------------------------
diff --git a/tests/mock/workflow.py b/tests/mock/workflow.py
new file mode 100644
index 0000000..b12b9fa
--- /dev/null
+++ b/tests/mock/workflow.py
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+
+import json
+
+from aria.orchestrator.decorators import workflow
+
+
+@workflow
+def mock_workflow(graph, ctx, output_path=None, **kwargs):  # pylint: disable=unused-argument
+    if output_path:
+        # writes call arguments to the specified output file
+        with open(output_path, 'w') as f:
+            json.dump(kwargs, f)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5b245b4a/tests/orchestrator/test_workflow_runner.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/test_workflow_runner.py b/tests/orchestrator/test_workflow_runner.py
new file mode 100644
index 0000000..aa89ac5
--- /dev/null
+++ b/tests/orchestrator/test_workflow_runner.py
@@ -0,0 +1,293 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+
+import json
+from datetime import datetime
+
+import pytest
+import mock
+
+from aria.modeling import exceptions as modeling_exceptions
+from aria.modeling import models
+from aria.orchestrator import exceptions
+from aria.orchestrator.workflow_runner import WorkflowRunner
+from aria.orchestrator.workflows.executor.process import ProcessExecutor
+
+from ..mock import (
+    topology,
+    workflow as workflow_mocks
+)
+from ..fixtures import (  # pylint: disable=unused-import
+    plugins_dir,
+    plugin_manager,
+    fs_model as model,
+    resource_storage as resource
+)
+
+
+def test_undeclared_workflow(request):
+    # validating a proper error is raised when the workflow is not declared in the service
+    with pytest.raises(exceptions.UndeclaredWorkflowError):
+        _create_workflow_runner(request, 'undeclared_workflow')
+
+
+def test_missing_workflow_implementation(service, request):
+    # validating a proper error is raised when the workflow code path does not exist
+    workflow = models.Operation(
+        name='test_workflow',
+        service=service,
+        implementation='nonexistent.workflow.implementation',
+        inputs={})
+    service.workflows['test_workflow'] = workflow
+
+    with pytest.raises(exceptions.WorkflowImplementationNotFoundError):
+        _create_workflow_runner(request, 'test_workflow')
+
+
+def test_builtin_workflow_instantiation(request):
+    # validates the workflow runner instantiates properly when provided with a builtin workflow
+    # (expecting no errors to be raised on undeclared workflow or missing workflow implementation)
+    workflow_runner = _create_workflow_runner(request, 'install')
+    tasks = list(workflow_runner._tasks_graph.tasks)
+    assert len(tasks) == 2  # expecting two WorkflowTasks
+
+
+def test_custom_workflow_instantiation(request):
+    # validates the workflow runner instantiates properly when provided with a custom workflow
+    # (expecting no errors to be raised on undeclared workflow or missing workflow implementation)
+    mock_workflow = _setup_mock_workflow_in_service(request)
+    workflow_runner = _create_workflow_runner(request, mock_workflow)
+    tasks = list(workflow_runner._tasks_graph.tasks)
+    assert len(tasks) == 0  # mock workflow creates no tasks
+
+
+def test_existing_active_executions(request, service, model):
+    existing_active_execution = models.Execution(
+        service=service,
+        status=models.Execution.STARTED,
+        workflow_name='uninstall')
+    model.execution.put(existing_active_execution)
+    with pytest.raises(exceptions.ActiveExecutionsError):
+        _create_workflow_runner(request, 'install')
+
+
+def test_existing_executions_but_no_active_ones(request, service, model):
+    existing_terminated_execution = models.Execution(
+        service=service,
+        status=models.Execution.TERMINATED,
+        workflow_name='uninstall')
+    model.execution.put(existing_terminated_execution)
+    # no active executions exist, so no error should be raised
+    _create_workflow_runner(request, 'install')
+
+
+def test_default_executor(request):
+    # validates the ProcessExecutor is used by the workflow runner by default
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    with mock.patch('aria.orchestrator.workflow_runner.Engine') as mock_engine_cls:
+        _create_workflow_runner(request, mock_workflow)
+        _, engine_kwargs = mock_engine_cls.call_args
+        assert isinstance(engine_kwargs.get('executor'), ProcessExecutor)
+
+
+def test_custom_executor(request):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    custom_executor = mock.MagicMock()
+    with mock.patch('aria.orchestrator.workflow_runner.Engine') as mock_engine_cls:
+        _create_workflow_runner(request, mock_workflow, executor=custom_executor)
+        _, engine_kwargs = mock_engine_cls.call_args
+        assert engine_kwargs.get('executor') == custom_executor
+
+
+def test_task_configuration_parameters(request):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    task_max_attempts = 5
+    task_retry_interval = 7
+    with mock.patch('aria.orchestrator.workflow_runner.Engine') as mock_engine_cls:
+        _create_workflow_runner(request, mock_workflow, task_max_attempts=task_max_attempts,
+                                task_retry_interval=task_retry_interval)
+        _, engine_kwargs = mock_engine_cls.call_args
+        assert engine_kwargs['workflow_context']._task_max_attempts == task_max_attempts
+        assert engine_kwargs['workflow_context']._task_retry_interval == task_retry_interval
+
+
+def test_execute(request, service):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    mock_engine = mock.MagicMock()
+    with mock.patch('aria.orchestrator.workflow_runner.Engine', return_value=mock_engine) \
+            as mock_engine_cls:
+        workflow_runner = _create_workflow_runner(request, mock_workflow)
+
+        _, engine_kwargs = mock_engine_cls.call_args
+        assert engine_kwargs['workflow_context'].service.id == service.id
+        assert engine_kwargs['workflow_context'].execution.workflow_name == 'test_workflow'
+
+        workflow_runner.execute()
+        mock_engine.execute.assert_called_once_with()
+
+
+def test_cancel_execution(request):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    mock_engine = mock.MagicMock()
+    with mock.patch('aria.orchestrator.workflow_runner.Engine', return_value=mock_engine):
+        workflow_runner = _create_workflow_runner(request, mock_workflow)
+        workflow_runner.cancel()
+        mock_engine.cancel_execution.assert_called_once_with()
+
+
+def test_execution_model_creation(request, service, model):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    with mock.patch('aria.orchestrator.workflow_runner.Engine') as mock_engine_cls:
+        workflow_runner = _create_workflow_runner(request, mock_workflow)
+
+        _, engine_kwargs = mock_engine_cls.call_args
+        assert engine_kwargs['workflow_context'].execution == workflow_runner.execution
+        assert model.execution.get(workflow_runner.execution.id) == workflow_runner.execution
+        assert workflow_runner.execution.service.id == service.id
+        assert workflow_runner.execution.workflow_name == mock_workflow
+        assert workflow_runner.execution.created_at <= datetime.utcnow()
+        assert workflow_runner.execution.inputs == dict()
+
+
+def test_execution_inputs_override_workflow_inputs(request):
+    wf_inputs = {'input1': 'value1', 'input2': 'value2', 'input3': 5}
+    mock_workflow = _setup_mock_workflow_in_service(
+        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:
+        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'
+        # overrode input2
+        assert workflow_runner.execution.inputs['input2'].value == 'overriding-value2'
+        # overrode input of integer type
+        assert workflow_runner.execution.inputs['input3'].value == 7
+
+
+def test_execution_inputs_undeclared_inputs(request):
+    mock_workflow = _setup_mock_workflow_in_service(request)
+
+    with pytest.raises(modeling_exceptions.UndeclaredInputsException):
+        _create_workflow_runner(request, mock_workflow, inputs={'undeclared_input': 'value'})
+
+
+def test_execution_inputs_missing_required_inputs(request):
+    mock_workflow = _setup_mock_workflow_in_service(
+        request, inputs={'required_input': models.Parameter.wrap('required_input', value=None)})
+
+    with pytest.raises(modeling_exceptions.MissingRequiredInputsException):
+        _create_workflow_runner(request, mock_workflow, inputs={})
+
+
+def test_execution_inputs_wrong_type_inputs(request):
+    mock_workflow = _setup_mock_workflow_in_service(
+        request, inputs={'input': models.Parameter.wrap('input', 'value')})
+
+    with pytest.raises(modeling_exceptions.InputsOfWrongTypeException):
+        _create_workflow_runner(request, mock_workflow, inputs={'input': 5})
+
+
+def test_execution_inputs_builtin_workflow_with_inputs(request):
+    # built-in workflows don't have inputs
+    with pytest.raises(modeling_exceptions.UndeclaredInputsException):
+        _create_workflow_runner(request, 'install', inputs={'undeclared_input': 'value'})
+
+
+def test_workflow_function_parameters(request, tmpdir):
+    # validating the workflow function is passed with the
+    # merged execution inputs, in dict form
+
+    # the workflow function parameters will be written to this file
+    output_path = str(tmpdir.join('output'))
+    wf_inputs = {'output_path': output_path, 'input1': 'value1', 'input2': 'value2', 'input3': 5}
+
+    mock_workflow = _setup_mock_workflow_in_service(
+        request, inputs=dict((name, models.Parameter.wrap(name, val)) for name, val
+                             in wf_inputs.iteritems()))
+
+    _create_workflow_runner(request, mock_workflow,
+                            inputs={'input2': 'overriding-value2', 'input3': 7})
+
+    with open(output_path) as f:
+        wf_call_kwargs = json.load(f)
+    assert len(wf_call_kwargs) == 3
+    assert wf_call_kwargs.get('input1') == 'value1'
+    assert wf_call_kwargs.get('input2') == 'overriding-value2'
+    assert wf_call_kwargs.get('input3') == 7
+
+
+@pytest.fixture
+def service(model):
+    # sets up a service in the storage
+    service_id = topology.create_simple_topology_two_nodes(model)
+    service = model.service.get(service_id)
+    return service
+
+
+def _setup_mock_workflow_in_service(request, inputs=None):
+    # sets up a mock workflow as part of the service, including uploading
+    # the workflow code to the service's dir on the resource storage
+    service = request.getfuncargvalue('service')
+    resource = request.getfuncargvalue('resource')
+
+    source = workflow_mocks.__file__
+    resource.service_template.upload(str(service.service_template.id), source)
+    mock_workflow_name = 'test_workflow'
+    workflow = models.Operation(
+        name=mock_workflow_name,
+        service=service,
+        implementation='workflow.mock_workflow',
+        inputs=inputs or {})
+    service.workflows[mock_workflow_name] = workflow
+    return mock_workflow_name
+
+
+def _create_workflow_runner(request, workflow_name, inputs=None, executor=None,
+                            task_max_attempts=None, task_retry_interval=None):
+    # helper method for instantiating a workflow runner
+    service_id = request.getfuncargvalue('service').id
+    model = request.getfuncargvalue('model')
+    resource = request.getfuncargvalue('resource')
+    plugin_manager = request.getfuncargvalue('plugin_manager')
+
+    # task configuration parameters can't be set to None, therefore only
+    # passing those if they've been set by the test
+    task_configuration_kwargs = dict()
+    if task_max_attempts is not None:
+        task_configuration_kwargs['task_max_attempts'] = task_max_attempts
+    if task_retry_interval is not None:
+        task_configuration_kwargs['task_retry_interval'] = task_retry_interval
+
+    return WorkflowRunner(
+        workflow_name=workflow_name,
+        service_id=service_id,
+        inputs=inputs or {},
+        executor=executor,
+        model_storage=model,
+        resource_storage=resource,
+        plugin_manager=plugin_manager,
+        **task_configuration_kwargs)


[02/18] incubator-ariatosca git commit: fixed pylint in tests

Posted by mx...@apache.org.
fixed pylint 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/94c8d722
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/94c8d722
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/94c8d722

Branch: refs/heads/logger_task
Commit: 94c8d7221e54679a4e60cd0873f271c73b4908b6
Parents: 45f61a0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:06:24 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:06:24 2017 +0300

----------------------------------------------------------------------
 tests/orchestrator/context/test_resource_render.py           | 8 ++++----
 tests/orchestrator/context/test_serialize.py                 | 2 --
 tests/orchestrator/execution_plugin/test_local.py            | 7 ++++---
 .../orchestrator/workflows/executor/test_process_executor.py | 6 +++++-
 tests/utils/test_plugin.py                                   | 2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/context/test_resource_render.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_resource_render.py b/tests/orchestrator/context/test_resource_render.py
index 8113746..8249086 100644
--- a/tests/orchestrator/context/test_resource_render.py
+++ b/tests/orchestrator/context/test_resource_render.py
@@ -65,8 +65,8 @@ def resources(tmpdir, ctx):
     variables_template_path = tmpdir.join(_VARIABLES_TEMPLATE_PATH)
     variables_template_path.write(_VARIABLES_TEMPLATE)
     ctx.resource.service.upload(entry_id='1',
-                                   source=str(implicit_ctx_template_path),
-                                   path=_IMPLICIT_CTX_TEMPLATE_PATH)
+                                source=str(implicit_ctx_template_path),
+                                path=_IMPLICIT_CTX_TEMPLATE_PATH)
     ctx.resource.service.upload(entry_id='1',
-                                   source=str(variables_template_path),
-                                   path=_VARIABLES_TEMPLATE_PATH)
+                                source=str(variables_template_path),
+                                path=_VARIABLES_TEMPLATE_PATH)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/context/test_serialize.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py
index 420f7f9..ab3a5b6 100644
--- a/tests/orchestrator/context/test_serialize.py
+++ b/tests/orchestrator/context/test_serialize.py
@@ -15,8 +15,6 @@
 
 import pytest
 
-import aria
-from aria.storage import sql_mapi
 from aria.orchestrator.workflows import api
 from aria.orchestrator.workflows.core import engine
 from aria.orchestrator.workflows.executor import process

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/execution_plugin/test_local.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/execution_plugin/test_local.py b/tests/orchestrator/execution_plugin/test_local.py
index 67d527c..58506ba 100644
--- a/tests/orchestrator/execution_plugin/test_local.py
+++ b/tests/orchestrator/execution_plugin/test_local.py
@@ -482,9 +482,10 @@ if __name__ == '__main__':
                 node.service,
                 'test',
                 'op',
-                operation_kwargs=dict(implementation='{0}.{1}'.format(
-                    operations.__name__,
-                    operations.run_script_locally.__name__),
+                operation_kwargs=dict(
+                    implementation='{0}.{1}'.format(
+                        operations.__name__,
+                        operations.run_script_locally.__name__),
                     inputs=inputs)
             )
             node.interfaces[interface.name] = interface

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 8f2c8a2..7d627a0 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -28,7 +28,11 @@ from aria.orchestrator.workflows.executor import process
 
 import tests.storage
 import tests.resources
-from tests.fixtures import plugins_dir, plugin_manager, fs_model as model
+from tests.fixtures import (  # pylint: disable=unused-import
+    plugins_dir,
+    plugin_manager,
+    fs_model as model
+)
 
 
 class TestProcessExecutor(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/utils/test_plugin.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_plugin.py b/tests/utils/test_plugin.py
index df82515..3350247 100644
--- a/tests/utils/test_plugin.py
+++ b/tests/utils/test_plugin.py
@@ -20,7 +20,7 @@ import pytest
 from aria.orchestrator import exceptions
 from aria.utils.plugin import create as create_plugin
 
-from ..fixtures import (
+from ..fixtures import (  # pylint: disable=unused-import
     plugins_dir,
     plugin_manager,
     inmemory_model as model


[09/18] incubator-ariatosca git commit: fixed debugging issue in cli

Posted by mx...@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/logger_task
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()


[12/18] incubator-ariatosca git commit: Clean up the code a bit

Posted by mx...@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/logger_task
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)
 
 


[17/18] incubator-ariatosca git commit: logger wip

Posted by mx...@apache.org.
logger wip


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/03103f6b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/03103f6b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/03103f6b

Branch: refs/heads/logger_task
Commit: 03103f6b97d81bf559892d6388f8ba177926a08d
Parents: 5b245b4
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 6 11:54:44 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 10 12:50:58 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/executions.py                 | 12 +++-
 aria/cli/logger.py                              | 66 +++++++++++++++++++-
 aria/logger.py                                  |  1 -
 aria/modeling/orchestration.py                  |  4 +-
 aria/orchestrator/context/common.py             | 11 +---
 aria/orchestrator/context/operation.py          | 13 ----
 aria/orchestrator/context/workflow.py           |  4 +-
 aria/orchestrator/workflow_runner.py            |  6 +-
 aria/orchestrator/workflows/events_logging.py   | 19 +++---
 aria/orchestrator/workflows/executor/process.py |  6 +-
 10 files changed, 99 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 396985a..a84a8a2 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -12,7 +12,7 @@
 # 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 aria.cli.logger import LogConsumer
 from .. import utils
 from ..table import print_data
 from ..cli import aria
@@ -139,13 +139,19 @@ def start(workflow_name,
 
     logger.info('Starting {0}execution. Press Ctrl+C cancel'.format('dry ' if dry else ''))
     execution_thread.start()
+
+    log_consumer = LogConsumer(model_storage, workflow_runner.execution_id)
     try:
         while execution_thread.is_alive():
-            # using join without a timeout blocks and ignores KeyboardInterrupt
-            execution_thread.join(1)
+            for log in log_consumer:
+                logger.log(log)
+
     except KeyboardInterrupt:
         _cancel_execution(workflow_runner, execution_thread, logger)
 
+    for log in log_consumer:
+        logger.log(log)
+
     # raise any errors from the execution thread (note these are not workflow execution errors)
     execution_thread.raise_error_if_exists()
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/cli/logger.py
----------------------------------------------------------------------
diff --git a/aria/cli/logger.py b/aria/cli/logger.py
index 289dbd3..bfafbfa 100644
--- a/aria/cli/logger.py
+++ b/aria/cli/logger.py
@@ -51,6 +51,42 @@ DEFAULT_LOGGER_CONFIG = {
 }
 
 
+class _ModelLogLogger(object):
+    def __init__(self, logger, level, formats):
+        self._logger = logger
+        self._level = level
+        self._formats = formats
+
+    def log(self, item):
+        kwargs = dict(item=item)
+        formats = self._formats[self.level]
+        if 'created_at' in formats:
+            kwargs['created_at'] = item.created_at.strftime(formats['created_at'])
+        if 'level' in formats:
+            kwargs['level'] = formats['level'].format(item.level)
+        if 'msg' in formats:
+            kwargs['msg'] = formats['msg'].format(item.msg)
+
+        if 'actor' in formats and item.task:
+            kwargs['actor'] = formats['actor'].format(item.task.actor)
+        if 'execution' in formats:
+            kwargs['execution'] = formats['execution'].format(item.execution)
+
+        msg = formats['main_msg'].format(**kwargs)
+        return getattr(self._logger, item.level.lower())(msg)
+
+    @property
+    def level(self):
+        return logging.INFO if self._level is NO_VERBOSE else logging.DEBUG
+
+    @level.setter
+    def level(self, level):
+        self._level = level
+
+    def __getattr__(self, item):
+        return getattr(self._logger, item)
+
+
 class Logging(object):
 
     def __init__(self, config):
@@ -58,7 +94,18 @@ class Logging(object):
         self._verbosity_level = NO_VERBOSE
         self._all_loggers = []
         self._configure_loggers(config)
-        self._lgr = logging.getLogger('aria.cli.main')
+
+        self._lgr = _ModelLogLogger(
+            logging.getLogger('aria.cli.main'),
+            self._verbosity_level,
+            {logging.INFO: {
+                'main_msg': '{item.msg}',
+            },
+             logging.DEBUG: {
+                'main_msg': '{created_at} | {item.level[0]} | {item.msg}',
+                'created_at': '%H:%M:%S'
+            }
+        })
 
     @property
     def logger(self):
@@ -77,7 +124,7 @@ class Logging(object):
 
     @verbosity_level.setter
     def verbosity_level(self, level):
-        self._verbosity_level = level
+        self._verbosity_level = self._lgr.level = level
         if self.is_high_verbose_level():
             for logger_name in self._all_loggers:
                 logging.getLogger(logger_name).setLevel(logging.DEBUG)
@@ -111,3 +158,18 @@ class Logging(object):
             self._all_loggers.append(logger_name)
 
         logging.config.dictConfig(logger_dict)
+
+
+class LogConsumer(object):
+
+    def __init__(self, model_storage, execution_id):
+        self._last_visited_id = 0
+        self._model_storage = model_storage
+        self._execution_id = execution_id
+
+    def __iter__(self):
+
+        for log in self._model_storage.log.iter(filters=dict(
+                execution_fk=self._execution_id, id=dict(gt=self._last_visited_id)  )):
+            self._last_visited_id = log.id
+            yield log

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index bbb6c7a..040ab3f 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -168,7 +168,6 @@ class _SQLAlchemyHandler(logging.Handler):
         log = self._cls(
             execution_fk=self._execution_id,
             task_fk=record.task_id,
-            actor=record.prefix,
             level=record.levelname,
             msg=str(record.msg),
             created_at=created_at,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 12a56f6..f880d31 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -393,7 +393,6 @@ class LogBase(ModelMixin):
     level = Column(String)
     msg = Column(String)
     created_at = Column(DateTime, index=True)
-    actor = Column(String)
 
     # region foreign keys
 
@@ -408,5 +407,4 @@ class LogBase(ModelMixin):
     # endregion
 
     def __repr__(self):
-        return "<{self.created_at}: [{self.level}] @{self.actor}> {msg}".format(
-            self=self, msg=self.msg[:50])
+        return "{msg}".format(msg=self.msg)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 11b5eb9..c9ca53b 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -39,15 +39,13 @@ class BaseContext(object):
     """
 
     class PrefixedLogger(object):
-        def __init__(self, logger, prefix='', task_id=None):
+        def __init__(self, logger, task_id=None):
             self._logger = logger
-            self._prefix = prefix
             self._task_id = task_id
 
         def __getattr__(self, item):
             if item.upper() in logging._levelNames:
-                return partial(getattr(self._logger, item),
-                               extra={'prefix': self._prefix, 'task_id': self._task_id})
+                return partial(getattr(self._logger, item), extra=dict(task_id=self._task_id))
             else:
                 return getattr(self._logger, item)
 
@@ -73,7 +71,6 @@ class BaseContext(object):
             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())
             self.logger.addHandler(self._get_sqla_handler())
 
     def _get_sqla_handler(self):
@@ -103,10 +100,6 @@ class BaseContext(object):
                 self.logger.removeHandler(handler)
 
     @property
-    def logging_id(self):
-        raise NotImplementedError
-
-    @property
     def model(self):
         """
         Access to the model storage

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py
index cbd186c..6aed377 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -57,10 +57,6 @@ class BaseOperationContext(BaseContext):
         return '{name}({0})'.format(details, name=self.name)
 
     @property
-    def logging_id(self):
-        raise NotImplementedError
-
-    @property
     def task(self):
         """
         The task in the model storage
@@ -121,10 +117,6 @@ class NodeOperationContext(BaseOperationContext):
     """
 
     @property
-    def logging_id(self):
-        return self.node.name or self.node.id
-
-    @property
     def node_template(self):
         """
         the node of the current operation
@@ -147,11 +139,6 @@ class RelationshipOperationContext(BaseOperationContext):
     """
 
     @property
-    def logging_id(self):
-        return '{0}->{1}'.format(self.source_node.name or self.source_node.id,
-                                 self.target_node.name or self.target_node.id)
-
-    @property
     def source_node_template(self):
         """
         The source node

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/workflow.py b/aria/orchestrator/context/workflow.py
index ad4a2ff..9d8c0d1 100644
--- a/aria/orchestrator/context/workflow.py
+++ b/aria/orchestrator/context/workflow.py
@@ -52,8 +52,8 @@ class WorkflowContext(BaseContext):
                 name=self.__class__.__name__, self=self))
 
     @property
-    def logging_id(self):
-        return '{0}[{1}]'.format(self._workflow_name, self._execution_id)
+    def workflow_name(self):
+        return self._workflow_name
 
     @property
     def execution(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py
index 1cdf1de..6c18baf 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -92,8 +92,12 @@ class WorkflowRunner(object):
             tasks_graph=self._tasks_graph)
 
     @property
+    def execution_id(self):
+        return self._execution_id
+
+    @property
     def execution(self):
-        return self._model_storage.execution.get(self._execution_id)
+        return self._model_storage.execution.get(self.execution_id)
 
     @property
     def service(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/workflows/events_logging.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/events_logging.py b/aria/orchestrator/workflows/events_logging.py
index e831bfe..07981e9 100644
--- a/aria/orchestrator/workflows/events_logging.py
+++ b/aria/orchestrator/workflows/events_logging.py
@@ -26,16 +26,21 @@ from .. import events
 
 @events.start_task_signal.connect
 def _start_task_handler(task, **kwargs):
-    task.context.logger.debug('Event: Starting task: {task.name}'.format(task=task))
+    task.context.logger.debug('{actor.name} {task.interface_name}.{task.operation_name} started...'
+                             .format(actor=task.actor, task=task))
 
 
 @events.on_success_task_signal.connect
 def _success_task_handler(task, **kwargs):
-    task.context.logger.debug('Event: Task success: {task.name}'.format(task=task))
+    task.context.logger.info('{actor.name} {task.interface_name}.{task.operation_name} successful'
+                             .format(actor=task.actor, task=task))
 
 
 @events.on_failure_task_signal.connect
 def _failure_operation_handler(task, exception, **kwargs):
+    # todo: add full support for exceptions and errors logging
+    task.context.logger.info('{actor.name} {task.interface_name}.{task.operation_name} failed'
+                             .format(actor=task.actor, task=task))
     error = '{0}: {1}'.format(type(exception).__name__, exception)
     task.context.logger.error('Event: Task failure: {task.name} [{error}]'.format(
         task=task, error=error))
@@ -43,24 +48,24 @@ def _failure_operation_handler(task, exception, **kwargs):
 
 @events.start_workflow_signal.connect
 def _start_workflow_handler(context, **kwargs):
-    context.logger.debug('Event: Starting workflow: {context.name}'.format(context=context))
+    context.logger.info("Starting '{ctx.workflow_name}' workflow execution".format(ctx=context))
 
 
 @events.on_failure_workflow_signal.connect
 def _failure_workflow_handler(context, **kwargs):
-    context.logger.debug('Event: Workflow failure: {context.name}'.format(context=context))
+    context.logger.info("'{ctx.workflow_name}' workflow execution failed".format(ctx=context))
 
 
 @events.on_success_workflow_signal.connect
 def _success_workflow_handler(context, **kwargs):
-    context.logger.debug('Event: Workflow success: {context.name}'.format(context=context))
+    context.logger.info("'{ctx.workflow_name}' workflow execution succeeded".format(ctx=context))
 
 
 @events.on_cancelled_workflow_signal.connect
 def _cancel_workflow_handler(context, **kwargs):
-    context.logger.debug('Event: Workflow cancelled: {context.name}'.format(context=context))
+    context.logger.info("'{ctx.workflow_name}' workflow execution canceled".format(ctx=context))
 
 
 @events.on_cancelling_workflow_signal.connect
 def _cancelling_workflow_handler(context, **kwargs):
-    context.logger.debug('Event: Workflow cancelling: {context.name}'.format(context=context))
+    context.logger.info("Cancelling '{ctx.workflow_name}' workflow execution".format(ctx=context))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03103f6b/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index dc369ab..83d8b55 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -148,8 +148,10 @@ class ProcessExecutor(base.BaseExecutor):
     def _create_arguments_dict(self, task):
         return {
             'task_id': task.id,
-            'implementation': task.implementation,
-            'operation_inputs': Parameter.unwrap_dict(task.inputs),
+            # 'implementation': task.implementation,
+            'implementation': 'aria.orchestrator.execution_plugin.operations.run_script_locally',
+            # 'operation_inputs': Parameter.unwrap_dict(task.inputs),
+            'operation_inputs': dict(script_path=task.implementation),
             'port': self._server_port,
             'context': task.context.serialization_dict,
         }


[13/18] incubator-ariatosca git commit: Add tests for service-templates validate

Posted by mx...@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/logger_task
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)


[04/18] incubator-ariatosca git commit: fixed workflows show cli command

Posted by mx...@apache.org.
fixed workflows show cli command


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ef3f6a07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ef3f6a07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ef3f6a07

Branch: refs/heads/logger_task
Commit: ef3f6a070805eaf8d7fc624fbc8f95acb0e3d3f7
Parents: e2dd671
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:22:54 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:22:54 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/workflows.py | 45 ++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ef3f6a07/aria/cli/commands/workflows.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/workflows.py b/aria/cli/commands/workflows.py
index 2666675..72dea5b 100644
--- a/aria/cli/commands/workflows.py
+++ b/aria/cli/commands/workflows.py
@@ -41,8 +41,8 @@ def show(workflow_name, service_name, model_storage, logger):
     """
     logger.info('Retrieving workflow {0} for service {1}'.format(
         workflow_name, service_name))
-    service = model_storage.service.get(service_name)
-    workflow = next((wf for wf in service.workflows if
+    service = model_storage.service.get_by_name(service_name)
+    workflow = next((wf for wf in service.workflows.values() if
                      wf.name == workflow_name), None)
     if not workflow:
         raise AriaCliError(
@@ -52,33 +52,32 @@ def show(workflow_name, service_name, model_storage, logger):
         'service_template_name': service.service_template_name,
         'service_name': service.name
     }
-    print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
+    print_data(WORKFLOW_COLUMNS, workflow.to_dict(), 'Workflows:', defaults=defaults)
 
-    # print workflow parameters
-    mandatory_params = dict()
-    optional_params = dict()
-    for param_name, param in workflow.parameters.iteritems():
-        params_group = optional_params if 'default' in param else \
-            mandatory_params
-        params_group[param_name] = param
+    # print workflow inputs
+    required_inputs = dict()
+    optional_inputs = dict()
+    for input_name, input in workflow.inputs.iteritems():
+        inputs_group = optional_inputs if input.value is not None else required_inputs
+        inputs_group[input_name] = input
 
-    logger.info('Workflow Parameters:')
-    logger.info('\tMandatory Parameters:')
-    for param_name, param in mandatory_params.iteritems():
-        if 'description' in param:
-            logger.info('\t\t{0}\t({1})'.format(param_name,
-                                                param['description']))
+    logger.info('Workflow Inputs:')
+    logger.info('\tMandatory Inputs:')
+    for input_name, input in required_inputs.iteritems():
+        if input.description is not None:
+            logger.info('\t\t{0}\t({1})'.format(input_name,
+                                                input.description))
         else:
-            logger.info('\t\t{0}'.format(param_name))
+            logger.info('\t\t{0}'.format(input_name))
 
-    logger.info('\tOptional Parameters:')
-    for param_name, param in optional_params.iteritems():
-        if 'description' in param:
+    logger.info('\tOptional Inputs:')
+    for input_name, input in optional_inputs.iteritems():
+        if input.description is not None:
             logger.info('\t\t{0}: \t{1}\t({2})'.format(
-                param_name, param['default'], param['description']))
+                input_name, input.value, input.description))
         else:
-            logger.info('\t\t{0}: \t{1}'.format(param_name,
-                                                param['default']))
+            logger.info('\t\t{0}: \t{1}'.format(input_name,
+                                                input.value))
     logger.info('')
 
 


[11/18] incubator-ariatosca git commit: Add tests for service-templates inputs

Posted by mx...@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/logger_task
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),))
 


[10/18] incubator-ariatosca git commit: Add test for non `unique name` exception from service-templates store

Posted by mx...@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/logger_task
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):
 


[03/18] incubator-ariatosca git commit: created fixtures.py for tests

Posted by mx...@apache.org.
created fixtures.py for 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/e2dd671d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e2dd671d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e2dd671d

Branch: refs/heads/logger_task
Commit: e2dd671d1d74a4fa570a251aa265d4902204d40f
Parents: 94c8d72
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:09:28 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:09:28 2017 +0300

----------------------------------------------------------------------
 tests/fixtures.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e2dd671d/tests/fixtures.py
----------------------------------------------------------------------
diff --git a/tests/fixtures.py b/tests/fixtures.py
new file mode 100644
index 0000000..3b1b9b5
--- /dev/null
+++ b/tests/fixtures.py
@@ -0,0 +1,70 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+
+import shutil
+
+import pytest
+
+from aria import (
+    application_model_storage,
+    application_resource_storage
+)
+from aria.orchestrator import plugin
+from aria.storage import (
+    sql_mapi,
+    filesystem_rapi
+)
+
+from . import storage
+
+
+@pytest.fixture
+def inmemory_model():
+    model = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                      initiator=storage.init_inmemory_model_storage)
+    yield model
+    storage.release_sqlite_storage(model)
+
+
+@pytest.fixture
+def fs_model(tmpdir):
+    result = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                       initiator_kwargs=dict(base_dir=str(tmpdir)),
+                                       initiator=sql_mapi.init_storage)
+    yield result
+    storage.release_sqlite_storage(result)
+
+
+@pytest.fixture
+def resource_storage(tmpdir):
+    result = tmpdir.join('resources')
+    result.mkdir()
+    resource_storage = application_resource_storage(
+        filesystem_rapi.FileSystemResourceAPI,
+        api_kwargs=dict(directory=str(result)))
+    yield resource_storage
+    shutil.rmtree(str(result))
+
+
+@pytest.fixture
+def plugins_dir(tmpdir):
+    result = tmpdir.join('plugins')
+    result.mkdir()
+    return str(result)
+
+
+@pytest.fixture
+def plugin_manager(model, plugins_dir):
+    return plugin.PluginManager(model=model, plugins_dir=plugins_dir)


[14/18] incubator-ariatosca git commit: Add tests for service-templates delete

Posted by mx...@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/logger_task
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='')


[08/18] incubator-ariatosca git commit: fixed a test

Posted by mx...@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/logger_task
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, {}),


[18/18] incubator-ariatosca git commit: initial support for traceback and exception in operation logs

Posted by mx...@apache.org.
initial support for traceback and exception in operation logs


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/14219f96
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/14219f96
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/14219f96

Branch: refs/heads/logger_task
Commit: 14219f96ba2547403ad32d5696678d9b83136736
Parents: 03103f6
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 6 13:56:00 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 10 12:50:59 2017 +0300

----------------------------------------------------------------------
 aria/logger.py                                      |  4 ++++
 aria/modeling/orchestration.py                      |  4 ++++
 aria/orchestrator/context/common.py                 |  7 ++++++-
 aria/orchestrator/workflows/events_logging.py       | 16 ++++++++--------
 aria/orchestrator/workflows/executor/base.py        |  4 ++--
 aria/orchestrator/workflows/executor/process.py     |  6 ++++--
 aria/orchestrator/workflows/executor/thread.py      |  8 ++++++--
 examples/hello-world/scripts/stop.sh                |  2 ++
 .../workflows/executor/test_executor.py             |  2 ++
 9 files changed, 38 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index 040ab3f..c473340 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -171,6 +171,10 @@ class _SQLAlchemyHandler(logging.Handler):
             level=record.levelname,
             msg=str(record.msg),
             created_at=created_at,
+
+            # Not mandatory.
+            error=getattr(record, 'error', None),
+            traceback=getattr(record, 'traceback', None)
         )
         self._session.add(log)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index f880d31..ee336b7 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -394,6 +394,10 @@ class LogBase(ModelMixin):
     msg = Column(String)
     created_at = Column(DateTime, index=True)
 
+    # In case of failed execution
+    error = Column(String)
+    traceback = Column(Text)
+
     # region foreign keys
 
     @declared_attr

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index c9ca53b..9af0804 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -45,10 +45,15 @@ class BaseContext(object):
 
         def __getattr__(self, item):
             if item.upper() in logging._levelNames:
-                return partial(getattr(self._logger, item), extra=dict(task_id=self._task_id))
+                return partial(self._logger_with_task_id, _level=item)
             else:
                 return getattr(self._logger, item)
 
+        def _logger_with_task_id(self, *args, **kwargs):
+            level = kwargs.pop('_level')
+            kwargs.setdefault('extra', {})['task_id'] = self._task_id
+            return getattr(self._logger, level)(*args, **kwargs)
+
     def __init__(
             self,
             name,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/orchestrator/workflows/events_logging.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/events_logging.py b/aria/orchestrator/workflows/events_logging.py
index 07981e9..c4bc8c4 100644
--- a/aria/orchestrator/workflows/events_logging.py
+++ b/aria/orchestrator/workflows/events_logging.py
@@ -26,7 +26,7 @@ from .. import events
 
 @events.start_task_signal.connect
 def _start_task_handler(task, **kwargs):
-    task.context.logger.debug('{actor.name} {task.interface_name}.{task.operation_name} started...'
+    task.context.logger.info('{actor.name} {task.interface_name}.{task.operation_name} started...'
                              .format(actor=task.actor, task=task))
 
 
@@ -37,14 +37,14 @@ def _success_task_handler(task, **kwargs):
 
 
 @events.on_failure_task_signal.connect
-def _failure_operation_handler(task, exception, **kwargs):
+def _failure_operation_handler(task, exception, traceback, **kwargs):
     # todo: add full support for exceptions and errors logging
-    task.context.logger.info('{actor.name} {task.interface_name}.{task.operation_name} failed'
-                             .format(actor=task.actor, task=task))
-    error = '{0}: {1}'.format(type(exception).__name__, exception)
-    task.context.logger.error('Event: Task failure: {task.name} [{error}]'.format(
-        task=task, error=error))
-
+    task.context.logger.error(
+        '{actor.name} {task.interface_name}.{task.operation_name} failed'
+        .format(actor=task.actor, task=task),
+        extra=dict(error='{0}: {1}'.format(type(exception).__name__, exception),
+                   traceback=traceback)
+    )
 
 @events.start_workflow_signal.connect
 def _start_workflow_handler(context, **kwargs):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/orchestrator/workflows/executor/base.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/base.py b/aria/orchestrator/workflows/executor/base.py
index 4ae046d..39becef 100644
--- a/aria/orchestrator/workflows/executor/base.py
+++ b/aria/orchestrator/workflows/executor/base.py
@@ -44,8 +44,8 @@ class BaseExecutor(logger.LoggerMixin):
         events.start_task_signal.send(task)
 
     @staticmethod
-    def _task_failed(task, exception):
-        events.on_failure_task_signal.send(task, exception=exception)
+    def _task_failed(task, exception, traceback=None):
+        events.on_failure_task_signal.send(task, exception=exception, traceback=traceback)
 
     @staticmethod
     def _task_succeeded(task):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index 83d8b55..c75697f 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -236,9 +236,10 @@ class ProcessExecutor(base.BaseExecutor):
         except BaseException as e:
             e.message += 'Task failed due to {0}.'.format(request['exception']) + \
                          UPDATE_TRACKED_CHANGES_FAILED_STR
-            self._task_failed(task, exception=e)
+            self._task_failed(
+                task, exception=e, traceback=exceptions.get_exception_as_string(*sys.exc_info()))
         else:
-            self._task_failed(task, exception=request['exception'])
+            self._task_failed(task, exception=request['exception'], traceback=request['traceback'])
 
     def _handle_apply_tracked_changes_request(self, task_id, request, response):
         task = self._tasks[task_id]
@@ -322,6 +323,7 @@ class _Messenger(object):
                 'type': type,
                 'task_id': self.task_id,
                 'exception': exceptions.wrap_if_needed(exception),
+                'traceback': exceptions.get_exception_as_string(*sys.exc_info()),
                 'tracked_changes': tracked_changes
             })
             response = _recv_message(sock)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/aria/orchestrator/workflows/executor/thread.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/thread.py b/aria/orchestrator/workflows/executor/thread.py
index 8b443cc..d69c4a1 100644
--- a/aria/orchestrator/workflows/executor/thread.py
+++ b/aria/orchestrator/workflows/executor/thread.py
@@ -20,7 +20,9 @@ Thread based executor
 import Queue
 import threading
 
-from aria.utils import imports
+import sys
+
+from aria.utils import imports, exceptions
 
 from .base import BaseExecutor
 from ....modeling.models import Parameter
@@ -64,7 +66,9 @@ class ThreadExecutor(BaseExecutor):
                     task_func(ctx=task.context, **inputs)
                     self._task_succeeded(task)
                 except BaseException as e:
-                    self._task_failed(task, exception=e)
+                    self._task_failed(task,
+                                      exception=e)
+                                      # traceback=exceptions.get_exception_as_string(*sys.exc_info()))
             # Daemon threads
             except BaseException as e:
                 pass

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/examples/hello-world/scripts/stop.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/stop.sh b/examples/hello-world/scripts/stop.sh
index 5461caf..dea152a 100755
--- a/examples/hello-world/scripts/stop.sh
+++ b/examples/hello-world/scripts/stop.sh
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+exit 1
+
 set -e
 
 TEMP_DIR="/tmp"

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/14219f96/tests/orchestrator/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py
index d84d1ec..e39a993 100644
--- a/tests/orchestrator/workflows/executor/test_executor.py
+++ b/tests/orchestrator/workflows/executor/test_executor.py
@@ -15,6 +15,7 @@
 
 import logging
 import uuid
+from collections import namedtuple
 from contextlib import contextmanager
 
 import pytest
@@ -119,6 +120,7 @@ class MockTask(object):
         self.ignore_failure = False
         self.interface_name = 'interface_name'
         self.operation_name = 'operation_name'
+        self.actor = namedtuple('actor', 'name')(name='actor_name')
 
         for state in models.Task.STATES:
             setattr(self, state.upper(), state)