djay87 closed pull request #212: ARIA-118 plugin.yaml importing
URL: https://github.com/apache/incubator-ariatosca/pull/212
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/aria/core.py b/aria/core.py
index e3b3b360..20cb0f99 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -21,6 +21,7 @@
 from .parser import consumption
 from .parser.loading.location import UriLocation
 from .orchestrator import topology
+from .utils import collections
 
 
 class Core(object):
@@ -46,16 +47,17 @@ def plugin_manager(self):
         return self._plugin_manager
 
     def validate_service_template(self, service_template_path):
-        self._parse_service_template(service_template_path)
+        self.parse_service_template(service_template_path)
 
     def create_service_template(self, service_template_path, 
service_template_dir,
                                 service_template_name):
-        context = self._parse_service_template(service_template_path)
+        context = self.parse_service_template(service_template_path)
         service_template = context.modeling.template
         service_template.name = service_template_name
         self.model_storage.service_template.put(service_template)
         self.resource_storage.service_template.upload(
             entry_id=str(service_template.id), source=service_template_dir)
+        return service_template
 
     def delete_service_template(self, service_template_id):
         service_template = 
self.model_storage.service_template.get(service_template_id)
@@ -114,10 +116,11 @@ def delete_service(self, service_id, force=False):
 
         self.model_storage.service.delete(service)
 
-    @staticmethod
-    def _parse_service_template(service_template_path):
+    def parse_service_template(self, service_template_path):
+        plugin_dir = self.plugin_manager._plugins_dir
         context = consumption.ConsumptionContext()
         context.presentation.location = UriLocation(service_template_path)
+        context.loading.prefixes = collections.StrictList([plugin_dir])
         # Most of the parser uses the topology package in order to manipulate 
the models.
         # However, here we use the Consumer mechanism, but this should change 
