Пример #1
0
    def test_unit(self):
        rid = ID()
        u1 = Unit(rid=rid)
        self.assertIsNotNone(u1.get_id())
        self.assertEqual(UnitState.DEFAULT, u1.get_state())
        self.assertIsNone(u1.get_property(name="foo"))
        self.assertIsNone(u1.get_parent_id())
        self.assertIsNotNone(u1.get_reservation_id())
        self.assertIsNone(u1.get_slice_id())
        self.assertIsNone(u1.get_actor_id())

        self.assertEqual(0, u1.get_sequence())
        u1.increment_sequence()
        self.assertEqual(1, u1.get_sequence())
        u1.decrement_sequence()
        self.assertEqual(0, u1.get_sequence())

        db = self.make_actor_database()

        slice_id = ID()
        from fabric_cf.actor.core.container.globals import GlobalsSingleton
        actor_id = GlobalsSingleton.get().get_container().get_actor().get_guid(
        )

        slice_obj = SliceFactory.create(slice_id=slice_id, name="test_slice")
        db.add_slice(slice_object=slice_obj)

        reservation = ClientReservationFactory.create(rid=rid,
                                                      slice_object=slice_obj)
        u1.set_actor_id(actor_id=actor_id)
        u1.set_reservation(reservation=reservation)
        u1.set_slice_id(slice_id=slice_id)

        db.add_reservation(reservation=reservation)

        u1.start_prime()
        self.assertEqual(UnitState.PRIMING, u1.get_state())
        u1.set_property(name="foo", value="bar")
        u1.increment_sequence()
        u1.increment_sequence()
        resource_type = ResourceType(resource_type="1")
        u1.set_resource_type(rtype=resource_type)
        self.assertEqual(2, u1.get_sequence())

        db.add_unit(u=u1)

        self.assertIsNotNone(db.get_unit(uid=rid))
Пример #2
0
 def transfer_in(self, *, unit: Unit):
     """
     Transfer in a unit
     @param unit unit
     """
     try:
         if unit.start_prime():
             unit.set_reservation(reservation=self.reservation)
             unit.set_slice_id(slice_id=self.reservation.get_slice_id())
             unit.set_actor_id(actor_id=self.plugin.get_actor().get_guid())
             self.plugin.transfer_in(reservation=self.reservation,
                                     unit=unit)
         else:
             self.post(
                 u=unit,
                 message="Unit cannot be transferred., State={}".format(
                     unit.get_state()))
     except Exception as e:
         self.fail(u=unit, message="Transfer in for node failed", e=e)