

def fake_db_instance(**updates):
    if ('instance_type' in updates):
        if isinstance(updates['instance_type'], objects.Flavor):
            flavor = updates['instance_type']
        else:
            flavor = objects.Flavor(**updates['instance_type'])
        flavorinfo = jsonutils.dumps({
            'cur': flavor.obj_to_primitive(),
            'old': None,
            'new': None,
        })
    else:
        flavorinfo = None
    db_instance = {
        'id': 1,
        'deleted': False,
        'uuid': str(uuid.uuid4()),
        'user_id': 'fake-user',
        'project_id': 'fake-project',
        'host': 'fake-host',
        'created_at': datetime.datetime(1955, 11, 5),
        'pci_devices': [],
        'security_groups': [],
        'metadata': {
            
        },
        'system_metadata': {
            
        },
        'root_gb': 0,
        'ephemeral_gb': 0,
        'extra': {
            'pci_requests': None,
            'flavor': flavorinfo,
            'numa_topology': None,
            'vcpu_model': None,
        },
        'tags': [],
        'services': [],
    }
    for (name, field) in objects.Instance.fields.items():
        if (name in db_instance):
            continue
        if field.nullable:
            db_instance[name] = None
        elif (field.default != fields.UnspecifiedDefault):
            db_instance[name] = field.default
        elif (name in ['flavor', 'ec2_ids']):
            pass
        else:
            raise Exception(('fake_db_instance needs help with %s' % name))
    if updates:
        db_instance.update(updates)
    if db_instance.get('security_groups'):
        db_instance['security_groups'] = fake_db_secgroups(db_instance, db_instance['security_groups'])
    return db_instance

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/fake_instance.py fake_db_instance/original