'Create a test instance.'

def _create_instance_obj(self, params=None, flavor=None):

    if (not params):
        params = {}
    if (flavor is None):
        flavor = self._create_flavor()
    now = timeutils.utcnow()
    instance = objects.Instance()
    instance.metadata = {}
    instance.metadata.update(params.pop('metadata', {}))
    instance.system_metadata = params.pop('system_metadata', {})
    instance._context = self.context
    instance.id = 1
    instance.uuid = uuidutils.generate_uuid()
    instance.cell_name = 'api!child'
    instance.vm_state = vm_states.ACTIVE
    instance.task_state = None
    instance.image_ref = FAKE_IMAGE_REF
    instance.reservation_id = 'r-fakeres'
    instance.user_id = self.user_id
    instance.project_id = self.project_id
    instance.host = 'fake_host'
    instance.node = NODENAME
    instance.instance_type_id = flavor.id
    instance.ami_launch_index = 0
    instance.memory_mb = 0
    instance.vcpus = 0
    instance.root_gb = 0
    instance.ephemeral_gb = 0
    instance.architecture = fields_obj.Architecture.X86_64
    instance.os_type = 'Linux'
    instance.locked = False
    instance.created_at = now
    instance.updated_at = now
    instance.launched_at = now
    instance.disable_terminate = False
    instance.info_cache = objects.InstanceInfoCache()
    instance.flavor = flavor
    instance.old_flavor = instance.new_flavor = None
    if params:
        instance.update(params)
    instance.obj_reset_changes()
    return instance
