Skip to content

Commit 454328d

Browse files
Dmitrishin-
authored andcommitted
Fix readonly in mounts.
Signed-off-by: Dmitri Zimine [email protected]
1 parent 18eb08e commit 454328d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

docker/types/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __init__(self, target, source, type='volume', read_only=False,
135135
'Only acceptable mount types are `bind` and `volume`.'
136136
)
137137
self['Type'] = type
138+
self['ReadOnly'] = read_only
138139

139140
if type == 'bind':
140141
if propagation is not None:
@@ -174,7 +175,7 @@ def parse_mount_string(cls, string):
174175
else:
175176
target = parts[1]
176177
source = parts[0]
177-
read_only = not (len(parts) == 3 or parts[2] == 'ro')
178+
read_only = not (len(parts) == 2 or parts[2] == 'rw')
178179
return cls(target, source, read_only=read_only)
179180

180181

tests/unit/types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
from docker.types.services import Mount
3+
4+
5+
class TestMounts(unittest.TestCase):
6+
def test_parse_mount_string_docker(self):
7+
mount = Mount.parse_mount_string("foo/bar:/buz:ro")
8+
self.assertEqual(mount['Source'], "foo/bar")
9+
self.assertEqual(mount['Target'], "/buz")
10+
self.assertEqual(mount['ReadOnly'], True)
11+
12+
mount = Mount.parse_mount_string("foo/bar:/buz:rw")
13+
self.assertEqual(mount['ReadOnly'], False)
14+
15+
mount = Mount.parse_mount_string("foo/bar:/buz")
16+
self.assertEqual(mount['ReadOnly'], False)

0 commit comments

Comments
 (0)