From: Navneet Singh Date: Sun, 21 Sep 2014 22:48:48 +0000 (+0530) Subject: NetApp fix vol migration unusability X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c61577773c6da7dbe9d21c9f25962192119ce165;p=openstack-build%2Fcinder-build.git NetApp fix vol migration unusability This patch fixes the volume migration related issue in which the volume became unusable after successfull inbound migration due to volume id usage instead of name_id. Closes-bug: #1370098 Change-Id: Iacb14ea07890859b5cf8a27c150aa5f6e8a98777 --- diff --git a/cinder/tests/test_netapp_eseries_iscsi.py b/cinder/tests/test_netapp_eseries_iscsi.py index 4aae0d14c..a86429ed5 100644 --- a/cinder/tests/test_netapp_eseries_iscsi.py +++ b/cinder/tests/test_netapp_eseries_iscsi.py @@ -596,7 +596,7 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): volume = {'id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'size': 1, 'volume_name': 'lun1', 'host': 'hostname@backend#DDP', 'os_type': 'linux', 'provider_location': 'lun1', - 'id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', + 'name_id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'provider_auth': 'provider a b', 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} @@ -609,14 +609,14 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): volume_sec = {'id': 'b6c01641-8955-4917-a5e3-077147478575', 'size': 2, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'lun1', - 'id': 'b6c01641-8955-4917-a5e3-077147478575', + 'name_id': 'b6c01641-8955-4917-a5e3-077147478575', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} volume_clone = {'id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'size': 3, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_sm', - 'id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', + 'name_id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', @@ -624,7 +624,7 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): volume_clone_large = {'id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'size': 6, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_lg', - 'id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', + 'name_id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', @@ -686,11 +686,14 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): self.driver.delete_volume(self.volume) def test_create_vol_snapshot_destroy(self): + self.driver.db = mock.Mock( + volume_get=mock.Mock(return_value=self.volume)) self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot(self.volume_sec, self.snapshot) self.driver.delete_snapshot(self.snapshot) self.driver.delete_volume(self.volume) + self.assertEqual(1, self.driver.db.volume_get.call_count) def test_map_unmap(self): self.driver.create_volume(self.volume) @@ -749,8 +752,11 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): self.driver.delete_volume(self.volume) def test_cloned_volume_destroy(self): + self.driver.db = mock.Mock( + volume_get=mock.Mock(return_value=self.volume)) self.driver.create_volume(self.volume) - self.driver.create_cloned_volume(self.snapshot, self.volume) + self.driver.create_cloned_volume(self.volume_sec, self.volume) + self.assertEqual(1, self.driver.db.volume_get.call_count) self.driver.delete_volume(self.volume) def test_map_by_creating_host(self): @@ -766,19 +772,25 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): self.driver.get_volume_stats(refresh=True) def test_create_vol_snapshot_diff_size_resize(self): + self.driver.db = mock.Mock( + volume_get=mock.Mock(return_value=self.volume)) self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot( self.volume_clone, self.snapshot) + self.assertEqual(1, self.driver.db.volume_get.call_count) self.driver.delete_snapshot(self.snapshot) self.driver.delete_volume(self.volume) def test_create_vol_snapshot_diff_size_subclone(self): + self.driver.db = mock.Mock( + volume_get=mock.Mock(return_value=self.volume)) self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot( self.volume_clone_large, self.snapshot) self.driver.delete_snapshot(self.snapshot) + self.assertEqual(1, self.driver.db.volume_get.call_count) self.driver.delete_volume(self.volume) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', @@ -786,14 +798,14 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): def test_get_pool(self): self.driver._objects['pools'] = [{'volumeGroupRef': 'fake_ref', 'label': 'ddp1'}] - pool = self.driver.get_pool({'id': 'fake-uuid'}) + pool = self.driver.get_pool({'name_id': 'fake-uuid'}) self.assertEqual(pool, 'ddp1') @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', mock.Mock(return_value={'volumeGroupRef': 'fake_ref'})) def test_get_pool_no_pools(self): self.driver._objects['pools'] = [] - pool = self.driver.get_pool({'id': 'fake-uuid'}) + pool = self.driver.get_pool({'name_id': 'fake-uuid'}) self.assertEqual(pool, None) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', @@ -801,7 +813,7 @@ class NetAppEseriesISCSIDriverTestCase(test.TestCase): def test_get_pool_no_match(self): self.driver._objects['pools'] = [{'volumeGroupRef': 'fake_ref2', 'label': 'ddp2'}] - pool = self.driver.get_pool({'id': 'fake-uuid'}) + pool = self.driver.get_pool({'name_id': 'fake-uuid'}) self.assertEqual(pool, None) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_create_volume', diff --git a/cinder/volume/drivers/netapp/eseries/iscsi.py b/cinder/volume/drivers/netapp/eseries/iscsi.py index be26cbbe8..2df3bc20c 100644 --- a/cinder/volume/drivers/netapp/eseries/iscsi.py +++ b/cinder/volume/drivers/netapp/eseries/iscsi.py @@ -94,6 +94,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): def do_setup(self, context): """Any initialization the volume driver does while starting.""" + self.context = context na_utils.check_flags(self.REQUIRED_FLAGS, self.configuration) port = self.configuration.netapp_server_port @@ -304,7 +305,8 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): if vol.get('label') == label: self._cache_volume(vol) return self._get_cached_volume(label) - raise exception.NetAppDriverException(_("Volume %s not found."), uid) + raise exception.NetAppDriverException(_("Volume %(uid)s not found.") + % {'uid': uid}) def _get_cached_volume(self, label): vol_id = self._objects['volumes']['label_ref'][label] @@ -339,7 +341,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): :param volume: The volume hosted by the driver. :return: Name of the pool where given volume is hosted. """ - eseries_volume = self._get_volume(volume['id']) + eseries_volume = self._get_volume(volume['name_id']) for pool in self._objects['pools']: if pool['volumeGroupRef'] == eseries_volume['volumeGroupRef']: return pool['label'] @@ -358,7 +360,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): msg = _("Pool is not available in the volume host field.") raise exception.InvalidHost(reason=msg) - eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['id']) + eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['name_id']) # get size of the requested volume creation size_gb = int(volume['size']) @@ -493,7 +495,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): def delete_volume(self, volume): """Deletes a volume.""" try: - vol = self._get_volume(volume['id']) + vol = self._get_volume(volume['name_id']) self._delete_volume(vol['label']) except KeyError: LOG.info(_LI("Volume %s already deleted."), volume['id']) @@ -510,7 +512,8 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): """Creates a snapshot.""" snap_grp, snap_image = None, None snapshot_name = utils.convert_uuid_to_es_fmt(snapshot['id']) - vol = self._get_volume(snapshot['volume_id']) + os_vol = self.db.volume_get(self.context, snapshot['volume_id']) + vol = self._get_volume(os_vol['name_id']) vol_size_gb = int(vol['totalSizeInBytes']) / units.Gi pools = self._get_sorted_avl_storage_pools(vol_size_gb) try: @@ -552,7 +555,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): def initialize_connection(self, volume, connector): """Allow connection to connector and return connection info.""" initiator_name = connector['initiator'] - vol = self._get_latest_volume(volume['id']) + vol = self._get_latest_volume(volume['name_id']) iscsi_details = self._get_iscsi_service_details() iscsi_det = self._get_iscsi_portal_for_vol(vol, iscsi_details) mapping = self._map_volume_to_host(vol, initiator_name) @@ -712,7 +715,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): def terminate_connection(self, volume, connector, **kwargs): """Disallow connection from connector.""" - vol = self._get_volume(volume['id']) + vol = self._get_volume(volume['name_id']) host = self._get_host_with_port(connector['initiator']) mapping = self._get_cached_vol_mapping_for_host(vol, host) self._client.delete_volume_mapping(mapping['lunMappingRef']) @@ -781,7 +784,7 @@ class NetAppEseriesISCSIDriver(driver.ISCSIDriver): def extend_volume(self, volume, new_size): """Extend an existing volume to the new size.""" stage_1, stage_2 = 0, 0 - src_vol = self._get_volume(volume['id']) + src_vol = self._get_volume(volume['name_id']) src_label = src_vol['label'] stage_label = 'tmp-%s' % utils.convert_uuid_to_es_fmt(uuid.uuid4()) extend_vol = {'id': uuid.uuid4(), 'size': new_size}