summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2019-07-08 15:26:00 +0200
committerBrian Coca <bcoca@users.noreply.github.com>2019-07-08 15:25:59 +0200
commit79fdc2190a799e59bdc2c9c9c0f0937bde924cf0 (patch)
treef87d0c0a7ed512fa0195042348eb6f060672a4e1
parentUpdate ec2_snapshot.py (#58753) (diff)
downloadansible-79fdc2190a799e59bdc2c9c9c0f0937bde924cf0.tar.xz
ansible-79fdc2190a799e59bdc2c9c9c0f0937bde924cf0.zip
role: Fix role's hash_params (#55263)
* role: Fix role's hash_params Fix based upon work done by alikins. Fixes: #20596 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * review comments Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r--changelogs/fragments/20596-role-param_fix.yaml2
-rw-r--r--lib/ansible/playbook/role/__init__.py4
-rw-r--r--test/units/playbook/role/test_role.py46
3 files changed, 50 insertions, 2 deletions
diff --git a/changelogs/fragments/20596-role-param_fix.yaml b/changelogs/fragments/20596-role-param_fix.yaml
new file mode 100644
index 0000000000..eb02c15156
--- /dev/null
+++ b/changelogs/fragments/20596-role-param_fix.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+- Fixed role's hash_params behavior to not union (https://github.com/ansible/ansible/issues/20596).
diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py
index bb304fa755..9230f48a30 100644
--- a/lib/ansible/playbook/role/__init__.py
+++ b/lib/ansible/playbook/role/__init__.py
@@ -68,7 +68,7 @@ def hash_params(params):
new_params = set()
for k, v in params.items():
# Hash each entry individually
- new_params.update((k, hash_params(v)))
+ new_params.add((k, hash_params(v)))
new_params = frozenset(new_params)
elif isinstance(params, (Set, Sequence)):
@@ -79,7 +79,7 @@ def hash_params(params):
new_params = set()
for v in params:
# Hash each entry individually
- new_params.update(hash_params(v))
+ new_params.add(hash_params(v))
new_params = frozenset(new_params)
else:
# This is just a guess.
diff --git a/test/units/playbook/role/test_role.py b/test/units/playbook/role/test_role.py
index b6386a99e6..f94037e911 100644
--- a/test/units/playbook/role/test_role.py
+++ b/test/units/playbook/role/test_role.py
@@ -118,6 +118,52 @@ class TestHashParams(unittest.TestCase):
self.assertRaises(TypeError, hash_params, params)
+ def test_param_dict_dupe_values(self):
+ params1 = {'foo': False}
+ params2 = {'bar': False}
+
+ res1 = hash_params(params1)
+ res2 = hash_params(params2)
+
+ hash1 = hash(res1)
+ hash2 = hash(res2)
+ self.assertNotEqual(res1, res2)
+ self.assertNotEqual(hash1, hash2)
+
+ def test_param_dupe(self):
+ params1 = {
+ # 'from_files': {},
+ 'tags': [],
+ u'testvalue': False,
+ u'testvalue2': True,
+ # 'when': []
+ }
+ params2 = {
+ # 'from_files': {},
+ 'tags': [],
+ u'testvalue': True,
+ u'testvalue2': False,
+ # 'when': []
+ }
+ res1 = hash_params(params1)
+ res2 = hash_params(params2)
+
+ self.assertNotEqual(hash(res1), hash(res2))
+ self.assertNotEqual(res1, res2)
+
+ foo = {}
+ foo[res1] = 'params1'
+ foo[res2] = 'params2'
+
+ self.assertEqual(len(foo), 2)
+
+ del foo[res2]
+ self.assertEqual(len(foo), 1)
+
+ for key in foo:
+ self.assertTrue(key in foo)
+ self.assertIn(key, foo)
+
class TestRole(unittest.TestCase):