[NetApp] Fix deepcopy of sqlalchemy objects inside the driver
This patch fix a sqlalchemy object copy made in the driver that can raise a 'DetachedInstanceError' exception, depending on changes made in the DB model. A simple copy is being made instead, to have a new share object with share server information inside it. Change-Id: I5fef50a17bc72ba66a3a9d6f786742bcb5745d7b Signed-off-by: Douglas Viroel <viroel@gmail.com>
This commit is contained in:
parent
0d8f415e86
commit
1269a8669d
manila
share/drivers/netapp/dataontap/cluster_mode
tests/share/drivers/netapp/dataontap/cluster_mode
@ -569,9 +569,8 @@ class NetAppCmodeFileStorageLibrary(object):
|
||||
}
|
||||
# NOTE(dviroel): Data Motion functions access share's 'share_server'
|
||||
# attribute to get vserser information.
|
||||
dest_share = copy.deepcopy(share.to_dict())
|
||||
dest_share['share_server'] = (share_server.to_dict()
|
||||
if share_server else None)
|
||||
dest_share = copy.copy(share.to_dict())
|
||||
dest_share['share_server'] = share_server
|
||||
|
||||
dm_session = data_motion.DataMotionSession()
|
||||
# Source host info
|
||||
|
@ -20,7 +20,6 @@ variant creates Data ONTAP storage virtual machines (i.e. 'vservers')
|
||||
as needed to provision shares.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import re
|
||||
|
||||
from oslo_log import log
|
||||
@ -680,12 +679,10 @@ class NetAppCmodeMultiSVMFileStorageLibrary(
|
||||
if parent_share['host'] != share['host']:
|
||||
# 1. Retrieve source and destination vservers from source and
|
||||
# destination shares
|
||||
new_share = copy.deepcopy(share.to_dict())
|
||||
new_share['share_server'] = share_server.to_dict()
|
||||
|
||||
dm_session = data_motion.DataMotionSession()
|
||||
src_vserver = dm_session.get_vserver_from_share(parent_share)
|
||||
dest_vserver = dm_session.get_vserver_from_share(new_share)
|
||||
dest_vserver = dm_session.get_vserver_from_share_server(
|
||||
share_server)
|
||||
|
||||
# 2. Retrieve the source share host's client and cluster name
|
||||
src_share_host = share_utils.extract_host(
|
||||
@ -697,7 +694,7 @@ class NetAppCmodeMultiSVMFileStorageLibrary(
|
||||
|
||||
# 3. Retrieve new share host's client
|
||||
dest_share_host = share_utils.extract_host(
|
||||
new_share['host'], level='backend_name')
|
||||
share['host'], level='backend_name')
|
||||
dest_share_client = data_motion.get_client_for_backend(
|
||||
dest_share_host, vserver_name=dest_vserver)
|
||||
dest_share_cluster_name = dest_share_client.get_cluster_name()
|
||||
|
@ -1311,7 +1311,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
|
||||
mock.Mock(return_value=mock_dm_session))
|
||||
mock_get_vserver = self.mock_object(
|
||||
mock_dm_session, 'get_vserver_from_share',
|
||||
mock.Mock(side_effect=[src_vserver, dest_vserver]))
|
||||
mock.Mock(return_value=src_vserver))
|
||||
mock_get_vserver_from_share_server = self.mock_object(
|
||||
mock_dm_session, 'get_vserver_from_share_server',
|
||||
mock.Mock(return_value=dest_vserver))
|
||||
src_vserver_client = mock.Mock()
|
||||
dest_vserver_client = mock.Mock()
|
||||
mock_extract_host = self.mock_object(
|
||||
@ -1345,8 +1348,9 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
|
||||
internal_share['share_server'] = copy.deepcopy(fake.SHARE_SERVER)
|
||||
|
||||
mock_dm_constr.assert_called_once()
|
||||
mock_get_vserver.assert_has_calls([mock.call(fake_parent_share),
|
||||
mock.call(internal_share)])
|
||||
mock_get_vserver.assert_called_once_with(fake_parent_share)
|
||||
mock_get_vserver_from_share_server.assert_called_once_with(
|
||||
fake_share_server)
|
||||
mock_extract_host.assert_has_calls([
|
||||
mock.call(fake_parent_share['host'], level='backend_name'),
|
||||
mock.call(internal_share['host'], level='backend_name')])
|
||||
|
Loading…
x
Reference in New Issue
Block a user