Kaydet (Commit) 7b2fd8cf authored tarafından Joffrey F's avatar Joffrey F

Merge pull request #562 from smothiki/mems

make memory units compatible with native docker cli
......@@ -322,6 +322,9 @@ def parse_bytes(s):
if len(s) == 0:
s = 0
else:
if s[-2:-1].isalpha() and s[-1].isalpha():
if (s[-1] == "b" or s[-1] == "B"):
s = s[:-1]
units = BYTE_UNITS
suffix = s[-1].lower()
......
......@@ -6,7 +6,7 @@ from docker.client import Client
from docker.errors import DockerException
from docker.utils import (
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
create_host_config, Ulimit, LogConfig
create_host_config, Ulimit, LogConfig, parse_bytes
)
from docker.utils.ports import build_port_bindings, split_port
from docker.auth import resolve_authconfig
......@@ -37,6 +37,12 @@ class UtilsTest(base.BaseTestCase):
self.assertEqual(parse_repository_tag("url:5000/repo:tag"),
("url:5000/repo", "tag"))
def test_parse_bytes(self):
self.assertEqual(parse_bytes("512MB"), (536870912))
self.assertEqual(parse_bytes("512M"), (536870912))
self.assertRaises(DockerException, parse_bytes, "512MK")
self.assertRaises(DockerException, parse_bytes, "512L")
def test_parse_host(self):
invalid_hosts = [
'0.0.0.0',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment