Fix Share Migration KeyError on dict.pop

In Share migration it is always trying to remove the Copy object
from dictionary, even if it has not been added yet. So, dict.pop()
should include second argument to not throw exception.

Improved unit test to cover this variation.

Closes-bug: #1555630
Change-Id: If81c14cbeb03e41501d825cab000ceb1aa2cae7c
This commit is contained in:
Rodrigo Barbieri 2016-03-10 12:45:05 -03:00
parent cdab09b822
commit b8e9ae892a
2 changed files with 3 additions and 2 deletions

View File

@ -104,7 +104,7 @@ class DataManager(manager.Manager):
context, share_ref, share_instance_id, dest_share_instance_id)
raise exception.ShareDataCopyFailed(reason=msg)
finally:
self.busy_tasks_shares.pop(share_id)
self.busy_tasks_shares.pop(share_id, None)
LOG.info(_LI(
"Completed copy operation of migrating share content from share "

View File

@ -86,7 +86,8 @@ class DataManagerTestCase(test.TestCase):
self.mock_object(data_utils, 'Copy',
mock.Mock(return_value='fake_copy'))
self.manager.busy_tasks_shares[self.share['id']] = 'fake_copy'
if exc is None:
self.manager.busy_tasks_shares[self.share['id']] = 'fake_copy'
self.mock_object(self.manager, '_copy_share_data',
mock.Mock(side_effect=exc))