Merge "Tests: Split up NFS backup notification test"

This commit is contained in:
Jenkins 2017-01-11 12:23:33 +00:00 committed by Gerrit Code Review
commit 479bd49278

View File

@ -204,17 +204,27 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
backup = objects.Backup.get_by_id(self.ctxt, FAKE_BACKUP_ID)
self.assertEqual(backup['container'], UPDATED_CONTAINER_NAME)
@mock.patch('cinder.backup.drivers.posix.PosixBackupDriver.'
'update_container_name',
return_value='testcontainer1')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_end')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_notification')
def test_backup_default_container_notify(self, _send_progress,
_send_progress_end):
def test_backup_container_notify_1(self, _send_progress,
_send_progress_end,
_mock_update_container_name):
# This unit test writes data to disk. It should be
# updated to not do that.
volume_id = fake.VOLUME_ID
self._create_backup_db_entry(volume_id=volume_id,
container=None)
container='testcontainer1')
# If the backup_object_number_per_notification is set to 1,
# the _send_progress method will be called for sure.
_send_progress.reset_mock()
_send_progress_end.reset_mock()
CONF.set_override("backup_object_number_per_notification", 1)
CONF.set_override("backup_enable_progress_timer", False)
service = nfs.NFSBackupDriver(self.ctxt)
@ -224,11 +234,29 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
self.assertTrue(_send_progress.called)
self.assertTrue(_send_progress_end.called)
@mock.patch('cinder.backup.drivers.posix.PosixBackupDriver.'
'update_container_name',
return_value='testcontainer2')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_end')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_notification')
def test_backup_container_notify_2(self, _send_progress,
_send_progress_end,
_mock_update_container_name):
# This unit test writes data to disk. It should be
# updated to not do that.
volume_id = fake.VOLUME_ID
self._create_backup_db_entry(volume_id=volume_id,
container='testcontainer2')
# If the backup_object_number_per_notification is increased to
# another value, the _send_progress method will not be called.
_send_progress.reset_mock()
_send_progress_end.reset_mock()
CONF.set_override("backup_object_number_per_notification", 10)
CONF.set_override("backup_enable_progress_timer", False)
service = nfs.NFSBackupDriver(self.ctxt)
self.volume_file.seek(0)
backup = objects.Backup.get_by_id(self.ctxt, fake.BACKUP_ID)
@ -236,6 +264,23 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
self.assertFalse(_send_progress.called)
self.assertTrue(_send_progress_end.called)
@mock.patch('cinder.backup.drivers.posix.PosixBackupDriver.'
'update_container_name',
return_value='testcontainer3')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_end')
@mock.patch('cinder.backup.drivers.nfs.NFSBackupDriver.'
'_send_progress_notification')
def test_backup_container_notify_3(self, _send_progress,
_send_progress_end,
_mock_update_container_name):
# This unit test writes data to disk. It should be
# updated to not do that.
volume_id = fake.VOLUME_ID
self._create_backup_db_entry(volume_id=volume_id,
container='testcontainer3')
# If the timer is enabled, the _send_progress will be called,
# since the timer can trigger the progress notification.
_send_progress.reset_mock()