From c6e04928fb98d0ed8b5904526ab77f92a072ab2d Mon Sep 17 00:00:00 2001 From: Nobuhiro Uematsu Date: Thu, 4 Mar 2021 12:15:46 +0900 Subject: [PATCH] ETSI-NFV SOL 001 translation: AffinityRule The current heat-translator supports several conversions of resources defined in ETSI NFV-SOL 001[1]. This patch supports the conversion of new resource types. Specifically, the following types related to 'PlacementConstraints'. - tosca.groups.nfv.PlacementGroup - tosca.policies.nfv.AffinityRule - tosca.policies.nfv.AntiAffinityRule [1] https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/001/02.06.01_60/gs_NFV-SOL001v020601p.pdf Co-Authored-By: Hiroo Kitamura hiroo.kitamura@ntt-at.co.jp Implements: blueprint support-placement-constraints Change-Id: Ic22a6183ee0d7c8357063bdafbb1a11c1a6efa3c --- .../tosca_policies_nfv_common_affinityrule.py | 72 ++++++ .../tosca_groups_nfv_placementgroup.py | 32 +++ .../tosca_policies_nfv_affinityrule.py | 33 +++ .../tosca_policies_nfv_antiaffinityrule.py | 33 +++ ...osca_nfv_vdu_affinity_with_scope_nfvi.yaml | 85 +++++++ ...v_vdu_affinity_with_unsupported_scope.yaml | 233 ++++++++++++++++++ ...vdu_affinity_with_unsupported_targets.yaml | 155 ++++++++++++ .../hot_nfv_vdu_affinity_with_scope_nfvi.yaml | 48 ++++ ...v_vdu_affinity_with_unsupported_scope.yaml | 80 ++++++ ...vdu_affinity_with_unsupported_targets.yaml | 56 +++++ .../tests/test_etsi_tosca_hot_translation.py | 27 ++ .../tests/test_translate_node_template.py | 3 + 12 files changed, 857 insertions(+) create mode 100644 translator/hot/tosca/etsi_nfv/common_affinityrule/tosca_policies_nfv_common_affinityrule.py create mode 100644 translator/hot/tosca/etsi_nfv/tosca_groups_nfv_placementgroup.py create mode 100644 translator/hot/tosca/etsi_nfv/tosca_policies_nfv_affinityrule.py create mode 100644 translator/hot/tosca/etsi_nfv/tosca_policies_nfv_antiaffinityrule.py create mode 100644 translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_scope_nfvi.yaml create mode 100644 translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_scope.yaml create mode 100644 translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_targets.yaml create mode 100644 translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_scope_nfvi.yaml create mode 100644 translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_scope.yaml create mode 100644 translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_targets.yaml diff --git a/translator/hot/tosca/etsi_nfv/common_affinityrule/tosca_policies_nfv_common_affinityrule.py b/translator/hot/tosca/etsi_nfv/common_affinityrule/tosca_policies_nfv_common_affinityrule.py new file mode 100644 index 00000000..5fde1eab --- /dev/null +++ b/translator/hot/tosca/etsi_nfv/common_affinityrule/tosca_policies_nfv_common_affinityrule.py @@ -0,0 +1,72 @@ +# +# Licensed 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 translator.hot.syntax.hot_resource import HotResource + +# Name used to dynamically load appropriate map class. +TARGET_CLASS_NAME = 'ToscaNfvCommonAffinityRule' + + +class ToscaNfvCommonAffinityRule(HotResource): + """Translate common TOSCA policy type tosca.policies.nfv.AffinityRule.""" + + GROUP_SUFFIX = '_group' + + def __init__(self, policy, csar_dir=None, hot_template_parameters=None): + self.own_resource_name = policy.name + self.GROUP_SUFFIX + super(ToscaNfvCommonAffinityRule, self).__init__( + policy, + name=self.own_resource_name, + type='OS::Nova::ServerGroup', + csar_dir=csar_dir) + self.policy = policy + self.hot_template_parameters = hot_template_parameters + + def handle_properties(self, resources): + policy_props = self.policy.properties + rule = 'anti-affinity' if self.is_anti else 'affinity' + + # NOTE: In ETSI-NFV SOL001, nfvi_node/zone/zone_group/nfvi_pop + # is specified as 'scope'. + # This code only supports nfvi_node as 'scope'and no conversion + # for other'scope'. + scope = policy_props.get('scope', None) + if scope != 'nfvi_node': + self.name = None + self.type = None + return + + # NOTE: In ETSI-NFV SOL001, + # - tosca.nodes.nfv.Vdu.Compute + # - tosca.nodes.nfv.VnfVirtualLink + # - tosca.groups.nfv.PlacementGroup + # is specified as'targets'. + # This code only supports tosca.nodes.nfv.Vdu.Compute as 'targets' + # and no conversion for other 'targets'. + is_exists_server = False + for resource in resources: + if self.policy.type in self.toscatype and \ + resource.name in self.policy.targets and \ + resource.type == 'OS::Nova::Server': + self.properties['name'] = self.name + self.properties['policies'] = [rule] + if not resource.properties.get('scheduler_hints'): + resource.properties['scheduler_hints'] = {} + resource.properties['scheduler_hints'].update( + {'group': '{ get_resource: %s }' % (self.name)} + ) + is_exists_server = True + + if is_exists_server is False: + self.name = None + self.type = None diff --git a/translator/hot/tosca/etsi_nfv/tosca_groups_nfv_placementgroup.py b/translator/hot/tosca/etsi_nfv/tosca_groups_nfv_placementgroup.py new file mode 100644 index 00000000..d1dccf60 --- /dev/null +++ b/translator/hot/tosca/etsi_nfv/tosca_groups_nfv_placementgroup.py @@ -0,0 +1,32 @@ +# +# Licensed 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 translator.hot.syntax.hot_resource import HotResource + +# Name used to dynamically load appropriate map class. +TARGET_CLASS_NAME = 'ToscaNfvPlacementGroup' + + +class ToscaNfvPlacementGroup(HotResource): + """Translate TOSCA group type tosca.groups.nfv.PlacementGroup.""" + + toscatype = 'tosca.groups.nfv.PlacementGroup' + + def __init__(self, nodetemplate, csar_dir=None): + super(ToscaNfvPlacementGroup, self).__init__( + nodetemplate, + type=None, + csar_dir=csar_dir) + + def handle_properties(self): + pass diff --git a/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_affinityrule.py b/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_affinityrule.py new file mode 100644 index 00000000..f22ac19a --- /dev/null +++ b/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_affinityrule.py @@ -0,0 +1,33 @@ +# +# Licensed 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 translator.hot.tosca.etsi_nfv.common_affinityrule.\ + tosca_policies_nfv_common_affinityrule import ToscaNfvCommonAffinityRule + +# Name used to dynamically load appropriate map class. +TARGET_CLASS_NAME = 'ToscaNfvAffinityRule' + + +class ToscaNfvAffinityRule(ToscaNfvCommonAffinityRule): + """Translate TOSCA policy type tosca.policies.nfv.AffinityRule.""" + + toscatype = 'tosca.policies.nfv.AffinityRule' + + def __init__(self, policy, csar_dir=None): + super(ToscaNfvAffinityRule, self).__init__( + policy, + csar_dir=csar_dir) + self.is_anti = False + + def handle_properties(self, resources): + super().handle_properties(resources) diff --git a/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_antiaffinityrule.py b/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_antiaffinityrule.py new file mode 100644 index 00000000..e1604552 --- /dev/null +++ b/translator/hot/tosca/etsi_nfv/tosca_policies_nfv_antiaffinityrule.py @@ -0,0 +1,33 @@ +# +# Licensed 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 translator.hot.tosca.etsi_nfv.common_affinityrule.\ + tosca_policies_nfv_common_affinityrule import ToscaNfvCommonAffinityRule + +# Name used to dynamically load appropriate map class. +TARGET_CLASS_NAME = 'ToscaNfvAntiAffinityRule' + + +class ToscaNfvAntiAffinityRule(ToscaNfvCommonAffinityRule): + """Translate TOSCA policy type tosca.policies.nfv.AntiAffinityRule.""" + + toscatype = 'tosca.policies.nfv.AntiAffinityRule' + + def __init__(self, policy, csar_dir=None): + super(ToscaNfvAntiAffinityRule, self).__init__( + policy, + csar_dir=csar_dir) + self.is_anti = True + + def handle_properties(self, resources): + super().handle_properties(resources) diff --git a/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_scope_nfvi.yaml b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_scope_nfvi.yaml new file mode 100644 index 00000000..bf92ca56 --- /dev/null +++ b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_scope_nfvi.yaml @@ -0,0 +1,85 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 + +description: > + Template for deploying two VDUs with scope nfvi_node. + +imports: + - etsi_nfv_sol001_common_types.yaml + - etsi_nfv_sol001_vnfd_types.yaml + +topology_template: + node_templates: + VDU1: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU1 + description: VDU1 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU1 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU2: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU2 + description: VDU2 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU2 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + + policies: + - Affinity: + type: tosca.policies.nfv.AffinityRule + targets: [ VDU1 ] + properties: + scope: nfvi_node + - AntiAffinity: + type: tosca.policies.nfv.AntiAffinityRule + targets: [ VDU2 ] + properties: + scope: nfvi_node \ No newline at end of file diff --git a/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_scope.yaml b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_scope.yaml new file mode 100644 index 00000000..55d75d41 --- /dev/null +++ b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_scope.yaml @@ -0,0 +1,233 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 + +description: > + Template for deploying six VDUs with unsupported scope type. + +imports: + - etsi_nfv_sol001_common_types.yaml + - etsi_nfv_sol001_vnfd_types.yaml + +topology_template: + node_templates: + VDU1: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU1 + description: VDU1 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU1 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU2: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU2 + description: VDU2 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU2 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU3: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU3 + description: VDU3 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU3 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU4: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU4 + description: VDU4 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU4 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU5: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU5 + description: VDU5 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU5 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU6: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU6 + description: VDU6 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU6 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + + policies: + - Affinity: + type: tosca.policies.nfv.AffinityRule + targets: [ VDU1 ] + properties: + scope: nfvi_pop + - AntiAffinity: + type: tosca.policies.nfv.AffinityRule + targets: [ VDU2 ] + properties: + scope: zone + - Affinity: + type: tosca.policies.nfv.AffinityRule + targets: [ VDU3 ] + properties: + scope: zone_group + - Affinity: + type: tosca.policies.nfv.AntiAffinityRule + targets: [ VDU4 ] + properties: + scope: nfvi_pop + - AntiAffinity: + type: tosca.policies.nfv.AntiAffinityRule + targets: [ VDU5 ] + properties: + scope: zone + - Affinity: + type: tosca.policies.nfv.AntiAffinityRule + targets: [ VDU6 ] + properties: + scope: zone_group diff --git a/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_targets.yaml b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_targets.yaml new file mode 100644 index 00000000..4617a267 --- /dev/null +++ b/translator/tests/data/etsi_nfv/tosca_nfv_vdu_affinity_with_unsupported_targets.yaml @@ -0,0 +1,155 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 + +description: > + Template for deploying four VDUs with unsupported targets. + +imports: + - etsi_nfv_sol001_common_types.yaml + - etsi_nfv_sol001_vnfd_types.yaml + +topology_template: + node_templates: + VDU1: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU1 + description: VDU1 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU1 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU2: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU2 + description: VDU2 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU2 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU3: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU3 + description: VDU3 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU3 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + VDU4: + type: tosca.nodes.nfv.Vdu.Compute + properties: + name: VDU4 + description: VDU4 compute node + vdu_profile: + min_number_of_instances: 1 + max_number_of_instances: 1 + sw_image_data: + name: Software of VDU4 + version: '0.4.0' + checksum: + algorithm: sha-512 + hash: 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 + container_format: bare + disk_format: qcow2 + min_disk: 1 GiB + size: 1 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: Files/images/cirros-0.4.0-x86_64-disk.img + capabilities: + virtual_compute: + properties: + virtual_memory: + virtual_mem_size: 512 MiB + virtual_cpu: + num_virtual_cpu: 1 + virtual_local_storage: + - size_of_storage: 1 GiB + + groups: + AffinityGroup: + type: tosca.groups.nfv.PlacementGroup + members: [ VDU1, VDU2 ] + AntiAffinityGroup: + type: tosca.groups.nfv.PlacementGroup + members: [ VDU3, VDU4 ] + + policies: + - Affinity: + type: tosca.policies.nfv.AffinityRule + targets: [ AffinityGroup ] + properties: + scope: nfvi_node + - AntiAffinity: + type: tosca.policies.nfv.AntiAffinityRule + targets: [ AntiAffinityGroup ] + properties: + scope: nfvi_node diff --git a/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_scope_nfvi.yaml b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_scope_nfvi.yaml new file mode 100644 index 00000000..7134a8ed --- /dev/null +++ b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_scope_nfvi.yaml @@ -0,0 +1,48 @@ +heat_template_version: 2013-05-23 + +description: > + Template for deploying two VDUs with scope nfvi_node. + +parameters: {} +resources: + VDU1: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU1_flavor } + name: VDU1 + image: #ADD_YOUR_IMAGE_HERE + scheduler_hints: + group: { get_resource: Affinity_group } + VDU2: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU2_flavor } + name: VDU2 + image: #ADD_YOUR_IMAGE_HERE + scheduler_hints: + group: { get_resource: AntiAffinity_group } + Affinity_group: + type: OS::Nova::ServerGroup + properties: + name: Affinity_group + policies: + - affinity + AntiAffinity_group: + type: OS::Nova::ServerGroup + properties: + name: AntiAffinity_group + policies: + - anti-affinity + VDU1_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU2_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 +outputs: {} \ No newline at end of file diff --git a/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_scope.yaml b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_scope.yaml new file mode 100644 index 00000000..af793c31 --- /dev/null +++ b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_scope.yaml @@ -0,0 +1,80 @@ +heat_template_version: 2013-05-23 + +description: > + Template for deploying six VDUs with unsupported scope type. + +parameters: {} +resources: + VDU1: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU1_flavor } + name: VDU1 + image: #ADD_YOUR_IMAGE_HERE + VDU2: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU2_flavor } + name: VDU2 + image: #ADD_YOUR_IMAGE_HERE + VDU3: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU3_flavor } + name: VDU3 + image: #ADD_YOUR_IMAGE_HERE + VDU4: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU4_flavor } + name: VDU4 + image: #ADD_YOUR_IMAGE_HERE + VDU5: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU5_flavor } + name: VDU5 + image: #ADD_YOUR_IMAGE_HERE + VDU6: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU6_flavor } + name: VDU6 + image: #ADD_YOUR_IMAGE_HERE + VDU1_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU2_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU3_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU4_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU5_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU6_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 +outputs: {} diff --git a/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_targets.yaml b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_targets.yaml new file mode 100644 index 00000000..b882e312 --- /dev/null +++ b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_vdu_affinity_with_unsupported_targets.yaml @@ -0,0 +1,56 @@ +heat_template_version: 2013-05-23 + +description: > + Template for deploying four VDUs with unsupported targets. + +parameters: {} +resources: + VDU1: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU1_flavor } + name: VDU1 + image: #ADD_YOUR_IMAGE_HERE + VDU2: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU2_flavor } + name: VDU2 + image: #ADD_YOUR_IMAGE_HERE + VDU3: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU3_flavor } + name: VDU3 + image: #ADD_YOUR_IMAGE_HERE + VDU4: + type: OS::Nova::Server + properties: + flavor: { get_resource: VDU4_flavor } + name: VDU4 + image: #ADD_YOUR_IMAGE_HERE + VDU1_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU2_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU3_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 + VDU4_flavor: + type: OS::Nova::Flavor + properties: + ram: 512 + vcpus: 1 + disk: 1 +outputs: {} diff --git a/translator/tests/test_etsi_tosca_hot_translation.py b/translator/tests/test_etsi_tosca_hot_translation.py index 938dbf82..a3cb66ac 100644 --- a/translator/tests/test_etsi_tosca_hot_translation.py +++ b/translator/tests/test_etsi_tosca_hot_translation.py @@ -331,3 +331,30 @@ class EtsiToscaHotTranslationTest(TestCase): expected_msg, self.log_fixture.output ) + + def test_hot_translate_etsi_nfv_vdu_with_scope_nfvi(self): + tosca_file = '../tests/data/etsi_nfv/' \ + 'tosca_nfv_vdu_affinity_with_scope_nfvi.yaml' + hot_files = [ + '../tests/data/hot_output/etsi_nfv/' + 'hot_nfv_vdu_affinity_with_scope_nfvi.yaml', + ] + self._test_successful_translation(tosca_file, hot_files, params={}) + + def test_hot_translate_etsi_nfv_vdu_with_unsupported_scope(self): + tosca_file = '../tests/data/etsi_nfv/' \ + 'tosca_nfv_vdu_affinity_with_unsupported_scope.yaml' + hot_files = [ + '../tests/data/hot_output/etsi_nfv/' + 'hot_nfv_vdu_affinity_with_unsupported_scope.yaml', + ] + self._test_successful_translation(tosca_file, hot_files, params={}) + + def test_hot_translate_etsi_nfv_vdu_with_unsupported_targets(self): + tosca_file = '../tests/data/etsi_nfv/' \ + 'tosca_nfv_vdu_affinity_with_unsupported_targets.yaml' + hot_files = [ + '../tests/data/hot_output/etsi_nfv/' + 'hot_nfv_vdu_affinity_with_unsupported_targets.yaml', + ] + self._test_successful_translation(tosca_file, hot_files, params={}) diff --git a/translator/tests/test_translate_node_template.py b/translator/tests/test_translate_node_template.py index cb3f77c4..d1601b4b 100644 --- a/translator/tests/test_translate_node_template.py +++ b/translator/tests/test_translate_node_template.py @@ -39,6 +39,9 @@ class TranslateNodeTemplatesTest(TestCase): 'tosca.nodes.nfv.Vdu.VirtualBlockStorage', 'tosca.nodes.nfv.VduCp', 'tosca.nodes.nfv.VnfVirtualLink', + 'tosca.groups.nfv.PlacementGroup', + 'tosca.policies.nfv.AffinityRule', + 'tosca.policies.nfv.AntiAffinityRule', 'tosca.policies.nfv.InstantiationLevels', 'tosca.policies.nfv.ScalingAspects', 'tosca.policies.nfv.VduInitialDelta',