Exemplo n.º 1
0
def test_smartctl_triple():
    expected = [
        {
            "brand": "Western Digital",
            "capacity-decibyte": 40000000000,
            "family": "Caviar",
            "model": "WD400BB-00DKA0",
            "smart-data": "ok",
            "sn": "WCAHM786543",
            "spin-rate-rpm": 7200,
            "ide-ports-n": 1,
            "type": "hdd",
        },
        {
            "brand": "Seagate",
            "capacity-decibyte": 1000000000000,
            "family": "Desktop SSHD",
            "hdd-form-factor": "3.5",
            "model": "ST1000DX001-1CM162",
            "sata-ports-n": 1,
            "smart-data": "ok",
            "sn": "45DL0LXD",
            "spin-rate-rpm": 7200,
            "type": "hdd",
            "wwn": "5 3152 256262626",
        },
        {
            "brand": "Western Digital",
            "capacity-decibyte": 160000000000,
            "family": "Caviar SE",
            "model": "WD1600JS-60MHB5",
            "sata-ports-n": 1,
            "smart-data": "ok",
            "spin-rate-rpm": 7200,
            "sn": "WCANM89765430",
            "type": "hdd",
        },
    ]

    filedir = "tests/source_files/smartctl/"
    output = read_smartctl.parse_smartctl(read_file(filedir, "three.txt"))

    assert len(output) == 3
    assert output == expected
Exemplo n.º 2
0
def test_smartctl_virtual_scsi():
    expected = [
        {
            "brand":
            "Msft",
            "capacity-decibyte":
            275000000000,
            "model":
            "Virtual Disk",
            "notes":
            "This is a SCSI disk, however it is not possible to detect the "
            "exact connector type. Please set the correct one manually.",
            "type":
            "ssd",
        },
        {
            "brand":
            "Msft",
            "capacity-decibyte":
            275000000000,
            "model":
            "Virtual Disk",
            "notes":
            "This is a SCSI disk, however it is not possible to detect the "
            "exact connector type. Please set the correct one manually.",
            "type":
            "ssd",
        },
    ]

    filedir = "tests/source_files/smartctl/"
    output = read_smartctl.parse_smartctl(
        read_file(filedir, "virtual_scsi.txt"))

    assert len(output) == 2
    assert output == expected
Exemplo n.º 3
0
def test_smartctl_single(filename, expected):
    filedir = "tests/source_files/smartctl/"
    output = read_smartctl.parse_smartctl(read_file(filedir, filename))

    assert output == expected
Exemplo n.º 4
0
def test_77_no_disks_disk_that_doesnt_exist():
    expect = []
    output = read_smartctl.parse_smartctl(read_file(filedir, "smartctl.txt"))

    assert output == expect
Exemplo n.º 5
0
def call_parsers(
    generated_files_path: str,
    components: Set[ParserComponents],
    gpu_location: GpuLocation,
    interactive: bool = False,
) -> list:
    generated_files_path = generated_files_path.rstrip("/")

    def read_file(name: str) -> str:
        path = os.path.join(generated_files_path, name)
        try:
            with open(path, "r") as f:
                output = f.read()
            return output
        except FileNotFoundError:
            raise InputFileNotFoundError(path)

    result = []

    # TODO: if linux, else windows
    if sys.platform == "win32":
        pass
    else:
        if not components.isdisjoint(
            {ParserComponents.CASE, ParserComponents.MOTHERBOARD}):
            result += parse_motherboard(
                read_file("baseboard.txt"),
                read_file("connector.txt"),
                read_file("net.txt"),
                interactive,
            )
            if gpu_location == GpuLocation.MOTHERBOARD:
                _merge_gpu(
                    result,
                    "motherboard",
                    parse_lspci_and_glxinfo(False, read_file("lspci.txt"), ""),
                )
        if ParserComponents.CASE in components:
            result += parse_case(read_file("chassis.txt"),
                                 _find_component("motherboard", result))
        if ParserComponents.CPU in components:
            result += parse_lscpu(read_file("lscpu.txt"))
            if gpu_location == GpuLocation.CPU:
                _merge_gpu(
                    result,
                    "cpu",
                    parse_lspci_and_glxinfo(False, read_file("lspci.txt"), ""),
                )
        if ParserComponents.GPU in components and gpu_location == GpuLocation.DISCRETE:
            result += parse_lspci_and_glxinfo(True, read_file("lspci.txt"),
                                              read_file("glxinfo.txt"),
                                              interactive)
        if ParserComponents.RAM in components:
            result += parse_decode_dimms(read_file("dimms.txt"), interactive)
        if ParserComponents.HDD in components or ParserComponents.SSD in components:
            result += parse_smartctl(read_file("smartctl.txt"), interactive)
        if ParserComponents.PSU in components:
            result += parse_psu(_find_component("case", result))

    result = _do_cleanup(result, interactive)
    return result