def test_backup_restore_attach_error(self, mock_detach, mock_attach, mock_sec_opts, mock_get_conn, mock_notify, mock_working, mock_our_back, mock_msg_create, mock_get_vol, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='creating', volume_id=fake.VOLUME_ID, snapshot_id=None) fake_backup.__getitem__.side_effect = ({ 'status': 'restoring', 'size': 1 }.__getitem__) mock_vol = mock.MagicMock() mock_vol.__getitem__.side_effect = ({ 'status': 'restoring-backup', 'size': 1 }.__getitem__) mock_get_vol.return_value = mock_vol mock_working.return_value = True mock_our_back.return_value = True mock_attach.side_effect = exception.InvalidBackup(reason="test reason") self.assertRaises(exception.InvalidBackup, manager.restore_backup, fake_context, fake_backup, fake.VOLUME_ID) self.assertEqual(message_field.Action.BACKUP_RESTORE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.ATTACH_ERROR)
def test_backup_restore_backup_invalid_state(self, mock_notify, mock_msg_create, mock_get_vol, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='creating', volume_id=fake.VOLUME_ID, snapshot_id=None) fake_backup.__getitem__.side_effect = ({ 'status': 'available', 'size': 1 }.__getitem__) mock_vol = mock.MagicMock() mock_vol.__getitem__.side_effect = ({ 'status': 'restoring-backup', 'size': 1 }.__getitem__) mock_get_vol.return_value = mock_vol self.assertRaises(exception.InvalidBackup, manager.restore_backup, fake_context, fake_backup, fake.VOLUME_ID) self.assertEqual(message_field.Action.BACKUP_RESTORE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_INVALID_STATE)
def test_backup_delete_driver_error(self, mock_notify, mock_working, mock_our_back, mock_msg_create, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='deleting', volume_id=fake.VOLUME_ID, snapshot_id=None) fake_backup.__getitem__.side_effect = ({ 'display_name': 'fail_on_delete' }.__getitem__) mock_working.return_value = True mock_our_back.return_value = True self.assertRaises(IOError, manager.delete_backup, fake_context, fake_backup) self.assertEqual(message_field.Action.BACKUP_DELETE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_DELETE_DRIVER_ERROR)
def test_backup_create_cleanup_error(self, mock_detach, mock_open, mock_backup, mock_attach, mock_cleanup, mock_get_bak_dev, mock_get_conn, mock_notify, mock_working, mock_msg_create, mock_get_vol, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='creating', volume_id=fake.VOLUME_ID, snapshot_id=None) mock_vol = mock.MagicMock() mock_vol.__getitem__.side_effect = {'status': 'backing-up'}.__getitem__ mock_get_vol.return_value = mock_vol mock_working.return_value = True mock_attach.return_value = {'device': {'path': '/dev/sdb'}} mock_cleanup.side_effect = exception.InvalidVolume( reason="test reason") self.assertRaises(exception.InvalidVolume, manager.create_backup, fake_context, fake_backup) self.assertEqual(message_field.Action.BACKUP_CREATE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_CREATE_CLEANUP_ERROR)
def test_backup_delete_invalid_state(self, mock_notify, mock_msg_create, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='available', volume_id=fake.VOLUME_ID, snapshot_id=None) self.assertRaises(exception.InvalidBackup, manager.delete_backup, fake_context, fake_backup) self.assertEqual(message_field.Action.BACKUP_DELETE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_INVALID_STATE)
def test_backup_delete_service_down(self, mock_notify, mock_working, mock_msg_create, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='deleting', volume_id=fake.VOLUME_ID, snapshot_id=None) mock_working.return_value = False self.assertRaises(exception.InvalidBackup, manager.delete_backup, fake_context, fake_backup) self.assertEqual(message_field.Action.BACKUP_DELETE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_SERVICE_DOWN)
def test_backup_create_service_down(self, mock_notify, mock_working, mock_run, mock_msg_create, mock_get_vol, mock_vol_update): manager = backup_manager.BackupManager() fake_context = mock.MagicMock() fake_backup = mock.MagicMock(id=fake.BACKUP_ID, status='creating', volume_id=fake.VOLUME_ID, snapshot_id=None) mock_vol = mock.MagicMock() mock_vol.__getitem__.side_effect = {'status': 'backing-up'}.__getitem__ mock_get_vol.return_value = mock_vol mock_working.return_value = False mock_run.side_effect = exception.InvalidBackup(reason='test reason') self.assertRaises(exception.InvalidBackup, manager.create_backup, fake_context, fake_backup) self.assertEqual(message_field.Action.BACKUP_CREATE, fake_context.message_action) self.assertEqual(message_field.Resource.VOLUME_BACKUP, fake_context.message_resource_type) self.assertEqual(fake_backup.id, fake_context.message_resource_id) mock_msg_create.assert_called_with( fake_context, detail=message_field.Detail.BACKUP_SERVICE_DOWN)