Commit Graph

44 Commits

Author SHA1 Message Date
Tobias Urdin c253b38e21 Move CircularDependencyException to common
Moves the exception from inside the engine code
to the common code so that we can use it in the
API fault middleware.

Change-Id: I017b95153c358829501f6a5740918cdb005fb32f
2023-02-27 12:22:38 +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
Hervé Beraud fccd312871 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 3 of a serie of 28 patches

Change-Id: If6e66839c128dde5fb80d90155dedb598da8d53b
2020-04-22 12:23:44 +02:00
Zane Bitter d64de0e4e1 Don't use Dependencies repr in tests
Change-Id: I92fb9928bf839568bb3e4cfb547ddbb579b991cf
2017-09-26 16:46:17 -04:00
Zane Bitter d8a53517be Fix nonsensical docs in dependencies.py
It's really confusing every time you have to think about the difference
between requires() and require_by() in the dependencies graph. That was
helped not at all by 5189bbebab, which
added a requires() method to the Dependencies class with a parameter
name that is exactly backwards from correctly representing what it
means, as well as a docstring that is copied without modification from
the required_by() method, which obviously returns the opposite data. In
addition, the new docstring for the Node.requires() function made no
sense.

Change-Id: Ie9d8bedf83947b197f2defd309fd996060514100
2017-07-05 16:17:17 -04:00
Zane Bitter c93e44dc1e Use __slots__ for dependencies.Node
The number of nodes in the dependency graph is not huge (one per resource),
but we tend to make a lot of copies - the whole graph must be copied every
time we iterate through it. Since the Node class has only two attributes
and is basically never modified, we can easily save a little memory by
defining __slots__ for it.

Change-Id: Ibe36016a5889c9f1bd89672b1b03b2bc69b7925b
2016-12-01 15:35:15 -05:00
Zane Bitter e79f28d28a Fix unfortunate spelling error
Change-Id: I2ceab6579112d55f496c0bbe37c42263b54bb0c9
2016-04-04 12:43:16 -04:00
Ethan Lynn 6cf8dc6e56 Fix problems in unicode template support
If we use unicode as resource name or parameter,
we are likely to encounter unicode problems.
This patch aims to fix unicode problems, and
there are several things to be clear:

1. For the class wrap with six.python_2_unicode_compatible, in
python2 their original __str__ function will map to __unicode__,
and new __str__ function comes from __unicode__.encode.
So we should always return unicode in __str__() if wrap
with python_2_unicode_compatible.

2. python_2_unicode_compatible will not handle __repr__,
__repr__ should return str in all versions of python.

Co-Authored-By: Ethan Lynn <xjunlin@cn.ibm.com>
Closes-Bug: #1524194
Change-Id: Ib4af43d153e0edf9d66308bf8e7b93a3be501d2e
2016-03-04 01:59:40 +00: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
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 62e95ddc1e py34: heat.tests.test_engine_service
* convert map to list in heat.engine.api. This is done because stacks
  are garbage collected once we go out of scope using weakrefs. However,
  in python 3, since everything is lazily loaded, when we iterate over
  the stack['resources'] iterable, we end up referencing the previously
  garbage collected stack object. So resolve everything before returning
  the list.
* sort the __repr__ of dependencies to return a consistent string
* Don't encode support_status. There is no need to encode it. Without
* this, in py3, we'd effectively be comparing a unicode string to byte string
  and thus breaking the environment.get_types() API partially.
* test_case: explcitly cast strings to int before comparing them with integers.
* test_case: use a more accurate sorted expression

partial blueprint heat-python34-support

Change-Id: Ic9d78034b7e5478c4cb14344d64b9e838a12bf57
2015-08-03 22:58:35 +05:30
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
Sirushti Murugesan f1f4d60e0a Add __bool__ for classes that implement __nonzero__
__nonzero__ has been renamed to __bool__ in python3.4. So add the
__bool__ magic method that will in turn call the existing __nonzero__
method. This avoids the scheduler going into an infinte loop when
it checks for the no. of tasks remaining.

partial blueprint heat-python34-support

Change-Id: I5de554805a2af9abc15808427ce489720287f6b3
2015-07-02 07:56:31 +00:00
Angus Salkeld ad104c51bf convergence: sync_point fixes
This is a merge of 4 reviews:
I52f1611d34def3474acba0e5eee054e11c5fc5ad
Ic374a38c9d76763be341d3a80f53fa396c9c2256
Iecd21ccb4392369f66fa1b3a0cf55aad754aeac4
I77b81097d2dcf01efa540237ed5ae14896ed1670

- make sure sender is a tuple (otherwise the serialization
  function in sync_point breaks.)
- Update updated_time on any lifecycle operation(CREATE/UPDATE/DELETE)
  over a stack.
- adjust sync_point logic to account for deletes
   Done by having only a single stack sync point
   for both updates and deletes.
