Huawei: Check before add initiator
Currently we just check whether the iSCSI initiator has been added to host, but not check whether the host is our expected host or other host. Closes-Bug: #1580933 Change-Id: I6ea891431e36d6536d6c77dedba41bc747883b08
This commit is contained in:
@@ -863,6 +863,16 @@ FAKE_ISCSI_INITIATOR_RESPONSE = """
|
||||
"RUNNINGSTATUS":"28",
|
||||
"TYPE":222,
|
||||
"USECHAP":"true"
|
||||
},
|
||||
{
|
||||
"ISFREE":"true",
|
||||
"ID":"ini-1"
|
||||
},
|
||||
{
|
||||
"ISFREE":"false",
|
||||
"ID":"ini-2",
|
||||
"PARENTNAME":"Host2",
|
||||
"PARENTID":"2"
|
||||
}]
|
||||
}
|
||||
"""
|
||||
@@ -1340,7 +1350,7 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/iscsidevicename'] = (
|
||||
FAKE_GET_ISCSI_DEVICE_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator?range=[0-256]/GET'] = (
|
||||
FAKE_COMMON_SUCCESS_RESPONSE)
|
||||
FAKE_ISCSI_INITIATOR_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator/'] = (
|
||||
FAKE_ISCSI_INITIATOR_RESPONSE)
|
||||
@@ -4534,6 +4544,17 @@ class HuaweiFCDriverTestCase(HuaweiTestBase):
|
||||
model_update['status'],
|
||||
"Consistency Group created failed")
|
||||
|
||||
def test_is_initiator_associated_to_host_raise(self):
|
||||
self.assertRaises(exception.VolumeBackendAPIException,
|
||||
self.driver.client.is_initiator_associated_to_host,
|
||||
'ini-2', '1')
|
||||
|
||||
def test_is_initiator_associated_to_host_true(self):
|
||||
ret = self.driver.client.is_initiator_associated_to_host('ini-1', '1')
|
||||
self.assertFalse(ret)
|
||||
ret = self.driver.client.is_initiator_associated_to_host('ini-2', '2')
|
||||
self.assertTrue(ret)
|
||||
|
||||
|
||||
class HuaweiConfTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -1987,7 +1987,8 @@ class HuaweiISCSIDriver(HuaweiBaseDriver, driver.ISCSIDriver):
|
||||
self.client.delete_lungroup_mapping_view(view_id,
|
||||
lungroup_id)
|
||||
self.client.delete_lungroup(lungroup_id)
|
||||
if self.client.is_initiator_associated_to_host(initiator_name):
|
||||
if self.client.is_initiator_associated_to_host(initiator_name,
|
||||
host_id):
|
||||
self.client.remove_iscsi_from_host(initiator_name)
|
||||
hostgroup_name = constants.HOSTGROUP_PREFIX + host_id
|
||||
hostgroup_id = self.client.find_hostgroup(hostgroup_name)
|
||||
|
||||
@@ -497,7 +497,7 @@ class RestClient(object):
|
||||
added = self._initiator_is_added_to_array(initiator_name)
|
||||
if not added:
|
||||
self._add_initiator_to_array(initiator_name)
|
||||
if not self.is_initiator_associated_to_host(initiator_name):
|
||||
if not self.is_initiator_associated_to_host(initiator_name, host_id):
|
||||
self._associate_initiator_to_host(initiator_name,
|
||||
host_id)
|
||||
|
||||
@@ -763,17 +763,25 @@ class RestClient(object):
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_initiator_associated_to_host(self, ininame):
|
||||
def is_initiator_associated_to_host(self, ininame, host_id):
|
||||
"""Check whether the initiator is associated to the host."""
|
||||
url = "/iscsi_initiator?range=[0-256]"
|
||||
result = self.call(url, None, "GET")
|
||||
self._assert_rest_result(
|
||||
result, _('Check initiator associated to host error.'))
|
||||
|
||||
if 'data' in result:
|
||||
for item in result['data']:
|
||||
if item['ID'] == ininame and item['ISFREE'] == "true":
|
||||
for item in result.get('data'):
|
||||
if item['ID'] == ininame:
|
||||
if item['ISFREE'] == "true":
|
||||
return False
|
||||
if item['PARENTID'] == host_id:
|
||||
return True
|
||||
else:
|
||||
msg = (_("Initiator %(ini)s has been added to another "
|
||||
"host %(host)s.") % {"ini": ininame,
|
||||
"host": item['PARENTNAME']})
|
||||
LOG.error(msg)
|
||||
raise exception.VolumeBackendAPIException(data=msg)
|
||||
return True
|
||||
|
||||
def _add_initiator_to_array(self, initiator_name):
|
||||
|
||||
Reference in New Issue
Block a user