"Fossies" - the Fresh Open Source Software Archive

Member "cinder-14.0.2/cinder/tests/unit/fake_group.py" (4 Oct 2019, 2491 Bytes) of package /linux/misc/openstack/cinder-14.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #    Copyright 2016 EMC 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 
   15 from oslo_versionedobjects import fields
   16 
   17 from cinder import objects
   18 from cinder.tests.unit import fake_constants as fake
   19 
   20 
   21 def fake_db_group(**updates):
   22     db_group = {
   23         'id': fake.GROUP_ID,
   24         'name': 'group-1',
   25         'status': 'available',
   26         'user_id': fake.USER_ID,
   27         'project_id': fake.PROJECT_ID,
   28         'group_type_id': fake.GROUP_TYPE_ID,
   29         'group_snapshot_id': None,
   30         'source_group_id': None,
   31     }
   32 
   33     for name, field in objects.Group.fields.items():
   34         if name in db_group:
   35             continue
   36         if field.nullable:
   37             db_group[name] = None
   38         elif field.default != fields.UnspecifiedDefault:
   39             db_group[name] = field.default
   40         else:
   41             raise Exception('fake_db_group needs help with %s.' % name)
   42 
   43     if updates:
   44         db_group.update(updates)
   45 
   46     return db_group
   47 
   48 
   49 def fake_db_group_type(**updates):
   50     db_group_type = {
   51         'id': fake.GROUP_TYPE_ID,
   52         'name': 'type-1',
   53         'description': 'A fake group type',
   54         'is_public': True,
   55         'projects': [],
   56         'group_specs': {},
   57     }
   58 
   59     for name, field in objects.GroupType.fields.items():
   60         if name in db_group_type:
   61             continue
   62         if field.nullable:
   63             db_group_type[name] = None
   64         elif field.default != fields.UnspecifiedDefault:
   65             db_group_type[name] = field.default
   66         else:
   67             raise Exception('fake_db_group_type needs help with %s.' % name)
   68 
   69     if updates:
   70         db_group_type.update(updates)
   71 
   72     return db_group_type
   73 
   74 
   75 def fake_group_obj(context, **updates):
   76     return objects.Group._from_db_object(
   77         context, objects.Group(), fake_db_group(**updates))
   78 
   79 
   80 def fake_group_type_obj(context, **updates):
   81     return objects.GroupType._from_db_object(
   82         context, objects.GroupType(), fake_db_group_type(**updates))