Skip to content

Commit

Permalink
Fix comparing values with unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Dellweg committed Nov 25, 2019
1 parent 503531f commit a3ab4e8
Show file tree
Hide file tree
Showing 17 changed files with 3,112 additions and 1,436 deletions.
26 changes: 20 additions & 6 deletions plugins/module_utils/foreman_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,15 @@ def _update_entity(self, resource, desired_entity, current_entity, params, entit
desired_entity = _flatten_entity(desired_entity, entity_spec)
current_entity = _flatten_entity(current_entity, entity_spec)
for key, value in desired_entity.items():
if current_entity.get(key) != value:
payload[key] = value
# String comparison needs extra care in face of unicode
if entity_spec[key].get('type', 'str') == 'str':
if to_native(current_entity.get(key)) != to_native(value):
self.warn("I: {} {!r} : {!r} {}".format(key, current_entity.get(key), value, entity_spec))
payload[key] = value
else:
if current_entity.get(key) != value:
self.warn("II: {} {!r} : {!r} {}".format(key, current_entity.get(key), value, entity_spec))
payload[key] = value
if payload:
payload['id'] = current_entity['id']
if not self.check_mode:
Expand Down Expand Up @@ -642,10 +649,7 @@ def _entity_spec_helper(spec):
for key, value in spec.items():
entity_value = {}
argument_value = value.copy()
if 'flat_name' in argument_value:
flat_name = argument_value.pop('flat_name')
entity_value['flat_name'] = flat_name
entity_spec[flat_name] = {}
flat_name = argument_value.pop('flat_name', None)

if argument_value.get('type') == 'entity':
entity_value['type'] = argument_value.pop('type')
Expand All @@ -657,8 +661,18 @@ def _entity_spec_helper(spec):
argument_value['elements'] = 'dict'
_dummy, argument_value['options'] = _entity_spec_helper(argument_value.pop('entity_spec'))
entity_value = None
elif 'type' in argument_value:
entity_value['type'] = argument_value['type']

if flat_name:
entity_value['flat_name'] = flat_name
entity_spec[flat_name] = {}
if 'type' in argument_value:
entity_spec[flat_name]['type'] = argument_value.get('type', 'str')

if entity_value is not None:
entity_spec[key] = entity_value

if argument_value.get('type') != 'invisible':
argument_spec[key] = argument_value

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/katello_content_view_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
'date_type': {},
'end_date': {},
'start_date': {},
'types': {},
'types': {'type': 'list'},
}

content_filter_rule_erratum_id_spec = {
Expand Down
8 changes: 6 additions & 2 deletions tests/test_entity_spec_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_full_entity():
spec = {
'name': {},
'count': {'type': 'int', 'aliases': ['number']},
'facilities': {'type': 'list'},
'street': {'type': 'entity', 'flat_name': 'street_id'},
'houses': {'type': 'entity_list', 'flat_name': 'house_ids'},
'prices': {'type': 'nested_list', 'entity_spec': {
Expand All @@ -23,6 +24,7 @@ def test_full_entity():
assert spec == {
'name': {},
'count': {'type': 'int', 'aliases': ['number']},
'facilities': {'type': 'list'},
'street': {'type': 'entity', 'flat_name': 'street_id'},
'houses': {'type': 'entity_list', 'flat_name': 'house_ids'},
'prices': {'type': 'nested_list', 'entity_spec': {
Expand All @@ -32,15 +34,17 @@ def test_full_entity():
assert entity_spec == {
'id': {},
'name': {},
'count': {},
'count': {'type': 'int'},
'facilities': {'type': 'list'},
'street': {'type': 'entity', 'flat_name': 'street_id'},
'street_id': {},
'houses': {'type': 'entity_list', 'flat_name': 'house_ids'},
'house_ids': {},
'house_ids': {'type': 'list'},
}
assert argument_spec == {
'name': {},
'count': {'type': 'int', 'aliases': ['number']},
'facilities': {'type': 'list'},
'street': {},
'houses': {'type': 'list'},
'prices': {'type': 'list', 'elements': 'dict', 'options': {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_playbooks/architecture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
vars:
operatingsystem_name: "TestOS2"
operatingsystem_state: present
- include: tasks/architecture.yml
vars:
architecture_state: absent
- hosts: tests
gather_facts: false
vars_files:
Expand Down
Loading

0 comments on commit a3ab4e8

Please sign in to comment.