in the future.
         consumption.ConsumerChain(
diff --git a/extensions/aria_extension_tosca/simple_v1_0/presenter.py 
b/extensions/aria_extension_tosca/simple_v1_0/presenter.py
index 28c9f7ba..08a50cd4 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/presenter.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/presenter.py
@@ -38,6 +38,8 @@ class ToscaSimplePresenter1_0(Presenter): # pylint: 
disable=invalid-name,abstrac
     SIMPLE_PROFILE_LOCATION = 'tosca-simple-1.0/tosca-simple-1.0.yaml'
     SPECIAL_IMPORTS = {
         'aria-1.0': 'aria-1.0/aria-1.0.yaml'}
+    PLUGIN_IMPORT_FILE = '/plugin.yaml'
+    PLUGIN_REPOSITORY = 'plugins'
 
     @property
     @cachedmethod
@@ -74,7 +76,11 @@ def _get_import_locations(self, context):
             import_locations.append(self.SIMPLE_PROFILE_LOCATION)
         imports = self._get('service_template', 'imports')
         if imports:
-            import_locations += [self.SPECIAL_IMPORTS.get(i.file, i.file) for 
i in imports]
+            for i in imports:
+                if i.repository == self.PLUGIN_REPOSITORY:
+                    import_locations += [i.file + self.PLUGIN_IMPORT_FILE]
+                else:
+                    import_locations += [self.SPECIAL_IMPORTS.get(i.file, 
i.file)]
         return FrozenList(import_locations) if import_locations else 
EMPTY_READ_ONLY_LIST
 
     @cachedmethod
diff --git a/tests/parser/service_templates.py 
b/tests/parser/service_templates.py
index 9e8fcae1..091fc0cf 100644
--- a/tests/parser/service_templates.py
+++ b/tests/parser/service_templates.py
@@ -62,6 +62,21 @@ def consume_types_use_case(use_case_name, 
consumer_class_name='instance', cache=
     assert not context.validation.has_issues
     return context, dumper
 
+def consume_import_use_case(use_case_name, consumer_class_name='instance',
+                            plugin_dir=None, cache=True):
+    cachedmethod.ENABLED = cache
+    uri = get_service_template_uri('tosca-simple-1.0', 'imports', 
use_case_name,
+                                   '{0}.yaml'.format(use_case_name))
+    context = create_context(uri, plugin_dir=plugin_dir)
+    inputs_file = get_example_uri('tosca-simple-1.0', 'imports', 
use_case_name, 'inputs.yaml')
+    if os.path.isfile(inputs_file):
+        context.args.append('--inputs={0}'.format(inputs_file))
+    consumer, dumper = create_consumer(context, consumer_class_name)
+    consumer.consume()
+    context.validation.dump_issues()
+    assert not context.validation.has_issues
+    return context, dumper
+
 
 def consume_node_cellar(consumer_class_name='instance', cache=True):
     consume_test_case(
diff --git a/tests/parser/test_tosca_simple_v1_0/presentation/test_imports.py 
b/tests/parser/test_tosca_simple_v1_0/presentation/test_imports.py
new file mode 100644
index 00000000..b0a29870
--- /dev/null
+++ b/tests/parser/test_tosca_simple_v1_0/presentation/test_imports.py
@@ -0,0 +1,22 @@
+# 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.
+
+from tests.parser.service_templates import consume_import_use_case
+from tests.helpers import get_resource_uri
+
+
+def test_use_case_plugin_import_1():
+    plugin_dir = get_resource_uri('plugins')
+    consume_import_use_case('plugin-import-1', 'instance', 
plugin_dir=plugin_dir)
diff --git a/tests/parser/utils.py b/tests/parser/utils.py
index f0e890f8..3334a1be 100644
--- a/tests/parser/utils.py
+++ b/tests/parser/utils.py
@@ -25,6 +25,7 @@
     ServiceInstance
 )
 from aria.utils.imports import import_fullname
+from aria.utils import collections
 
 
 def create_context(uri,
@@ -32,6 +33,7 @@ def create_context(uri,
                    reader_source='aria.parser.reading.DefaultReaderSource',
                    
presenter_source='aria.parser.presentation.DefaultPresenterSource',
                    presenter=None,
+                   plugin_dir=None,
                    debug=False):
     context = ConsumptionContext()
     context.loading.loader_source = import_fullname(loader_source)()
@@ -40,6 +42,8 @@ def create_context(uri,
     context.presentation.presenter_source = import_fullname(presenter_source)()
     context.presentation.presenter_class = import_fullname(presenter)
     context.presentation.print_exceptions = debug
+    if plugin_dir:
+        context.loading.prefixes = collections.StrictList([plugin_dir])
     return context
 
 
diff --git a/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml 
b/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml
new file mode 100644
index 00000000..9e8d5d46
--- /dev/null
+++ b/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml
@@ -0,0 +1,28 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+
+topology_template:
+
+  policies:
+    import-plugin:
+      description: >-
+        plugin to test import of plugin.yaml.
+      type: aria.Plugin
+      properties:
+        version: 1.0.0
+
+node_types:
+
+  myapp.nodes.Network:
+    derived_from: tosca.nodes.Root
+    properties:
+      resource_id:
+        default: ''
+        type: string
+    interfaces:
+      Standard:
+        create:
+          implementation: create-network.sh 
+
+        delete:
+          implementation: delete-network.sh
diff --git 
a/tests/resources/service-templates/tosca-simple-1.0/imports/plugin-import-1/plugin-import-1.yaml
 
b/tests/resources/service-templates/tosca-simple-1.0/imports/plugin-import-1/plugin-import-1.yaml
new file mode 100644
index 00000000..b2160c45
--- /dev/null
+++ 
b/tests/resources/service-templates/tosca-simple-1.0/imports/plugin-import-1/plugin-import-1.yaml
@@ -0,0 +1,15 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+imports:
+  - aria-1.0
+  - file: import-plugin-1.0.0 
+    repository: plugins
+
+topology_template:
+
+  node_templates:
+    Network:
+      type: myapp.nodes.Network
+      properties:
+         resource_id: helloworld_network
+


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to