From 396f2186f4cbe3ac3c0f043ded2d99a321f97b3b Mon Sep 17 00:00:00 2001 From: Sahdev Zala Date: Wed, 4 May 2016 13:30:58 -0700 Subject: [PATCH] Move translator to use new TOSCA parser release There are couple of things that needs to be changed in heat-translator for it to use TOSCA parser 0.5.0 PyPI release. Change-Id: I25a703ed00b4f03b92d7e41a119c703d0d63d9eb --- translator/hot/tosca/tests/test_tosca_compute.py | 2 +- translator/hot/tosca/tosca_compute.py | 12 +++++++++--- translator/hot/translate_node_templates.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/translator/hot/tosca/tests/test_tosca_compute.py b/translator/hot/tosca/tests/test_tosca_compute.py index e0cdbb65..9f9f0936 100644 --- a/translator/hot/tosca/tests/test_tosca_compute.py +++ b/translator/hot/tosca/tests/test_tosca_compute.py @@ -144,7 +144,7 @@ class ToscaComputeTest(TestCase): properties: #left intentionally ''' - expectedprops = {'flavor': 'm1.nano'} + expectedprops = {'flavor': None} self._tosca_compute_test( tpl_snippet, expectedprops) diff --git a/translator/hot/tosca/tosca_compute.py b/translator/hot/tosca/tosca_compute.py index 4ae85f6b..08fbfc67 100755 --- a/translator/hot/tosca/tosca_compute.py +++ b/translator/hot/tosca/tosca_compute.py @@ -112,11 +112,17 @@ class ToscaCompute(HotResource): if host_capability: for prop in host_capability.get_properties_objects(): host_cap_props[prop.name] = prop.value - flavor = self._best_flavor(host_cap_props) + # if HOST properties are not specified, we should not attempt to + # find best match of flavor + if host_cap_props: + flavor = self._best_flavor(host_cap_props) if os_capability: for prop in os_capability.get_properties_objects(): os_cap_props[prop.name] = prop.value - image = self._best_image(os_cap_props) + # if OS properties are not specified, we should not attempt to + # find best match of image + if os_cap_props: + image = self._best_image(os_cap_props) hot_properties['flavor'] = flavor hot_properties['image'] = image return hot_properties @@ -155,6 +161,7 @@ class ToscaCompute(HotResource): def _populate_image_dict(self): '''Populates and returns the images dict using Glance ReST API''' + images_dict = {} try: access_dict = translator.common.utils.get_ks_access_dict() access_token = translator.common.utils.get_token_id(access_dict) @@ -170,7 +177,6 @@ class ToscaCompute(HotResource): if glance_response.status_code != 200: return None images = json.loads(glance_response.content)["images"] - images_dict = {} for image in images: image_resp = requests.get(glance_url + '/v2/images/' + image["id"], diff --git a/translator/hot/translate_node_templates.py b/translator/hot/translate_node_templates.py index 46cdd71d..14cf6337 100644 --- a/translator/hot/translate_node_templates.py +++ b/translator/hot/translate_node_templates.py @@ -317,7 +317,7 @@ class TranslateNodeTemplates(object): elif isinstance(input_value, GetAttribute): # for the attribute # get the proper target type to perform the translation - args = input_value.result() + args = input_value.result().args hot_target = self._find_hot_resource_for_tosca(args[0], resource) return hot_target.get_hot_attribute(args[1], args)