Merge "Filter valid FC initiator while FC attaching"

This commit is contained in:
Zuul 2017-11-25 16:23:43 +00:00 committed by Gerrit Code Review
commit 7511ff461d
5 changed files with 42 additions and 0 deletions

View File

@ -1628,6 +1628,12 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?range=[0-256]&PARENTID=1/GET'] = (
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?PARENTTYPE=21&PARENTID=1/GET'] = (
FAKE_GET_FC_PORT_RESPONSE)
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator/count/GET'] = '''
{"data":{"COUNT":"2"},"error":{"code":0}}'''
MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?range=[0-100]/GET'] = (
FAKE_FC_INFO_RESPONSE)
MAP_COMMAND_TO_FAKE_RESPONSE['/SMARTCACHEPARTITION/0/GET'] = (
FAKE_SMARTCACHEPARTITION_RESPONSE)
@ -5343,6 +5349,10 @@ class HuaweiFCDriverTestCase(HuaweiTestBase):
wwns = self.driver.client.get_online_free_wwns()
self.assertEqual(['1'], wwns)
def test_get_fc_initiator_on_array(self):
wwns = self.driver.client.get_fc_initiator_on_array()
self.assertListEqual(["10000090fa0d6754", "10000090fa0d6755"], wwns)
@mock.patch.object(rest_client.RestClient, 'call',
return_value={"data": {"ID": 1}, "error": {"code": 0}})
def test_rename_lun(self, mock_call):

View File

@ -129,3 +129,5 @@ LUN_COPY_SPEED_TYPES = (
LUN_COPY_SPEED_HIGH,
LUN_COPY_SPEED_HIGHEST
) = ('1', '2', '3', '4')
MAX_QUERY_COUNT = 100

View File

@ -2148,6 +2148,9 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver):
online_wwns_in_host = (
self.client.get_host_online_fc_initiators(host_id))
online_free_wwns = self.client.get_online_free_wwns()
fc_initiators_on_array = self.client.get_fc_initiator_on_array()
wwns = [i for i in wwns if i in fc_initiators_on_array]
for wwn in wwns:
if (wwn not in online_wwns_in_host
and wwn not in online_free_wwns):

View File

@ -126,6 +126,9 @@ class HuaweiHyperMetro(object):
online_wwns_in_host = (
self.rmt_client.get_host_online_fc_initiators(host_id))
online_free_wwns = self.rmt_client.get_online_free_wwns()
fc_initiators_on_array = self.rmt_client.get_fc_initiator_on_array()
wwns = [i for i in wwns if i in fc_initiators_on_array]
for wwn in wwns:
if (wwn not in online_wwns_in_host
and wwn not in online_free_wwns):

View File

@ -1114,6 +1114,30 @@ class RestClient(object):
return wwns
def _get_fc_initiator_count(self):
url = '/fc_initiator/count'
result = self.call(url, None, "GET")
self._assert_rest_result(result, _('Get fc initiator count error.'))
return int(result['data']['COUNT'])
def get_fc_initiator_on_array(self):
count = self._get_fc_initiator_count()
if count <= 0:
return []
fc_initiators = []
for i in range((count - 1) // constants.MAX_QUERY_COUNT + 1):
url = '/fc_initiator?range=[%d-%d]' % (
i * constants.MAX_QUERY_COUNT,
(i + 1) * constants.MAX_QUERY_COUNT)
result = self.call(url, None, "GET")
msg = _('Get FC initiators from array error.')
self._assert_rest_result(result, msg)
for item in result.get('data', []):
fc_initiators.append(item['ID'])
return fc_initiators
def add_fc_port_to_host(self, host_id, wwn):
"""Add a FC port to the host."""
url = "/fc_initiator/" + wwn