Support string index for list in get_param
Accept for string index like '1' for list in get_param function For example, with lengths equal to [4,5,6]. We can write down something like this: `length: {get_param: [lengths,'1']}`. Closes-Bug: #1566321 Change-Id: I52447dea93ff2e6a32d597a632093661feed7c71
This commit is contained in:
parent
0d0ea75e64
commit
1df6d2aa79
|
@ -80,6 +80,14 @@ class GetParam(function.Function):
|
|||
raise TypeError(_('Path components in "%s" '
|
||||
'must be strings') % self.fn_name)
|
||||
|
||||
if isinstance(collection, collections.Sequence
|
||||
) and isinstance(key, six.string_types):
|
||||
try:
|
||||
key = int(key)
|
||||
except ValueError:
|
||||
raise TypeError(_("Path components in '%s' "
|
||||
"must be a integer "
|
||||
"parsable strings.") % self.fn_name)
|
||||
return collection[key]
|
||||
|
||||
try:
|
||||
|
|
|
@ -1661,6 +1661,10 @@ class StackParametersTest(common.HeatTestCase):
|
|||
dict(params={'list': 'foo,bar'},
|
||||
snippet={'properties': {'prop1': {'get_param': ['list', 1]}}},
|
||||
expected={'properties': {'prop1': 'bar'}})),
|
||||
('get_list_attr_string_index',
|
||||
dict(params={'list': 'foo,bar'},
|
||||
snippet={'properties': {'prop1': {'get_param': ['list', '1']}}},
|
||||
expected={'properties': {'prop1': 'bar'}})),
|
||||
('get_flat_dict_attr',
|
||||
dict(params={'flat_dict':
|
||||
{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}},
|
||||
|
|
Loading…
Reference in New Issue