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
This commit is contained in:
tyagi 2015-05-12 01:27:17 -07:00
parent 7d9b5a265f
commit c38bee4977
14 changed files with 64 additions and 29 deletions

View File

@ -47,9 +47,9 @@ class Schema(constr.Schema):
) )
TYPES = ( TYPES = (
STRING, MAP, LIST, STRING, MAP, LIST, INTEGER
) = ( ) = (
'String', 'Map', 'List', 'String', 'Map', 'List', 'Integer'
) )
def __init__(self, description=None, 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"), LOG.warn(_("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name, {'name': attrib.name,
'att_type': attrib.schema.MAP}) '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): def __getitem__(self, key):
if key not in self: if key not in self:

View File

@ -116,16 +116,19 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup):
_("A map of resource names to the specified attribute of each " _("A map of resource names to the specified attribute of each "
"individual resource. " "individual resource. "
"Requires heat_template_version: 2014-10-16 or higher."), "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( OUTPUTS_LIST: attributes.Schema(
_("A list of the specified attribute of each individual resource. " _("A list of the specified attribute of each individual resource. "
"Requires heat_template_version: 2014-10-16 or higher."), "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( CURRENT_SIZE: attributes.Schema(
_("The current size of AutoscalingResourceGroup."), _("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 = {} update_policy_schema = {}

View File

@ -63,7 +63,8 @@ class Restarter(signal_responder.SignalResponder):
attributes_schema = { attributes_schema = {
ALARM_URL: 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
), ),
} }

View File

@ -103,7 +103,8 @@ class InstanceGroup(stack_resource.StackResource):
attributes_schema = { attributes_schema = {
INSTANCE_LIST: attributes.Schema( INSTANCE_LIST: attributes.Schema(
_("A comma-delimited list of server ip addresses. " _("A comma-delimited list of server ip addresses. "
"(Heat extension).") "(Heat extension)."),
type=attributes.Schema.STRING
), ),
} }
rolling_update_schema = { rolling_update_schema = {

View File

@ -154,7 +154,8 @@ class RandomString(resource.Resource):
VALUE: attributes.Schema( VALUE: attributes.Schema(
_('The random string generated by this resource. This value is ' _('The random string generated by this resource. This value is '
'also available by referencing the resource.'), 'also available by referencing the resource.'),
cache_mode=attributes.Schema.CACHE_NONE cache_mode=attributes.Schema.CACHE_NONE,
type=attributes.Schema.STRING
), ),
} }

View File

@ -88,10 +88,12 @@ class RemoteStack(resource.Resource):
attributes_schema = { attributes_schema = {
NAME_ATTR: attributes.Schema( NAME_ATTR: attributes.Schema(
_('Name of the stack.') _('Name of the stack.'),
type=attributes.Schema.STRING
), ),
OUTPUTS: attributes.Schema( 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
), ),
} }

View File

