def create_sliver(self, name: str, pci_address: str, gpu_name: str) -> Unit: u = Unit(rid=ID(uid=name)) sliver = NodeSliver() cap = Capacities(core=2, ram=6, disk=10) sliver.set_properties(type=NodeType.VM, site="UKY", capacity_allocations=cap) sliver.label_allocations = Labels(instance_parent="uky-w2.fabric-testbed.net") catalog = InstanceCatalog() instance_type = catalog.map_capacities_to_instance(cap=cap) cap_hints = CapacityHints(instance_type=instance_type) sliver.set_properties(capacity_hints=cap_hints, capacity_allocations=catalog.get_instance_capacities(instance_type=instance_type)) sliver.set_properties(name=name) sliver.set_properties(image_type='qcow2', image_ref='default_ubuntu_20') component = ComponentSliver() labels = Labels(bdf=pci_address) component.set_properties(type=ComponentType.GPU, model='Tesla T4', name=gpu_name, label_allocations=labels) sliver.attached_components_info = AttachedComponentsInfo() sliver.attached_components_info.add_device(device_info=component) u.set_sliver(sliver=sliver) u.set_resource_type(rtype=ResourceType(resource_type=NodeType.VM.name)) return u
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))
def test_d_add_update_get_unit(self): actor = self.prepare_actor_database() db = actor.get_plugin().get_database() slice_obj = SliceFactory.create(slice_id=ID(), name="slice-1") db.add_slice(slice_object=slice_obj) rset = ResourceSet() term = Term(start=datetime.now(), end=datetime.now().replace(minute=20)) res = AuthorityReservationFactory.create(resources=rset, term=term, slice_obj=slice_obj, rid=ID()) db.add_reservation(reservation=res) rtype = ResourceType(resource_type="12") u = Unit(rid=res.get_reservation_id(), slice_id=slice_obj.get_slice_id(), actor_id=actor.get_guid()) u.set_resource_type(rtype=rtype) db.add_unit(u=u) self.assertIsNotNone(db.get_unit(uid=u.get_id()))