Skip to content

[BUG] Byte conversion factors off by power of 10 in _parse_numbers() in modules/disk.py #65490

Open
@themowski

Description

@themowski

Description

I was looking at salt/modules/disk.py and came across the following in the definition of _parse_numbers:

postPrefixes = {
"K": "10E3",
"M": "10E6",
"G": "10E9",
"T": "10E12",
"P": "10E15",
"E": "10E18",
"Z": "10E21",
"Y": "10E24",
}

It seems to me that these are all off by a factor of 10: K should be 1E3, not 10E3, and so on.

This function seems to only be used by the _iostat_aix() function, so I don't know how large the impact is, or whether this may even be expected behavior on AIX platforms.

Example

I loaded the definition of _parse_numbers into an interpreter to play around with it. As noted, it seems to me that these values are off by a factor of 10:

>>> float(_parse_numbers("1.0K"))
10000.0
# I would expect 1000.0

>>> float(_parse_numbers("32.8K"))
328000.0
# I would expect 32800.0

Suggested fix

Remove the extra 0 characters. I also recommend replacing the E with e, which helps distinguish the numbers from the e more easily (when written with a lowercase e, the current 10e3 value looks very suspect, especially next to the K suffix).

postPrefixes = {
    "K": "1e3",
    "M": "1e6",
    "G": "1e9",
    "T": "1e12",
    "P": "1e15",
    "E": "1e18",
    "Z": "1e21",
    "Y": "1e24",
}

As a separate note, postPrefixes is IMO a poor name and should be renamed unit_to_bytes or unit_suffixes or something more clear, although that is unrelated to the issue at hand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AIXaffects this operating systemBugbroken, incorrect, or confusing behaviorgood first issuegood for someone new to saltneeds-triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions