Beispiel #1
0
    def setUp(self):
        super(TestInstanceListObjects, self).setUp()

        self.context = context.RequestContext('fake', 'fake')
        self.num_instances = 3
        self.instances = []

        start = datetime.datetime(1985, 10, 25, 1, 21, 0)
        dt = start
        spread = datetime.timedelta(minutes=10)

        cells = objects.CellMappingList.get_all(self.context)
        # Create three instances in each of the real cells. Leave the
        # first cell empty to make sure we don't break with an empty
        # one
        for cell in cells[1:]:
            for i in range(0, self.num_instances):
                with context.target_cell(self.context, cell) as cctx:
                    inst = objects.Instance(
                        context=cctx,
                        project_id=self.context.project_id,
                        user_id=self.context.user_id,
                        created_at=start,
                        launched_at=dt,
                        instance_type_id=i,
                        hostname='%s-inst%i' % (cell.name, i))
                    inst.create()
                    if i % 2 == 0:
                        # Make some faults for this instance
                        for n in range(0, i + 1):
                            msg = 'fault%i-%s' % (n, inst.hostname)
                            f = objects.InstanceFault(context=cctx,
                                                      instance_uuid=inst.uuid,
                                                      code=i,
                                                      message=msg,
                                                      details='fake',
                                                      host='fakehost')
                            f.create()

                self.instances.append(inst)
                im = objects.InstanceMapping(context=self.context,
                                             project_id=inst.project_id,
                                             user_id=inst.user_id,
                                             instance_uuid=inst.uuid,
                                             cell_mapping=cell)
                im.create()
                dt += spread
def fake_fault_obj(context, instance_uuid, code=404,
                   message='HTTPNotFound',
                   details='Stock details for test',
                   **updates):
    fault = {
        'id': 1,
        'instance_uuid': instance_uuid,
        'code': code,
        'message': message,
        'details': details,
        'host': 'fake_host',
        'deleted': False,
        'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
        'updated_at': None,
        'deleted_at': None
    }
    if updates:
        fault.update(updates)
    return objects.InstanceFault._from_db_object(context,
                                                 objects.InstanceFault(),
                                                 fault)
Beispiel #3
0
def add_instance_fault_from_pf9_error(context, instance, pf9_errors):
    """
    PF9 function: Create fault object with collected errors
    :param context:
    :param instance:
    :param pf9_errors:
    :return:
    """
    def _form_reasons(pf9_errors):
        reasons = []
        for host, msg in pf9_errors:
            reasons.append('Host {host} failed with error: {msg}'.format(
                host=host, msg=msg))

        return '\n'.join(reasons)

    fault_obj = objects.InstanceFault(context=context)
    fault_obj.host = CONF.host
    fault_obj.instance_uuid = instance['uuid']

    fault = exception.NoValidHost(reason=_form_reasons(pf9_errors))
    fault_obj.update(exception_to_dict(fault))
    fault_obj.details = ''
    fault_obj.create()