]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix manage_existing function in infortrend driver
authorLee <jessy1092@gmail.com>
Tue, 23 Jun 2015 06:50:51 +0000 (14:50 +0800)
committerLee <jessy1092@gmail.com>
Wed, 24 Jun 2015 06:42:29 +0000 (14:42 +0800)
For infortrend driver, it should update provider_location
information (partition id and system id).

Otherwise, the volume would miss the infortrend partition
after importing partition.

Change-Id: Icc34d2e6c27bca6580449aac5a54893b89dcd261

cinder/tests/unit/test_infortrend_common.py
cinder/volume/drivers/infortrend/eonstor_ds_cli/common_cli.py

index 4ec5e1fc7f98b683e798d417ed4e7e4222991931..efdcc9c2c8d63a26370e4743abef19d9f6ace83c 100644 (file)
@@ -1760,15 +1760,22 @@ class InfortrendiSCSICommonTestCase(InfortrendTestCass):
         test_pool = self.cli_data.fake_lv_id[0]
         test_partition_id = self.cli_data.fake_partition_id[2]
         test_ref_volume_id = test_ref_volume['source-id'].replace('-', '')
+        test_model_update = {
+            'provider_location': 'system_id^%s@partition_id^%s' % (
+                int(self.cli_data.fake_system_id[0], 16),
+                test_partition_id),
+        }
 
         mock_commands = {
             'ShowPartition': self.cli_data.get_test_show_partition_detail(
                 'cinder-unmanaged-%s' % test_ref_volume_id[:-17], test_pool),
             'SetPartition': SUCCEED,
+            'ShowDevice': self.cli_data.get_test_show_device(),
         }
         self._driver_setup(mock_commands)
 
-        self.driver.manage_existing(test_volume, test_ref_volume)
+        model_update = self.driver.manage_existing(
+            test_volume, test_ref_volume)
 
         expect_cli_cmd = [
             mock.call('SetPartition', test_partition_id,
@@ -1776,6 +1783,7 @@ class InfortrendiSCSICommonTestCase(InfortrendTestCass):
         ]
         self._assert_cli_has_calls(expect_cli_cmd)
         self.assertEqual(1, log_info.call_count)
+        self.assertDictMatch(model_update, test_model_update)
 
     def test_manage_existing_rename_fail(self):
 
@@ -1797,6 +1805,24 @@ class InfortrendiSCSICommonTestCase(InfortrendTestCass):
             test_volume,
             test_ref_volume)
 
+    def test_manage_existing_with_part_not_found(self):
+
+        test_volume = self.cli_data.test_volume
+        test_ref_volume = self.cli_data.test_ref_volume
+
+        mock_commands = {
+            'ShowPartition':
+                self.cli_data.get_test_show_partition_detail(),
+            'SetPartition': SUCCEED,
+        }
+        self._driver_setup(mock_commands)
+
+        self.assertRaises(
+            exception.ManageExistingInvalidReference,
+            self.driver.manage_existing,
+            test_volume,
+            test_ref_volume)
+
     @mock.patch.object(common_cli.LOG, 'info')
     def test_manage_existing_with_import(self, log_info):
 
@@ -1804,15 +1830,22 @@ class InfortrendiSCSICommonTestCase(InfortrendTestCass):
         test_ref_volume = self.cli_data.test_ref_volume_with_import
         test_pool = self.cli_data.fake_lv_id[0]
         test_partition_id = self.cli_data.fake_partition_id[2]
+        test_model_update = {
+            'provider_location': 'system_id^%s@partition_id^%s' % (
+                int(self.cli_data.fake_system_id[0], 16),
+                test_partition_id),
+        }
 
         mock_commands = {
             'ShowPartition': self.cli_data.get_test_show_partition_detail(
                 test_ref_volume['source-name'], test_pool),
             'SetPartition': SUCCEED,
+            'ShowDevice': self.cli_data.get_test_show_device(),
         }
         self._driver_setup(mock_commands)
 
-        self.driver.manage_existing(test_volume, test_ref_volume)
+        model_update = self.driver.manage_existing(
+            test_volume, test_ref_volume)
 
         expect_cli_cmd = [
             mock.call('SetPartition', test_partition_id,
@@ -1820,6 +1853,7 @@ class InfortrendiSCSICommonTestCase(InfortrendTestCass):
         ]
         self._assert_cli_has_calls(expect_cli_cmd)
         self.assertEqual(1, log_info.call_count)
+        self.assertDictMatch(model_update, test_model_update)
 
     @mock.patch.object(common_cli.LOG, 'info')
     def test_unmanage(self, log_info):
index 6f3f7e60a735436fb77ea85a56298e3e39f69cc3..52a21bf3cee4d439e74b238ff05a8535972d3284 100644 (file)
@@ -1731,6 +1731,12 @@ class InfortrendCommon(object):
         volume_name = self._get_existing_volume_ref_name(ref)
         part_entry = self._get_latter_volume_dict(volume_name)
 
+        if part_entry is None:
+            msg = _('Specified logical volume does not exist.')
+            LOG.error(msg)
+            raise exception.ManageExistingInvalidReference(
+                existing_ref=ref, reason=msg)
+
         rc, map_info = self._execute('ShowMap', 'part=%s' % part_entry['ID'])
 
         if len(map_info) != 0:
@@ -1746,11 +1752,27 @@ class InfortrendCommon(object):
 
         part_entry = self._get_latter_volume_dict(volume_name)
 
+        if part_entry is None:
+            msg = _('Specified logical volume does not exist.')
+            LOG.error(msg)
+            raise exception.ManageExistingInvalidReference(
+                existing_ref=ref, reason=msg)
+
         self._execute('SetPartition', part_entry['ID'], 'name=%s' % volume_id)
 
+        model_dict = {
+            'system_id': self._get_system_id(self.ip),
+            'partition_id': part_entry['ID'],
+        }
+        model_update = {
+            "provider_location": self._concat_provider_location(model_dict),
+        }
+
         LOG.info(_LI('Rename Volume %(volume_id)s completed.'), {
             'volume_id': volume['id']})
 
+        return model_update
+
     def _get_existing_volume_ref_name(self, ref):
         volume_name = None
         if 'source-name' in ref:
@@ -1798,7 +1820,7 @@ class InfortrendCommon(object):
         rc, part_list = self._execute('ShowPartition', '-l')
 
         latest_timestamps = 0
-        ref_dict = {}
+        ref_dict = None
 
         for entry in part_list:
             if entry['Name'] == volume_name: