From b828b5d33b24719d77174c8cfb9d611c7dbc2a91 Mon Sep 17 00:00:00 2001 From: Patrick Murray Date: Wed, 23 Aug 2017 14:43:09 -0400 Subject: [PATCH] Fixing Issue #27270 - EFS TypeError (#27318) * Fixing Issue #27270 regarding a TypeError invoked by the addition of a Filter type and List type. * Fix SecurityGroup from always being reported as changed on PY3 On Python3, filter returns a generator. This causes us to report that security groups are always defined on Python3 even when there are none. Also change filter() calls into list comprehensions. --- lib/ansible/modules/cloud/amazon/efs.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/efs.py b/lib/ansible/modules/cloud/amazon/efs.py index e0c73975da..b501d928a4 100644 --- a/lib/ansible/modules/cloud/amazon/efs.py +++ b/lib/ansible/modules/cloud/amazon/efs.py @@ -403,10 +403,9 @@ class EFSConnection(object): targets_to_create, intersection, targets_to_delete = dict_diff(current_targets, targets, True) - """ To modify mount target it should be deleted and created again """ - changed = filter( - lambda sid: not targets_equal(['SubnetId', 'IpAddress', 'NetworkInterfaceId'], - current_targets[sid], targets[sid]), intersection) + # To modify mount target it should be deleted and created again + changed = [sid for sid in intersection if not targets_equal(['SubnetId', 'IpAddress', 'NetworkInterfaceId'], + current_targets[sid], targets[sid])] targets_to_delete = list(targets_to_delete) + changed targets_to_create = list(targets_to_create) + changed @@ -434,17 +433,16 @@ class EFSConnection(object): ) result = True - security_groups_to_update = filter( - lambda sid: 'SecurityGroups' in targets[sid] and - current_targets[sid]['SecurityGroups'] != targets[sid]['SecurityGroups'], - intersection - ) + # If no security groups were passed into the module, then do not change it. + security_groups_to_update = [sid for sid in intersection if + 'SecurityGroups' in targets[sid] and + current_targets[sid]['SecurityGroups'] != targets[sid]['SecurityGroups']] if security_groups_to_update: for sid in security_groups_to_update: self.connection.modify_mount_target_security_groups( MountTargetId=current_targets[sid]['MountTargetId'], - SecurityGroups=targets[sid]['SecurityGroups'] + SecurityGroups=targets[sid].get('SecurityGroups', None) ) result = True