Commit Graph

192 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
Zuul 4c5abb4909 Merge "Return empty list instead of None for tags" 2020-05-11 21:59:55 +00:00
Marc Methot 156f276665 Logging Consistency
A simple matter of having log lines fit
with all the others. It will now match the
ambiguous standard.

Also change comments inline to alias with log fixes.

Change-Id: I4a2ed6134f70c2965811f75ccb6ab8221fa0e960
Story: #2007319
Task: 38830
2020-04-27 06:34:31 +00:00
Hervé Beraud 5877da06a1 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 4 of a serie of 28 patches

Change-Id: I871c2dad10abc35790e730c7c4c5272f499b7623
2020-04-22 12:23:44 +02:00
Zane Bitter 6e3fd87340 Return empty list instead of None for tags
If a stack has no tags, return an empty list [] instead of None for its
tags list.

Change-Id: I3c3c083d7261172d08b933de7c63b6a489ed6ccd
Depends-On: https://review.opendev.org/687769
Task: 37009
2019-10-10 17:40:42 -04:00
Zane Bitter 2540dfd450 Allow tags to be removed with update --existing
When updating a stack using the PATCH method (i.e. passing --existing on
the command line), the existing tags are kept unless otherwise
specified. However, while it was possible to set a new set of tags on
such an update, it was not possible to remove all of the tags because an
empty string was treated the same as None or a missing tags key (both of
which are treated as no change).

When the user explicitly requests an empty tags list (by passing ''),
honour that request.

Note that while None is treated the same as a missing key, in practice
the API never sends us a value of None; the key is never sent to the
engine if the user passes null to the API. The input string is split by
the API so the engine receives data with the key then the value is
always a Python list.

Change-Id: I6ae355b0a8af017c7a9145c9483c1ad3f2ac5ca5
Task: 37010
2019-10-10 17:40:42 -04:00
Zane Bitter 78b7a471c2 Make tags handling more robust
Avoid loading the tags from the DB and then re-saving every time
the stack is stored when the stack has tags. Avoid attempting to
lazy-load the tags from the DB multiple times when there are no tags.
Avoid lazy-loading the existing tags on an update when we intend to
overwrite them anyway. Avoid writing the same set of tags multiple
times.

e.g. in a legacy update, previously we rewrote the current set of tags
when changing the state to IN_PROGRESS, then wrote the new set of tags
regardless of whether they had changed, then wrote the new set of tags
again when the update completed. In a convergence update we also did
three writes but in a different order, so that the new tags were written
every time. With this change we write the new set of tags only once.

This could also have prevented stacks with tags from being updated from
legacy to convergence, because the (unchanged) tag list would get
rewritten from inside a DB transaction. This is not expected so the
stack_tags_set() API does not pass subtransactions=True when creating a
transaction, which would cause a DB error.

Change-Id: Ia52818cfc9479d5fa6e3b236988694f47998acda
Task: 37001
2019-10-10 17:40:42 -04:00
Saravanan KR 14b14dcfc7 Add exception log for stack preview
TripleO uses stack preview for deploy preparation tasks.
When there is a error in SoftwareConfig template, 'config'
results in null, without any debug or error message. Adding
log message to identify such errors easily.

Change-Id: I5700e091336fa11c7edcdd575ee27f0a49639ff8
2019-09-21 13:02:00 +05:30
Zuul e15538c198 Merge "Return stack.outputs when stack in DELETE_FAILED" 2018-02-01 06:38:08 +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
Saravanan KR 554add6004 Refactor the format_validate_parameter fuction to reduce complexity
Adding a if condition to format_validate_parameter function, is
failing the pep validation, because of complexity is going beyond
the 20 limit. Separating the constraints from the base makes it,
simpler.

Change-Id: Iaa4cdfceea67a17af1e17512cc28eb54dd52907d
2017-10-31 17:09:36 +05:30
chestack a410b072aa Return stack.outputs when stack in DELETE_FAILED
Users can not view outputs of stacks in DELETE_FAILED.
But it's useful for magnum to get cluster info from stack.outputs
and for users to debug failed stacks.

Change-Id: Ib3927c61660b1b2162d5b34809b48401062a6f02
Close-Bug: #1712274
2017-08-22 15:33:13 +08:00
Jenkins 5e8ceba9ce Merge "Remove duplicated `show_deleted` param extraction" 2017-08-17 03:30:36 +00:00
ricolin 552f94b928 Add converge flag in stack update for observing on reality
Add converge parameter for stack update API and RPC call,
that allow triggering observe on reality. This will be
triggered by API call with converge argument (with True
or False value) within. This flag also works for resources
within nested stack.
Implements bp get-reality-for-resources

