Commit Graph

221 Commits

Author SHA1 Message Date
Zane Bitter f7eddbef83 Fix 'if' function with only 2 arguments
This had a similar problem as when null values were passed explicitly
before the fix for bug 1709620.

Change-Id: I02fb4c8815bc24d4c0c339022aa857dc344d58e9
Story: 2011108
Task: 49921
2024-04-24 12:06:07 +12: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
Zuul 5eec3e4bd0 Merge "Modify 'if' Macro to allow optional properties" 2020-11-02 17:46:26 +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
Sean McGinnis fd6cf83554
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I8f764e9ba46a4e2055be61eb0fe97d155ab1c70e
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-05-05 08:42:11 -05:00
Hervé Beraud d7d3dcbb50 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 26 of a serie of 28 patches

Change-Id: I861e30278e66b680cd64ef659ff889414d4e55fb
2020-04-23 14:49:12 +02:00
rabi 1e4a92237f Remove mox from test_hot
Change-Id: Ib188f26d4f494f6dc6f5e10e82f70f8e51b69252
goal: mox-removal
2018-04-03 08:07:31 +05:30
Zuul 624968ea47 Merge "Allow paths as lists in function.validate()" 2018-01-08 08:07:49 +00: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
Zane Bitter cb80df4f4a Allow paths as lists in function.validate()
Previously when calling function.validate() we passed the path to the
function in the template (used for debugging purposes) as a string. This
change allows us to pass it as a list of path components, as we do
elsewhere, so that higher-level code that catches StackValidationFailed
can deal with its components separately.

Change-Id: I017aa6f7511b8478ef8273522ab8087684ae71c6
2017-11-16 14:18:11 -05:00
Jenkins 4e0536476f Merge "Allow conditions to return null values" 2017-09-11 10:45:15 +00:00
Jenkins dd28f15a2f Merge "Strip disabled resources from depends_on in add_resource()" 2017-08-28 19:13:59 +00:00
rabi 44c188c80f Allow conditions to return null values
Change-Id: I44ec701319786a4f8f64e04d77c6a31bb2de1d20
Closes-Bug: #1709620
2017-08-11 14:57:49 +00: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 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 633f4c9f00 Get dep_attrs from StackDefinition
Since function.dep_attrs() returns logical resource names (rather
than actual objects), we can just as easily use the StackDefinition to
calculate it instead of the Stack and Resource objects.

In the legacy path, we must ensure we use the StackDefinition from the
*new* stack to determine which attributes to include in the NodeData, since
that's what we're going to be using it for. In the convergence path the
current stack definition already contains the new template.

Also, update the *new* stack's definition with the NodeData obtained from
completed resources (in addition to the existing stack's), so that that
data may be used in calculating the dep_attrs for future resources. This is
required when get_attr functions are nested in the template.

Change-Id: I23efcc091eae53470f7f9cb3ca21e09f00f43808
Partially-Implements: blueprint stack-definition
2017-07-21 10:30:34 -04:00
Zane Bitter cc3c60647b Update StackDefinition resource data when getting outputs
Before returning the stack outputs, update the StackDefinition with the
resource data needed to resolve them. This will enable us to switch to
resolving outputs via the StackDefinition in a subsequent patch.

Change-Id: Ide3920385d9c4841c18024e1eb1456eed5c8eef5
Partially-Implements: blueprint stack-definition
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 cfff39ce68 Always cache attributes in outputs in Resource.node_data()
Ensure that attributes that are referenced in outputs get cached (and
therefore stored in the database) even when they are not referenced by
other resources.

Change-Id: I667ab04f91edddef5c5dbec0a89d465110c312b4
Closes-Bug: #1660831
2017-07-10 22:06:45 -04: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 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
Jenkins 8ce536f0e4 Merge "Support 'list_concat_unique'" 2017-05-24 10:55:52 +00:00
M V P Nitesh e596c96611 Replace assertRaisesRegexp with assertRaisesRegex
This replaces the deprecated (in python 3.2) unittest.TestCase
method assertRaisesRegexp() with assertRaisesRegex()

Change-Id: I405875738337433a36cba78023534615dea8b7b6
2017-05-19 18:13:59 +05:30
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
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 6abdb1c62f Merge "Separate management of parent resource into separate class" 2017-03-30 12:45:03 +00:00
Jenkins 34df3cd915 Merge "Add a node_data() method to Resource" 2017-03-23 04:53:00 +00:00
Jenkins 6d0c714172 Merge "Add a NodeData class to roll up resource data" 2017-03-21 06:48:56 +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 48fb66bdf3 Separate management of parent resource into separate class
The facade_resource intrinsic function needs to access the parent resource
of a stack, which it does via the stack.parent_resource property. Accessing
this for the first time loads the parent stack and all of its resources if
they were not already. This made sense when all nested stacks in a tree
were handled in-memory at the same time, but now that they are processed by
separate engines it is inefficient.

This change moves responsibility for lazy-loading the parent stack to a
separate ParentResourceProxy class, and makes access more efficient again
by avoiding the loading of resources if the stack was not already in
memory. It also resolves a circular reference between nested stacks and
their parent stacks.

We now have a well-defined API behind which we can potentially make further
efficiency improvements while giving third-party Function plugin developers
confidence that we won't break them without notice.

Change-Id: Ibfd80544889778f3499bcbe421b83f0a5aa6a7f7
Partially-Implements: blueprint stack-definition
2017-02-24 10:19:21 -05:00
Zane Bitter 39269d2aa0 Add a node_data() method to Resource
This will allow the snapshotting of attribute/refid values to occur on both
the legacy and convergence paths (currently it is used only for
convergence).

Change-Id: I9a8fce9c6d22d84ec967087b62bff77f5a6de3db
Partially-Implements: blueprint stack-definition
2017-02-24 10:10:53 -05:00
Zane Bitter bc4fde4dce Add a NodeData class to roll up resource data
Formalise the format for the output data from a node in the convergence
graph (i.e. resource reference ID, attributes, &c.) by creating an object
with an API rather than ad-hoc dicts.

Change-Id: I7a705b41046bfbf81777e233e56aba24f3166510
Partially-Implements: blueprint stack-definition
2017-02-24 10:10:26 -05:00
Jason Dunsmore aee10997ac Move CFN pseudo functions out of Parameters base class
And create a CfnParameters class, similar to HOTParameters.

Change-Id: I5e71ce9affb8188b696c12e9f008678ce08a913c
2017-01-27 15:24:44 -06: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
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
Jenkins 708bda5152 Merge "Add a modulo core constraint" 2016-10-26 04:12:29 +00:00
Jenkins 3a062fdf22 Merge "Add new hot function str_replace_strict" 2016-10-17 10:52:27 +00: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
Crag Wolfe aac3e7aae6 Add new hot function str_replace_strict
In many cases, a user would rather see an error result if a
str_replace param is not substituted in the template, rather than the
function silently doing nothing.

Since str_replace is set in its ways, introduce a new function
str_replace_strict which behaves identically to str_replace except
that a ValueError is raised if any of the param's are not found
in the template.

Change-Id: I8b8c69bb49dfeb74e05af4871602c20493b081eb
2016-10-10 10:24:55 -07:00
rabi 89526b5ea7 Use empty list for None values in repeat function
Atrributes would return `None` before the resource is
created, hence resource validation would fail when
using repeat function. Use empty list instead to avoid
it.

Change-Id: I93f65d6604944ccae40f65ef52754dcec69e9886
Closes-Bug: #1629899
2016-10-04 15:40:01 +05:30