Skip to content

Commit

Permalink
Check return code instead of output for iscsiadm
Browse files Browse the repository at this point in the history
 * iscsiadm returns 255 on no records
 * Refixes bug 922232

Change-Id: If177c3c79c6ad974c2bed0ad72a62e956af451e0
  • Loading branch information
vishvananda committed Feb 7, 2012
1 parent 16882ad commit a933e36
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions nova/virt/libvirt/volume.py
Expand Up @@ -108,10 +108,16 @@ def connect_volume(self, connection_info, mount_device):
iscsi_properties = connection_info['data']
# NOTE(vish): if we are on the same host as nova volume, the
# discovery makes the target so we don't need to
# run --op new
(out, err) = self._run_iscsiadm(iscsi_properties, ())
if err and err.strip() == "iscsiadm: no records found!":
self._run_iscsiadm(iscsi_properties, ('--op', 'new'))
# run --op new. Therefore, we check to see if the
# target exists, and if we get 255 (Not Found), then
# we run --op new
try:
self._run_iscsiadm(iscsi_properties, ())
except exception.ProcessExecutionError as exc:
if exc.exit_code == 255:
self._run_iscsiadm(iscsi_properties, ('--op', 'new'))
else:
raise

if iscsi_properties.get('auth_method'):
self._iscsiadm_update(iscsi_properties,
Expand Down

0 comments on commit a933e36

Please sign in to comment.