Change-Id: I151b575b714dcc9a5971a1573c126152ecd7ea93
2017-08-07 05:39:29 +00:00
ricolin e1ea0424ef Remove duplicated `show_deleted` param extraction
We will handle `show_deleted` param extraction in list stack API
call. Also we don't actually require to do extract it in extract_args.
Since extract_args is used in create/update stack which won't
require to have a show_deleted args.

Change-Id: I6b96dc1bb780e7658d7ef50c42fca81f12388551
2017-07-27 14:06:57 +08:00
Zane Bitter 10a75d87dd Always return live resource attributes in list_stack_resources
Currently, we do live resolution of attribute values when in
list_stack_resources with detail enabled. However, in future we will cache
in the database those values that are referenced elsewhere in the template.
Since it's unlikely that every attribute would be referenced in the
template, this could lead to the API returning an inconsistent mix of live
and cached data.

Caching all of the attribute values on the off chance that someone might
request them through this obscure API would be expensive, and there are
also users that need to be able to access live resource attributes via
Heat. Therefore, always return live data for the resource attributes in
this API.

Change-Id: Ifea71b30299076d14d9bb91f3bce4dd7fc4c88a1
Related-Bug: #1660831
2017-06-08 21:48:17 -04:00
rabi c0a3bcbfa3 Fix format_stack_preview for py3
Also fixes test_res_group_with_nested_template functional
test.

Change-Id: I23fab6b8acc11bb32332dd0042ecd6b8ac289f56
2017-04-05 10:48:43 +05:30
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
Jenkins 30e6359517 Merge "Add attributes schema for OS::Keystone::User" 2017-03-21 12:45:35 +00:00
Kanagaraj Manickam c2e944c6fc Add attributes schema for OS::Keystone::User
Add `attributes_schema` and `_resolve_attribute` for OS::Keystone::User.
This patch allow get_attr works with OS::Keystone::User resource.
Partial-Bug: #1648004
Closes-bug: #1659923

Co-Authored-By: Rico Lin <rico.lin.guanyu@gmail.com>
Change-Id: I4e8e984c42120e23887ad9997df2fa530709be52
2017-03-19 13:18:20 +05:30
Crag Wolfe 3e30b16624 Omit rsrc prop data in rpc api for multiple events
The list_events rpc api no longer includes resource properties data
when returning multiple events. In the "show event" case where an event
uuid is included in the list_events request, the resource properties data
for that single event continues to be included in the output.

Note that there is no change in behaviour on the heat-api side (see
heat/api/openstack/v1/events.py). Previously when listing multiple
events, it had just been ignoring the resource properties data it
fetched from the list_events rpc api, not including it in the output
it returned (e.g., to python-heatclient).

Change-Id: I7ac83d848cdd0e6c313870c0a4d59a5d9b2301f5
Partial-Bug: #1665506
2017-03-01 10:05:37 -05:00
huangtianhua eaca4eb51b Returns project info while getting sd with admin context
This change adds project information of software configs
if using admin context.

Change-Id: Ia26919aa1177a9366c65710becb2097b79e02445
Closes-Bug: #1646312
2016-12-23 01:13:38 +00:00
Crag Wolfe 892a4eac36 Do not load templates in stop_traversal
When iterating through nested stacks in stop_traversal, there is no
need to load or process templates.

Change-Id: If2795cff4a9e7052e2186c811cdcd3e9451f9ff6
2016-11-07 11:27:21 -08:00
Ana Krivokapic b1144b22ce Add a modulo core constraint
A modulo constraint will be used to restrict numeric values to
leave a certain remainder when divided with certain divisor.
E.g. we can use this to constrain values to even/odd numbers.

Change-Id: I9d7db4307be2a2b93cc928cf5912af7b49c72076
2016-10-11 16:55:11 +02:00
Jenkins c4f9e64979 Merge "Handle outputs with an OutputDefinition class" 2016-09-12 15:21:42 +00:00
Zane Bitter 7de1c141db Handle outputs with an OutputDefinition class
This is the last remaining area of the code where we were slinging around
CloudFormation-formatted snippets of template. Replace it with a proper API
along the lines of ResourceDefinition.

The default implementation of the new template.Template.outputs() method is
equivalent to what we have previously done spread throughout the code, so
that third-party Template plugins will not be affected until they have had
time to write their own custom implementations.

Change-Id: Ib65dad6db55ae5dafab473bebba67e841ca9a984
2016-09-09 16:14:16 -04:00
Thomas Herve f655726560 Restore timezone information in API response
When oslo_utils isotime was deprecated, we switch to isoformat and lost
the timezone information. This switches back to a function which put the
Z suffix indicating UTC. It's a potential backward incompatible change,
but presumably better than sending incomplete information.

