Commit Graph

124 Commits

Author SHA1 Message Date
Rodolfo Alonso Hernandez 4fe338cafb Use stdlib fnmatch module
oslo.utils fnmatch module has been deprecated [1].

[1]4c893c92f5

Change-Id: Ib33ff22fdd0ec8ceb0b2d4f7ae7ec581e9d998b4
2021-06-25 10:48:49 +00:00
Zuul 98dc789fbc Merge "Switch to collections.abc.*" 2021-03-12 08:07:07 +00:00
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 6b3d15d677 Optimise resource type listing
Minimise the amount of work needed to filter the list of resource types.

Change-Id: If2ccb662a3591336625a3ab0581efbcf2b0ca62e
Task: 37976
2020-04-30 09:44:07 -04: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
Zane Bitter 76ec5af884 Docs: Eliminate warnings in docs generation
Fix all of the existing sphinx warnings, and treat warnings as errors in
future.

Change-Id: I084ef65da1002c47c7d05a68d6f0268b89a36a7a
Depends-On: https://review.openstack.org/553639
Depends-On: https://review.openstack.org/559348
2018-06-21 16:38:47 -04:00
ricolin 46f0e16d11 [policy in code] part3 (resource types)
Allow use policy in code to resource type's rule.
Also add test for override the in-code resource type rule in json
file.
Partially-Implements: bp policy-in-code

Change-Id: Id6c21732e66de6c421427ded98de52f5da0a4db2
2017-12-01 01:34:55 +08:00
Zane Bitter 331df3abe8 Use pydoc for formatting docstrings
pydoc is part of the standard library and is much more robust at formatting
docstings than any trivial hand-rolled munger could be. For example, it
correctly preserves indentation within the docstring. Use it when
generating descriptions from docstrings for the API.

Change-Id: Ib565a64d990a45c652a9475255c37805f86070b4
2017-03-28 15:36:53 +00:00
liyi 8f10215ffd Remove log translations
Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW translation markers to simplify logging and to
avoid confusion with new contributions.

See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html

Change-Id: Ieec8028305099422e1b0f8fc84bc90c9ca6c694f
2017-03-25 17:11:50 +08: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
Zane Bitter adb8629a90 Use __slots__ in ResourceInfo classes
A TripleO environment typically contains hundreds of resource type
mappings. And a TripleO deployment typically contains hundreds of nested
stacks. The result is typically tens of thousands of ResourceInfo objects
all loaded in memory at the same time.

This change saves memory by using slots for these classes instead of
__dict__. I'd expect this to save on the order of tens of megabytes of RAM
in a TripleO deployment - comparatively modest, but an easy win given that
it is such a simple change.

