From c38bee49778259c808b68ca4d0782b80274dddcf Mon Sep 17 00:00:00 2001 From: tyagi Date: Tue, 12 May 2015 01:27:17 -0700 Subject: [PATCH] Add attribute type for heat resources Add type field to the schema of the heat resources. Also added Integer type to attributes schema. Change-Id: Icd09f28a29a52be1904f76887a37c7f17786c4a6 Implements: blueprint add-type-in-attributes-schema --- heat/engine/attributes.py | 9 +++++++-- .../openstack/heat/autoscaling_group.py | 9 ++++++--- .../resources/openstack/heat/ha_restarter.py | 3 ++- .../resources/openstack/heat/instance_group.py | 3 ++- .../resources/openstack/heat/random_string.py | 3 ++- .../resources/openstack/heat/remote_stack.py | 6 ++++-- .../resources/openstack/heat/resource_group.py | 6 ++++-- .../resources/openstack/heat/scaling_policy.py | 3 ++- .../openstack/heat/software_config.py | 3 ++- .../openstack/heat/software_deployment.py | 18 ++++++++++++------ .../resources/openstack/heat/swiftsignal.py | 12 ++++++++---- .../resources/openstack/heat/wait_condition.py | 5 +++-- .../openstack/heat/wait_condition_handle.py | 9 ++++++--- heat/tests/test_attributes.py | 4 ++++ 14 files changed, 64 insertions(+), 29 deletions(-) diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 956f61d197..fa3b51c69e 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.py @@ -47,9 +47,9 @@ class Schema(constr.Schema): ) TYPES = ( - STRING, MAP, LIST, + STRING, MAP, LIST, INTEGER ) = ( - 'String', 'Map', 'List', + 'String', 'Map', 'List', 'Integer' ) def __init__(self, description=None, @@ -185,6 +185,11 @@ class Attributes(collections.Mapping): LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), {'name': attrib.name, 'att_type': attrib.schema.MAP}) + elif attrib.schema.type == attrib.schema.INTEGER: + if not isinstance(value, int): + LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"), + {'name': attrib.name, + 'att_type': attrib.schema.INTEGER}) def __getitem__(self, key): if key not in self: diff --git a/heat/engine/resources/openstack/heat/autoscaling_group.py b/heat/engine/resources/openstack/heat/autoscaling_group.py index f5d872a2d1..bf16dc30a3 100644 --- a/heat/engine/resources/openstack/heat/autoscaling_group.py +++ b/heat/engine/resources/openstack/heat/autoscaling_group.py @@ -116,16 +116,19 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup): _("A map of resource names to the specified attribute of each " "individual resource. " "Requires heat_template_version: 2014-10-16 or higher."), - support_status=support.SupportStatus(version='2014.2') + support_status=support.SupportStatus(version='2014.2'), + type=attributes.Schema.MAP ), OUTPUTS_LIST: attributes.Schema( _("A list of the specified attribute of each individual resource. " "Requires heat_template_version: 2014-10-16 or higher."), - support_status=support.SupportStatus(version='2014.2') + support_status=support.SupportStatus(version='2014.2'), + type=attributes.Schema.LIST ), CURRENT_SIZE: attributes.Schema( _("The current size of AutoscalingResourceGroup."), - support_status=support.SupportStatus(version='2015.1') + support_status=support.SupportStatus(version='2015.1'), + type=attributes.Schema.INTEGER ), } update_policy_schema = {} diff --git a/heat/engine/resources/openstack/heat/ha_restarter.py b/heat/engine/resources/openstack/heat/ha_restarter.py index 32408d4e05..74db80af73 100644 --- a/heat/engine/resources/openstack/heat/ha_restarter.py +++ b/heat/engine/resources/openstack/heat/ha_restarter.py @@ -63,7 +63,8 @@ class Restarter(signal_responder.SignalResponder): attributes_schema = { ALARM_URL: attributes.Schema( - _("A signed url to handle the alarm (Heat extension).") + _("A signed url to handle the alarm (Heat extension)."), + type=attributes.Schema.STRING ), } diff --git a/heat/engine/resources/openstack/heat/instance_group.py b/heat/engine/resources/openstack/heat/instance_group.py index 9574fdc9ca..7f7bc366b3 100644 --- a/heat/engine/resources/openstack/heat/instance_group.py +++ b/heat/engine/resources/openstack/heat/instance_group.py @@ -103,7 +103,8 @@ class InstanceGroup(stack_resource.StackResource): attributes_schema = { INSTANCE_LIST: attributes.Schema( _("A comma-delimited list of server ip addresses. " - "(Heat extension).") + "(Heat extension)."), + type=attributes.Schema.STRING ), } rolling_update_schema = { diff --git a/heat/engine/resources/openstack/heat/random_string.py b/heat/engine/resources/openstack/heat/random_string.py index d2b1fea270..f5e6d8ac0e 100644 --- a/heat/engine/resources/openstack/heat/random_string.py +++ b/heat/engine/resources/openstack/heat/random_string.py @@ -154,7 +154,8 @@ class RandomString(resource.Resource): VALUE: attributes.Schema( _('The random string generated by this resource. This value is ' 'also available by referencing the resource.'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), } diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 6f7fd3579d..27d6ba3e0d 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -88,10 +88,12 @@ class RemoteStack(resource.Resource): attributes_schema = { NAME_ATTR: attributes.Schema( - _('Name of the stack.') + _('Name of the stack.'), + type=attributes.Schema.STRING ), OUTPUTS: attributes.Schema( - _('A dict of key-value pairs output from the stack.') + _('A dict of key-value pairs output from the stack.'), + type=attributes.Schema.MAP ), } diff --git a/heat/engine/resources/openstack/heat/resource_group.py b/heat/engine/resources/openstack/heat/resource_group.py index adad46bd7b..9d21d72d5e 100644 --- a/heat/engine/resources/openstack/heat/resource_group.py +++ b/heat/engine/resources/openstack/heat/resource_group.py @@ -172,13 +172,15 @@ class ResourceGroup(stack_resource.StackResource): attributes_schema = { REFS: attributes.Schema( - _("A list of resource IDs for the resources in the group") + _("A list of resource IDs for the resources in the group"), + type=attributes.Schema.LIST ), ATTR_ATTRIBUTES: attributes.Schema( _("A map of resource names to the specified attribute of each " "individual resource. " "Requires heat_template_version: 2014-10-16."), - support_status=support.SupportStatus(version='2014.2') + support_status=support.SupportStatus(version='2014.2'), + type=attributes.Schema.MAP ), } diff --git a/heat/engine/resources/openstack/heat/scaling_policy.py b/heat/engine/resources/openstack/heat/scaling_policy.py index c05f3ed66c..4d40b838c7 100644 --- a/heat/engine/resources/openstack/heat/scaling_policy.py +++ b/heat/engine/resources/openstack/heat/scaling_policy.py @@ -100,7 +100,8 @@ class AutoScalingPolicy(signal_responder.SignalResponder, attributes_schema = { ALARM_URL: attributes.Schema( - _("A signed url to handle the alarm.") + _("A signed url to handle the alarm."), + type=attributes.Schema.STRING ), SIGNAL_URL: attributes.Schema( _("A url to handle the alarm using native API."), diff --git a/heat/engine/resources/openstack/heat/software_config.py b/heat/engine/resources/openstack/heat/software_config.py index 36110c7ffd..b75fcda0f5 100644 --- a/heat/engine/resources/openstack/heat/software_config.py +++ b/heat/engine/resources/openstack/heat/software_config.py @@ -150,7 +150,8 @@ class SoftwareConfig(resource.Resource): attributes_schema = { CONFIG_ATTR: attributes.Schema( - _("The config value of the software config.") + _("The config value of the software config."), + type=attributes.Schema.STRING ), } diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 321a931127..ae188173ec 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -166,13 +166,16 @@ class SoftwareDeployment(signal_responder.SignalResponder): attributes_schema = { STDOUT: attributes.Schema( - _("Captured stdout from the configuration execution.") + _("Captured stdout from the configuration execution."), + type=attributes.Schema.STRING ), STDERR: attributes.Schema( - _("Captured stderr from the configuration execution.") + _("Captured stderr from the configuration execution."), + type=attributes.Schema.STRING ), STATUS_CODE: attributes.Schema( - _("Returned status code from the configuration execution") + _("Returned status code from the configuration execution"), + type=attributes.Schema.STRING ), } @@ -621,15 +624,18 @@ class SoftwareDeploymentGroup(resource_group.ResourceGroup): attributes_schema = { STDOUTS: attributes.Schema( _("A map of Nova names and captured stdouts from the " - "configuration execution to each server.") + "configuration execution to each server."), + type=attributes.Schema.MAP ), STDERRS: attributes.Schema( _("A map of Nova names and captured stderrs from the " - "configuration execution to each server.") + "configuration execution to each server."), + type=attributes.Schema.MAP ), STATUS_CODES: attributes.Schema( _("A map of Nova names and returned status code from the " - "configuration execution") + "configuration execution"), + type=attributes.Schema.MAP ), } diff --git a/heat/engine/resources/openstack/heat/swiftsignal.py b/heat/engine/resources/openstack/heat/swiftsignal.py index f6eaaaa877..41ee362065 100644 --- a/heat/engine/resources/openstack/heat/swiftsignal.py +++ b/heat/engine/resources/openstack/heat/swiftsignal.py @@ -71,11 +71,13 @@ class SwiftSignalHandle(resource.Resource): _('Tokens are not needed for Swift TempURLs. This attribute is ' 'being kept for compatibility with the ' 'OS::Heat::WaitConditionHandle resource'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), ENDPOINT: attributes.Schema( _('Endpoint/url which can be used for signalling handle'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), CURL_CLI: attributes.Schema( _('Convenience attribute, provides curl CLI command ' @@ -84,7 +86,8 @@ class SwiftSignalHandle(resource.Resource): '--data-binary \'{"status": "SUCCESS"}\' ' ', or signal failure by adding ' '--data-binary \'{"status": "FAILURE"}\''), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), } @@ -177,7 +180,8 @@ class SwiftSignal(resource.Resource): attributes_schema = { DATA: attributes.Schema( - _('JSON data that was uploaded via the SwiftSignalHandle.') + _('JSON data that was uploaded via the SwiftSignalHandle.'), + type=attributes.Schema.STRING ) } diff --git a/heat/engine/resources/openstack/heat/wait_condition.py b/heat/engine/resources/openstack/heat/wait_condition.py index fad28a33a0..21f5a316d6 100644 --- a/heat/engine/resources/openstack/heat/wait_condition.py +++ b/heat/engine/resources/openstack/heat/wait_condition.py @@ -74,9 +74,10 @@ class HeatWaitCondition(resource.Resource): attributes_schema = { DATA: attributes.Schema( - _('JSON serialized dict containing data associated with wait ' + _('JSON string containing data associated with wait ' 'condition signals sent to the handle.'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), } diff --git a/heat/engine/resources/openstack/heat/wait_condition_handle.py b/heat/engine/resources/openstack/heat/wait_condition_handle.py index 6081c17695..b83b6c5c07 100644 --- a/heat/engine/resources/openstack/heat/wait_condition_handle.py +++ b/heat/engine/resources/openstack/heat/wait_condition_handle.py @@ -44,11 +44,13 @@ class HeatWaitConditionHandle(wc_base.BaseWaitConditionHandle): attributes_schema = { TOKEN: attributes.Schema( _('Token for stack-user which can be used for signalling handle'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), ENDPOINT: attributes.Schema( _('Endpoint/url which can be used for signalling handle'), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), CURL_CLI: attributes.Schema( _('Convenience attribute, provides curl CLI command ' @@ -57,7 +59,8 @@ class HeatWaitConditionHandle(wc_base.BaseWaitConditionHandle): '--data-binary \'{"status": "SUCCESS"}\' ' ', or signal failure by adding ' '--data-binary \'{"status": "FAILURE"}\''), - cache_mode=attributes.Schema.CACHE_NONE + cache_mode=attributes.Schema.CACHE_NONE, + type=attributes.Schema.STRING ), } diff --git a/heat/tests/test_attributes.py b/heat/tests/test_attributes.py index 14a6aaae2d..d57d8094f7 100644 --- a/heat/tests/test_attributes.py +++ b/heat/tests/test_attributes.py @@ -195,6 +195,10 @@ class AttributesTypeTest(common.HeatTestCase): ('map_type', dict(a_type=attributes.Schema.MAP, value={}, + invalid_value='invalid_value')), + ('integer_type', + dict(a_type=attributes.Schema.INTEGER, + value=1, invalid_value='invalid_value')) ]