From 21720f6beeff2bde02cef7d27340822624d305a4 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Wed, 29 Jul 2015 16:13:02 +0200 Subject: [PATCH] Return devicenodes as empty list if no LUN's got connected. It is possible for an intiator to successfully connect to a target, whilst getting no LUN's back. If no devicenodes get detected, it makes more sense to return an empty list than plainly None. This potentially avoids further tasks to have to check if devicenodes is iterable. --- .../modules/extras/system/open_iscsi.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/ansible/modules/extras/system/open_iscsi.py b/lib/ansible/modules/extras/system/open_iscsi.py index e2477538888..f7df640d5c0 100644 --- a/lib/ansible/modules/extras/system/open_iscsi.py +++ b/lib/ansible/modules/extras/system/open_iscsi.py @@ -206,18 +206,15 @@ def target_device_node(module, target): # a given target... devices = glob.glob('/dev/disk/by-path/*%s*' % target) - if len(devices) == 0: - return None - else: - devdisks = [] - for dev in devices: - # exclude partitions - if "-part" not in dev: - devdisk = os.path.realpath(dev) - # only add once (multi-path?) - if devdisk not in devdisks: - devdisks.append(devdisk) - return devdisks + devdisks = [] + for dev in devices: + # exclude partitions + if "-part" not in dev: + devdisk = os.path.realpath(dev) + # only add once (multi-path?) + if devdisk not in devdisks: + devdisks.append(devdisk) + return devdisks def target_isauto(module, target):