Trivial: Fix unnecessary redundant code

While translating node_template, heat-translator first checks whether
the policy is derived from the policies 'tosca.policies.Scaling' or
'tosca.policies.Monitoring', If yes, then it adds them into
TOSCA_TO_HOT_TYPE map. In the subsequent code, it again checks for
those policies and if they are not present in TOSCA_TO_HOT_TYPE map
then it raises UnsupportedTypeError exception.

This patch removes this unnecessary redundant code of checking
policies again and ensures that the affected code is getting
covered through test case.

TrivialFix
Change-Id: Ibe435e23e7ac11834e662745d327e6f99280f9f5
This commit is contained in:
dineshbhor 2018-05-20 22:45:35 -07:00 committed by Nguyen Hai
parent 74f6c5bbef
commit b8c2c86333
4 changed files with 50 additions and 3 deletions

View File

@ -276,9 +276,7 @@ class TranslateNodeTemplates(object):
if policy.is_derived_from('tosca.policies.Placement'):
TOSCA_TO_HOT_TYPE[policy_type.type] = \
TOSCA_TO_HOT_TYPE['tosca.policies.Placement']
if not policy.is_derived_from('tosca.policies.Monitoring') and \
not policy.is_derived_from('tosca.policies.Scaling') and \
policy_type.type not in TOSCA_TO_HOT_TYPE:
if policy_type.type not in TOSCA_TO_HOT_TYPE:
raise UnsupportedTypeError(type=_('%s') % policy_type.type)
elif policy_type.type == 'tosca.policies.Scaling.Cluster':
self.hot_template_version = '2016-04-08'

View File

@ -92,6 +92,9 @@ policy_types:
If the policy is not strict, it is allowed to continue even if the
nova-scheduler fails to assign hosts under the policy.
tosca.policies.tacker.ABC:
derived_from: tosca.policies.Root
tosca.policies.tacker.Failure:
derived_from: tosca.policies.Root
action:

View File

@ -0,0 +1,32 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: >
Template for deploying the nodes based on given policies.
imports:
- tacker_defs.yaml
- tacker_nfv_defs.yaml
topology_template:
node_templates:
my_server:
type: tosca.nodes.Compute
capabilities:
# Host container properties
host:
properties:
num_cpus: 2
disk_size: 10 GB
mem_size: 512 MB
# Guest Operating System properties
os:
properties:
# host Operating System image properties
architecture: x86_64
type: Linux
distribution: RHEL
version: 6.5
policies:
- my_compute_abc_policy:
type: tosca.policies.tacker.ABC
description: Apply my ABC policy to my application's servers
targets: [ my_server ]

View File

@ -563,6 +563,20 @@ class ToscaHotTranslationTest(TestCase):
.translate)
self.assertEqual(expected_msg, err.__str__())
def test_translate_unsupported_tosca_policy_type(self):
tosca_file = ('../tests/data/nfv/'
'test_tosca_unsupported_policy_type.yaml')
tosca_tpl = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), tosca_file))
params = {}
expected_msg = _('Type "tosca.policies.tacker.ABC" is valid TOSCA '
'type but translation support is not yet available.')
tosca = ToscaTemplate(tosca_tpl, params, True)
err = self.assertRaises(UnsupportedTypeError,
TOSCATranslator(tosca, params)
.translate)
self.assertEqual(expected_msg, err.__str__())
def test_hot_translate_cluster_scaling_policy(self):
tosca_file = '../tests/data/autoscaling/tosca_cluster_autoscaling.yaml'
hot_file = '../tests/data/hot_output/autoscaling/' \