Change-Id: Ia0f17be794618d7b41c463e1992755947c56d4d1
Partial-Bug: #1626675
2016-10-04 16:46:58 -04:00
Ji-Wei 2a66246536 Raise NotImplementedError instead of NotImplemented
NotImplementedError is the name of the exception
(https://docs.python.org/2/library/exceptions.html).
NotImplemented is the name of a constant
(https://docs.python.org/2/library/constants.html).
>>> raise NotImplemented()
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    raise NotImplemented()
TypeError: 'NotImplementedType' object is not callable
>>> raise NotImplementedError()
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    raise NotImplementedError()
NotImplementedError
This patch fix it.

Change-Id: I939eaa4b4b7c574f7a6447725e3a6ad5b128f1b7
Closes-Bug: #1339855
2016-09-18 16:52:59 +08:00
Steven Hardy b47c002556 Keep encrypted_param_names environment internal to heat
Currently this is reflected in the user_env_as_dict output, which means
not only is it stored in the DB (which we want), but also passed around
to nested stack (which we don't want because it's derived from the parent
stack hidden parameters), and also to the user via stack environment show
(the API returns it but heatclient currently hides it), which we also don't
want because it's not a valid key in user-provided environments.

Change-Id: If5821ccb4a8bbf98012a2541ddd3c8e91455e5cc
Closes-Bug: #1590507
2016-06-30 18:12:29 +01:00
Jenkins a758dff5aa Merge "Correct message when extension is not available" 2016-06-28 04:45:14 +00:00
Zane Bitter ad2b579ed6 Use LOG.exception() properly
Contrary to popular belief, LOG.exception() is not a method to which you
pass an exception in order to log it. Rather, you pass the message to be
logged at ERROR level, and the exception is retrieved automatically via
sys.exc_info().

Change-Id: I197cf94ada34a7ce80fc4026a99d95cd50823882
2016-06-27 11:28:34 +02:00
Dmitriy Uvarenkov 558a8cd1e8 Correct message when extension is not available
Now if extension is not available, user gets
message 'Service endpoint not in service catalog'
which is incorrect. Patch corrects this behavior
and adds improved messages with more info.

Change-Id: I9b6c0d2921519590ef105be35e31db29cd1e3ecc
2016-06-27 11:09:32 +03: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
Peter Razumovsky 42bfc8a282 Add to resource-type-list returning description
Add to resource-type-list command ability to return
resource description.

@APIImpact
@DocImpact

Change-Id: Ia92699e5ca60a891e9704c468e447e1053be7609
Closes-bug: #1558049
2016-05-25 16:10:34 +03:00
Jenkins 0093937ec4 Merge "use thread safe fnmatch" 2016-04-26 14:14:18 +00:00
ZhiQiang Fan bc7e503cc0 use thread safe fnmatch
fnmatch is not thread safe in python <2.7.10, let's use the safe
one in oslo.utils

Change-Id: I09c8e25b584a253fa19c9f546188b419c2d5b35b
ref: https://hg.python.org/cpython/rev/fe12c34c39eb
2016-04-21 12:29:19 +08:00
Zane Bitter 7f801dfd24 Break reference cycle between ResourceRegistry and ResourceInfo
ResourceInfo should hold only a weak reference to the ResourceRegistry
it is held in, otherwise there is a cycle that means the entire registry
has to wait for garbage collection in order to be deallocated.

Change-Id: I708aa1e9bac696eb16e9ef21089ca6e14e84e067
Partial-Bug: #1570974
2016-04-20 15:08:12 -04:00
Zane Bitter ec5e5c57a2 Break reference cycle between Environment and ResourceRegistry
The commit 08431c7c06 added a reference to
the Environment object from the ResourceRegistry object, which is itself
an attribute of the environment. This causes a reference cycle that
means that the environment and everything referenced by it (including
the potentially very large files dict) will only be deallocated when it
is garbage collected since the reference counts will never hit zero.
This has probably been contributing substantially to memory
fragmentation.

Change-Id: Ib251b5f5ffc07fe1a06f5e44124024831d4ba1b2
Partial-Bug: #1570974
2016-04-20 15:07:32 -04:00
Anh Tran 07847b6ae0 Removing some redundant words
This patch removes some redundant words.

Change-Id: I0aebf6505c0e1ba2f1c2348b84b579f40622eda4
2016-03-25 11:43:49 +00:00
Joe D'Andrea 7ccf4d045e Explicitly naming resources in "unsupported" warnings
Warnings that a resource is not supported are now prefaced
with the resource name and status (e.g., DEPRECATED). In
addition, the warning is now logged via LOG.warn(_LW()).

Previously, warnings.warn(six.text_type()) was used. In
addition to being routed to the log file, it included a
confusing reference to the last line of invocation, which
was the fragment "info.value.support_status.message))".

Change-Id: I006120a395007d88f3ba04a4af89283a1a077c3f
Closes-Bug: #1524512
2016-03-16 14:26:44 +00:00
Thomas Herve 08634c0399 Clean initial registered messages
Remove clutter at startup when we log the list of registered resources.

Change-Id: I4eb0cdcbaab1ce3a02f063bf9983e63e8d4581a0
2016-03-01 11:03:08 +01:00
Jenkins 99f7c51dd3 Merge "Add post hooks" 2016-02-22 03:49:44 +00:00
Jenkins 19d12f6ac5 Merge "Handle missing plugin in is_service_available" 2016-02-10 12:53:16 +00:00
Thomas Herve 76f99a9036 Handle missing plugin in is_service_available
When a client is not installed, Heat should behave as if the service was
unavailable. We recently started exposing exceptions when checking for
service availability, which displayed that it fails if the client plugin
returs None. Let's test and handle that case.

Change-Id: I71d5fd5be2efd7734d8569e4d26ab1b512453343
Closes-Bug: #1543759
2016-02-10 11:55:03 +01:00
Thomas Herve c1fd6c62e8 Add post hooks
This adds hooks after create, update and delete operations.

Change-Id: Ie90d8881ec4b275e5513c21033ad004c52283ac0
2016-02-10 09:13:32 +01:00
Rabi Mishra 311e597b3c Restrict update/replace of resource
Restricts update/replace of resource based on
environment 'restricted_actions' entry for a resource.

This also adds a 'preview_update' method to Resource
class which is now leveraged by stack-preview.

Change-Id: Iea80a6572aa696ee607682e5113204d1c82389fa
Blueprint: stack-update-restrict
2016-02-09 10:30:11 +05:30
Jenkins 7106e622aa Merge "Remove warnings in heat" 2016-01-25 10:25:39 +00: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 26e6d5f6d7 Load template files only from their known source
Modify get_class to ensure that user-defined resources cannot result in
reads from the local filesystem. Only resources defined by the operator
in the global environment should read local files.

Change-Id: I845e7d23c73242a4a4c9c40599690ab705c75caa
Closes-Bug: #1496277
2016-01-18 19:09:24 -05:00
Thomas Herve 4f3246db45 Event transport
Implement a new mechanism to allow specifying a target in the
environment to send events to. It adds zaqar as the first
implementation.

Depends-On: Ie04f9204f3ba0f75de32253f096f439c512cddee
Change-Id: Icfc3864e08693cb4b4f921641af380b39bcf0bc0
2016-01-05 10:22:57 +01:00
Jenkins 809cd7b668 Merge "Using LOG.warning replace LOG.warn" 2015-12-30 08:27:05 +00:00
LiuNanke 208d2debd0 Using LOG.warning replace LOG.warn
*Python 3 deprecated the logger.warn method, see:
*https://docs.python.org/3/library/logging.html#logging.warning
*so we prefer to use warning to avoid DeprecationWarning.

Change-Id: I07ee9c97c3548c965aaf83d34b37b23e9baba584
2015-12-29 09:32:42 +00:00
Jenkins fcb23785b3 Merge "Allow many-to-one glob mapping in registry" 2015-12-07 16:35:11 +00:00
Jenkins 456e01818a Merge "Add a separate get_class_to_instantiate() method to Environment" 2015-12-07 10:29:07 +00:00
Jenkins e6908458d6 Merge "Raise EntityNotFound in get_resource_info()" 2015-12-04 14:28:59 +00:00
Pavlo Shchelokovskyy 02a0025338 Allow many-to-one glob mapping in registry
This allows mapping several resource type to a single type in the
resource registry.
Mostly useful for testing (map many to OS::Heat::None).
Needed to improve the heat-templates gate.

Change-Id: I5b56c71b5575b73432b0e24df1dc8f8402c17a0c
Closes-Bug: #1499748
Related-Bug: #1492942
2015-12-02 13:57:56 +00:00
Jenkins 2542bc9f7f Merge "Implement pre-delete hook" 2015-12-02 08:47:43 +00:00
Zane Bitter 06a713c445 Add a separate get_class_to_instantiate() method to Environment
We were previously using get_class for two different purposes - to get a
resource plugin on which we could perform introspection to obtain the
properties and attributes schema, and to get a resource plugin we could
instantiate to create a Resource object. These are both the same except in
the case of a TemplateResource, where having two different use cases for
the same piece of code was adding considerable extra complexity. Combining
the use cases in this way also made the error handling confusing (leading
to bug 1518458).

This change separates out the two cases.

Change-Id: I3bde081cd4537810c8c6a0948ab447c3fb7ca9bc
Related-Bug: #1447194
Related-Bug: #1518458
Related-Bug: #1508115
2015-11-30 19:23:04 -05:00
Zane Bitter 9935c38e5c Raise EntityNotFound in get_resource_info()
Rather than return None when doing get_resource_info() on resource types
that don't exist, raise an EntityNotFound exception. We can then catch that
and turn it into StackValidationFailed where appropriate, but we don't make
assumptions about where the code is being called from at the point where we
raise the exception.

Change-Id: Idf6f837befea8ccb10fdaf9196490da3dd5be1fb
Related-Bug: #1447194
Related-Bug: #1518458
2015-11-30 18:08:56 -05:00
Zane Bitter 517f91ce27 Fix HTTP error codes due to invalid templates
This reverts commit 9a4d719ea1 and creates a
new exception type, InvalidGlobalResource, that is raised when a
non-existent template is referenced in the global environment and which
results in an HTTP 500 error.

This fixes the cases where we could return 404 or 500 errors as a result of
template validation failures, when we should return a 400 error.

Change-Id: I3c7b3182957448bb13514696cc2e12f5aaddd253
Closes-Bug: #1518458
Related-Bug: #1447194
2015-11-20 21:27:13 -05:00
ricolin f3556594b7 Use EntityNotFound instead of ResourceTypeNotFound.
Replace and remove ResourceTypeNotFound.

Change-Id: I1761eb59021b20625ea1886c5e70c8a0f9633d17
Partial-Bug: #1515603
2015-11-19 22:58:01 +08:00
Thomas Herve c0457f17fc Implement pre-delete hook
Add a hook running before resource deletion.

blueprint pre-delete-hook

Depends-On: Ia362650261b0b6c03ce431cbcf292a1685b59883
Change-Id: I8f57cab5ea9ff54d84195add1ba5065520e83489
2015-11-18 16:40:16 +01: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
Steven Hardy 5d6234ecf6 Reduce frequency of logging environment resources
Currently we log all template resources every time any API call
happens which indirectly creates an Environment object, which
results in a lot of duplicate bloat in the heat logs (not even
at debug level..)

So, instead log all environment resources (e.g those from resource
plugins and the global environment) only when we start the
service, and log user-provided template resources only when we
do the template validation on create/update, for only the root stack,
because we pass a derived subset environment down to all children.

We also switch to using the string representation of the ResourceInfo
objects, as this contains a bit more useful info than the current
log format.

Change-Id: I20007c1ad6bf8b1479c1d60a5c392b8b9e1c06c4
Closes-Bug: #1499330
2015-09-28 17:12:03 +01: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
Jenkins cff9dda9c3 Merge "Validate TemplateResource schema when based on other templates" 2015-09-16 11:02:59 +00:00