- Serialize/deserialize input_data for RPC
- Make GraphKey's the norm in convergence worker
- move temp_update_requires functionality to tests
  During intial stages of convergence to simulate the entire cycle
  some part of worker code was written in stack.py.
  Now that the convergence worker is implemented, this code needs to
  be executed only in tests.
- Fix dictionary structure that's passed to resoure.(create/update)
- Temporarily disable loading cache_data for stack to help fix other
  issues.

Change-Id: Iecd21ccb4392369f66fa1b3a0cf55aad754aeac4
Co-Authored-by: Sirushti Murugesan <sirushti.murugesan@hp.com>
Co-Authored-by: Rakesh H S <rh-s@hp.com>
2015-06-19 08:24:19 +05:30
Rakesh H S 9994950f40 fix for retrieving leaf nodes in convergence stack delete
When generating the dependencies, the deletion order is already taken
care, hence we need not reverse the graph.

Change-Id: Iff158443f2281a07e3a136a4cf6f77f7be592d3f
2015-05-05 14:47:02 +05:30
Rakesh H S 5189bbebab Convergence prepare traversal
Generates the graph for traversal in convergence.

* Updates current traversal for the stack
* Deletes any sync_point entries of previous traversal
* Generates the graph for traversal based on
  - resources loaded from db for the stack
  - resources that exist in present template
* Stores resource.current_template_id and resource.requires
* Stores the edges of graph in stack.current_deps
* Creates sync_points for each node in graph
* Creates sync_point for stack.

blueprint convergence-prepare-traversal

Change-Id: I507e67b39c820ed46d3b269fc76d6cf18d0ef2d7
2015-05-03 17:44:04 +05:30
Sirushti Murugesan 8257306624 Use six.moves.map/filter/zip
partial blueprint heat-python34-support

Change-Id: Iec4d228933d5cdc2474a8090cc524673d0ecdb2c
2015-04-24 11:52:39 +05:30
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
Peter Razumovsky 15ea5e132e Convert unicode to six in heat/engine
This patch converts unicode to six.text_type in
heat/engine for python 3.x compatibility.

Change-Id: I8395582c7e504ff7b710cb5f6034c2f8b6bc8957
2015-01-22 12:16:54 +03: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 03b3cf777e Fix [H302] errors in heat/engine
Change-Id: Ib3e1a6f9d5e82e9fb29b000157b57dbc3883b42e
2014-11-26 16:43:55 +03:00
Ethan Lynn 04f0271931 Add unicode support for resource name
When using template which has resource name in unicode to create
stack will failed with encode/decode error.
This patch override __str__ & __unicode__ function in related
classes to make them compatible with unicode.

blueprint: template-unicode-support
Change-Id: Ie677d180d2131abd052101996900414e2b2ef4ad
2014-10-16 10:37:27 +08:00
Ethan Lynn c2211f0e0a Switch heat engine to oslo.i18n
Remove gettextutils from heat engine and import oslo.i18n.

blueprint oslo-i18n

Change-Id: Iadf4cfc0f9a0b94c1f2fa1eb71f807539247b34e
2014-09-16 14:08:53 +08:00
Christian Berendt 58e141b2ac replace dict.iteritems() with six.iteritems(dict)
According to https://wiki.openstack.org/wiki/Python3 dict.iteritems()
should be replaced with six.iteritems(dict).

Change-Id: I9e2881a006433c8b44a3caccebc73bae4973a041
2014-08-06 10:56:09 +08:00
liu-sheng 5541f43903 Use None instead of mutables in method params defaults
Mutables in the method params defaults might cause errors and
that's why it's anti-pattern in most of the cases and should be
removed.

Change-Id: I8bc284f12ce72082a0482410ec2c20c2fc087a4b
Closes-Bug: #1327473
2014-07-02 16:33:12 +08:00
Jenkins 06ac482ac5 Merge "Order imports in alphabetical order (5/9)" 2014-04-11 00:24:30 +00:00
Jenkins d951d9eb58 Merge "Make the first line of every file consistent." 2014-04-08 08:51:07 +00:00
Pavlo Shchelokovskyy bcceff368d Order imports in alphabetical order (5/9)
This patch is one in a series to re-enable H306 style check rule
(imports are in alphabetical order).
It touches engine files (without resources).

Implements: blueprint reduce-flake8-ignored-rules (partial)
Change-Id: Ifd36fc49199c48af891bd8e7cc2d2262a53032eb
2014-04-07 21:35:23 +03:00
lizheming 59b976fc7b Use six.move.xrange to replace xrange
in python3.x, there is no method named xrange(),
it has been replaced by range(),which is equal to xrange()
in python2.x. so we must fix this issue.
we use six module to fix this issue.

