'Test normal backup restoration.'

@mock.patch('cinder.utils.brick_get_connector_properties')
@mock.patch('cinder.utils.temporary_chown')
@mock.patch('six.moves.builtins.open')
@mock.patch.object(os.path, 'isdir', return_value=False)
def test_restore_backup(self, mock_isdir, mock_open, mock_temporary_chown, mock_get_conn):

    vol_size = 1
    vol_id = self._create_volume_db_entry(status='restoring-backup', size=vol_size)
    backup = self._create_backup_db_entry(status=fields.BackupStatus.RESTORING, volume_id=vol_id)
    properties = {}
    mock_get_conn.return_value = properties
    mock_open.return_value = open('/dev/null', 'wb')
    mock_secure_enabled = self.volume_mocks['secure_file_operations_enabled']
    mock_secure_enabled.return_value = False
    vol = objects.Volume.get_by_id(self.ctxt, vol_id)
    attach_info = {'device': {'path': '/dev/null'}}
    mock_detach_device = self.mock_object(self.backup_mgr, '_detach_device')
    mock_attach_device = self.mock_object(self.backup_mgr, '_attach_device')
    mock_attach_device.return_value = attach_info
    self.backup_mgr.restore_backup(self.ctxt, backup, vol_id)
    mock_temporary_chown.assert_called_once_with('/dev/null')
    mock_get_conn.assert_called_once_with()
    mock_secure_enabled.assert_called_once_with(self.ctxt, vol)
    mock_attach_device.assert_called_once_with(self.ctxt, vol, properties)
    mock_detach_device.assert_called_once_with(self.ctxt, attach_info, vol, properties, force=True)
    vol = objects.Volume.get_by_id(self.ctxt, vol_id)
    self.assertEqual('available', vol['status'])
    backup = db.backup_get(self.ctxt, backup.id)
    self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
