diff --git a/heat/api/aws/utils.py b/heat/api/aws/utils.py index dd43e7931..9b3a6ecb8 100644 --- a/heat/api/aws/utils.py +++ b/heat/api/aws/utils.py @@ -111,4 +111,5 @@ def reformat_dict_keys(keymap={}, inputdict={}): ''' Utility function for mapping one dict format to another ''' - return dict([(outk, inputdict[ink]) for ink, outk in keymap.items()]) + return dict([(outk, inputdict[ink]) for ink, outk in keymap.items() + if ink in inputdict]) diff --git a/heat/tests/test_api_aws.py b/heat/tests/test_api_aws.py index 920454b76..507b4dcb3 100644 --- a/heat/tests/test_api_aws.py +++ b/heat/tests/test_api_aws.py @@ -181,6 +181,13 @@ class AWSCommon(unittest.TestCase): result = api_utils.reformat_dict_keys(keymap, data) self.assertEqual(result, expected) + def test_reformat_dict_keys_missing(self): + keymap = {"foo": "bar", "foo2": "bar2"} + data = {"foo": 123} + expected = {"bar": 123} + result = api_utils.reformat_dict_keys(keymap, data) + self.assertEqual(result, expected) + def setUp(self): print "setup complete"