From 8b131919945e98bf59a1c3a9548a67756940b5a3 Mon Sep 17 00:00:00 2001
From: liuke2 <liuke2@huawei.com>
Date: Sat, 20 Feb 2016 17:02:50 +0800
Subject: [PATCH] Huawei: Creating hypermetro failed in the remote pool

Create the hypermetro failed when use the remote pools on the
huawei driver, the log print get pool id fail. The 'pool_id'
is not exist in the LUN property dictionary, so the 'pool_id'
should be modified to 'PARENTID' to save the remote pool id.

Closes-Bug:#1547798
Change-Id:Ic99531dad4fab5e22e295e19bbfa94c789247d93
---
 cinder/tests/unit/test_huawei_drivers.py   | 29 ++++++++++++++++++++++
 cinder/volume/drivers/huawei/hypermetro.py |  2 +-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py
index 2fa6cb5e3..68e428efe 100644
--- a/cinder/tests/unit/test_huawei_drivers.py
+++ b/cinder/tests/unit/test_huawei_drivers.py
@@ -2280,6 +2280,35 @@ class HuaweiISCSIDriverTestCase(test.TestCase):
                           self.driver.metro.create_hypermetro,
                           '2', param)
 
+    @mock.patch.object(rest_client.RestClient, 'get_all_pools',
+                       return_value=FAKE_STORAGE_POOL_RESPONSE)
+    @mock.patch.object(rest_client.RestClient, 'get_pool_info',
+                       return_value=FAKE_FIND_POOL_RESPONSE)
+    @mock.patch.object(rest_client.RestClient, 'create_lun',
+                       return_value={'CAPACITY': '2097152',
+                                     'DESCRIPTION': '2f0635',
+                                     'HEALTHSTATUS': '1',
+                                     'ALLOCTYPE': '1',
+                                     'WWN': '6643e8c1004c5f6723e9f454003',
+                                     'ID': '1',
+                                     'RUNNINGSTATUS': '27',
+                                     'NAME': '5mFHcBv4RkCcD'})
+    @mock.patch.object(rest_client.RestClient, 'get_hyper_domain_id',
+                       return_value='11')
+    @mock.patch.object(hypermetro.HuaweiHyperMetro, '_wait_volume_ready',
+                       return_value=True)
+    def test_create_hypermetro_remote_pool_parentid(self,
+                                                    mock_volume_ready,
+                                                    mock_hyper_domain,
+                                                    mock_create_lun,
+                                                    mock_pool_info,
+                                                    mock_all_pool_info):
+        param = {'TYPE': '11',
+                 'PARENTID': ''}
+        self.driver.metro.create_hypermetro('2', param)
+        lun_PARENTID = mock_create_lun.call_args[0][0]['PARENTID']
+        self.assertEqual(FAKE_FIND_POOL_RESPONSE['ID'], lun_PARENTID)
+
     @mock.patch.object(rest_client.RestClient, 'check_lun_exist',
                        return_value=True)
     @mock.patch.object(rest_client.RestClient, 'check_hypermetro_exist',
diff --git a/cinder/volume/drivers/huawei/hypermetro.py b/cinder/volume/drivers/huawei/hypermetro.py
index 1109822b9..d752fa6f7 100644
--- a/cinder/volume/drivers/huawei/hypermetro.py
+++ b/cinder/volume/drivers/huawei/hypermetro.py
@@ -45,7 +45,7 @@ class HuaweiHyperMetro(object):
                 raise exception.VolumeBackendAPIException(data=err_msg)
 
             # Create remote lun.
-            lun_params['pool_id'] = pool['ID']
+            lun_params['PARENTID'] = pool['ID']
             remotelun_info = self.rmt_client.create_lun(lun_params)
             remote_lun_id = remotelun_info['ID']
 
-- 
2.45.2