Commit Graph

248 Commits

Author SHA1 Message Date
David Vallee Delisle 0f7ce2cfa6 Adding oslo.config entry points for yaql and cache opts
To assist with automated configuration validation, we need entry points
for oslo.config.opts for yaql and cache options.

Change-Id: I228282d2c05f6583fe972470b326e7182f635b39
2024-01-09 10:39:46 +09:00
Brendan Shephard 56d99bf658 Improve map_merge logging
Templates can be complex and contain multiple instances of
map_merges. Debugging this can be complex, so this change
aims to improve the mapping and help users determine where
the problem has occured.

With this change, instead of just saying an error occured,
we will now return the object that the error occurred with
and a note about it's type. This will allow for quick
identification of what the problem was.

Change-Id: I1c4da88029bbf1a3cfb58f5e21da28ec2912f924
2022-11-03 15:47:01 +10:00
ramishra a8f8528d1e Preserve order in list_concat_unique
Also, we should not modify a list when iterating
over it.

Task: 42359
Closes-Bug: #1925373
Change-Id: Iaa2c05b4155d93f44de60b6f98a69450c1512817
2021-04-23 11:49:23 +05:30
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 71a9c3d690 Modify 'if' Macro to allow optional properties
Change-Id: I931d88e79fc077d12fc9bd39009061ffe87f1262
Story: 2007388
Task: 38973
2020-10-27 16:59:30 -04:00
Zane Bitter 674a62ae9b Add template version 2021-04-16 for Wallaby
Change-Id: I57047682cfa82ba6ca4affff54fab5216e9ba51c
Story: 2007388
2020-10-27 16:55:38 -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
James Slagle a8c44bddaa Log args during list_concat
list_concat checks that all args are lists. If that fails, the exception
will now show which args aren't a list, and show all the args. This is
useful context to help find the error in the template.

Change-Id: Ic88257fd36bdde884e8ac4f17186c42b76ec538b
2019-03-27 01:54:05 +00:00
Zane Bitter bb3ddcf573 Ensure Functions can be created without stack definition
In a number of places we parse templates passing None as the stack
definition, in order to be able to extract information from the template
in cases where we don't actually need to resolve functions.

However, the GetParam and GetFile HOT functions require an actual stack
definition to be passed in order to initialise them. So far we haven't
encountered any cases where those functions appear where we pass None
for the stack definition. Ensure that all Functions can always be
created even with no stack definition.

Note that the cfn ParamRef class is not affected, as the Ref function
always selects the GetResource implementation when the stack definition
is None.

Change-Id: Ic947dcdc17e9dbc58459a92ba970c292d70578cd
2018-10-18 17:00:10 -04:00
Niels Boehm b384c179a2 Fix some typos in docstrings.
Change-Id: I94709efb56ed00805c5628e9f3e7a4c58ddc5428
2018-07-17 14:47:45 +00:00
ricolin 6665d9989f Add Rocky versions
* Add Rocky code name
* Add new HOT version for Rocky release
The new version is "2018-08-31" or "rocky".
* Add sem-ver flag
Sem-Ver: api-break

Change-Id: I261b6c28b8b7ee9e75ca9a895155a656ef82cd0d
2018-04-26 14:44:03 +08:00
Luis Tomas Bolivar bd8df9a8b9 Fix bypass list length check when all values are None
The patch https://review.openstack.org/#/c/527001/ bypassed the None
list but did not consider the case where all the for_each lists are
getting their values from attributes and therefore are None.

This patch set fix it by also skipping the check if all the values
are None -- as len(value_lens) would be 0 in that case.

Closes-bug: #1732934
Change-Id: Iba574bbd3877f9ca1ca755c384b3ddb47aec711c
2018-01-03 16:46:05 +01:00
Khaled Qarout 89643db005 Bypass list length check for None values in repeat function
Attributes may return "None" before the resource is created,
so the length check for for_each lists in repeat function will fail.
Bybass the length check for the None list

Change-Id: Ida81060e62340b3ea37ba0fdd7443dc88ba6c5aa
Closes-bug: #1732934
2017-12-13 06:31:51 -05: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
Jenkins be5edd2279 Merge "Clarify make_url validation errors" 2017-08-30 09:31:16 +00:00
Jenkins dd28f15a2f Merge "Strip disabled resources from depends_on in add_resource()" 2017-08-28 19:13:59 +00:00
huangtianhua c3546d9309 * Add new HOT version for Queens release
The new version is "2018-03-02" or "queens".

