From 0e39714312c2a380eb3e9e74a9b0e509b77036df Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 23 Jun 2015 14:50:51 +0800 Subject: [PATCH] Fix manage_existing function in infortrend driver 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 | 38 ++++++++++++++++++- .../infortrend/eonstor_ds_cli/common_cli.py | 24 +++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/cinder/tests/unit/test_infortrend_common.py b/cinder/tests/unit/test_infortrend_common.py index 4ec5e1fc7..efdcc9c2c 100644 --- a/cinder/tests/unit/test_infortrend_common.py +++ b/cinder/tests/unit/test_infortrend_common.py @@ -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): diff --git a/cinder/volume/drivers/infortrend/eonstor_ds_cli/common_cli.py b/cinder/volume/drivers/infortrend/eonstor_ds_cli/common_cli.py index 6f3f7e60a..52a21bf3c 100644 --- a/cinder/volume/drivers/infortrend/eonstor_ds_cli/common_cli.py +++ b/cinder/volume/drivers/infortrend/eonstor_ds_cli/common_cli.py @@ -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: -- 2.45.2