Change-Id: Ia901798cf16b9a48982e6845fa3e5deffc3bd509
Closes-Bug: #1268439
2014-03-14 09:32:24 +08:00
Jason Dunsmore af464c9afc Make the first line of every file consistent.
Change-Id: I2e1a809cfca8e88693551d58d33e747f54ee5eb1
2014-03-04 09:03:04 -06:00
Jason Dunsmore 97135cbfc0 Remove vim header from files.
Change-Id: Ia6131f8fcac6902c80c80aa805c8cd7a2a41f280
Closes-Bug: #1229324
2014-03-04 08:51:56 -06:00
Richard Lee 8e2f66ac60 Add way to group exceptions in DependencyTaskGroup
DependencyTaskGroup currently aborts execution if any exceptions are
raised.  This commit provides a way of aggregating all the exceptions
during execution and re-raising them only at the end.

blueprint stack-check

Change-Id: I6af314cc112f9286c8b38739870c6fa8b4ba9b5a
2014-01-09 00:08:37 -06:00
Angus Salkeld c5e93e6c6b use msg_fmt not message in Exceptions
This doesn't solve the problem yet, but clarifies
the format string from the final string.

Partial-bug: #1243883
Change-Id: Ia0f19423248304984cc53926dfb87c6a49c90e11
2013-10-24 10:44:15 -10:00
Liang Chen a67f85267a Evaluate lazy translation in exception __str__
The OpenStackException.__str__ method returns
self._error_string which is actually a gettextutil.Message
object not a str.

str(o) will check the return type of o.__str__() and raise
TypeError if __str__ returns non-string object.

The fix will not go into oslo as OpenStackException is
about to be deprecated. And this patch is also the first
step to remove all the references to oslo exception.py.

Fixes bug #1208454

Change-Id: Ib6abe3517bcb1b34fc6a71e5c46ee3774e067f9a
2013-08-23 23:02:06 +08:00
Zane Bitter 23aa437766 Make the API for getting dependency graph edges public
This will allow us to build new dependency graphs from combinations of
existing graphs.

Change-Id: I6da62607fa1e361d4d2e1581fd286c62f0d9470a
2013-08-22 15:02:08 +02:00
Jenkins d4fe600c12 Merge "add missing gettextutils imports" 2013-07-02 16:08:44 +00:00
Steven Hardy ec40a9ebe7 add missing gettextutils imports
Several files use the "_" function, but don't import it from
gettextutils - this leads to a "NameError: name '_' is not
defined" error if you try to import/use the modules from an
interactive python shell or standalone test-code.

Change-Id: Id28b45d71eeda64fbfaa6234b12cff45fcd2ce40
2013-07-02 14:22:24 +01:00
Steve Baker 5c5519af26 Expose resource dependency required_by to REST API.
Each resource can generate a list of names of resources which
require this resource as a direct (non transitive) dependency.

This information is returned in the list as well as the show REST calls
so that a diagram of the running stack can be built with a single
request.

Other uses of exposing this information is:
- template authors debugging their own template dependency issues
- integration tests validating template dependencies

Change-Id: Ibe62345afa87e49c4e2152a5fcb74e5ee003124e
2013-07-01 11:14:45 +12:00
Zane Bitter 1f0a9bc2d1 Move deletion from dependency graph to __delitem__
Graph objects are mutable, and will in future be used for operations other
than a topological sort, so abstract out the code for deleting backlinks to
a node from the other nodes that have dependencies on it when it is
removed.

Change-Id: I86b81303ed2dffd969a2db10535761f108f4808a
2013-05-28 10:16:37 +02:00
Zane Bitter 0e31ec7e73 Make the mutable dependency graph a separate class
Rather than copying dictionaries internally, provide a separate Graph class
that can be copied externally as well.

Change-Id: Id0bd55944369da59d7da1713369fce0d73ffe814
2013-05-28 10:16:37 +02:00
Zane Bitter e0ab9767cf Make dependency graph node class public
We're going to start making more use of it, so there's no point hiding it
away inside the Dependencies class.

Change-Id: I10c4a05493697f8834623cd798ef35161a0c219b
2013-05-28 10:16:37 +02:00
Angus Salkeld 796fe8a213 Fix PEP H402 "one line docstring needs punctuation."
Change-Id: Id0aa43187f6d5e62308f4b329bc9458a512d808d
2013-05-20 21:55:11 +10:00
Zane Bitter 0f47986b65 Fix error in Dependencies representation
This mostly only exists for debugging, but it's helpful if it can actually
run.

Change-Id: Ie29da5e7e58aed54aaaffa4df479fa0d96ce78fe
2013-05-17 08:14:10 -07:00
Zane Bitter 067e037064 Do proper dependency calculations
Change-Id: Ic8a9bd2105ebfff3604a45b45eac39da3b1bbcf5
Signed-off-by: Zane Bitter <zbitter@redhat.com>
2012-06-15 11:29:08 +02:00