Change-Id: Icbb7ff4d717dd10d18a93387edfdb8fcee3d7927
2017-08-22 10:03:18 +08:00
Jenkins d0a3a886b2 Merge "Fix formatting in make_url error messages" 2017-08-04 05:56:53 +00:00
Zane Bitter 4f983037de Fix formatting in make_url error messages
Change-Id: I318227e1d7da3824c11fb3e875aa95f20a3f6f39
2017-08-01 10:14:15 -04:00
Zane Bitter c25034f5cd Strip disabled resources from depends_on in add_resource()
When we add a resource to a template using add_resource(), strip any
references to resources that are not present in the template from
'depends_on'. This means that resources that are present and depended on
but conditionally disabled in the source template will not be depended
on in the destination template, where they're not present at all (and
thus would cause errors when the template is used).

Change-Id: I58a64cd523cc0d1da8cd39793f0c839189458d99
Closes-Bug: #1701677
Related-Bug: #1649900
2017-07-21 10:55:23 -04:00
Zane Bitter ee5dc7c120 Implement all_dep_attrs() more efficiently for get_attr
Override the default implementation of all_dep_attrs() (which calls
dep_attrs() in a loop). This makes all_dep_attrs() for GetAtt and its
arguments as efficient as dep_attrs(), even if we only need the data for a
single resource (as in convergence after we update a resource).

Change-Id: Ia6a4d132e655ef24fb158959d05967d7f1c7fef8
Related-Bug: #1684272
2017-07-21 10:44:51 -04:00
Zane Bitter 764b8fb251 Use StackDefinition in intrinsic functions for resolving data
This unifies the 'lightweight stack' used in convergence with the how
things work the rest of the time: we now always obtain resource data from
the StackDefinition's ResourceProxy objects. This means that when we are
checking an individual resource, we will never create all of the other
Resource objects for the stack in memory (although we already avoided
loading data for them from the database) - now we will only create
ResourceProxy objects as needed.

Change-Id: Id7472557e26d172df88841ff7f20afdd7f5bfada
Implements: blueprint stack-definition
2017-07-21 10:30:34 -04:00
Zane Bitter 0bd3c307e1 Don't call Stack.has_cache_data() in Functions
This check was added in 0638030671 because
originally the Resource objects other than the one we were checking were
not initialised with any data during a convergence resource check.
Therefore they would be in the INIT_COMPLETE state, but would return valid
attribute values from the cache data.

It was made redundant by 1956ddd2a6, which
loaded the resource state in the Resource objects. The state will never be
INIT_COMPLETE.

This code requires the Function's 'stack' member to be a Stack object, so
we have to get rid of it in order to be able to start using a
StackDefinition object in its place.

Change-Id: I1a97401bf126a3ec10cc420bbb0786b785035d48
2017-07-21 10:30:34 -04:00
Jenkins 798f64ee91 Merge "Support 'permutations' for 'repeat' function" 2017-07-21 04:33:36 +00:00
huangtianhua ba7f7888f6 Support 'permutations' for 'repeat' function
Adds a new section 'permutations' for 'repeat'
function to decide whether to do nested loops
to iterate over all the permutations of
the elements in the given lists, the default value
is True if no specify and keep the same behavior as
before.
For example:

  repeat:
    template:
      network: %net%
      port: %port%
      ip: %ip%
    for_each:
      %net%: [n1, n2]
      %port%: [p1, p2]
      %ip%: [ip1, ip2]
    permutations: False

Will be resolve to:
   [{network: n1, port: p1, ip: ip1},
    {network: n2, port: p2, ip: ip2}]

Change-Id: I2a008400fb71453f6a78656f2e041ae2efa098a2
Blueprint: improve-repeat-function
2017-07-18 09:32:15 +00:00
Zane Bitter b902d93ade Handle errors calculating dep_attrs for nested get_attr
Ensure that in convergence we can calculate the dep_attrs of a resource,
including the attributes referenced in outputs, even if:

- One of the resource's attributes is referenced in an ouput; and
- The attribute path itself also contains a get_attr function; and
- The attribute referenced by the inner get_attr function in the output is
  not referenced by any resources.

Since the attributes referenced only in outputs (and not in resources) are
not passed to dependent resources in the NodeData, the data required to
resolve the inner get_attr function is not available. Therefore getting the
dep_attrs for the relevant resource from the output definition would fail.
The next patch does so during the calculation of the NodeData, and any
resulting exception is not caught (bug 1703043), so the stack would end up
stuck IN_PROGRESS.

