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 (cherry picked from commit6f9135b6a4
) (cherry picked from commit96c3892bb1
)
This commit is contained in:
parent
e7dfaecd37
commit
ea39101a9c
|
@ -381,7 +381,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]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue