From 09c782f1147e4375ba824e298c0a78cd07d0e397 Mon Sep 17 00:00:00 2001
From: Wilson Liu <liuxinguo@huawei.com>
Date: Wed, 17 Feb 2016 12:48:17 +0800
Subject: [PATCH] Huawei: Manage volume fails due to lower array version

When we try to import an existing volume to cinder, we try
to find whether the volume already exists in a hypermetro.
But if the array version is lower than V3R3, the request
to find the hypermetro info will fail because array version
lower than V3R3 does not support hypermetro.

Closes-Bug: #1546375
Change-Id: Ia28e62f3924155e813df80f3c4932e3f0f10333e
---
 cinder/tests/unit/test_huawei_drivers.py      | 22 +++++++++++++++++++
 cinder/volume/drivers/huawei/huawei_driver.py |  5 ++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py
index e5b173ed6..3c275eac8 100644
--- a/cinder/tests/unit/test_huawei_drivers.py
+++ b/cinder/tests/unit/test_huawei_drivers.py
@@ -2413,6 +2413,28 @@ class HuaweiISCSIDriverTestCase(test.TestCase):
                                    test_volume, external_ref)
             self.assertIsNotNone(re.search('HyperMetroPair', ex.msg))
 
+    @mock.patch.object(rest_client.RestClient, 'get_hypermetro_pairs')
+    @mock.patch.object(rest_client.RestClient, 'rename_lun')
+    @mock.patch.object(rest_client.RestClient, 'get_lun_info',
+                       return_value={'CAPACITY': 2097152,
+                                     'ID': 'ID1',
+                                     'PARENTNAME': 'StoragePool001',
+                                     'HEALTHSTATUS': constants.STATUS_HEALTH})
+    @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name',
+                       return_value='ID1')
+    def test_manage_existing_with_lower_version(self, mock_get_by_name,
+                                                mock_get_info, mock_rename,
+                                                mock_get_hyper_pairs):
+        test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001',
+                       'id': '21ec7341-9256-497b-97d9-ef48edcf0635',
+                       'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf'}
+        mock_get_hyper_pairs.side_effect = (
+            exception.VolumeBackendAPIException(data='err'))
+        external_ref = {'source-name': 'LUN1'}
+        model_update = self.driver.manage_existing(test_volume,
+                                                   external_ref)
+        self.assertEqual({'provider_location': 'ID1'}, model_update)
+
     @ddt.data([[{'PRILUNID': 'ID1'}], []],
               [[{'PRILUNID': 'ID2'}], ['ID1', 'ID2']])
     @mock.patch.object(rest_client.RestClient, 'get_lun_info',
diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py
index 002612bba..2691cc09b 100644
--- a/cinder/volume/drivers/huawei/huawei_driver.py
+++ b/cinder/volume/drivers/huawei/huawei_driver.py
@@ -1081,9 +1081,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
         try:
             hypermetro_pairs = self.client.get_hypermetro_pairs()
         except exception.VolumeBackendAPIException:
-            msg = _("Failed to get HyperMetroPair.")
-            raise exception.ManageExistingInvalidReference(
-                existing_ref=external_ref, reason=msg)
+            hypermetro_pairs = []
+            LOG.debug("Can't get hypermetro info, pass the check.")
 
         for pair in hypermetro_pairs:
             if pair.get('LOCALOBJID') == lun_id:
-- 
2.45.2