Merge branch 'dz-fix-mount_options' of https://github.com/dzimine/docker-py into dzimine-dz-fix-mount_options

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-01-09 14:19:25 -08:00
commit 155b95d143
2 changed files with 18 additions and 1 deletions

View File

@ -135,6 +135,7 @@ class Mount(dict):
'Only acceptable mount types are `bind` and `volume`.'
)
self['Type'] = type
self['ReadOnly'] = read_only
if type == 'bind':
if propagation is not None:
@ -174,7 +175,7 @@ class Mount(dict):
else:
target = parts[1]
source = parts[0]
read_only = not (len(parts) == 3 or parts[2] == 'ro')
read_only = not (len(parts) == 2 or parts[2] == 'rw')
return cls(target, source, read_only=read_only)

16
tests/unit/types.py Normal file
View File

@ -0,0 +1,16 @@
import unittest
from docker.types.services import Mount
class TestMounts(unittest.TestCase):
def test_parse_mount_string_docker(self):
mount = Mount.parse_mount_string("foo/bar:/buz:ro")
self.assertEqual(mount['Source'], "foo/bar")
self.assertEqual(mount['Target'], "/buz")
self.assertEqual(mount['ReadOnly'], True)
mount = Mount.parse_mount_string("foo/bar:/buz:rw")
self.assertEqual(mount['ReadOnly'], False)
mount = Mount.parse_mount_string("foo/bar:/buz")
self.assertEqual(mount['ReadOnly'], False)