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 @@ -180,8 +180,21 @@ def convert_volume_binds(binds):
180
180
result = []
181
181
for k , v in binds .items ():
182
182
if isinstance (v , dict ):
183
+ if 'ro' in v and 'mode' in v :
184
+ raise ValueError (
185
+ 'Binding cannot contain both "ro" and "mode": {}'
186
+ .format (repr (v ))
187
+ )
188
+
189
+ if 'ro' in v :
190
+ mode = 'ro' if v ['ro' ] else 'rw'
191
+ elif 'mode' in v :
192
+ mode = v ['mode' ]
193
+ else :
194
+ mode = 'rw'
195
+
183
196
result .append ('{0}:{1}:{2}' .format (
184
- k , v ['bind' ], 'ro' if v . get ( 'ro' , False ) else 'rw'
197
+ k , v ['bind' ], mode
185
198
))
186
199
else :
187
200
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_binds_list (self ):
812
859
try :
813
860
self .client .create_container (
You can’t perform that action at this time.
0 commit comments