To avoid this, ignore any errors resolving attribute path components in the
course of calculating the dep_attrs of a given resource. This may mean that
an attribute value required for the outputs is not stored in the database,
but it can still be resolved live later.

Change-Id: I2ed1e3dacd371e36656559ba92dfada05df0ceba
Related-Bug: #1660831
2017-07-10 16:43:38 -04:00
Jenkins 250a7d91d3 Merge "Fix wrong function description" 2017-07-04 07:59:27 +00:00
ricolin fec05f17d7 Fix wrong function description
Correct function name in description for test function.
Also correct function sample in hot function class `MapMerge`.

Change-Id: I61acec48e4a8365940d3e6e3d0a93d0c58fbda43
2017-07-04 13:27:28 +08:00
Zane Bitter 4250958a03 Add an add_output() method to Template
This helps with dynamically building templates, and is similar to the
add_resource method.

Change-Id: I51ce5c913438083d6d43eb6d8a8bf55cfa8ea3ee
Related-Bug: #1660831
2017-06-29 09:07:02 -04:00
huangtianhua f4c4ec63ab Add 'contains' function
Add new function 'contains' to check whether
the specific value is in a sequence. The resolve
result of the new function is a boolean value, so
we put it as a condition function too.

Change-Id: I90074070dd917df13345fb7c8d4ed09e4a76e864
Blueprint: support-contains-function
2017-06-22 07:26:19 +00:00
huangtianhua 127ec7307f Correct the error msg for 'repeat' function
Now we support the map and list valuse of
the "for_each" argument to 'repeat' function,
but the error message tells "...must be lists",
it's inappropriate.

Closes-Bug: #1672936
Change-Id: I3bbe370772be7d01e63c1e88afffbd507ff75507
2017-06-02 01:20:05 +00:00
Steven Hardy d887f34c9b Clarify make_url validation errors
The current output can be a little confusing in the case where
you have multiple make_url calls in one template - adding the
args to the output gives you a better chance to debug as you
can e.g compare the path with the template.

Change-Id: I73a0ffa8ee7d6a7f7a210548c966eb9faf6f5f5b
Closes-Bug: #1693490
2017-05-26 18:54:53 +00:00
huangtianhua 77e5072621 Allow function 'yaql' as condition function
Allow 'yaql' in condition definition, like:

parameters:
  ServiceNames:
    type: comma_delimited_list
    default: ['neutron', 'heat']
conditions:
  contains_neutron:
    yaql:
      expression: $.data.service_names.contains('neutron')
      data:
        service_names:
          get_param: ServiceNames

Closes-Bug: #1693093

Change-Id: I83a540336c01a696780621fb2b39486a6abf0917
2017-05-25 01:19:26 +00:00
huangtianhua 812e786efb Support 'list_concat_unique'
Adds function 'list_concat_unique' to concat
several lists using python's extend function
and make sure without repeating items.

Blueprint: support-list-concat-unique-function
Change-Id: Ia0e35eb578ebe91543c644155a86030b3258118b
2017-05-18 01:29:48 +00:00
huangtianhua de6a8c1be0 Fix validation of function 'list_concat'
Now the function 'list_concat' allows string type
args, like {'list_concat': 'I am string'} or
{'list_concat': ['v1', 'v2']}, this patch fixes the
validation to avoid string type args.

Change-Id: If6d73a90e25f38a37c0503fe0b1aaa93a6fbc380
Closes-Bug: #1685434
2017-05-17 02:08:28 +00:00
Jenkins d6d836ff62 Merge "Add the HOT fuction str_replace_vstrict" 2017-05-15 06:10:17 +00:00
chenaidong1 3431dfede2 Correct the class equivalent judgement error
for n, f in six.iteritems(self.functions):
            if not isinstance(f, hot_funcs.Removed):
                self._parser_condition_functions[n] = function.Invalid
            else:
                self._parser_condition_functions[n] = f

In the above codes, "f" is a class ,not an instance, therefore isinstance is uncorrect.

Change-Id: I9ec41d19b77acf6e083b7c5cb5b779dc54b4e547
2017-04-28 17:17:43 +08:00
Jenkins 6d570b70f5 Merge "Don't escape /s in make_url query strings" 2017-04-22 06:54:08 +00:00
Crag Wolfe 1f8d70346a Add the HOT fuction str_replace_vstrict
The already existing str_replace_strict function raises an error if a
param is not present in the template. str_replace_vstrict, newly added
in this patch, is identical but also raises an error if any of the
params have an empty value.

