From c06b2e4622c3931fcaa2369d1c1e49054f46fb38 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 18 Jan 2016 15:08:07 -0500 Subject: [PATCH] correctly deals with non serializable type combine_vars shoudl really be data types, but some just get in in test, add dict to mock and avoid combine_vars using object --- lib/ansible/utils/vars.py | 11 +++++++++-- test/units/plugins/strategies/test_strategy_base.py | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/utils/vars.py b/lib/ansible/utils/vars.py index 569bad2847a..4d44a068c20 100644 --- a/lib/ansible/utils/vars.py +++ b/lib/ansible/utils/vars.py @@ -28,7 +28,8 @@ from ansible.compat.six import iteritems, string_types from ansible import constants as C from ansible.errors import AnsibleError from ansible.parsing.splitter import parse_kv -from ansible.utils.unicode import to_unicode +from ansible.utils.unicode import to_unicode, to_str + def _validate_mutable_mappings(a, b): """ @@ -43,8 +44,14 @@ def _validate_mutable_mappings(a, b): # a variable number of arguments instead. if not (isinstance(a, MutableMapping) and isinstance(b, MutableMapping)): + myvars = [] + for x in [a, b]: + try: + myvars.append(dumps(x)) + except: + myvars.append(to_str(x)) raise AnsibleError("failed to combine variables, expected dicts but got a '{0}' and a '{1}': \n{2}\n{3}".format( - a.__class__.__name__, b.__class__.__name__, dumps(a), dumps(b)) + a.__class__.__name__, b.__class__.__name__, myvars[0], myvars[1]) ) def combine_vars(a, b): diff --git a/test/units/plugins/strategies/test_strategy_base.py b/test/units/plugins/strategies/test_strategy_base.py index 53e243f926b..da14f6887aa 100644 --- a/test/units/plugins/strategies/test_strategy_base.py +++ b/test/units/plugins/strategies/test_strategy_base.py @@ -193,6 +193,7 @@ class TestStrategyBase(unittest.TestCase): mock_inventory.get_host.side_effect = _get_host mock_inventory.get_group.side_effect = _get_group mock_inventory.clear_pattern_cache.return_value = None + mock_inventory.get_host_vars.return_value = {} mock_var_mgr = MagicMock() mock_var_mgr.set_host_variable.return_value = None