From 36cee8f1c04b9d9928cf4819f76e5d20ea50fad0 Mon Sep 17 00:00:00 2001
From: liuke2 <liuke2@huawei.com>
Date: Tue, 16 Feb 2016 20:12:08 +0800
Subject: [PATCH] Huawei: Judgement failure when creating hypermetro

Huawei hypermetro is created in the absence of remote pools, it has
the judgement failure which will lead to incorrect logs. We cannot
find the location of the error according to the log.

Closes-Bug:#1545898
Change-Id:Ic99531dad4fab5e22e295e19bbfa94c7892e5635
---
 cinder/tests/unit/test_huawei_drivers.py   | 14 ++++++++++++++
 cinder/volume/drivers/huawei/hypermetro.py |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py
index 6f2bef9fe45..c71879fa8bc 100644
--- a/cinder/tests/unit/test_huawei_drivers.py
+++ b/cinder/tests/unit/test_huawei_drivers.py
@@ -2323,6 +2323,20 @@ class HuaweiISCSIDriverTestCase(test.TestCase):
                           self.driver.create_volume, hyper_volume)
         mock_delete_lun.assert_called_with('1')
 
+    @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={})
+    def test_create_hypermetro_remote_pool_none_fail(self,
+                                                     mock_pool_info,
+                                                     mock_all_pool_info):
+        param = {'TYPE': '11',
+                 'PARENTID': ''}
+        self.driver.client.login()
+        self.assertRaises(exception.VolumeBackendAPIException,
+                          self.driver.metro.create_hypermetro,
+                          '2', param)
+
     @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 0db361334ff..3031433c736 100644
--- a/cinder/volume/drivers/huawei/hypermetro.py
+++ b/cinder/volume/drivers/huawei/hypermetro.py
@@ -40,6 +40,11 @@ class HuaweiHyperMetro(object):
             config_pool = self.configuration.metro_storage_pools
             remote_pool = self.rmt_client.get_all_pools()
             pool = self.rmt_client.get_pool_info(config_pool, remote_pool)
+            if not pool:
+                err_msg = _("Remote pool cannot be found.")
+                LOG.error(err_msg)
+                raise exception.VolumeBackendAPIException(data=err_msg)
+
             # Create remote lun.
             lun_params['pool_id'] = pool['ID']
             remotelun_info = self.rmt_client.create_lun(lun_params)