]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Huawei: Check before delete host
authorWilson Liu <liuxinguo@huawei.com>
Mon, 22 Feb 2016 05:03:26 +0000 (13:03 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Wed, 9 Mar 2016 14:19:06 +0000 (22:19 +0800)
Currently we delete the host without checking
whether the host already belongs to a host
group. If a host already belongs to a hostgroup,
an error will occur. So we should do the check
before delete it.

Closed-Bug: #1548183
Change-Id: Ibfa0bb4930e6d932c332aacb19ae81f9daad55ce

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

index e599fad5050590f04f5c346965fdadf1a5fd92a3..350b9616e4db8053ab0733ff6dc9caeac961ecb5 100644 (file)
@@ -3523,6 +3523,24 @@ class HuaweiFCDriverTestCase(test.TestCase):
         data = {"NAME": new_name, "DESCRIPTION": des}
         mock_call.assert_called_once_with(url, data, "PUT")
 
+    @mock.patch.object(rest_client.RestClient, 'call',
+                       return_value={"data": {}})
+    def test_is_host_associated_to_hostgroup_no_data(self, mock_call):
+        res = self.driver.client.is_host_associated_to_hostgroup('1')
+        self.assertFalse(res)
+
+    @mock.patch.object(rest_client.RestClient, 'call',
+                       return_value={"data": {'ISADD2HOSTGROUP': 'true'}})
+    def test_is_host_associated_to_hostgroup_true(self, mock_call):
+        res = self.driver.client.is_host_associated_to_hostgroup('1')
+        self.assertTrue(res)
+
+    @mock.patch.object(rest_client.RestClient, 'call',
+                       return_value={"data": {'ISADD2HOSTGROUP': 'false'}})
+    def test_is_host_associated_to_hostgroup_false(self, mock_call):
+        res = self.driver.client.is_host_associated_to_hostgroup('1')
+        self.assertFalse(res)
+
 
 class HuaweiConfTestCase(test.TestCase):
     def setUp(self):
index 8ad8c80b3505c8eff321ced1340d2a0f9b789299..aa3324628044295e20e8a32e87055a6a3666dc20 100644 (file)
@@ -1665,7 +1665,8 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver):
                         self.client.get_host_fc_initiators(host_id))
                     iqns_in_host = (
                         self.client.get_host_iscsi_initiators(host_id))
-                    if not wwns_in_host and not iqns_in_host:
+                    if not (wwns_in_host or iqns_in_host or
+                       self.client.is_host_associated_to_hostgroup(host_id)):
                         self.client.remove_host(host_id)
 
                     msg = _('No FC initiator can be added to host.')
index 2023b55538524ab55ad8eb65f8801d3f70535f95..3d6a1b4eb54f3a161df989a8f64784f5b0df5efa 100644 (file)
@@ -2094,3 +2094,11 @@ class RestClient(object):
 
         msg = _('Set pair secondary access error.')
         self._assert_rest_result(result, msg)
+
+    def is_host_associated_to_hostgroup(self, host_id):
+        url = "/host/" + host_id
+        result = self.call(url, None, "GET")
+        data = result.get('data')
+        if data is not None:
+            return data.get('ISADD2HOSTGROUP') == 'true'
+        return False