From: Wilson Liu Date: Tue, 16 Feb 2016 03:24:23 +0000 (+0800) Subject: Match the ip more accurately in Huawei driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b2816f3b4ab605ed3c40dcacabd183f7cbe8b12d;p=openstack-build%2Fcinder-build.git Match the ip more accurately in Huawei driver Currently we didn't match the ip in the iqn accurately, now we will fix this in this patch. Closes-Bug: #1545914 Change-Id: I32232fcc6cad733b0dd8fa8c323297f6fbac3137 --- diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index 6ea717e6b..961a9eea2 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -3040,6 +3040,45 @@ class HuaweiISCSIDriverTestCase(test.TestCase): portg = self.driver.client.get_tgt_port_group('test_portg') self.assertIsNone(portg) + def test_get_tgt_iqn_from_rest_match(self): + match_res = { + 'data': [{ + 'TYPE': 249, + 'ID': '0+iqn.2006-08.com: 210048cee9d: 111.111.111.19,t,0x01' + }, { + 'TYPE': 249, + 'ID': '0+iqn.2006-08.com: 210048cee9d: 111.111.111.191,t,0x01' + }], + 'error': { + 'code': 0 + } + } + ip = '111.111.111.19' + expected_iqn = 'iqn.2006-08.com: 210048cee9d: 111.111.111.19' + self.mock_object(rest_client.RestClient, 'call', + mock.Mock(return_value=match_res)) + iqn = self.driver.client._get_tgt_iqn_from_rest(ip) + self.assertEqual(expected_iqn, iqn) + + def test_get_tgt_iqn_from_rest_mismatch(self): + match_res = { + 'data': [{ + 'TYPE': 249, + 'ID': '0+iqn.2006-08.com: 210048cee9d: 111.111.111.191,t,0x01' + }, { + 'TYPE': 249, + 'ID': '0+iqn.2006-08.com: 210048cee9d: 111.111.111.192,t,0x01' + }], + 'error': { + 'code': 0 + } + } + ip = '111.111.111.19' + self.mock_object(rest_client.RestClient, 'call', + mock.Mock(return_value=match_res)) + iqn = self.driver.client._get_tgt_iqn_from_rest(ip) + self.assertIsNone(iqn) + class FCSanLookupService(object): diff --git a/cinder/volume/drivers/huawei/rest_client.py b/cinder/volume/drivers/huawei/rest_client.py index 90e85eae9..1a3e005d8 100644 --- a/cinder/volume/drivers/huawei/rest_client.py +++ b/cinder/volume/drivers/huawei/rest_client.py @@ -15,6 +15,7 @@ import ast import json +import re import six import socket import time @@ -1244,11 +1245,14 @@ class RestClient(object): if result['error']['code'] != 0: LOG.warning(_LW("Can't find target iqn from rest.")) return target_iqn - + ip_pattern = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') if 'data' in result: for item in result['data']: - if target_ip in item['ID']: - target_iqn = item['ID'] + ips = re.findall(ip_pattern, item['ID']) + for ip in ips: + if target_ip == ip: + target_iqn = item['ID'] + break if not target_iqn: LOG.warning(_LW("Can't find target iqn from rest."))