Commit Graph

18 Commits

Author SHA1 Message Date
Zane Bitter 4deef7e728 Allow null values to be returned from Macros
This change allows a Macro returns a 'null' value (as opposed to None)
that makes it effectively cease to exist when that makes sense. If it
appears as a list item, that list item is dropped. If it appears as a
value in a dict, the corresponding key is removed from the dict. If it
appears as a property value, the property is treated as if the user had
not mentioned it in the template.

In all other circumstances (as an argument to a Function, as the top
level of some other field, like an output value), the result will still
appear as None.

A null value is represented internally by the Ellipsis singleton (to
distinguish it from None, which is a value that may appear in the
template from a user or be returned from a Function).

Change-Id: Iaed0982e0db902f6eaf8f986c12b4885bd77e8b9
Story: 2007388
Task: 38976
2020-05-04 14:09:27 -04:00
Hervé Beraud 062ce29a3b 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 27 of a serie of 28 patches

Change-Id: I85b44a770b0e98885fb10c2874d9c153cc76959a
2020-04-23 14:49:12 +02:00
Zane Bitter b0916ad5bb Cache names of required resources in ResourceDefinition
In order to calculate the dependencies of a ResourceDefinition, we have to
pass it a Stack object. This means we can't infer anything about the
resource's dependencies without instantiating the whole stack, and it means
we can't easily cache the result so we have to walk the entire
properties/metadata every time we need the dependencies.

This change splits a required_resource_names() method (the same as added to
OutputDefinition in the previous patch) out of the dependencies() method.
This new method calculates as much as we can know from the resource
definition alone and caches the result, while the dependencies() method
uses the (cached) result to calculate the graph dependencies for a given
Stack.

This also opens the way in future to changing the Function API to return
dependencies by name instead of as ResourceProxy objects.

Change-Id: Icdd0b2dd41116adae5e57ff3ef0e662ba75e6e2c
2017-07-21 10:44:51 -04:00
Thomas Herve e1aeabaa03 Ignore dependency errors with conditions
If a resource is conditionally defined, depending on it raises an error
in the case it's not defined. This patch fixes that by checking if the
resource is present in the template regardless of the conditions.

Change-Id: Iefae1fcea720bee4ed69ad1a5fe403d52d54433c
Closes-Bug: #1649900
2017-01-12 21:52:15 +01:00
Zane Bitter 2c6fc7bcd6 Remove support for accessing ResourceDefinition like a dict
Heat no longer accesses resource definitions as if they were snippets of a
CloudFormation template, but rather uses the APIs of the ResourceDefinition
class. The ability to treat this class as a snippet of CloudFormation
template has been deprecated for several release cycles to allow
third-party plugins to move away from it; this change removes that ability.

Change-Id: Ia9c63662438d4c979b897118b3a7a736161bcbca
2016-10-14 19:35:39 -04:00
Zane Bitter 58c0bbf0e1 Get rid of cfn-compatibility in ResourceDefinition.Diff
Force use of the API only.

Change-Id: I93e2aa1eff6cfc545227457973f5240a4538ba7e
2016-10-14 16:03:00 -04:00
ricolin c385388ea1 Add support for a resource level external_id
This adds support for the following to the template:
 heat_template_version: 2016-10-14
 resources:
   ...
   res_a:
     type: OS::Nova::Server
     external_id: the-new-server-id
     properties:
     ...

Co-Authored-By: Rico Lin <rico.l@inwinstack.com>

blueprint external-resources
Change-Id: I8fda1380504d1d8b1e96649bf20b86d6309fdeca
2016-08-12 15:59:14 +08:00
Zane Bitter 75b56789e6 Implement diffs of ResourceDefinitions
The last remaining code using the deprecated methods in the
ResourceDefinition class to treat the definition like a CloudFormation
template snippet is the tmpl_diff in the Resource class. Replace the dict
diff with a Diff object that has an API which can be queried instead. For
backward compatibility with existing resource plugins, the current diff
objects are for now able to be treated like dicts. However, this is marked
deprecated and can be removed along with the equivalent support for
ResourceDefinitions in the future.

