File tree Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -177,8 +177,21 @@ def convert_volume_binds(binds):
177
177
result = []
178
178
for k , v in binds .items ():
179
179
if isinstance (v , dict ):
180
+ if 'ro' in v and 'mode' in v :
181
+ raise ValueError (
182
+ 'Binding cannot contain both "ro" and "mode": {}'
183
+ .format (repr (v ))
184
+ )
185
+
186
+ if 'ro' in v :
187
+ mode = 'ro' if v ['ro' ] else 'rw'
188
+ elif 'mode' in v :
189
+ mode = v ['mode' ]
190
+ else :
191
+ mode = 'rw'
192
+
180
193
result .append ('{0}:{1}:{2}' .format (
181
- k , v ['bind' ], 'ro' if v . get ( 'ro' , False ) else 'rw'
194
+ k , v ['bind' ], mode
182
195
))
183
196
else :
184
197
result .append ('{0}:{1}:rw' .format (k , v ))
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ container_id = c.create_container(
10
10
host_config = docker.utils.create_host_config(binds = {
11
11
' /home/user1/' : {
12
12
' bind' : ' /mnt/vol2' ,
13
- ' ro ' : False
13
+ ' mode ' : ' rw ' ,
14
14
},
15
15
' /var/www' : {
16
16
' bind' : ' /mnt/vol1' ,
17
- ' ro ' : True
17
+ ' mode ' : ' ro ' ,
18
18
}
19
19
})
20
20
)
Original file line number Diff line number Diff line change @@ -808,6 +808,53 @@ def test_create_container_with_binds_rw(self):
808
808
DEFAULT_TIMEOUT_SECONDS
809
809
)
810
810
811
+ def test_create_container_with_binds_mode (self ):
812
+ try :
813
+ mount_dest = '/mnt'
814
+ mount_origin = '/tmp'
815
+ self .client .create_container (
816
+ 'busybox' , 'true' , host_config = create_host_config (
817
+ binds = {mount_origin : {
818
+ "bind" : mount_dest ,
819
+ "mode" : "z" ,
820
+ }}
821
+ )
822
+ )
823
+ except Exception as e :
824
+ self .fail ('Command should not raise exception: {0}' .format (e ))
825
+
826
+ args = fake_request .call_args
827
+ self .assertEqual (args [0 ][0 ], url_prefix +
828
+ 'containers/create' )
829
+ expected_payload = self .base_create_payload ()
830
+ expected_payload ['HostConfig' ] = create_host_config ()
831
+ expected_payload ['HostConfig' ]['Binds' ] = ["/tmp:/mnt:z" ]
832
+ self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
833
+ self .assertEqual (args [1 ]['headers' ],
834
+ {'Content-Type' : 'application/json' })
835
+ self .assertEqual (
836
+ args [1 ]['timeout' ],
837
+ DEFAULT_TIMEOUT_SECONDS
838
+ )
839
+
840
+ def test_create_container_with_binds_mode_and_ro_error (self ):
841
+ try :
842
+ mount_dest = '/mnt'
843
+ mount_origin = '/tmp'
844
+ self .client .create_container (
845
+ 'busybox' , 'true' , host_config = create_host_config (
846
+ binds = {mount_origin : {
847
+ "bind" : mount_dest ,
848
+ "mode" : "z" ,
849
+ "ro" : True ,
850
+ }}
851
+ )
852
+ )
853
+ except ValueError :
854
+ return
855
+
856
+ self .fail ('Command should raise ValueError' )
857
+
811
858
def test_create_container_with_port_binds (self ):
812
859
self .maxDiff = None
813
860
try :
You can’t perform that action at this time.
0 commit comments