Change-Id: I78ab2dd025f1d00d4afaf72070e481aa8e09c5e8
Closes-Bug: #1607562
2016-09-07 23:29:50 +02:00
huangtianhua 56fad61131 Adds some infos for stack notification
Adds 'description', 'tags' and 'updated_at' for stack
notification for projects such as Searchlight to store
stack metadata.

Change-Id: I7067e6649661d88cb86b4021a27ebbb6393cc7af
Closes-Bug: #1603163
2016-08-05 14:21:57 +08:00
Steve Baker 26b0dd2a3e Do not populate unused stack and watch rule objects
These fields are lazy loaded, so cause extra unnecessary database
access.

The watch rules are needed when formatting every watch data metric for
the cloudwatch API, so an id->name map of all rules is built to avoid
repeated lazy loading of every rule.

Change-Id: I36dd43172ccd402f08a45b254ae47e208b7b8c08
Related-Bug: #1479723
2016-07-11 09:56:29 +12:00
Jenkins 6a4faf6d1d Merge "Fix the definition of has_nested()" 2016-06-30 13:43:47 +00:00
Jenkins 47262c079d Merge "Sync context with oslo.context" 2016-06-29 02:41:26 +00:00
Jenkins 257e0a9f67 Merge "Implement event list nested-depth" 2016-06-28 03:01:59 +00:00
huangtianhua faec3a0962 Decouple hot and cfn for outputs
The changes including:
1. Avoid hard code of resource and output keys
2. Decouple hot and cfn for outputs

Change-Id: I1fd7e08ff5c699ddfcf98c81aed5f0d91c4248b3
2016-06-24 10:08:28 +00:00
huangtianhua ccdb9c9ae6 Show 'deletion_time' for stack-list/stack-show apis
We support to get the deleted stacks by filter in stack-list
api, support to show the deleted stack by stack-id,
so to show the 'deletion_time' info of stacks.

Change-Id: I8c55fe7f6a899ca66aa3fef15c93195c03c5aa11
Closes-Bug: #1587214
2016-06-20 10:23:35 +08:00
Jamie Lennox 87a37f5db2 Sync context with oslo.context
Heat makes a lot of variations to the basic oslo.context which are going
to make it very hard to reuse with features added to the base
oslo.context.

There are a number of changes here that will make the heat context
options more like those from oslo.context.

*) context.user and context.tenant are IDs, not names. This will be
   important for policy credentials.

*) kwargs should be passed through to base context so it can be extended
   in the base class.

Change-Id: Ib0d60c6af196ba5c00459110b7a6190cff916d6f
2016-06-17 11:46:00 +10:00
Steve Baker 32ade7a243 Implement event list nested-depth
The GET call to list events will support a nested_depth parameter. The
response will have an additional links url with the ref 'root_stack'
to indicate that this API supports nested_depth queries.

This has the following consequences for old/new combinations of
client/server
- new heatclient, new server - nested_depth param is set, server
  returns nested events
- new heatclient, old server - nested_depth param is set, server
  returns events with no root_stack, heatclient falls back to
  recursive event fetch
- old heatclient, new server - nested_depth param is never set,
  recursive event fetch works as before

Here are some timings for a TripleO overcloud stack with ~700 events.

Current heat and python-heatclient master:
time openstack stack event list --nested-depth 4 overcloud |wc -l
744
real    0m17.500s

This change, with heatclient 31278ff5f77b152b5ef7a4197e15c441c72ff163:
time openstack stack event list --nested-depth 4 overcloud  |wc -l
608
real    0m1.725s

The difference in event count (744 vs 608) is due to the stack events
being filtered out for stacks with zero resources - these are a source
of unnecessary noise so their removal should be considered an improvement.

Closes-Bug: #1588561

Change-Id: I27e1ffb770e00a7f929c081b2a505e2007f5d584
2016-06-14 13:39:38 +12:00
Steve Baker 7bfbace79f Use Event versioned object for event_list formatting
This change removes the event.Event.load method, and switches
api.format_event to using the Event versioned object instead.

Since the only purpose of loading the stack is to get its identifier,
this is now also coming from a Stack versioned object.

Related-Bug: #1588561
Change-Id: I7b1fc99894818b44cde08cf08b010b1d1fb94e9f
2016-06-13 09:39:52 +12: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 091ed70d53 Fix the definition of has_nested()
Since Iab7a997c0b4d9dcb8ceb3d2f49692216fe611df1 StackResource.has_nested()
returns True unconditionally. However, some parts of the code expect that
if has_nested() returns True, the caller will be able to call nested() and
not get None returned (this was the original definition of has_nested()).
This change restores the definition without the need to load the nested
stack (which is expensive, and the reason for changing this in the first
place).

