Exemple #1
0
    def test_constraint_place_engine_constraint_violated(self):
        # Create constraint place engine
        image_datastore = "ds1"
        image_datastores = [{"name": image_datastore, "used_for_vms": True}]
        option = PlacementOption(1, 1, image_datastores)
        ds_map = {image_datastore: DatastoreInfo(5, 0)}
        ds_mgr = self.create_datastore_manager(ds_map, image_datastores)
        engine = ConstraintDiskPlaceEngine(ds_mgr, option)
        ds = engine.placeable_datastores()
        selector = DatastoreSelector.init_datastore_selector(ds_mgr, ds)

        # Try place
        disks = [
            Disk(disk_id="ds1",
                 capacity_gb=1,
                 constraints=[
                     ResourceConstraint(ResourceConstraintType.DATASTORE,
                                        ["ds2"])
                 ]),
        ]
        place_result = engine.place(DisksPlacement(disks, selector))

        # Verify place result
        assert_that(place_result.result,
                    equal_to(PlaceResultCode.NO_SUCH_RESOURCE))
Exemple #2
0
    def test_constraint_place_engine(self):
        # Create constraint place engine
        image_datastore = "ds1"
        image_datastores = [{"name": image_datastore, "used_for_vms": True}]
        option = PlacementOption(1, 1, image_datastores)
        ds_map = {
            image_datastore: DatastoreInfo(10, 0),
            "ds2": DatastoreInfo(20, 0),
            "ds3": DatastoreInfo(30, 0)
        }
        ds_mgr = self.create_datastore_manager(ds_map, image_datastore)
        engine = ConstraintDiskPlaceEngine(ds_mgr, option)
        ds = engine.placeable_datastores()
        selector = DatastoreSelector.init_datastore_selector(ds_mgr, ds)

        # Try place
        disks = [
            Disk(disk_id="disk", capacity_gb=5, constraints=[]),
            Disk(disk_id="disk-in-ds1",
                 capacity_gb=5,
                 constraints=[
                     ResourceConstraint(ResourceConstraintType.DATASTORE,
                                        ["ds1"])
                 ]),
            Disk(disk_id="disk-in-ds2",
                 capacity_gb=5,
                 constraints=[
                     ResourceConstraint(ResourceConstraintType.DATASTORE,
                                        ["ds2"])
                 ]),
            Disk(disk_id="disk-in-ds3",
                 capacity_gb=5,
                 constraints=[
                     ResourceConstraint(ResourceConstraintType.DATASTORE,
                                        ["ds3"])
                 ]),
            Disk(capacity_gb=5, constraints=[]),
        ]
        disks_placement = DisksPlacement(disks, selector)
        place_result = engine.place(disks_placement)

        # Verify place result
        assert_that(place_result.result, equal_to(PlaceResultCode.OK))

        # Verify placement list and unplaced list
        disks_placement = place_result.disks_placement
        assert_that(disks_placement.placement_list, has_length(3))
        assert_that(disks_placement.disks, has_length(2))
        assert_that([d.resource_id for d in disks_placement.placement_list],
                    contains_inanyorder("disk-in-ds1", "disk-in-ds2",
                                        "disk-in-ds3"))
        for placement in disks_placement.placement_list:
            assert_that(placement.type, equal_to(AgentResourcePlacement.DISK))
            assert_that("disk-in-" + placement.container_id,
                        equal_to(placement.resource_id))
    def test_constraint_place_engine(self):
        # Create constraint place engine
        image_datastore = "ds1"
        image_datastores = [{"name": image_datastore,
                             "used_for_vms": True}]
        option = PlacementOption(1, 1, image_datastores)
        ds_map = {image_datastore: DatastoreInfo(10, 0),
                  "ds2": DatastoreInfo(20, 0),
                  "ds3": DatastoreInfo(30, 0)}
        ds_mgr = self.create_datastore_manager(ds_map, image_datastore)
        engine = ConstraintDiskPlaceEngine(ds_mgr, option)
        ds = engine.placeable_datastores()
        selector = DatastoreSelector.init_datastore_selector(ds_mgr, ds)

        # Try place
        disks = [
            Disk(disk_id="disk", capacity_gb=5, constraints=[]),
            Disk(disk_id="disk-in-ds1", capacity_gb=5, constraints=[
                ResourceConstraint(
                    ResourceConstraintType.DATASTORE, ["ds1"])]),
            Disk(disk_id="disk-in-ds2", capacity_gb=5, constraints=[
                ResourceConstraint(
                    ResourceConstraintType.DATASTORE, ["ds2"])]),
            Disk(disk_id="disk-in-ds3", capacity_gb=5, constraints=[
                ResourceConstraint(
                    ResourceConstraintType.DATASTORE, ["ds3"])]),
            Disk(capacity_gb=5, constraints=[]),
        ]
        disks_placement = DisksPlacement(disks, selector)
        place_result = engine.place(disks_placement)

        # Verify place result
        assert_that(place_result.result, equal_to(PlaceResultCode.OK))

        # Verify placement list and unplaced list
        disks_placement = place_result.disks_placement
        assert_that(disks_placement.placement_list, has_length(3))
        assert_that(disks_placement.disks, has_length(2))
        assert_that([d.resource_id for d in disks_placement.placement_list],
                    contains_inanyorder("disk-in-ds1", "disk-in-ds2",
                                        "disk-in-ds3"))
        for placement in disks_placement.placement_list:
            assert_that(placement.type,
                        equal_to(AgentResourcePlacement.DISK))
            assert_that("disk-in-" + placement.container_id,
                        equal_to(placement.resource_id))
    def test_constraint_place_engine_constraint_violated(self):
        # Create constraint place engine
        image_datastore = "ds1"
        image_datastores = [{"name": image_datastore,
                             "used_for_vms": True}]
        option = PlacementOption(1, 1, image_datastores)
        ds_map = {image_datastore: DatastoreInfo(5, 0)}
        ds_mgr = self.create_datastore_manager(ds_map, image_datastores)
        engine = ConstraintDiskPlaceEngine(ds_mgr, option)
        ds = engine.placeable_datastores()
        selector = DatastoreSelector.init_datastore_selector(ds_mgr, ds)

        # Try place
        disks = [
            Disk(disk_id="ds1", capacity_gb=1, constraints=[ResourceConstraint(
                 ResourceConstraintType.DATASTORE, ["ds2"])]),
        ]
        place_result = engine.place(DisksPlacement(disks, selector))

        # Verify place result
        assert_that(place_result.result,
                    equal_to(PlaceResultCode.NO_SUCH_RESOURCE))