@ -172,13 +172,15 @@ class ResourceGroup(stack_resource.StackResource):
attributes_schema = { attributes_schema = {
REFS: 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( ATTR_ATTRIBUTES: attributes.Schema(
_("A map of resource names to the specified attribute of each " _("A map of resource names to the specified attribute of each "
"individual resource. " "individual resource. "
"Requires heat_template_version: 2014-10-16."), "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
), ),
} }

View File

@ -100,7 +100,8 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
attributes_schema = { attributes_schema = {
ALARM_URL: 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( SIGNAL_URL: attributes.Schema(
_("A url to handle the alarm using native API."), _("A url to handle the alarm using native API."),

View File

@ -150,7 +150,8 @@ class SoftwareConfig(resource.Resource):
attributes_schema = { attributes_schema = {
CONFIG_ATTR: attributes.Schema( CONFIG_ATTR: attributes.Schema(
_("The config value of the software config.") _("The config value of the software config."),
type=attributes.Schema.STRING
), ),
} }

View File

@ -166,13 +166,16 @@ class SoftwareDeployment(signal_responder.SignalResponder):
attributes_schema = { attributes_schema = {
STDOUT: attributes.Schema( STDOUT: attributes.Schema(
_("Captured stdout from the configuration execution.") _("Captured stdout from the configuration execution."),
type=attributes.Schema.STRING
), ),
STDERR: attributes.Schema( STDERR: attributes.Schema(
_("Captured stderr from the configuration execution.") _("Captured stderr from the configuration execution."),
type=attributes.Schema.STRING
), ),
STATUS_CODE: attributes.Schema( 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 = { attributes_schema = {
STDOUTS: attributes.Schema( STDOUTS: attributes.Schema(
_("A map of Nova names and captured stdouts from the " _("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( STDERRS: attributes.Schema(
_("A map of Nova names and captured stderrs from the " _("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( STATUS_CODES: attributes.Schema(
_("A map of Nova names and returned status code from the " _("A map of Nova names and returned status code from the "
"configuration execution") "configuration execution"),
type=attributes.Schema.MAP
), ),
} }

View File

@ -71,11 +71,13 @@ class SwiftSignalHandle(resource.Resource):
_('Tokens are not needed for Swift TempURLs. This attribute is ' _('Tokens are not needed for Swift TempURLs. This attribute is '
'being kept for compatibility with the ' 'being kept for compatibility with the '
'OS::Heat::WaitConditionHandle resource'), 'OS::Heat::WaitConditionHandle resource'),
cache_mode=attributes.Schema.CACHE_NONE cache_mode=attributes.Schema.CACHE_NONE,
type=attributes.Schema.STRING
), ),
ENDPOINT: attributes.Schema( ENDPOINT: attributes.Schema(
_('Endpoint/url which can be used for signalling handle'), _('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( CURL_CLI: attributes.Schema(
_('Convenience attribute, provides curl CLI command ' _('Convenience attribute, provides curl CLI command '
@ -84,7 +86,8 @@ class SwiftSignalHandle(resource.Resource):
'--data-binary \'{"status": "SUCCESS"}\' ' '--data-binary \'{"status": "SUCCESS"}\' '
', or signal failure by adding ' ', or signal failure by adding '
'--data-binary \'{"status": "FAILURE"}\''), '--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 = { attributes_schema = {
DATA: 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
) )
} }

View File

@ -74,9 +74,10 @@ class HeatWaitCondition(resource.Resource):
attributes_schema = { attributes_schema = {
DATA: 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.'), 'condition signals sent to the handle.'),
cache_mode=attributes.Schema.CACHE_NONE cache_mode=attributes.Schema.CACHE_NONE,
type=attributes.Schema.STRING
), ),
} }

View File

@ -44,11 +44,13 @@ class HeatWaitConditionHandle(wc_base.BaseWaitConditionHandle):
attributes_schema = { attributes_schema = {
TOKEN: attributes.Schema( TOKEN: attributes.Schema(
_('Token for stack-user which can be used for signalling handle'), _('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: attributes.Schema(
_('Endpoint/url which can be used for signalling handle'), _('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( CURL_CLI: attributes.Schema(
_('Convenience attribute, provides curl CLI command ' _('Convenience attribute, provides curl CLI command '
@ -57,7 +59,8 @@ class HeatWaitConditionHandle(wc_base.BaseWaitConditionHandle):
'--data-binary \'{"status": "SUCCESS"}\' ' '--data-binary \'{"status": "SUCCESS"}\' '
', or signal failure by adding ' ', or signal failure by adding '
'--data-binary \'{"status": "FAILURE"}\''), '--data-binary \'{"status": "FAILURE"}\''),
cache_mode=attributes.Schema.CACHE_NONE cache_mode=attributes.Schema.CACHE_NONE,
type=attributes.Schema.STRING
), ),
} }

View File

@ -195,6 +195,10 @@ class AttributesTypeTest(common.HeatTestCase):
('map_type', ('map_type',
dict(a_type=attributes.Schema.MAP, dict(a_type=attributes.Schema.MAP,
value={}, value={},
invalid_value='invalid_value')),
('integer_type',
dict(a_type=attributes.Schema.INTEGER,
value=1,
invalid_value='invalid_value')) invalid_value='invalid_value'))
] ]