Handle deriving from custom policy definitions
Added the UT. Correcting indentation. Also ensure that the version list is always sorted so tests pass. Closes-Bug: #1712076 Change-Id: Idc15a9bb333003f3f9b401d3ee45dcd1dfec45ed Signed-off-by: Manas Mal <manaskrmal@yahoo.com> Co-Authored-By: Gregoire Gesmier <gesmier.gregoire@gmail.com> Co-Authored-By: Bob Haddleton <bob.haddleton@nokia.com>
This commit is contained in:
parent
e1219eedc8
commit
009e5f29d6
@ -60,8 +60,12 @@ class PolicyType(StatefulEntityType):
|
|||||||
parent_policy = self.parent_type.type if self.parent_type else None
|
parent_policy = self.parent_type.type if self.parent_type else None
|
||||||
if parent_policy:
|
if parent_policy:
|
||||||
while parent_policy != 'tosca.policies.Root':
|
while parent_policy != 'tosca.policies.Root':
|
||||||
|
if parent_policy in self.TOSCA_DEF:
|
||||||
policies[parent_policy] = self.TOSCA_DEF[parent_policy]
|
policies[parent_policy] = self.TOSCA_DEF[parent_policy]
|
||||||
parent_policy = policies[parent_policy]['derived_from']
|
parent_policy = policies[parent_policy]['derived_from']
|
||||||
|
elif self.custom_def and parent_policy in self.custom_def:
|
||||||
|
policies[parent_policy] = self.custom_def[parent_policy]
|
||||||
|
parent_policy = policies[parent_policy]['derived_from']
|
||||||
return policies
|
return policies
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -57,4 +57,4 @@ class TypeValidation(object):
|
|||||||
ExceptionCollector.appendException(
|
ExceptionCollector.appendException(
|
||||||
InvalidTemplateVersion(
|
InvalidTemplateVersion(
|
||||||
what=version + ' in ' + str(self.import_def),
|
what=version + ' in ' + str(self.import_def),
|
||||||
valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS)))
|
valid_versions='", "'. join(self.VALID_TEMPLATE_VERSIONS)))
|
||||||
|
@ -71,7 +71,7 @@ class ExtTools(object):
|
|||||||
return extensions
|
return extensions
|
||||||
|
|
||||||
def get_versions(self):
|
def get_versions(self):
|
||||||
return self.EXTENSION_INFO.keys()
|
return sorted(self.EXTENSION_INFO.keys())
|
||||||
|
|
||||||
def get_sections(self):
|
def get_sections(self):
|
||||||
sections = {}
|
sections = {}
|
||||||
|
@ -8,3 +8,9 @@ policy_types:
|
|||||||
entry_schema:
|
entry_schema:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
tosca.policies.Adva.Failure:
|
||||||
|
derived_from: tosca.policies.Root
|
||||||
|
|
||||||
|
tosca.policies.Adva.Failure.Restart:
|
||||||
|
derived_from: tosca.policies.Adva.Failure
|
||||||
|
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||||
|
|
||||||
|
description: >
|
||||||
|
Template for deploying servers based on policies.
|
||||||
|
|
||||||
|
imports:
|
||||||
|
- custom_definitions.yaml
|
||||||
|
|
||||||
|
topology_template:
|
||||||
|
node_templates:
|
||||||
|
my_server_1:
|
||||||
|
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
|
||||||
|
|
||||||
|
my_server_2:
|
||||||
|
type: tosca.nodes.Compute
|
||||||
|
capabilities:
|
||||||
|
host:
|
||||||
|
properties:
|
||||||
|
disk_size: 10 GB
|
||||||
|
num_cpus: 2
|
||||||
|
mem_size: 4096 MB
|
||||||
|
os:
|
||||||
|
properties:
|
||||||
|
architecture: x86_64
|
||||||
|
type: Linux
|
||||||
|
distribution: Ubuntu
|
||||||
|
version: 14.04
|
||||||
|
|
||||||
|
|
||||||
|
policies:
|
||||||
|
- My_failure_policy_restart:
|
||||||
|
type: tosca.policies.Adva.Failure.Restart
|
||||||
|
description: respawn the VDU
|
||||||
|
targets: [my_server_1]
|
||||||
|
|
||||||
|
|
@ -540,7 +540,7 @@ class ToscaTemplateTest(TestCase):
|
|||||||
"data/test_multiple_validation_errors.yaml")
|
"data/test_multiple_validation_errors.yaml")
|
||||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
||||||
None)
|
None)
|
||||||
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
valid_versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||||
err1_msg = (_('The template version "tosca_simple_yaml_1" is invalid. '
|
err1_msg = (_('The template version "tosca_simple_yaml_1" is invalid. '
|
||||||
'Valid versions are "%s".') % valid_versions)
|
'Valid versions are "%s".') % valid_versions)
|
||||||
exception.ExceptionCollector.assertExceptionMessage(
|
exception.ExceptionCollector.assertExceptionMessage(
|
||||||
@ -758,6 +758,48 @@ class ToscaTemplateTest(TestCase):
|
|||||||
if props and 'mem_size' in props.keys():
|
if props and 'mem_size' in props.keys():
|
||||||
self.assertEqual(props['mem_size'].value,
|
self.assertEqual(props['mem_size'].value,
|
||||||
'4096 MB')
|
'4096 MB')
|
||||||
|
# Test the following:
|
||||||
|
# check the inheritance between custom policies.
|
||||||
|
# It will first parse the tosca template located at
|
||||||
|
# data/policies/tosca_custom_policy_template.yaml where
|
||||||
|
# two empty customs policies have been created. The child
|
||||||
|
# empty custom policy tosca.policies.Adva.Failure.Restart
|
||||||
|
# is derived from its parent empty custom policy
|
||||||
|
# tosca.policies.Adva.Failure which is also derived
|
||||||
|
# from its parent empty policy tosca.policies.Root.
|
||||||
|
|
||||||
|
def test_policies_for_custom(self):
|
||||||
|
host_prop = {}
|
||||||
|
tosca_tpl = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
"data/policies/tosca_custom_policy_template.yaml")
|
||||||
|
tosca = ToscaTemplate(tosca_tpl)
|
||||||
|
|
||||||
|
for policy in tosca.topology_template.policies:
|
||||||
|
self.assertTrue(
|
||||||
|
policy.is_derived_from("tosca.policies.Root"))
|
||||||
|
if policy.name == 'My_failure_policy_restart':
|
||||||
|
self.assertEqual('tosca.policies.Adva.Failure.Restart',
|
||||||
|
policy.type)
|
||||||
|
targets = policy.targets
|
||||||
|
for target in targets:
|
||||||
|
if ('my_server_1' == target):
|
||||||
|
'''Test property value'''
|
||||||
|
for nodetemplate in tosca.nodetemplates:
|
||||||
|
if nodetemplate.name == target:
|
||||||
|
caps = nodetemplate.get_capabilities()
|
||||||
|
for cap in caps.keys():
|
||||||
|
generic_cap = \
|
||||||
|
nodetemplate.get_capability(cap)
|
||||||
|
if generic_cap:
|
||||||
|
for prop in \
|
||||||
|
generic_cap.\
|
||||||
|
get_properties_objects():
|
||||||
|
host_prop[prop.name] = prop.value
|
||||||
|
if cap == 'host':
|
||||||
|
self.assertEqual(host_prop
|
||||||
|
['mem_size'],
|
||||||
|
'512 MB')
|
||||||
|
|
||||||
def test_node_filter(self):
|
def test_node_filter(self):
|
||||||
tosca_tpl = os.path.join(
|
tosca_tpl = os.path.join(
|
||||||
|
@ -96,13 +96,12 @@ class ToscaTemplateValidationTest(TestCase):
|
|||||||
_('Template custom_types/imported_sample.yaml contains unknown '
|
_('Template custom_types/imported_sample.yaml contains unknown '
|
||||||
'field "tosca1_definitions_version". Refer to the definition'
|
'field "tosca1_definitions_version". Refer to the definition'
|
||||||
' to verify valid values.'))
|
' to verify valid values.'))
|
||||||
|
versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||||
exception.ExceptionCollector.assertExceptionMessage(
|
exception.ExceptionCollector.assertExceptionMessage(
|
||||||
exception.InvalidTemplateVersion,
|
exception.InvalidTemplateVersion,
|
||||||
_('The template version "tosca_simple_yaml_1_10 in '
|
_('The template version "tosca_simple_yaml_1_10 in '
|
||||||
'custom_types/imported_sample.yaml" is invalid. '
|
'custom_types/imported_sample.yaml" is invalid. '
|
||||||
'Valid versions are "tosca_simple_yaml_1_0, '
|
'Valid versions are "%s".') % versions)
|
||||||
'tosca_simple_profile_for_nfv_1_0_0, '
|
|
||||||
'tosca_simple_profile_for_mec_1_0_0".'))
|
|
||||||
exception.ExceptionCollector.assertExceptionMessage(
|
exception.ExceptionCollector.assertExceptionMessage(
|
||||||
exception.UnknownFieldError,
|
exception.UnknownFieldError,
|
||||||
_('Template custom_types/imported_sample.yaml contains unknown '
|
_('Template custom_types/imported_sample.yaml contains unknown '
|
||||||
@ -1436,7 +1435,7 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
|
|||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
"data/test_invalid_template_version.yaml")
|
"data/test_invalid_template_version.yaml")
|
||||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
||||||
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
valid_versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||||
exception.ExceptionCollector.assertExceptionMessage(
|
exception.ExceptionCollector.assertExceptionMessage(
|
||||||
exception.InvalidTemplateVersion,
|
exception.InvalidTemplateVersion,
|
||||||
(_('The template version "tosca_xyz" is invalid. Valid versions '
|
(_('The template version "tosca_xyz" is invalid. Valid versions '
|
||||||
@ -1447,7 +1446,7 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
|
|||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
"data/test_import_invalid_template_version.yaml")
|
"data/test_import_invalid_template_version.yaml")
|
||||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
||||||
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
valid_versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||||
exception.ExceptionCollector.assertExceptionMessage(
|
exception.ExceptionCollector.assertExceptionMessage(
|
||||||
exception.InvalidTemplateVersion,
|
exception.InvalidTemplateVersion,
|
||||||
(_('The template version "tosca_simple_yaml_XXX in '
|
(_('The template version "tosca_simple_yaml_XXX in '
|
||||||
|
@ -267,7 +267,7 @@ class ToscaTemplate(object):
|
|||||||
ExceptionCollector.appendException(
|
ExceptionCollector.appendException(
|
||||||
InvalidTemplateVersion(
|
InvalidTemplateVersion(
|
||||||
what=version,
|
what=version,
|
||||||
valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS)))
|
valid_versions='", "'. join(self.VALID_TEMPLATE_VERSIONS)))
|
||||||
else:
|
else:
|
||||||
if version != 'tosca_simple_yaml_1_0':
|
if version != 'tosca_simple_yaml_1_0':
|
||||||
update_definitions(version)
|
update_definitions(version)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user