Skip to content

Commit

Permalink
Make Fn::Select accept an integer selector again
Browse files Browse the repository at this point in the history
Closes-Bug: #1245863

Change-Id: I364da88f1c581b406d51e1b584778c7dd4e2564f
  • Loading branch information
Roman Podoliaka committed Oct 29, 2013
1 parent 614e196 commit 11ac4dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions heat/engine/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def resolve_select(s):
Note: can raise ValueError and TypeError
'''
def handle_select(args):
example = '"Fn::Select": ["4", ["str1", "str2"]]'
example = '"Fn::Select": [1, ["str1", "str2"]]'
if not isinstance(args, (list, tuple)):
raise TypeError(_('Arguments to "Fn::Select" must be a list'))

Expand All @@ -244,9 +244,9 @@ def handle_select(args):
'"Fn::Select" should be: %s') %
example)

if not isinstance(lookup, basestring):
raise TypeError(_('Index to "Fn::Select" '
'should be a string: %s') %
if not isinstance(lookup, (basestring, int)):
raise TypeError(_('Index to "Fn::Select" should be either a '
'string or an integer value: %s') %
example)
try:
index = int(lookup)
Expand Down
4 changes: 4 additions & 0 deletions heat/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ def test_select_from_list(self):
data = {"Fn::Select": ["1", ["foo", "bar"]]}
self.assertEqual(parser.Template.resolve_select(data), "bar")

def test_select_from_list_integer_index(self):
data = {"Fn::Select": [1, ["foo", "bar"]]}
self.assertEqual(parser.Template.resolve_select(data), "bar")

def test_select_from_list_out_of_bound(self):
data = {"Fn::Select": ["0", ["foo", "bar"]]}
self.assertEqual(parser.Template.resolve_select(data), "foo")
Expand Down

0 comments on commit 11ac4dd

Please sign in to comment.