This also allows the change from the original patch to be a bit tidier,
without a recurrence of the issue it initially caused (bug 1586906) that
was later fixed by I2ededcc57057f43206922b99bb72c43332336814.

Change-Id: Id26dc62b7513853b3f02a656518c59b3ff8d509a
Related-Bug: #1578854
2016-06-02 11:41:39 -04:00
Jenkins 70238b3d61 Merge "Stack list does direct stack object query" 2016-05-31 04:14:42 +00:00
Jenkins a3aa955085 Merge "Add to resource-type-list returning description" 2016-05-27 07:46: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
Steve Baker 0ef5d601c0 Don't load nested stack to build the identifier
StackResource is already building HeatIdentifier for the nested stack,
so this should be used by the resource formatter to avoid the overhead
of loading the nested stack.

Change-Id: Iab7a997c0b4d9dcb8ceb3d2f49692216fe611df1
Partial-Bug: #1578854
2016-05-25 12:56:47 +12:00
Steve Baker b3c228d707 Stack list does direct stack object query
Currently calls to get a collection of stacks via the stack object
have the following data access behaviour:
- One query to fetch the stack records
- One query per stack to fetch the raw template
- One query per stack to fetch the tags

This causes excessive database round trips when there are many stacks.
In addition, the list_stacks call results in a collection of full
stack objects to be created which builds a fully parsed stack - most
of this information is then discarded by the RPC and middleware
formatters so this overhead is for no benefit.

This change is the first step in changing the data access patterns by
querying the Stack versioned object directly instead of via the full
Stack object. A future change will apply an eager fetch and caching
approach to avoid unnecessary queries.

This change does the following:
- Service list_stacks calls stack_object.Stack.get_all directly
- Service list_stacks formats with new function
  api.format_stack_db_object with the exact fields required by the CFN
  and REST API list stacks formatters
- Since the description field is the only one that requires full stack
  parsing, it is now set to an empty string for stack listings via API
  or calls to aws cloudformation list-stacks [1]

This last point may be controversial, my attempts to find uses of the
stack description in stack listings found none that do, and the following
API uses which *don't* show the description:
- heat stack-list
- openstack stack list
- horizon stack list
- rackspace control panel stack list

If we want to add the description back later we could always add a
description field back to the Stack table to store the denormalised
description.

[1] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html

Partial-Bug: #1578851
Change-Id: I88b6f705e87ee7ff4acb7830dcddfc188ae6b3b2
2016-05-25 11:58:40 +12:00
Kanagaraj Manickam 516a543861 Fixes resource filter to handle physical_resource_id properly
The usage of resource.nova_instance property name is removed
and resource.physical_resource_id is used instead, except in
db schema. This patch takes care of this case, for the bug
fix made for resource filtering earlier.

Change-Id: Ic3aa5248232033fde0897a1b6400fa182e1c766a
Closes-bug: #1568974
2016-05-23 14:34:10 +05:30
Oleksii Chuprykov 0321d86443 Correct filters for resource search
We can search resources using this filter keys:
type, status, name, action, id, physical_resource_id. For more
information please see heat-stack-resource-search spec in heat-specs
repository and this commit: Iaae88f3b32bc2ba7b41a4078ef3aa8ffc07079b7
We pass `filters` as an argument to sqlalchemy that expects
filters keys to be a columns in a table. There are not such
columns `physical_resource_id`, `type` in Resource table, so
we get error while trying to filter resource by this keys.
Use `nova_instance` instead of `physical_resource_id` and filter
by `type` manually.

Closes-Bug: #1568974

Change-Id: I7b47eae000b244f58a05405746f5fcf9e922aff8
2016-05-17 12:18:15 +03:00
Jenkins 4e7a584e5c Merge "RPC API: Define correct constants for resource data" 2016-01-27 18:48:53 +00:00
Thomas Herve 76663a26d9 Return stack outputs when in progress
Don't filter out stack outputs when stack status is in progress,
returning it all the time instead.

Change-Id: Ife8f1eafe85e9ff4ce5f0a4692c64343c1c2d0b4
Closes-Bug: #1537693
2016-01-26 09:17:30 +01:00
Zane Bitter 415dc236ab RPC API: Define correct constants for resource data
For some reason we were using constants from a different data structure
(the resource schema) as field names in the resource data structure, even
though the names made no sense, just because they happened to have the
value we wanted. This change defines properly-named constants and puts them
in the RES_KEYS tuple where they belong.

Change-Id: Ia47ba64d85f0f4b93ba242b6d54e7f318fac7481
2016-01-22 13:01:45 -05:00