1#    Copyright (c) 2015 Intel Corporation
2#
3#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4#    not use this file except in compliance with the License. You may obtain
5#    a copy of the License at
6#
7#         http://www.apache.org/licenses/LICENSE-2.0
8#
9#    Unless required by applicable law or agreed to in writing, software
10#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12#    License for the specific language governing permissions and limitations
13#    under the License.
14
15from oslo_versionedobjects import fields
16
17from cinder import objects
18from cinder.objects import fields as c_fields
19from cinder.tests.unit import fake_constants as fake
20
21
22def fake_db_backup(**updates):
23    db_backup = {
24        'id': fake.BACKUP_ID,
25        'user_id': fake.USER_ID,
26        'project_id': fake.PROJECT_ID,
27        'volume_id': fake.VOLUME_ID,
28        'status': c_fields.BackupStatus.CREATING,
29        'host': 'fake_host',
30        'display_name': 'fake_name',
31        'size': 5,
32        'display_description': 'fake_description',
33        'service_metadata': 'fake_metadata',
34        'service': 'fake_service',
35        'object_count': 5,
36        'num_dependent_backups': 0,
37    }
38
39    for name, field in objects.Backup.fields.items():
40        if name in db_backup:
41            continue
42        if field.nullable:
43            db_backup[name] = None
44        elif field.default != fields.UnspecifiedDefault:
45            db_backup[name] = field.default
46        else:
47            raise Exception('fake_db_backup needs help with %s' % name)
48
49    if updates:
50        db_backup.update(updates)
51
52    return db_backup
53
54
55def fake_backup_obj(context, **updates):
56    return objects.Backup._from_db_object(context, objects.Backup(),
57                                          fake_db_backup(**updates))
58