Commit Graph

109 Commits

Author SHA1 Message Date
Stephen Finucane 57e9754093 Switch to collections.abc.*
The abstract base classes previously defined in 'collections' were moved
to 'collections.abc' in 3.3. The aliases will be removed in 3.10.
Preempt this change now with a simple find-replace:

  $ ag -l 'collections.($TYPES)' | \
      xargs sed -i 's/\(collections\)\.\($TYPES\)/\1.abc.\2/g'

Where $TYPES is the list of moved ABCs from [1].

[1] https://docs.python.org/3/library/collections.abc.html

Change-Id: Ia282479bb1d466bd2189ebb21b51d91e89b9581e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-01 11:15:59 +00:00
Zane Bitter b603470a12 Lazily cache parsed value of list/json parameters
Parsing the value of JSON parameters at the time we create them (or
update the default value) results in exceptions occurring while creating
the Stack object, that are then not caught and transformed. The result
is an HTTP 500 Internal Error reported by the API, with an unhelpful
error message.

By not parsing the JSON until it is needed, we ensure that any errors
will occur during validation, where errors are appropriately transformed
(to StackValidationFailed) and annotated with the necessary information
to help the user determine the source.

Depends-On: https://review.opendev.org/#/c/748359/

Change-Id: I70e341c344d6254173ad4519276626230087263a
Story: 2007957
Task: 40443
2020-08-28 03:54:19 +00:00
Hervé Beraud 8c0d58075b Remove six and python 2.7 full support
Six is in use to help us to keep support for python 2.7.
Since the ussuri cycle we decide to remove the python 2.7
support so we can go ahead and also remove six usage from
the python code.

Review process and help
-----------------------
Removing six introduce a lot of changes and an huge amount of modified files
To simplify reviews we decided to split changes into several patches to avoid
painful reviews and avoid mistakes.

To review this patch you can use the six documentation [1] to obtain help and
understand choices.

