Browse Source

Accept ISCSI_ERR_NO_OBJS_FOUND from iscsiadm

iscsiadm exits with code 21 (ISCSI_ERR_NO_OBJS_FOUND) when no nodes
exist. We must accept this as an empty result when attempting to get
node startup info, instead of producing a ProcessExecutionError.

Change-Id: I55f4b3b075bd7779e96777dee64bf577c45fddf1
Closes-Bug: 1756206
changes/04/554704/3 2.4.0
iain MacDonnell 4 years ago
parent
commit
296887a59e
  1. 5
      os_brick/initiator/connectors/iscsi.py
  2. 14
      os_brick/tests/initiator/connectors/test_iscsi.py

5
os_brick/initiator/connectors/iscsi.py

@ -1102,9 +1102,12 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
return (out, err)
def _get_node_startup_values(self, connection_properties):
# Exit code 21 (ISCSI_ERR_NO_OBJS_FOUND) occurs when no nodes
# exist - must consider this an empty (successful) result.
out, __ = self._run_iscsiadm_bare(
['-m', 'node', '--op', 'show', '-p',
connection_properties['target_portal']]) or ""
connection_properties['target_portal']],
check_exit_code=(0, 21)) or ""
node_values = out.strip()
node_values = node_values.split("\n")
iqn = None

14
os_brick/tests/initiator/connectors/test_iscsi.py

@ -1496,6 +1496,20 @@ Setting up iSCSI targets: unused
iqn3: node_startup3}
self.assertEqual(node_startups, expected_node_startups)
@mock.patch.object(iscsi.ISCSIConnector, '_execute')
def test_get_node_startup_values_no_nodes(self, exec_mock):
connection_properties = {'target_portal': 'ip1:port1'}
no_nodes_output = ''
no_nodes_err = 'iscsiadm: No records found\n'
exec_mock.return_value = (no_nodes_output, no_nodes_err)
res = self.connector._get_node_startup_values(connection_properties)
self.assertEqual({}, res)
exec_mock.assert_called_once_with(
'iscsiadm', '-m', 'node', '--op', 'show', '-p',
connection_properties['target_portal'],
root_helper=self.connector._root_helper, run_as_root=True,
check_exit_code=(0, 21))
@mock.patch.object(iscsi.ISCSIConnector, '_get_node_startup_values')
@mock.patch.object(iscsi.ISCSIConnector, '_iscsiadm_update')
def test_recover_node_startup_values(self, iscsiadm_update_mock,

Loading…
Cancel
Save