Improve accuracy of to_cpu_str converter function
@@ -95,11 +95,16 @@ def to_cpu_str(n_cpus):
"""Convert number of cpus to cpu string
(e.g. 0.5 -> '500m')
"""
- millicores = int(n_cpus * 1000)
+ if n_cpus == 0:
+ return "0"
+ millicores = n_cpus * 1000
if millicores % 1 == 0:
- return f"{millicores}m"
- nanocores = int(n_cpus * 1000000000)
- return f"{nanocores}n"
+ return f"{int(millicores)}m"
+ microcores = n_cpus * 1000000
+ if microcores % 1 == 0:
+ return f"{int(microcores)}u"
+ nanocores = n_cpus * 1000000000
+ return f"{int(nanocores)}n"
def to_n_cpus_from_cpu_str(cpu_str):
@@ -118,11 +123,6 @@ def to_n_cpus_from_cpu_str(cpu_str):
return 0
-# Error message which indicates a transient SSL error upon which request
-# can be retried
-TRANSIENT_SSL_ERROR = "The read operation timed out"
-
-
def find(value, predicate):
results = [x for x in value if predicate(x)]
return results[0] if len(results) > 0 else None