Change-Id: I5407135cc0435cfbad2d18964fe2119c999f67a3
2017-04-21 19:08:20 -07:00
Juan Antonio Osorio Robles 98faf03be4 Implement list_concat function
This function uses python's extend function for lists in order to
concatenate lists. So, given the input: [['v1', 'v2'], ['v3', 'v4']]
the result would be ['v1', 'v2', 'v3', 'v4'].

This comes as an alternative to using yaql's concat.

Change-Id: I082833e73388540b29f71b78293fd36fe04b7b92
2017-04-20 19:08:25 +03:00
Zane Bitter adffed9273 Don't escape /s in make_url query strings
Query strings are not _required_ to have slashes escaped, and in fact RFC
3986 suggests that "it is sometimes better for usability to avoid
percent-escaping those characters" (Section 3.4).

TripleO is currently unable to use the make_url function because its
database URLs contain slashes in the query, and end up in config files that
don't allow percent characters. This is probably not going to be an
isolated occurrence, so don't escape slashes in the query string.

Change-Id: I72f84e737b042ecfaabf5639c6164d46a072b423
2017-04-06 18:29:06 -04:00
Jenkins ec6b7008c0 Merge "Use a sentinel to indicate when all attributes are required" 2017-04-05 14:26:57 +00:00
Zane Bitter 6e7b3be2b8 Add a make_url intrinsic function
A large proportion of uses of the str_replace function is to build URLs out
of various components from various sources. This is invariably brittle,
with a failure to escape special characters, deal with IPv6 addresses, and
so on. The make_url function provides a both a tidier interface and correct
handling of these edge cases.

Change-Id: I61b6dff01cd509b3d1c54bca118632c276569f4e
2017-03-14 15:34:31 -04:00
Zane Bitter 2a887c06d8 Add new HOT version for Pike release
The new version is "2017-09-01" or "pike".

Change-Id: I7f1bccb39edc036c2b7b1340d430937bd0dc1de2
2017-03-14 15:34:31 -04:00
Zane Bitter 06afc2f3b0 Use a sentinel to indicate when all attributes are required
To generate its NodeData, a Resource must know which of its attributes
other parts of the template have dependencies on, which it determines by
asking the intrinsic functions in the template. Currently, the get_attr
function when used with no arguments depends on all of the attributes of
the resource (except 'show'), and it obtains this list from the Resource
itself (via the attributes_schema). This presents a chicken-and-egg problem
if we want to give Functions access only to a ResourceProxy based on the
NodeData.

Resolve this by returning a constant sentinel value (indicating that all
attributes are required) to the Resource, which can determine for itself
what attributes it has.

Change-Id: If209b589278fe1facb06e157fe76209fdd42a8a2
Partially-Implements: blueprint stack-definition
2017-02-24 10:19:21 -05:00
Jenkins be1720156e Merge "Sort JSON output in intrinsic functions" 2017-01-25 18:34:10 +00:00
Zane Bitter e950bbb6ad Don't load resources in dep_attrs
It's unnecessary to load the entire Resource just to get its name.

Change-Id: I09b9f49f5b3b631884ef0c513f3766df4502734b
Related-Bug: #1656429
2017-01-16 16:58:05 -05:00
Zane Bitter e8a5ce0720 Sort JSON output in intrinsic functions
When an intrinsic function serialises one of its arguments to JSON, sort
the keys in dicts so that the output is stable over time.

Change-Id: Ib509717837afff3b183707e2b4f99191fe572271
2017-01-11 17:29:17 -05:00
Steven Hardy c540293cfe map_replace allow noop colliding replacements
We should allow the case where the keys collide, but the
replacement is the same as the current key (e.g a noop).

This is useful when you want to do a map_replace based on a
user parameter, then the default can be to do a noop replace
but the user parameter may also be any other (non colliding)
value.

Change-Id: I8cc5761c219616b4f8c18b3f44c4bf864c5457f1
Closes-Bug: #1652034
2016-12-22 12:35:04 +00:00
Thomas Herve df674a715b Add filter function
Add a new HOT intrinsic function to filter out values from lists.

Closes-Bug: #1633512
Change-Id: Ie90001e6436b5ed5b29db7d3c166aba42299d3df
2016-11-04 10:46:12 +01:00