Tests: Fix up migrate notify tests

Search for notify calls in a way that ignores extra
notifications.

Remove mock_notify.assert_not_called()

Partial-Bug: #1803648

Change-Id: I5e0823453cbadbd7ab1dcaa3e651769629eb409e
This commit is contained in:
Eric Harney 2019-02-21 15:05:14 -05:00
parent b984410333
commit 6f9135b6a4
2 changed files with 20 additions and 4 deletions

View File

@ -403,7 +403,22 @@ class TestCase(testtools.TestCase):
return result
# Useful assertions
def assert_notify_called(self, mock_notify, calls):
def assert_notify_called(self, mock_notify, calls, any_order=False):
if any_order is True:
for c in calls:
# mock_notify.call_args_list = [
# mock.call('INFO', 'volume.retype', ...),
# mock.call('WARN', 'cinder.fire', ...)]
# m = mock_notify.call_args_list
# m[0] = Call
# m[0][0] = tuple('INFO', <context>, 'volume.retype', ...)
if not any(m for m in mock_notify.call_args_list
if (m[0][0] == c[0] # 'INFO'
and
m[0][2] == c[1])): # 'volume.retype'
raise AssertionError("notify call not found: %s" % c)
return
for i in range(0, len(calls)):
mock_call = mock_notify.call_args_list[i]
call = calls[i]

View File

@ -888,20 +888,21 @@ class VolumeMigrationTestCase(base.BaseVolumeTestCase):
self.assertEqual(CONF.host, volume.host)
self.assertEqual(1, volumes_in_use)
self.assert_notify_called(mock_notify,
(['INFO', 'volume.retype'],))
(['INFO', 'volume.retype'],),
any_order=True)
elif not exc:
self.assertEqual(old_vol_type['id'], volume.volume_type_id)
self.assertEqual('retyping', volume.status)
self.assertEqual(CONF.host, volume.host)
self.assertEqual(1, volumes_in_use)
self.assert_notify_called(mock_notify,
(['INFO', 'volume.retype'],))
(['INFO', 'volume.retype'],),
any_order=True)
else:
self.assertEqual(old_vol_type['id'], volume.volume_type_id)
self.assertEqual('available', volume.status)
self.assertEqual(CONF.host, volume.host)
self.assertEqual(0, volumes_in_use)
mock_notify.assert_not_called()
if encryption_changed:
self.assertTrue(_mig.called)
self.assertEqual(expected_replica_status, volume.replication_status)