The validation of iscsi session should be case insensitive

The validation of iscsi session should be case insensitive since IPv6
address is case insensitive. If the portal address are all lower cases,
and the address get from 'iscsiadm -m session' contain upper cases,
the validation of iscsi session will failed, the loop will be endless.

Change-Id: Ief5108e40f13cc53d8d9e9c5d1a5054f58f72aa0
Closes-bug: #1793627
(cherry picked from commit 8782c4accf)
This commit is contained in:
Yong Huang 2018-09-20 16:26:57 -04:00
parent 67cd70981c
commit e01e5db822
2 changed files with 32 additions and 1 deletions

View File

@ -1040,7 +1040,7 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
for s in sessions:
# Found our session, return session_id
if (s[0] in self.VALID_SESSIONS_PREFIX and
portal == s[2] and s[4] == target_iqn):
portal.lower() == s[2].lower() and s[4] == target_iqn):
return s[1], manual_scan
try:

View File

@ -1003,6 +1003,37 @@ Setting up iSCSI targets: unused
self.assertListEqual(expected_cmds, actual_cmds)
self.assertEqual(2, get_sessions_mock.call_count)
@mock.patch.object(iscsi.ISCSIConnector, '_get_iscsi_sessions_full')
def test_connect_to_iscsi_portal_ip_case_insensitive(self,
get_sessions_mock):
"""Connect creating node and session."""
session = 'session2'
get_sessions_mock.side_effect = [
[('tcp:', 'session1', 'iP1:port1', '1', 'tgt')],
[('tcp:', 'session1', 'Ip1:port1', '1', 'tgt'),
('tcp:', session, 'IP1:port1', '-1', 'tgt1')]
]
with mock.patch.object(self.connector, '_execute') as exec_mock:
exec_mock.side_effect = [('', 'error'), ('', None),
('', None), ('', None),
('', None)]
res = self.connector._connect_to_iscsi_portal(self.CON_PROPS)
# True refers to "manual scans", since the call to update
# node.session.scan didn't fail they are set to manual
self.assertEqual((session, True), res)
prefix = 'iscsiadm -m node -T tgt1 -p ip1:port1'
expected_cmds = [
prefix,
prefix + ' --interface default --op new',
prefix + ' --op update -n node.session.scan -v manual',
prefix + ' --login',
prefix + ' --op update -n node.startup -v automatic'
]
actual_cmds = [' '.join(args[0]) for args in exec_mock.call_args_list]
self.assertListEqual(expected_cmds, actual_cmds)
self.assertEqual(2, get_sessions_mock.call_count)
@mock.patch.object(iscsi.ISCSIConnector, '_get_iscsi_sessions_full')
def test_connect_to_iscsi_portal_all_exists_chap(self, get_sessions_mock):
"""Node and session already exists and we use chap authentication."""