def assert_failed(self,
                   r: ABCReservationMixin,
                   update_data: UpdateData = None):
     self.assertIsNotNone(r)
     if update_data is None:
         self.assertTrue(r.is_failed())
     else:
         self.assertTrue(update_data.failed)
     self.assertIsNotNone(r.get_notices())
Example #2
0
    def fill_reservation(*, reservation: ABCReservationMixin,
                         full: bool) -> ReservationMng:
        rsv_mng = None
        if isinstance(reservation, ABCControllerReservation):
            rsv_mng = LeaseReservationAvro()
            if reservation.get_redeem_predecessors() is not None and len(
                    reservation.get_redeem_predecessors()) > 0:
                rsv_mng.redeem_processors = []
                for p in reservation.get_redeem_predecessors():
                    pred = Converter.fill_reservation_predecessor(pred=p)
                    rsv_mng.redeem_processors.append(pred)

        elif isinstance(reservation, ABCClientReservation):
            rsv_mng = TicketReservationAvro()
        else:
            rsv_mng = ReservationMng()

        rsv_mng.set_reservation_id(str(reservation.get_reservation_id()))
        rsv_mng.set_slice_id(str(reservation.get_slice_id()))

        if reservation.get_type() is not None:
            rsv_mng.set_resource_type(str(reservation.get_type()))

        rsv_mng.set_units(reservation.get_units())
        rsv_mng.set_state(reservation.get_state().value)
        rsv_mng.set_pending_state(reservation.get_pending_state().value)

        if isinstance(reservation, ABCControllerReservation):
            rsv_mng.set_leased_units(reservation.get_leased_abstract_units())
            rsv_mng.set_join_state(reservation.get_join_state().value)
            authority = reservation.get_authority()

            if authority is not None:
                rsv_mng.set_authority(str(authority.get_guid()))

        if isinstance(reservation, ABCClientReservation):
            broker = reservation.get_broker()
            if broker is not None:
                rsv_mng.set_broker(str(broker.get_guid()))
            rsv_mng.set_renewable(reservation.is_renewable())
            rsv_mng.set_renew_time(reservation.get_renew_time())

        if reservation.get_term() is not None:
            rsv_mng.set_start(
                ActorClock.to_milliseconds(
                    when=reservation.get_term().get_start_time()))
            rsv_mng.set_end(
                ActorClock.to_milliseconds(
                    when=reservation.get_term().get_end_time()))
        else:
            if reservation.get_requested_term() is not None:
                rsv_mng.set_start(
                    ActorClock.to_milliseconds(
                        when=reservation.get_requested_term().get_start_time())
                )
                rsv_mng.set_end(
                    ActorClock.to_milliseconds(
                        when=reservation.get_requested_term().get_end_time()))

        if reservation.get_requested_term() is not None:
            rsv_mng.set_requested_end(
                ActorClock.to_milliseconds(
                    when=reservation.get_requested_term().get_end_time()))

        rsv_mng.set_notices(reservation.get_notices())

        if full:
            rsv_mng = Converter.attach_res_properties(mng=rsv_mng,
                                                      reservation=reservation)

        return rsv_mng