Additional informations
-----------------------
Changes related to 'six.b(data)' [2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

six.b [2] encode the given datas in latin-1 in python3 so I did the same
things in this patch.

Latin-1 is equal to iso-8859-1 [3].

This encoding is the default encoding [4] of certain descriptive HTTP
headers.

I suggest to keep latin-1 for the moment and to move to another encoding
in a follow-up patch if needed to move to most powerful encoding (utf8).

HTML4 support utf8 charset and utf8 is the default charset for HTML5 [5].

Note that this commit message is autogenerated and not necesserly contains
changes related to 'six.b'

[1] https://six.readthedocs.io/
[2] https://six.readthedocs.io/#six.b
[3] https://docs.python.org/3/library/codecs.html#standard-encodings
[4] https://www.w3schools.com/charsets/ref_html_8859.asp
[5] https://www.w3schools.com/html/html_charset.asp

Patch 6 of a serie of 28 patches

Change-Id: Ic56cf6da5ff9ab8f4bd218e6516b87f47165206d
2020-04-23 14:49:12 +02:00
Zuul 03bcacc536 Merge "Remove broken heat.resource_type custom constraint" 2017-12-05 21:48:17 +00:00
Saravanan KR a1a0609e8e Added tags attribute to the template parameter
In some scenarios, it is required to categorize the parameter.
Associating tags with the parameter, it is will be easy to
categorize the parameter and add simple validations to users.
This patch introduces a new attribute 'tags' with the parameters,
which is a list of strings.

Change-Id: I20fc95d606b0b8a08d3b46bf33f4860bff49c74f
2017-11-13 15:51:19 +05:30
Zane Bitter c26f367b03 Remove broken heat.resource_type custom constraint
This reverts the commits f5c32ad8fd and
14fdf72b000c82a80abb2587189dd7c6c7dfa0a0e.

The constraint never worked and the stuff to pass the template to
constraints (which was broken because we actually passed a
ResourceDefinition instead) is a pain. Just get rid of it rather than
fix it.

Change-Id: I4e1e787ad94ac1951f472ea066a9b1c9d3e03611
Closes-Bug: #1661403
2017-08-01 13:35:16 -04:00
Jenkins eac564aa1b Merge "Pretty print parameters in stack-show" 2017-06-22 14:53:45 +00:00
Jason Dunsmore 4940fc1a2a Pretty print parameters in stack-show
Previously, we were not using the specialized parameter class' __str__
method to print the parameters in the stack-show output with python
2.x.

Closes-Bug: #1613415
Change-Id: I44295ae567cef91eb484201099c7646cdb16fe08
2017-06-22 07:54:54 +00:00
Thomas Herve 98c89e0f4b Catch type errors when casting to int
Casting a parameter to a number can fail with a type error as well as a
value error. Let's catch it to get a proper validation error.

Change-Id: I63779a6227b834cedeeed1c4d5d49271e15e4ea9
Closes-Bug: #1698365
2017-06-16 14:39:56 +02:00
huangtianhua 088156e49b Remove deprecated functions
Change-Id: Ic41eb9782a3bb4bd716f6f06dccc3428c4a94306
2017-05-27 01:43:05 +00:00
Jason Dunsmore aee10997ac Move CFN pseudo functions out of Parameters base class
And create a CfnParameters class, similar to HOTParameters.

Change-Id: I5e71ce9affb8188b696c12e9f008678ce08a913c
2017-01-27 15:24:44 -06:00
Zane Bitter 21990655b6 Use __slots__ in Parameter classes
A typical stack may easily have dozens of parameters, so Parameter objects
are very common in memory. They're also very simple and change rarely, all
of which makes them a good candidate for being made lighter-weight using
slots to avoid creating __dict__.

Change-Id: I23e07876054cbaf220df1c9fc2d663b00130501b
Related-Bug: #1626675
2016-10-06 09:41:35 -04:00
Zane Bitter bca740a997 Avoid double init of classes with __new__
When __new__ returns an instance of the class (or a subclass), Python will
call __init__ on it afterwards. So if we return an initialised object of a
subclass, we end up calling both __new__ and __init__ twice. Avoid this by
calling object.__new__ and passing the desired subclass instead in
ResourceInfo and Parameter. Equivalent changes for Resource and Template
have been in place for some time.

Change-Id: I4c3f0bc9c1a39b9f0b964ccf1c6c638f86b3753e
2016-10-05 13:57:56 -04:00
rabi 80bc4fbebd Convert props form delimited params to lists
Use allow_conversion flag to convert comma_delimited_list
to list before validation when using from_parameter.

Change-Id: Id144aade23eee13df227acdb728906c8dd345337
Closes-Bug: #1617019
2016-08-26 17:43:33 +05:30
Jay Dobies 4fdf72b000 Make template available to parameter constraint checking
The validate method for a constraint only accepts the value being
verified. This is sufficient for most data checks (range, regex) and the
calls to one of the service clients. But it is limiting in the sense
that it prevents us from ever having constraints that span multiple
parameters (such as ensuring that two values are compatible).

What caused this is the atttempt to add a constraint to ensure a
parameter's value is a valid Heat resource type. To verify this, the
constraint code needs access to the resolved environment. I opted to
pass the entire template down instead to make things more flexible.

The call to the BaseCustomConstraint (which appears to be the entry
point for most plugins) will attempt to use the new signature with the
template, but will fall back to the original call for backward
compatibility.

Change-Id: I5dc94c964b35578e84da641278a4175a37038498
2016-06-20 14:30:25 -04:00
Zane Bitter 5566e6f2c8 Get rid of gratuitous use of six.iterkeys()
In Python3, dict.keys() returns a view object rather than a list. This
behaves differently in that changes to the dict also modify the view, and
in that the view type interacts with various operators in different ways to
lists.

One universally correct transformation to preserve Python2 behaviour in
Python3 would be to replace all instances of d.keys() with
list(six.iterkeys(d)), and indeed we did. However, like many automatic
transformations the results are usually unsightly, invariably inefficient,
and frequently absurd. Not least because list(d.keys()) and indeed list(d)
are also equivalent.

This patch changes to using the simplest correct method of accessing the
data we want in each case.

This reverts or rewrites most of commit
4ace95ad47.

Change-Id: Iba3cf48246d8cbc958d8fb577cd700a218b0bebf
2016-06-07 03:50:49 +00:00
Zane Bitter bfa7f8554b Get rid of Parameters._validate_template_parameters()
Apart from the fact that this method relied on knowledge of the template
format, it also checked nothing useful since we now won't even be able to
create the Parameters object unless all of the parameter definitions are in
fact dicts.

Change-Id: I950420b9016d350a427754d6a482b6ddf456bd6f
2016-06-03 15:42:43 -04:00
hmonika ea6ae8bfe1 string parameter type mismatch
Added the new method to convert
numeric value to string.

Change-Id: Ib0b4273d1a77ee599bf21fe8a1059869ade98aef
Closes-Bug: #1567373
2016-05-24 12:44:01 +00:00
Jason Dunsmore 98262c10d8 Immutable parameters
Add a new "immutable" boolean field to the parameters section in a HOT
template.  A value of True will result in the engine rejecting
stack-updates that include changes to that parameter.  When not
specified in the template, "immutable" defaults to False to ensure
backwards compatibility with old templates.

blueprint: immutable-parameters
Change-Id: If17df0b97e96ff2a1926451634e4744d6c3e26f1
2016-02-22 13:40:16 -06:00
Zane Bitter 388ee0257f Fix garbled docstrings
The process of bringing us into compliance with the H405 pep8 rule has left
us with a lot of docstrings that either don't follow the recommendations of
PEP0257, are misleading, wrong, or nonsensical. This patch attempts to fix
them up.

Change-Id: Icfe90b5ba3102a7e13ab659038a8b2af9019e9e6
2015-11-10 11:12:36 -05:00
James Slagle c643810f04 Raise StackValidationFailed on parameter validation
This changes the _validate methods for the JsonParam and
CommaDelimitedListParam to raise StackValidationFailed execeptions if
the parameters values fail to parse. A failure to parse will be
indicated with a ValueError exception, so that exception is caught and
StackValidationFailed is raised instead.

This brings these parameters in line with the behavior in the other
parameter type classes.

It also makes the validation failures much more helpful to users with
stacks with lots of parameters (TripleO), as the name of the parameter
that failed validation will now be logged as part of the exception.

Change-Id: Ife08272f0e95491c030e5d70499fe31d462c515c
2015-10-31 08:01:52 +00:00
Jiri Stransky 3827c61b25 Fix parameter_defaults for comma_delimited_list and json
When environment of a stack contained a parameter_defaults section with
a value for a parameter of type comma_delimited_list or json, that default
didn't get applied unless in a nested stack.

The issue was that CommaDelimitedListParam contains a variable to cache
its value, and that cache was only created upon creation of a
CommaDelimitedListParam object, but it wasn't updated on `set_default`
method call. The cache now updates on `set_default` too.

Co-Authored-By: Steven Hardy <shardy@redhat.com>
Change-Id: I85b13a79dbc97a77e20c0d5df8eaf05b3000815e
Closes-Bug: #1504137
2015-10-14 10:52:20 +02:00
Peter Razumovsky 2da170c435 Fix [H405] pep rule in heat/engine
Fix [H405] rule in heat/engine python
files.

Implements bp docstring-improvements

Change-Id: Iaa1541eb03c4db837ef3a0e4eb22393ba32e270f
2015-09-21 14:51:46 +03:00
Sirushti Murugesan 4dba62a7bb py34: heat.tests.test_parameters
* convert to unicode instead of converting to bytes
  when flattening lists to strings.
* test: convert to bytes before asserting to maintain
  py2 compatibility.

partial blueprint heat-python34-support

Change-Id: I7a9f40e90d829e0764d229526698a78479feeb2f
2015-08-27 13:48:35 +05:30
Jenkins 6d27c05f95 Merge "Adopt @six.python_2_unicode_compatible decorator" 2015-07-09 16:13:49 +00:00
Sirushti Murugesan 2c99f0090c Adopt @six.python_2_unicode_compatible decorator
On Python 3, the decorator does nothing. On Python 2, it aliases the
__str__ method to __unicode__ and creates a new __str__ method that
returns the result of __unicode__() encoded with UTF-8.

All instances of __unicode__ have been removed with the
aforementioned decorator in place instead.

Note: There are some instances of __str__ which aren't handled but
will be once we have actual python34 tests running in the gate.

partial blueprint heat-python34-support

Change-Id: I7271a2581e1c2bbc282933c7da73db810c7e09db
2015-07-09 12:44:03 +05:30
Jenkins ac35100975 Merge "Fix TypeError on joining list parameters" 2015-07-08 01:27:19 +00:00
Hongbin Lu 39c3bec7df Fix TypeError on joining list parameters
When parsing parameter of list type, convert each member to string.

Change-Id: I000a664ee6b606fd2592fddd1c3a28bef79b0939
Closes-Bug: 1467139
2015-07-01 18:01:49 -04:00
ubuntu b4b7f32ff6 Coverage: Removed unreachable code from heat engine
While looking for coverage metrics found unreachable code
Fixing the same in this commit

Change-Id: I1265057af4a91accff92f378e9e1f353d77813c6
2015-06-22 07:17:11 +05:30
Tetiana Lashchova 4ace95ad47 Use six.iterkeys(x) instead of x.keys()
Implements: partial blueprint heat-python34-support
Change-Id: I6f1c3091ca65dbef0f36bd6ba7f7fcbf77ff2e40
2015-04-23 17:18:40 +03:00
Tetiana Lashchova 4c6810ce1a Use six.itervalues(x) instead of x.values()
Change-Id: Ie71072940b7b5e599d9012be0bc1874b2a623003
Partial-Bug: #1446254
2015-04-21 09:05:49 +03:00
Angus Salkeld ac536c6114 Convert all non-test imports of json to jsonutils
As requested in:
https://review.openstack.org/#/c/116336/24/heat/engine/stack_resource.py

Change-Id: Icea97aa44d2a3461fdfa2324292fd3b2c2f000e1
2015-03-04 15:26:48 +10:00
Angus Salkeld 04e68f87ca Add ability to pass 0, "", {} or [] as a parameter
Normal issues with using values as booleans.

Closes-Bug: #1423946
Closes-Bug: #1425238
Co-Authored-by: Sergey Kraynev <skraynev@mirantis.com>
Co-Authored-by: Angus Salkeld <asalkeld@mirantis.com>
Change-Id: I9c6cd01ca722a65d3de6f28732ae07caefaa6cd8
2015-02-25 14:45:40 -05:00
Angus Salkeld f604953985 Only parse complex types if there is a value
This tries to bring it inline with the other value() methods.

Change-Id: Ib749c44127862b054a01ee74b3e1a716f7b637e8
Closes-bug: 1424600
2015-02-24 14:11:01 +10:00
Jens Rosenboom a99fe6a760 Make import of oslo libraries namespaceless
See https://blueprints.launchpad.net/oslo-incubator/+spec/drop-namespace-packages

Closes-Bug: 1423174
Change-Id: I48680ce6e7ce91005c147ab4388203946171d433
2015-02-18 22:54:10 +01:00
Jenkins f5565c0ba8 Merge "Don't validate custom constraints on default values" 2015-01-27 03:12:21 +00:00
Pavlo Shchelokovskyy cb8712281d Enable H904 style checking rule
Use parentheses instead of backslash for line continuation.

Plus, usage of escaped quotes in long strings is avoided where it makes
sense.

Change-Id: If2e78012b85a4430c6f03f65784cac2d032cf116
2015-01-20 11:14:06 +02:00
Pavlo Shchelokovskyy f1b5a782b7 Enable H402 style check
Full stop at the end of single-line docstring.

Change-Id: I9f24dbe0666069800979758d3628ed4f7fc4979b
2015-01-13 11:36:45 +02:00
Peter Razumovsky 7d09bc1c12 Don't validate custom constraints on default values
When user provides it's own parameter's value, there is no
reason to check custom constraint on default value of this
parameter. And if there is no user value, default value
validates anyway. So custom_constraint validation of default
values is unnecessary.

Change-Id: Ied3feefc7d062ddb20d42cfc5b2c30be4fdc3227
Closes-bug: #1394100
2015-01-12 13:28:12 +00:00
Pavlo Shchelokovskyy 2e9fcbba64 Enable E251 style check
unexpected space around 'equals' operator

Change-Id: I8566d918a2abb8cac358832fb5af551fad9b058f
2015-01-12 13:48:44 +02:00
Angus Salkeld 08431c7c06 Add "parameter_defaults" to the environment
This give the user a way to set defaults recursively down nested stacks
without having to create the parameter in every template (it's ignored
if the template does not have the parameter).

blueprint env-nested-usability
Change-Id: Ie6b4481417204a527d322fd532c341b9acbce473
2014-12-15 09:44:11 +10:00
Jenkins a71d51fe9a Merge "Use environment file in template-validate" 2014-11-21 07:25:59 +00:00
Peter Razumovsky 1343598890 Add Dimensions Default in AWS_CloudWatch_Alarm.yaml
Relying on [1], property Dimensions isn't required, but
this template has no Default value for Dimensions
(thereby making it required). This patch fix that omission.
Besides that, parameters have wrong parsing, because if
parameter with type 'CommaDelimitedList' has default
value '', parameter's parsing result would be [u''] instead
of []. this is wrong, so this patch fix it.

[1] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html

Change-Id: I259249659c8b5dc846432f8e08985b148b30d682
Closes-bug: #1386824
2014-11-20 17:05:17 +03:00
Doug Fish 09bc7ad79e Use environment file in template-validate
Use the -e parameter in template-validate to override any
Default values specified in the template.  This has the desirable
effect of making Horizon use parameters updated from the environment
file.

Change-Id: I84405d1d2f5245ab7cb8b909c2ea1407d5b2973e
Closes-Bug: #1388985
2014-11-13 11:35:53 -06:00
Ethan Lynn a53c73fc4a Using six.string_types for python3 compatible
For python3 compatible, using six.string_types instead of
basestring(). six.string_types represent basestring in
python2 and str in python3.

Change-Id: Ib4ba3d164f782601944023b99d6cc1ee2763ee85
2014-11-03 15:03:56 +08:00
Ethan Lynn 11c1b62052 Remove deprecated function i18n.install('heat')
Since i18n.install() is deprecated, remove it from heat codes and
import i18n._() to where it needed.

blueprint oslo-i18n
Change-Id: Icefada18b5a33112b425cd90d31d3a6a5f06188a
2014-10-13 10:31:28 +08:00
Julien Danjou 6519cf36fd Switch to oslo.utils
Change-Id: I74979d8f75b099858314a30c98bb252c379e0304
2014-09-30 14:27:59 +02:00
Jenkins 38aa12a015 Merge "Make str(json_param) return string vs python" 2014-09-13 03:35:14 +00:00
Endre Karlson 3913658527 Make str(json_param) return string vs python
Closes-Bug: #1366798

Change-Id: I3f435932787662cb1bfa91bd5a84c21cf6ddf9d0
2014-09-11 14:35:36 +00:00
Endre Karlson a22e0276bc Fix so that CSV as str return value
Closes-Bug: #1367393

Change-Id: I0e40b51482d62b94baab1187ddcc38e4aa2d854d
2014-09-09 18:28:29 +00:00