Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65543.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``disk._parse_numbers`` incorrectly multiplying SI suffix values by a factor of 10 (``10E3`` should be ``1E3``).
16 changes: 8 additions & 8 deletions salt/modules/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def _parse_numbers(text):

try:
postPrefixes = {
"K": "10E3",
"M": "10E6",
"G": "10E9",
"T": "10E12",
"P": "10E15",
"E": "10E18",
"Z": "10E21",
"Y": "10E24",
"K": "1e3",
"M": "1e6",
"G": "1e9",
"T": "1e12",
"P": "1e15",
"E": "1e18",
"Z": "1e21",
"Y": "1e24",
}
if text[-1] in postPrefixes:
v = decimal.Decimal(text[:-1])
Expand Down
22 changes: 22 additions & 0 deletions tests/pytests/unit/modules/test_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
"""

import decimal

import pytest

import salt.modules.disk as disk
Expand Down Expand Up @@ -395,3 +397,23 @@ def test_format__fat():
mock.assert_any_call(
["mkfs", "-t", "fat", "-F", 12, device], ignore_retcode=True
)


@pytest.mark.parametrize(
"text,expected",
[
("42", decimal.Decimal("42")),
("1K", decimal.Decimal("1000")),
("1.5K", decimal.Decimal("1500")),
("2.5M", decimal.Decimal("2500000")),
("1G", decimal.Decimal("1000000000")),
("1T", decimal.Decimal("1000000000000")),
],
)
def test_parse_numbers(text, expected):
"""
Test that _parse_numbers correctly parses numeric strings with SI suffixes.
Fixes issue #65490 where postPrefixes used 10E3 instead of 1E3, causing
values to be inflated by a factor of 10.
"""
assert disk._parse_numbers(text) == expected