Example #1
0
def get_devices(
    request: Request,
    _=Depends(jwt_auth_scheme)) -> Dict[str, HostsDevicesModel]:
    orch = Orchestrator(request.app.state.gstate.ceph_mgr)
    orch_devs_per_host: List[OrchDevicesPerHostModel] = orch.devices_ls()
    host_devs: Dict[str, HostsDevicesModel] = {}
    for orch_host in orch_devs_per_host:

        devices: List[DeviceModel] = []
        for dev in orch_host.devices:
            devices.append(
                DeviceModel(
                    available=dev.available,
                    device_id=dev.device_id,
                    model=dev.sys_api.model,
                    vendor=dev.sys_api.vendor,
                    human_readable_type=dev.human_readable_type,
                    size=int(dev.sys_api.size),
                    path=dev.path,
                    rejected_reasons=dev.rejected_reasons,
                ))

        host: HostsDevicesModel = HostsDevicesModel(address=orch_host.addr,
                                                    hostname=orch_host.name,
                                                    devices=devices)
        host_devs[orch_host.name] = host

    return host_devs
Example #2
0
def test_device_ls(
    get_data_contents: Callable[[str, str], str],
    mocker: MockerFixture,
    gstate: GlobalState,
) -> None:

    orch = Orchestrator(gstate.ceph_mgr)
    orch.call = mocker.MagicMock(return_value=json.loads(
        get_data_contents(DATA_DIR, "device_ls_not_available.json")))
    res: List[OrchDevicesPerHostModel] = orch.devices_ls()
    assert res[0].name == "asd"
Example #3
0
def test_devices_assimilated(
    get_data_contents: Callable[[str, str], str],
    mocker: MockerFixture,
    gstate: GlobalState,
) -> None:
    def device_ls_gen():
        raw = json.loads(
            get_data_contents(DATA_DIR, "device_ls_not_available.json"))
        devicels = parse_obj_as(List[OrchDevicesPerHostModel], raw)
        yield devicels
        devicels[0].devices[1].available = True
        yield devicels

    from gravel.controllers.orch.orchestrator import Orchestrator

    orch = Orchestrator(gstate.ceph_mgr)

    devicegen = device_ls_gen()
    orch.devices_ls = mocker.MagicMock(return_value=next(devicegen))
    assert orch.devices_assimilated("asd", ["/dev/vdb", "/dev/vdc"])

    orch.devices_ls = mocker.MagicMock(return_value=next(devicegen))
    assert not orch.devices_assimilated("asd", ["/dev/vdc"])