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.
Description
I was looking at
salt/modules/disk.pyand came across the following in the definition of_parse_numbers:salt/salt/modules/disk.py
Lines 42 to 51 in 93b6405
It seems to me that these are all off by a factor of 10:
Kshould be1E3, not10E3, 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_numbersinto an interpreter to play around with it. As noted, it seems to me that these values are off by a factor of 10:Suggested fix
Remove the extra
0characters. I also recommend replacing theEwithe, which helps distinguish the numbers from theemore easily (when written with a lowercasee, the current10e3value looks very suspect, especially next to theKsuffix).As a separate note,
postPrefixesis IMO a poor name and should be renamedunit_to_bytesorunit_suffixesor something more clear, although that is unrelated to the issue at hand.