From 01d2731abab62aee49c64581d1119c2a750fc7e1 Mon Sep 17 00:00:00 2001 From: "Bob.Haddleton" Date: Tue, 26 Jan 2016 09:32:54 -0600 Subject: [PATCH] Support flavor and image properties for Compute translation - If the tosca.nodes.Compute object does not have host or os capabilities specified, look for image and flavor properties to use, instead of leaving them set to None. This allows the user to define nodes that inherit from Compute and contain properties that contain specific image and flavors to be used. Change-Id: Ia2841639836795a8a6b7ca7fa0d03481cf7e5fd9 --- translator/hot/tosca/tosca_compute.py | 6 ++++-- .../data/hot_output/hot_flavor_and_image.yaml | 15 ++++++++++++++ .../data/test_tosca_flavor_and_image.yaml | 20 +++++++++++++++++++ .../tests/test_tosca_hot_translation.py | 9 +++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 translator/tests/data/hot_output/hot_flavor_and_image.yaml create mode 100644 translator/tests/data/test_tosca_flavor_and_image.yaml diff --git a/translator/hot/tosca/tosca_compute.py b/translator/hot/tosca/tosca_compute.py index de75207b..fcb0a1dd 100755 --- a/translator/hot/tosca/tosca_compute.py +++ b/translator/hot/tosca/tosca_compute.py @@ -112,14 +112,16 @@ class ToscaCompute(HotResource): for prop in host_capability.get_properties_objects(): host_cap_props[prop.name] = prop.value flavor = self._best_flavor(host_cap_props) + else: + flavor = self.nodetemplate.get_property_value("flavor") or None 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) + else: + image = self.nodetemplate.get_property_value("image") or None hot_properties['flavor'] = flavor hot_properties['image'] = image - # TODO(anyone): consider adding the flavor or image as a template - # parameter if no match is found. return hot_properties def _check_for_env_variables(self): diff --git a/translator/tests/data/hot_output/hot_flavor_and_image.yaml b/translator/tests/data/hot_output/hot_flavor_and_image.yaml new file mode 100644 index 00000000..2fe540e4 --- /dev/null +++ b/translator/tests/data/hot_output/hot_flavor_and_image.yaml @@ -0,0 +1,15 @@ +heat_template_version: 2013-05-23 + +description: > + Template for deploying a server with custom properties for image and flavor. + +parameters: {} +resources: + my_server: + type: OS::Nova::Server + properties: + flavor: m1.medium + image: rhel-6.5-test-image + key_name: userkey + user_data_format: SOFTWARE_CONFIG +outputs: {} diff --git a/translator/tests/data/test_tosca_flavor_and_image.yaml b/translator/tests/data/test_tosca_flavor_and_image.yaml new file mode 100644 index 00000000..f90094b7 --- /dev/null +++ b/translator/tests/data/test_tosca_flavor_and_image.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a server with custom properties for image and flavor. + +node_types: + tosca.nodes.nfv.VDU: + derived_from: tosca.nodes.Compute + properties: + image: + type: string + flavor: + type: string + +topology_template: + node_templates: + my_server: + type: tosca.nodes.nfv.VDU + properties: + flavor: m1.medium + image: rhel-6.5-test-image diff --git a/translator/tests/test_tosca_hot_translation.py b/translator/tests/test_tosca_hot_translation.py index 534f8ed9..c10b6d33 100644 --- a/translator/tests/test_tosca_hot_translation.py +++ b/translator/tests/test_tosca_hot_translation.py @@ -501,3 +501,12 @@ class ToscaHotTranslationTest(TestCase): 'heat-translator/master/translator/tests/data/' 'custom_types/wordpress1.yaml" cannot be accessed.') ExceptionCollector.assertExceptionMessage(URLException, expected_msg) + + def test_hot_translate_flavor_image(self): + tosca_file = '../tests/data/test_tosca_flavor_and_image.yaml' + hot_file = '../tests/data/hot_output/hot_flavor_and_image.yaml' + diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, + hot_file, + {}) + self.assertEqual({}, diff, ' : ' + + json.dumps(diff, indent=4, separators=(', ', ': ')))