]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Match the ip more accurately in Huawei driver
authorWilson Liu <liuxinguo@huawei.com>
Tue, 16 Feb 2016 03:24:23 +0000 (11:24 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Sat, 27 Feb 2016 01:51:43 +0000 (09:51 +0800)
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

cinder/tests/unit/test_huawei_drivers.py
cinder/volume/drivers/huawei/rest_client.py

index 6ea717e6b6daef3f651d5ab0bfea54669a9dae8c..961a9eea27d17f4d5e0a97c4b637cc697d8c6bee 100644 (file)
@@ -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):
 
index 90e85eae95b31164fc1fa2983588576100cb66ad..1a3e005d8ab71df2ea62685274e74cd2110eb91d 100644 (file)
@@ -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."))