Change-Id: I9ef50f0d9b142d464a1b02da7a46536c532d2ebd
2016-04-13 19:49:04 -04:00
Zane Bitter 6d786e6e7f Reinstate deprecation warnings
The commit 4188c40beb cleaned up a lot of
places where the warnings module was just being used as a non-standard way
to log a warning. However, the way the module was used in the rsrc_defn
module is correct and should not have been changed. By passing a
DeprecationWarning to warnings.warn() we not only make it easy to find
deprecated functions in the source, we also make it possible for developers
to test whether deprecated code is unused by forcing the exception to be
raised. There's also no point in translating these warnings, since they are
targeted at developers (mostly developers of third-party plugins) and not
operators per se. This patch reverts the change to that one file and its
tests.

Change-Id: I9cb1e739e9f173c8f70cb944e886cc3b49abc5f3
2016-04-13 19:49:04 -04:00
ricolin 4188c40beb Remove warnings in heat
Use warning in oslo_log instead.

Change-Id: I7c2cfe3cbd7ac8b1a5870cd53633342c5622ef0b
2016-01-20 22:00:52 +08:00
Zane Bitter a69431ab6c Make ResourceDefinition round-trip stable to avoid extra writes
The part of a ResourceDefinition that lists explicit dependencies was not
round-trip stable. As a result, when we copied a new resource definition
into the existing template during a stack update, we would end up rewriting
the template unnecesarily (i.e. even though we check for changes) every
time if depends_on was not specified in the resource originally. At the end
of each update, we write the new template to the DB in its entirety, which
removes these extra lines again, ensuring that we will experience the same
problem on every update. This was causing a *lot* of unnecessary writes.

This change ensures that the definition remains stable across a round-trip,
so that no unnecessary changes appear in the template.

Change-Id: If7292e49755db0153d7d0db9f7d3875fa9c1d408
Closes-Bug: #1494108
2015-09-11 14:27:55 -04:00
Sergey Kraynev 321aadd293 Add deprecation warning for ResourceDefinition
Docstring of class ResourceDefinition tells, that backward compatible
methods should be deprecated in favor of using methods in
ResourceDefinitionCore, but there is no any warning message about it.

This patch adds deprecation warnings.
Aslo related tests were changed to check, that deprecation warning is
really raised.

Change-Id: Ie881a1bdb88f4bcb1c03c037bcedf2a328d5d41c
2015-06-04 09:34:03 -04:00
Pavlo Shchelokovskyy 4279bd2923 Enable H305 and H307 style checks
Correct grouping and ordering of imports

Change-Id: I47ea0d53f80d7f0aeb01c1c6afd63713be87ddf4
2015-01-20 09:47:25 +02: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
Zhenguo Niu 09ecdc55a0 Don't import HeatTestCase directly
Fix the HeatTestCase import issue as required by H302,
a following patch of https://review.openstack.org/#/c/129846/

Change-Id: Iab9a508682e9fe2932b7d00b191c8a4cdea4738b
2014-10-22 14:15:11 +08:00
Zane Bitter d662581760 Add test for ResourceDefinition equality
ResourceDefinition objects compare equal if they are generated from
equivalent templates. Only the MRO stands between us and disaster (since
both superclasses - ResourceDefinitionCore and collections.Mapping - define
__eq__ methods), so add a test to confirm that we are getting the correct
one.

Change-Id: I8181f91f08fd81104fe493539511d6fd129522c8
2014-08-27 19:07:13 -04:00
Zane Bitter 01187b30f9 Add a method to freeze a ResourceDefinition
Change-Id: Idcbdd0efbc9c3b38c39b8ac1e64e9057fad15899
2014-08-27 19:07:13 -04:00
Zane Bitter f2c306c14c Add a ResourceDefinition class
This class provides a comparable, hashable representation of a resource's
definition in a template that is independent of the template format.

Implements: blueprint resource-template-api

Change-Id: I183114596863fbe0c0ff7cd22134b37493ed0dd9
2014-05-30 15:38:01 -04:00