48
48
49
49
warnings .simplefilter ('error' )
50
50
warnings .filterwarnings ('error' )
51
- create_host_config = docker .utils .create_host_config
52
51
53
52
54
53
def response (status_code = 200 , content = '' , headers = None , reason = None , elapsed = 0 ,
@@ -495,7 +494,7 @@ def test_create_container_with_cpuset(self):
495
494
def test_create_container_with_cgroup_parent (self ):
496
495
try :
497
496
self .client .create_container (
498
- 'busybox' , 'ls' , host_config = create_host_config (
497
+ 'busybox' , 'ls' , host_config = self . client . create_host_config (
499
498
cgroup_parent = 'test'
500
499
)
501
500
)
@@ -604,7 +603,7 @@ def test_create_named_container(self):
604
603
def test_create_container_with_mem_limit_as_int (self ):
605
604
try :
606
605
self .client .create_container (
607
- 'busybox' , 'true' , host_config = create_host_config (
606
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
608
607
mem_limit = 128.0
609
608
)
610
609
)
@@ -618,7 +617,7 @@ def test_create_container_with_mem_limit_as_int(self):
618
617
def test_create_container_with_mem_limit_as_string (self ):
619
618
try :
620
619
self .client .create_container (
621
- 'busybox' , 'true' , host_config = create_host_config (
620
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
622
621
mem_limit = '128'
623
622
)
624
623
)
@@ -632,7 +631,7 @@ def test_create_container_with_mem_limit_as_string(self):
632
631
def test_create_container_with_mem_limit_as_string_with_k_unit (self ):
633
632
try :
634
633
self .client .create_container (
635
- 'busybox' , 'true' , host_config = create_host_config (
634
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
636
635
mem_limit = '128k'
637
636
)
638
637
)
@@ -646,7 +645,7 @@ def test_create_container_with_mem_limit_as_string_with_k_unit(self):
646
645
def test_create_container_with_mem_limit_as_string_with_m_unit (self ):
647
646
try :
648
647
self .client .create_container (
649
- 'busybox' , 'true' , host_config = create_host_config (
648
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
650
649
mem_limit = '128m'
651
650
)
652
651
)
@@ -661,7 +660,7 @@ def test_create_container_with_mem_limit_as_string_with_m_unit(self):
661
660
def test_create_container_with_mem_limit_as_string_with_g_unit (self ):
662
661
try :
663
662
self .client .create_container (
664
- 'busybox' , 'true' , host_config = create_host_config (
663
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
665
664
mem_limit = '128g'
666
665
)
667
666
)
@@ -676,11 +675,13 @@ def test_create_container_with_mem_limit_as_string_with_g_unit(self):
676
675
677
676
def test_create_container_with_mem_limit_as_string_with_wrong_value (self ):
678
677
self .assertRaises (
679
- docker .errors .DockerException , create_host_config , mem_limit = '128p'
678
+ docker .errors .DockerException ,
679
+ self .client .create_host_config , mem_limit = '128p'
680
680
)
681
681
682
682
self .assertRaises (
683
- docker .errors .DockerException , create_host_config , mem_limit = '1f28'
683
+ docker .errors .DockerException ,
684
+ self .client .create_host_config , mem_limit = '1f28'
684
685
)
685
686
686
687
def test_start_container (self ):
@@ -726,7 +727,7 @@ def test_start_container_regression_573(self):
726
727
def test_create_container_with_lxc_conf (self ):
727
728
try :
728
729
self .client .create_container (
729
- 'busybox' , 'true' , host_config = create_host_config (
730
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
730
731
lxc_conf = {'lxc.conf.k' : 'lxc.conf.value' }
731
732
)
732
733
)
@@ -738,7 +739,7 @@ def test_create_container_with_lxc_conf(self):
738
739
url_prefix + 'containers/create'
739
740
)
740
741
expected_payload = self .base_create_payload ()
741
- expected_payload ['HostConfig' ] = create_host_config ()
742
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
742
743
expected_payload ['HostConfig' ]['LxcConf' ] = [
743
744
{"Value" : "lxc.conf.value" , "Key" : "lxc.conf.k" }
744
745
]
@@ -756,7 +757,7 @@ def test_create_container_with_lxc_conf(self):
756
757
def test_create_container_with_lxc_conf_compat (self ):
757
758
try :
758
759
self .client .create_container (
759
- 'busybox' , 'true' , host_config = create_host_config (
760
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
760
761
lxc_conf = [{'Key' : 'lxc.conf.k' , 'Value' : 'lxc.conf.value' }]
761
762
)
762
763
)
@@ -766,7 +767,7 @@ def test_create_container_with_lxc_conf_compat(self):
766
767
args = fake_request .call_args
767
768
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
768
769
expected_payload = self .base_create_payload ()
769
- expected_payload ['HostConfig' ] = create_host_config ()
770
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
770
771
expected_payload ['HostConfig' ]['LxcConf' ] = [
771
772
{"Value" : "lxc.conf.value" , "Key" : "lxc.conf.k" }
772
773
]
@@ -784,7 +785,7 @@ def test_create_container_with_binds_ro(self):
784
785
mount_dest = '/mnt'
785
786
mount_origin = '/tmp'
786
787
self .client .create_container (
787
- 'busybox' , 'true' , host_config = create_host_config (
788
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
788
789
binds = {mount_origin : {
789
790
"bind" : mount_dest ,
790
791
"ro" : True
@@ -798,7 +799,7 @@ def test_create_container_with_binds_ro(self):
798
799
self .assertEqual (args [0 ][0 ], url_prefix +
799
800
'containers/create' )
800
801
expected_payload = self .base_create_payload ()
801
- expected_payload ['HostConfig' ] = create_host_config ()
802
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
802
803
expected_payload ['HostConfig' ]['Binds' ] = ["/tmp:/mnt:ro" ]
803
804
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
804
805
self .assertEqual (args [1 ]['headers' ],
@@ -813,7 +814,7 @@ def test_create_container_with_binds_rw(self):
813
814
mount_dest = '/mnt'
814
815
mount_origin = '/tmp'
815
816
self .client .create_container (
816
- 'busybox' , 'true' , host_config = create_host_config (
817
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
817
818
binds = {mount_origin : {
818
819
"bind" : mount_dest ,
819
820
"ro" : False
@@ -827,7 +828,7 @@ def test_create_container_with_binds_rw(self):
827
828
self .assertEqual (args [0 ][0 ], url_prefix +
828
829
'containers/create' )
829
830
expected_payload = self .base_create_payload ()
830
- expected_payload ['HostConfig' ] = create_host_config ()
831
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
831
832
expected_payload ['HostConfig' ]['Binds' ] = ["/tmp:/mnt:rw" ]
832
833
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
833
834
self .assertEqual (args [1 ]['headers' ],
@@ -842,7 +843,7 @@ def test_create_container_with_binds_mode(self):
842
843
mount_dest = '/mnt'
843
844
mount_origin = '/tmp'
844
845
self .client .create_container (
845
- 'busybox' , 'true' , host_config = create_host_config (
846
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
846
847
binds = {mount_origin : {
847
848
"bind" : mount_dest ,
848
849
"mode" : "z" ,
@@ -856,7 +857,7 @@ def test_create_container_with_binds_mode(self):
856
857
self .assertEqual (args [0 ][0 ], url_prefix +
857
858
'containers/create' )
858
859
expected_payload = self .base_create_payload ()
859
- expected_payload ['HostConfig' ] = create_host_config ()
860
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
860
861
expected_payload ['HostConfig' ]['Binds' ] = ["/tmp:/mnt:z" ]
861
862
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
862
863
self .assertEqual (args [1 ]['headers' ],
@@ -871,7 +872,7 @@ def test_create_container_with_binds_mode_and_ro_error(self):
871
872
mount_dest = '/mnt'
872
873
mount_origin = '/tmp'
873
874
self .client .create_container (
874
- 'busybox' , 'true' , host_config = create_host_config (
875
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
875
876
binds = {mount_origin : {
876
877
"bind" : mount_dest ,
877
878
"mode" : "z" ,
@@ -887,7 +888,7 @@ def test_create_container_with_binds_mode_and_ro_error(self):
887
888
def test_create_container_with_binds_list (self ):
888
889
try :
889
890
self .client .create_container (
890
- 'busybox' , 'true' , host_config = create_host_config (
891
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
891
892
binds = [
892
893
"/tmp:/mnt/1:ro" ,
893
894
"/tmp:/mnt/2" ,
@@ -901,7 +902,7 @@ def test_create_container_with_binds_list(self):
901
902
self .assertEqual (args [0 ][0 ], url_prefix +
902
903
'containers/create' )
903
904
expected_payload = self .base_create_payload ()
904
- expected_payload ['HostConfig' ] = create_host_config ()
905
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
905
906
expected_payload ['HostConfig' ]['Binds' ] = [
906
907
"/tmp:/mnt/1:ro" ,
907
908
"/tmp:/mnt/2" ,
@@ -918,7 +919,7 @@ def test_create_container_with_port_binds(self):
918
919
self .maxDiff = None
919
920
try :
920
921
self .client .create_container (
921
- 'busybox' , 'true' , host_config = create_host_config (
922
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
922
923
port_bindings = {
923
924
1111 : None ,
924
925
2222 : 2222 ,
@@ -987,7 +988,7 @@ def test_create_container_with_links(self):
987
988
link_path = 'path'
988
989
alias = 'alias'
989
990
self .client .create_container (
990
- 'busybox' , 'true' , host_config = create_host_config (
991
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
991
992
links = {link_path : alias }
992
993
)
993
994
)
@@ -999,7 +1000,7 @@ def test_create_container_with_links(self):
999
1000
args [0 ][0 ], url_prefix + 'containers/create'
1000
1001
)
1001
1002
expected_payload = self .base_create_payload ()
1002
- expected_payload ['HostConfig' ] = create_host_config ()
1003
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1003
1004
expected_payload ['HostConfig' ]['Links' ] = ['path:alias' ]
1004
1005
1005
1006
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
@@ -1012,7 +1013,7 @@ def test_create_container_with_multiple_links(self):
1012
1013
link_path = 'path'
1013
1014
alias = 'alias'
1014
1015
self .client .create_container (
1015
- 'busybox' , 'true' , host_config = create_host_config (
1016
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
1016
1017
links = {
1017
1018
link_path + '1' : alias + '1' ,
1018
1019
link_path + '2' : alias + '2'
@@ -1025,7 +1026,7 @@ def test_create_container_with_multiple_links(self):
1025
1026
args = fake_request .call_args
1026
1027
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1027
1028
expected_payload = self .base_create_payload ()
1028
- expected_payload ['HostConfig' ] = create_host_config ()
1029
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1029
1030
expected_payload ['HostConfig' ]['Links' ] = [
1030
1031
'path1:alias1' , 'path2:alias2'
1031
1032
]
@@ -1039,7 +1040,7 @@ def test_create_container_with_links_as_list_of_tuples(self):
1039
1040
link_path = 'path'
1040
1041
alias = 'alias'
1041
1042
self .client .create_container (
1042
- 'busybox' , 'true' , host_config = create_host_config (
1043
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
1043
1044
links = [(link_path , alias )]
1044
1045
)
1045
1046
)
@@ -1049,7 +1050,7 @@ def test_create_container_with_links_as_list_of_tuples(self):
1049
1050
args = fake_request .call_args
1050
1051
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1051
1052
expected_payload = self .base_create_payload ()
1052
- expected_payload ['HostConfig' ] = create_host_config ()
1053
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1053
1054
expected_payload ['HostConfig' ]['Links' ] = ['path:alias' ]
1054
1055
1055
1056
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
@@ -1061,13 +1062,13 @@ def test_create_container_privileged(self):
1061
1062
try :
1062
1063
self .client .create_container (
1063
1064
'busybox' , 'true' ,
1064
- host_config = create_host_config (privileged = True )
1065
+ host_config = self . client . create_host_config (privileged = True )
1065
1066
)
1066
1067
except Exception as e :
1067
1068
self .fail ('Command should not raise exception: {0}' .format (e ))
1068
1069
1069
1070
expected_payload = self .base_create_payload ()
1070
- expected_payload ['HostConfig' ] = create_host_config ()
1071
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1071
1072
expected_payload ['HostConfig' ]['Privileged' ] = True
1072
1073
args = fake_request .call_args
1073
1074
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
@@ -1306,7 +1307,7 @@ def test_start_container_with_dict_instead_of_id(self):
1306
1307
def test_create_container_with_restart_policy (self ):
1307
1308
try :
1308
1309
self .client .create_container (
1309
- 'busybox' , 'true' , host_config = create_host_config (
1310
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
1310
1311
restart_policy = {
1311
1312
"Name" : "always" ,
1312
1313
"MaximumRetryCount" : 0
@@ -1319,7 +1320,7 @@ def test_create_container_with_restart_policy(self):
1319
1320
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1320
1321
1321
1322
expected_payload = self .base_create_payload ()
1322
- expected_payload ['HostConfig' ] = create_host_config ()
1323
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1323
1324
expected_payload ['HostConfig' ]['RestartPolicy' ] = {
1324
1325
"MaximumRetryCount" : 0 , "Name" : "always"
1325
1326
}
@@ -1336,14 +1337,14 @@ def test_create_container_with_added_capabilities(self):
1336
1337
try :
1337
1338
self .client .create_container (
1338
1339
'busybox' , 'true' ,
1339
- host_config = create_host_config (cap_add = ['MKNOD' ])
1340
+ host_config = self . client . create_host_config (cap_add = ['MKNOD' ])
1340
1341
)
1341
1342
except Exception as e :
1342
1343
self .fail ('Command should not raise exception: {0}' .format (e ))
1343
1344
args = fake_request .call_args
1344
1345
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1345
1346
expected_payload = self .base_create_payload ()
1346
- expected_payload ['HostConfig' ] = create_host_config ()
1347
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1347
1348
expected_payload ['HostConfig' ]['CapAdd' ] = ['MKNOD' ]
1348
1349
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
1349
1350
self .assertEqual (
@@ -1357,14 +1358,14 @@ def test_create_container_with_dropped_capabilities(self):
1357
1358
try :
1358
1359
self .client .create_container (
1359
1360
'busybox' , 'true' ,
1360
- host_config = create_host_config (cap_drop = ['MKNOD' ])
1361
+ host_config = self . client . create_host_config (cap_drop = ['MKNOD' ])
1361
1362
)
1362
1363
except Exception as e :
1363
1364
self .fail ('Command should not raise exception: {0}' .format (e ))
1364
1365
args = fake_request .call_args
1365
1366
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1366
1367
expected_payload = self .base_create_payload ()
1367
- expected_payload ['HostConfig' ] = create_host_config ()
1368
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1368
1369
expected_payload ['HostConfig' ]['CapDrop' ] = ['MKNOD' ]
1369
1370
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
1370
1371
self .assertEqual (
@@ -1377,7 +1378,7 @@ def test_create_container_with_dropped_capabilities(self):
1377
1378
def test_create_container_with_devices (self ):
1378
1379
try :
1379
1380
self .client .create_container (
1380
- 'busybox' , 'true' , host_config = create_host_config (
1381
+ 'busybox' , 'true' , host_config = self . client . create_host_config (
1381
1382
devices = ['/dev/sda:/dev/xvda:rwm' ,
1382
1383
'/dev/sdb:/dev/xvdb' ,
1383
1384
'/dev/sdc' ]
@@ -1388,7 +1389,7 @@ def test_create_container_with_devices(self):
1388
1389
args = fake_request .call_args
1389
1390
self .assertEqual (args [0 ][0 ], url_prefix + 'containers/create' )
1390
1391
expected_payload = self .base_create_payload ()
1391
- expected_payload ['HostConfig' ] = create_host_config ()
1392
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1392
1393
expected_payload ['HostConfig' ]['Devices' ] = [
1393
1394
{'CgroupPermissions' : 'rwm' ,
1394
1395
'PathInContainer' : '/dev/xvda' ,
@@ -1462,7 +1463,7 @@ def test_create_container_with_named_volume(self):
1462
1463
volume_name = 'name'
1463
1464
self .client .create_container (
1464
1465
'busybox' , 'true' ,
1465
- host_config = create_host_config (
1466
+ host_config = self . client . create_host_config (
1466
1467
binds = {volume_name : {
1467
1468
"bind" : mount_dest ,
1468
1469
"ro" : False
@@ -1477,7 +1478,7 @@ def test_create_container_with_named_volume(self):
1477
1478
'containers/create' )
1478
1479
expected_payload = self .base_create_payload ()
1479
1480
expected_payload ['VolumeDriver' ] = 'foodriver'
1480
- expected_payload ['HostConfig' ] = create_host_config ()
1481
+ expected_payload ['HostConfig' ] = self . client . create_host_config ()
1481
1482
expected_payload ['HostConfig' ]['Binds' ] = ["name:/mnt:rw" ]
1482
1483
self .assertEqual (json .loads (args [1 ]['data' ]), expected_payload )
1483
1484
self .assertEqual (args [1 ]['headers' ],
@@ -2536,12 +2537,12 @@ def test_tar_with_directory_symlinks(self):
2536
2537
2537
2538
def test_create_host_config_secopt (self ):
2538
2539
security_opt = ['apparmor:test_profile' ]
2539
- result = create_host_config (security_opt = security_opt )
2540
+ result = self . client . create_host_config (security_opt = security_opt )
2540
2541
self .assertIn ('SecurityOpt' , result )
2541
2542
self .assertEqual (result ['SecurityOpt' ], security_opt )
2542
2543
2543
2544
self .assertRaises (
2544
- docker .errors .DockerException , create_host_config ,
2545
+ docker .errors .DockerException , self . client . create_host_config ,
2545
2546
security_opt = 'wrong'
2546
2547
)
2547
2548
0 commit comments