Tests: mock notifier in CG tests
Related-Bug: #1582306 Change-Id: I84beab9d190e45d5a073b36ee18d89108a78d6dc
This commit is contained in:
parent
81a85378cd
commit
38c2af6655
@ -378,3 +378,13 @@ class TestCase(testtools.TestCase):
|
|||||||
'd1value': d1value,
|
'd1value': d1value,
|
||||||
'd2value': d2value,
|
'd2value': d2value,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def assert_notify_called(self, mock_notify, calls):
|
||||||
|
for i in range(0, len(calls)):
|
||||||
|
mock_call = mock_notify.call_args_list[i]
|
||||||
|
call = calls[i]
|
||||||
|
|
||||||
|
posargs = mock_call[0]
|
||||||
|
|
||||||
|
self.assertEqual(call[0], posargs[0])
|
||||||
|
self.assertEqual(call[1], posargs[2])
|
||||||
|
@ -460,6 +460,7 @@ class ConsistencyGroupTestCase(BaseVolumeTestCase):
|
|||||||
|
|
||||||
return cgsnap, snaps
|
return cgsnap, snaps
|
||||||
|
|
||||||
|
@mock.patch('cinder.tests.unit.fake_notifier.FakeNotifier._notify')
|
||||||
@mock.patch('cinder.volume.driver.VolumeDriver.create_consistencygroup',
|
@mock.patch('cinder.volume.driver.VolumeDriver.create_consistencygroup',
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value={'status': 'available'})
|
return_value={'status': 'available'})
|
||||||
@ -474,7 +475,8 @@ class ConsistencyGroupTestCase(BaseVolumeTestCase):
|
|||||||
return_value=({'status': 'deleted'}, []))
|
return_value=({'status': 'deleted'}, []))
|
||||||
def test_create_delete_cgsnapshot(self,
|
def test_create_delete_cgsnapshot(self,
|
||||||
mock_del_cgsnap, mock_create_cgsnap,
|
mock_del_cgsnap, mock_create_cgsnap,
|
||||||
mock_del_cg, _mock_create_cg):
|
mock_del_cg, _mock_create_cg,
|
||||||
|
mock_notify):
|
||||||
"""Test cgsnapshot can be created and deleted."""
|
"""Test cgsnapshot can be created and deleted."""
|
||||||
|
|
||||||
group = tests_utils.create_consistencygroup(
|
group = tests_utils.create_consistencygroup(
|
||||||
@ -488,11 +490,9 @@ class ConsistencyGroupTestCase(BaseVolumeTestCase):
|
|||||||
volume_id = volume['id']
|
volume_id = volume['id']
|
||||||
self.volume.create_volume(self.context, volume_id)
|
self.volume.create_volume(self.context, volume_id)
|
||||||
|
|
||||||
if len(self.notifier.notifications) > 2:
|
self.assert_notify_called(mock_notify,
|
||||||
self.assertFalse(self.notifier.notifications[2],
|
(['INFO', 'volume.create.start'],
|
||||||
self.notifier.notifications)
|
['INFO', 'volume.create.end']))
|
||||||
self.assertEqual(2, len(self.notifier.notifications),
|
|
||||||
self.notifier.notifications)
|
|
||||||
|
|
||||||
cgsnapshot_returns = self._create_cgsnapshot(group.id, [volume_id])
|
cgsnapshot_returns = self._create_cgsnapshot(group.id, [volume_id])
|
||||||
cgsnapshot = cgsnapshot_returns[0]
|
cgsnapshot = cgsnapshot_returns[0]
|
||||||
@ -502,51 +502,27 @@ class ConsistencyGroupTestCase(BaseVolumeTestCase):
|
|||||||
context.get_admin_context(),
|
context.get_admin_context(),
|
||||||
cgsnapshot.id).id)
|
cgsnapshot.id).id)
|
||||||
|
|
||||||
if len(self.notifier.notifications) > 6:
|
self.assert_notify_called(mock_notify,
|
||||||
self.assertFalse(self.notifier.notifications[6],
|
(['INFO', 'volume.create.start'],
|
||||||
self.notifier.notifications)
|
['INFO', 'volume.create.end'],
|
||||||
|
['INFO', 'cgsnapshot.create.start'],
|
||||||
msg = self.notifier.notifications[2]
|
['INFO', 'snapshot.create.start'],
|
||||||
self.assertEqual('cgsnapshot.create.start', msg['event_type'])
|
['INFO', 'cgsnapshot.create.end'],
|
||||||
expected = {
|
['INFO', 'snapshot.create.end']))
|
||||||
'created_at': 'DONTCARE',
|
|
||||||
'name': None,
|
|
||||||
'cgsnapshot_id': cgsnapshot.id,
|
|
||||||
'status': 'creating',
|
|
||||||
'tenant_id': fake.PROJECT_ID,
|
|
||||||
'user_id': fake.USER_ID,
|
|
||||||
'consistencygroup_id': group.id
|
|
||||||
}
|
|
||||||
self.assertDictMatch(expected, msg['payload'])
|
|
||||||
msg = self.notifier.notifications[3]
|
|
||||||
self.assertEqual('snapshot.create.start', msg['event_type'])
|
|
||||||
msg = self.notifier.notifications[4]
|
|
||||||
expected['status'] = 'available'
|
|
||||||
self.assertEqual('cgsnapshot.create.end', msg['event_type'])
|
|
||||||
self.assertDictMatch(expected, msg['payload'])
|
|
||||||
msg = self.notifier.notifications[5]
|
|
||||||
self.assertEqual('snapshot.create.end', msg['event_type'])
|
|
||||||
|
|
||||||
self.assertEqual(6, len(self.notifier.notifications),
|
|
||||||
self.notifier.notifications)
|
|
||||||
|
|
||||||
self.volume.delete_cgsnapshot(self.context, cgsnapshot)
|
self.volume.delete_cgsnapshot(self.context, cgsnapshot)
|
||||||
|
|
||||||
if len(self.notifier.notifications) > 10:
|
self.assert_notify_called(mock_notify,
|
||||||
self.assertFalse(self.notifier.notifications[10],
|
(['INFO', 'volume.create.start'],
|
||||||
self.notifier.notifications)
|
['INFO', 'volume.create.end'],
|
||||||
|
['INFO', 'cgsnapshot.create.start'],
|
||||||
msg = self.notifier.notifications[6]
|
['INFO', 'snapshot.create.start'],
|
||||||
self.assertEqual('cgsnapshot.delete.start', msg['event_type'])
|
['INFO', 'cgsnapshot.create.end'],
|
||||||
expected['status'] = 'available'
|
['INFO', 'snapshot.create.end'],
|
||||||
self.assertDictMatch(expected, msg['payload'])
|
['INFO', 'cgsnapshot.delete.start'],
|
||||||
msg = self.notifier.notifications[8]
|
['INFO', 'snapshot.delete.start'],
|
||||||
self.assertEqual('cgsnapshot.delete.end', msg['event_type'])
|
['INFO', 'cgsnapshot.delete.end'],
|
||||||
expected['status'] = 'deleted'
|
['INFO', 'snapshot.delete.end']))
|
||||||
self.assertDictMatch(expected, msg['payload'])
|
|
||||||
|
|
||||||
self.assertEqual(10, len(self.notifier.notifications),
|
|
||||||
self.notifier.notifications)
|
|
||||||
|
|
||||||
cgsnap = objects.CGSnapshot.get_by_id(
|
cgsnap = objects.CGSnapshot.get_by_id(
|
||||||
context.get_admin_context(read_deleted='yes'),
|
context.get_admin_context(read_deleted='yes'),
|
||||||
|
@ -169,16 +169,6 @@ class BaseVolumeTestCase(test.TestCase):
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def assert_notify_called(self, mock_notify, calls):
|
|
||||||
for i in range(0, len(calls)):
|
|
||||||
mock_call = mock_notify.call_args_list[i]
|
|
||||||
call = calls[i]
|
|
||||||
|
|
||||||
posargs = mock_call[0]
|
|
||||||
|
|
||||||
self.assertEqual(call[0], posargs[0])
|
|
||||||
self.assertEqual(call[1], posargs[2])
|
|
||||||
|
|
||||||
def fake_get_all_volume_groups(obj, vg_name=None, no_suffix=True):
|
def fake_get_all_volume_groups(obj, vg_name=None, no_suffix=True):
|
||||||
return [{'name': 'cinder-volumes',
|
return [{'name': 'cinder-volumes',
|
||||||
'size': '5.00',
|
'size': '5.00',
|
||||||
|
Loading…
Reference in New Issue
Block a user