machine_readable_bytes() accepts invalid and misleading SI prefixes

Bug #1557839 reported by Gavin Panella
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Invalid
Medium
Unassigned

Bug Description

For example:

  >>> machine_readable_bytes('1m')
  1000000

  >>> machine_readable_bytes('1K')
  1000

  >>> machine_readable_bytes('1p')
  1000000000000000

I would expect:

  >>> machine_readable_bytes('1m') # millibyte
  --> ValueError: smallest divisible unit is the byte.

  >>> machine_readable_bytes('1K')
  1024

  >>> machine_readable_bytes('1p') # picobyte
  --> ValueError: smallest divisible unit is the byte.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Hah. I had to check whether or not it was April Fools Day. What happens when you specify 1µ? ;-)

For the record, I think it's safe to assume that someone intended to write "megabyte", "kilobyte", or "terabyte". In other words, the current behavior is fine. If you believe the wiki, the standard is to use base 10 for storage sizes, which leaves little room for ambiguity.[1]

Unless, you know, you really did want me to allocate you that node with 1,000,000,000,000,000,000,000,000 picobytes of storage.

[1]: https://wiki.ubuntu.com/UnitsPolicy

Revision history for this message
Gavin Panella (allenap) wrote :

It is kind of funny, but we do need to be precise. Computers are well
enough provisioned now that disambiguating kB from KB from KiB is
uncommon, but the policy you linked to is fairly clear:

  Applications must use IEC standard for base-2 units: ...
  Applications must use SI standard for base-10 units: ...
  It is not allowed to use the SI standard for base-2 units:
    1 kB != 1,024 bytes
    KB (with a big k) does not exist

Revision history for this message
Mike Pontillo (mpontillo) wrote :

While that is true, I think excessive precision in this case could be a usability problem. (Also, I would hate to think that customers have written provisioning scripts that would suddenly break if we fix this.)

Revision history for this message
Mike Pontillo (mpontillo) wrote :

In other words, I think we should follow the robustness principle here: be liberal about the units we accept (millibyte and picobyte should be fine to recognize as megabyte and petabyte, respectively) and be conservative about what we display (correct units only).

Which leaves what to do with a capital K as a toss-up. It seems weird to have just one unit that behaves differently if it's capitalized.

If we really want to eliminate ambiguity, maybe we should optionally allow people to specify units with explicit exponents:

    5*10^6 # 5 MB
    5*2^20 # 5 MiB

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi!

**This is an automated message**

We believe this is may no longer be an issue in the latest MAAS release. Due to the report date of this, we are currently marking it as Invalid. If you believe this bug report still valid against the latest release of MAAS, or if you are still interested in this, please re-open this bug report.

Thanks

Changed in maas:
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.