From a933e3628ba8cc2fb985665a724799ee0a58aa16 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 7 Feb 2012 11:23:59 -0800 Subject: Check return code instead of output for iscsiadm * iscsiadm returns 255 on no records * Refixes bug 922232 Change-Id: If177c3c79c6ad974c2bed0ad72a62e956af451e0 --- nova/virt/libvirt/volume.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py index 2bcf60d72..b1e609690 100644 --- a/nova/virt/libvirt/volume.py +++ b/nova/virt/libvirt/volume.py @@ -108,10 +108,16 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver): 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, -- cgit