Skip to content

Commit 595965e

Browse files
committed
Adapt tests to new create_host_config usage
1 parent 4bd3c48 commit 595965e

File tree

2 files changed

+63
-49
lines changed

2 files changed

+63
-49
lines changed

tests/test.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
warnings.simplefilter('error')
5050
warnings.filterwarnings('error')
51-
create_host_config = docker.utils.create_host_config
5251

5352

5453
def response(status_code=200, content='', headers=None, reason=None, elapsed=0,
@@ -495,7 +494,7 @@ def test_create_container_with_cpuset(self):
495494
def test_create_container_with_cgroup_parent(self):
496495
try:
497496
self.client.create_container(
498-
'busybox', 'ls', host_config=create_host_config(
497+
'busybox', 'ls', host_config=self.client.create_host_config(
499498
cgroup_parent='test'
500499
)
501500
)
@@ -604,7 +603,7 @@ def test_create_named_container(self):
604603
def test_create_container_with_mem_limit_as_int(self):
605604
try:
606605
self.client.create_container(
607-
'busybox', 'true', host_config=create_host_config(
606+
'busybox', 'true', host_config=self.client.create_host_config(
608607
mem_limit=128.0
609608
)
610609
)
@@ -618,7 +617,7 @@ def test_create_container_with_mem_limit_as_int(self):
618617
def test_create_container_with_mem_limit_as_string(self):
619618
try:
620619
self.client.create_container(
621-
'busybox', 'true', host_config=create_host_config(
620+
'busybox', 'true', host_config=self.client.create_host_config(
622621
mem_limit='128'
623622
)
624623
)
@@ -632,7 +631,7 @@ def test_create_container_with_mem_limit_as_string(self):
632631
def test_create_container_with_mem_limit_as_string_with_k_unit(self):
633632
try:
634633
self.client.create_container(
635-
'busybox', 'true', host_config=create_host_config(
634+
'busybox', 'true', host_config=self.client.create_host_config(
636635
mem_limit='128k'
637636
)
638637
)
@@ -646,7 +645,7 @@ def test_create_container_with_mem_limit_as_string_with_k_unit(self):
646645
def test_create_container_with_mem_limit_as_string_with_m_unit(self):
647646
try:
648647
self.client.create_container(
649-
'busybox', 'true', host_config=create_host_config(
648+
'busybox', 'true', host_config=self.client.create_host_config(
650649
mem_limit='128m'
651650
)
652651
)
@@ -661,7 +660,7 @@ def test_create_container_with_mem_limit_as_string_with_m_unit(self):
661660
def test_create_container_with_mem_limit_as_string_with_g_unit(self):
662661
try:
663662
self.client.create_container(
664-
'busybox', 'true', host_config=create_host_config(
663+
'busybox', 'true', host_config=self.client.create_host_config(
665664
mem_limit='128g'
666665
)
667666
)
@@ -676,11 +675,13 @@ def test_create_container_with_mem_limit_as_string_with_g_unit(self):
676675

677676
def test_create_container_with_mem_limit_as_string_with_wrong_value(self):
678677
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'
680680
)
681681

682682
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'
684685
)
685686

686687
def test_start_container(self):
@@ -726,7 +727,7 @@ def test_start_container_regression_573(self):
726727
def test_create_container_with_lxc_conf(self):
727728
try:
728729
self.client.create_container(
729-
'busybox', 'true', host_config=create_host_config(
730+
'busybox', 'true', host_config=self.client.create_host_config(
730731
lxc_conf={'lxc.conf.k': 'lxc.conf.value'}
731732
)
732733
)
@@ -738,7 +739,7 @@ def test_create_container_with_lxc_conf(self):
738739
url_prefix + 'containers/create'
739740
)
740741
expected_payload = self.base_create_payload()
741-
expected_payload['HostConfig'] = create_host_config()
742+
expected_payload['HostConfig'] = self.client.create_host_config()
742743
expected_payload['HostConfig']['LxcConf'] = [
743744
{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}
744745
]
@@ -756,7 +757,7 @@ def test_create_container_with_lxc_conf(self):
756757
def test_create_container_with_lxc_conf_compat(self):
757758
try:
758759
self.client.create_container(
759-
'busybox', 'true', host_config=create_host_config(
760+
'busybox', 'true', host_config=self.client.create_host_config(
760761
lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}]
761762
)
762763
)
@@ -766,7 +767,7 @@ def test_create_container_with_lxc_conf_compat(self):
766767
args = fake_request.call_args
767768
self.assertEqual(args[0][0], url_prefix + 'containers/create')
768769
expected_payload = self.base_create_payload()
769-
expected_payload['HostConfig'] = create_host_config()
770+
expected_payload['HostConfig'] = self.client.create_host_config()
770771
expected_payload['HostConfig']['LxcConf'] = [
771772
{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}
772773
]
@@ -784,7 +785,7 @@ def test_create_container_with_binds_ro(self):
784785
mount_dest = '/mnt'
785786
mount_origin = '/tmp'
786787
self.client.create_container(
787-
'busybox', 'true', host_config=create_host_config(
788+
'busybox', 'true', host_config=self.client.create_host_config(
788789
binds={mount_origin: {
789790
"bind": mount_dest,
790791
"ro": True
@@ -798,7 +799,7 @@ def test_create_container_with_binds_ro(self):
798799
self.assertEqual(args[0][0], url_prefix +
799800
'containers/create')
800801
expected_payload = self.base_create_payload()
801-
expected_payload['HostConfig'] = create_host_config()
802+
expected_payload['HostConfig'] = self.client.create_host_config()
802803
expected_payload['HostConfig']['Binds'] = ["/tmp:/mnt:ro"]
803804
self.assertEqual(json.loads(args[1]['data']), expected_payload)
804805
self.assertEqual(args[1]['headers'],
@@ -813,7 +814,7 @@ def test_create_container_with_binds_rw(self):
813814
mount_dest = '/mnt'
814815
mount_origin = '/tmp'
815816
self.client.create_container(
816-
'busybox', 'true', host_config=create_host_config(
817+
'busybox', 'true', host_config=self.client.create_host_config(
817818
binds={mount_origin: {
818819
"bind": mount_dest,
819820
"ro": False
@@ -827,7 +828,7 @@ def test_create_container_with_binds_rw(self):
827828
self.assertEqual(args[0][0], url_prefix +
828829
'containers/create')
829830
expected_payload = self.base_create_payload()
830-
expected_payload['HostConfig'] = create_host_config()
831+
expected_payload['HostConfig'] = self.client.create_host_config()
831832
expected_payload['HostConfig']['Binds'] = ["/tmp:/mnt:rw"]
832833
self.assertEqual(json.loads(args[1]['data']), expected_payload)
833834
self.assertEqual(args[1]['headers'],
@@ -842,7 +843,7 @@ def test_create_container_with_binds_mode(self):
842843
mount_dest = '/mnt'
843844
mount_origin = '/tmp'
844845
self.client.create_container(
845-
'busybox', 'true', host_config=create_host_config(
846+
'busybox', 'true', host_config=self.client.create_host_config(
846847
binds={mount_origin: {
847848
"bind": mount_dest,
848849
"mode": "z",
@@ -856,7 +857,7 @@ def test_create_container_with_binds_mode(self):
856857
self.assertEqual(args[0][0], url_prefix +
857858
'containers/create')
858859
expected_payload = self.base_create_payload()
859-
expected_payload['HostConfig'] = create_host_config()
860+
expected_payload['HostConfig'] = self.client.create_host_config()
860861
expected_payload['HostConfig']['Binds'] = ["/tmp:/mnt:z"]
861862
self.assertEqual(json.loads(args[1]['data']), expected_payload)
862863
self.assertEqual(args[1]['headers'],
@@ -871,7 +872,7 @@ def test_create_container_with_binds_mode_and_ro_error(self):
871872
mount_dest = '/mnt'
872873
mount_origin = '/tmp'
873874
self.client.create_container(
874-
'busybox', 'true', host_config=create_host_config(
875+
'busybox', 'true', host_config=self.client.create_host_config(
875876
binds={mount_origin: {
876877
"bind": mount_dest,
877878
"mode": "z",
@@ -887,7 +888,7 @@ def test_create_container_with_binds_mode_and_ro_error(self):
887888
def test_create_container_with_binds_list(self):
888889
try:
889890
self.client.create_container(
890-
'busybox', 'true', host_config=create_host_config(
891+
'busybox', 'true', host_config=self.client.create_host_config(
891892
binds=[
892893
"/tmp:/mnt/1:ro",
893894
"/tmp:/mnt/2",
@@ -901,7 +902,7 @@ def test_create_container_with_binds_list(self):
901902
self.assertEqual(args[0][0], url_prefix +
902903
'containers/create')
903904
expected_payload = self.base_create_payload()
904-
expected_payload['HostConfig'] = create_host_config()
905+
expected_payload['HostConfig'] = self.client.create_host_config()
905906
expected_payload['HostConfig']['Binds'] = [
906907
"/tmp:/mnt/1:ro",
907908
"/tmp:/mnt/2",
@@ -918,7 +919,7 @@ def test_create_container_with_port_binds(self):
918919
self.maxDiff = None
919920
try:
920921
self.client.create_container(
921-
'busybox', 'true', host_config=create_host_config(
922+
'busybox', 'true', host_config=self.client.create_host_config(
922923
port_bindings={
923924
1111: None,
924925
2222: 2222,
@@ -987,7 +988,7 @@ def test_create_container_with_links(self):
987988
link_path = 'path'
988989
alias = 'alias'
989990
self.client.create_container(
990-
'busybox', 'true', host_config=create_host_config(
991+
'busybox', 'true', host_config=self.client.create_host_config(
991992
links={link_path: alias}
992993
)
993994
)
@@ -999,7 +1000,7 @@ def test_create_container_with_links(self):
9991000
args[0][0], url_prefix + 'containers/create'
10001001
)
10011002
expected_payload = self.base_create_payload()
1002-
expected_payload['HostConfig'] = create_host_config()
1003+
expected_payload['HostConfig'] = self.client.create_host_config()
10031004
expected_payload['HostConfig']['Links'] = ['path:alias']
10041005

10051006
self.assertEqual(json.loads(args[1]['data']), expected_payload)
@@ -1012,7 +1013,7 @@ def test_create_container_with_multiple_links(self):
10121013
link_path = 'path'
10131014
alias = 'alias'
10141015
self.client.create_container(
1015-
'busybox', 'true', host_config=create_host_config(
1016+
'busybox', 'true', host_config=self.client.create_host_config(
10161017
links={
10171018
link_path + '1': alias + '1',
10181019
link_path + '2': alias + '2'
@@ -1025,7 +1026,7 @@ def test_create_container_with_multiple_links(self):
10251026
args = fake_request.call_args
10261027
self.assertEqual(args[0][0], url_prefix + 'containers/create')
10271028
expected_payload = self.base_create_payload()
1028-
expected_payload['HostConfig'] = create_host_config()
1029+
expected_payload['HostConfig'] = self.client.create_host_config()
10291030
expected_payload['HostConfig']['Links'] = [
10301031
'path1:alias1', 'path2:alias2'
10311032
]
@@ -1039,7 +1040,7 @@ def test_create_container_with_links_as_list_of_tuples(self):
10391040
link_path = 'path'
10401041
alias = 'alias'
10411042
self.client.create_container(
1042-
'busybox', 'true', host_config=create_host_config(
1043+
'busybox', 'true', host_config=self.client.create_host_config(
10431044
links=[(link_path, alias)]
10441045
)
10451046
)
@@ -1049,7 +1050,7 @@ def test_create_container_with_links_as_list_of_tuples(self):
10491050
args = fake_request.call_args
10501051
self.assertEqual(args[0][0], url_prefix + 'containers/create')
10511052
expected_payload = self.base_create_payload()
1052-
expected_payload['HostConfig'] = create_host_config()
1053+
expected_payload['HostConfig'] = self.client.create_host_config()
10531054
expected_payload['HostConfig']['Links'] = ['path:alias']
10541055

10551056
self.assertEqual(json.loads(args[1]['data']), expected_payload)
@@ -1061,13 +1062,13 @@ def test_create_container_privileged(self):
10611062
try:
10621063
self.client.create_container(
10631064
'busybox', 'true',
1064-
host_config=create_host_config(privileged=True)
1065+
host_config=self.client.create_host_config(privileged=True)
10651066
)
10661067
except Exception as e:
10671068
self.fail('Command should not raise exception: {0}'.format(e))
10681069

10691070
expected_payload = self.base_create_payload()
1070-
expected_payload['HostConfig'] = create_host_config()
1071+
expected_payload['HostConfig'] = self.client.create_host_config()
10711072
expected_payload['HostConfig']['Privileged'] = True
10721073
args = fake_request.call_args
10731074
self.assertEqual(args[0][0], url_prefix + 'containers/create')
@@ -1306,7 +1307,7 @@ def test_start_container_with_dict_instead_of_id(self):
13061307
def test_create_container_with_restart_policy(self):
13071308
try:
13081309
self.client.create_container(
1309-
'busybox', 'true', host_config=create_host_config(
1310+
'busybox', 'true', host_config=self.client.create_host_config(
13101311
restart_policy={
13111312
"Name": "always",
13121313
"MaximumRetryCount": 0
@@ -1319,7 +1320,7 @@ def test_create_container_with_restart_policy(self):
13191320
self.assertEqual(args[0][0], url_prefix + 'containers/create')
13201321

13211322
expected_payload = self.base_create_payload()
1322-
expected_payload['HostConfig'] = create_host_config()
1323+
expected_payload['HostConfig'] = self.client.create_host_config()
13231324
expected_payload['HostConfig']['RestartPolicy'] = {
13241325
"MaximumRetryCount": 0, "Name": "always"
13251326
}
@@ -1336,14 +1337,14 @@ def test_create_container_with_added_capabilities(self):
13361337
try:
13371338
self.client.create_container(
13381339
'busybox', 'true',
1339-
host_config=create_host_config(cap_add=['MKNOD'])
1340+
host_config=self.client.create_host_config(cap_add=['MKNOD'])
13401341
)
13411342
except Exception as e:
13421343
self.fail('Command should not raise exception: {0}'.format(e))
13431344
args = fake_request.call_args
13441345
self.assertEqual(args[0][0], url_prefix + 'containers/create')
13451346
expected_payload = self.base_create_payload()
1346-
expected_payload['HostConfig'] = create_host_config()
1347+
expected_payload['HostConfig'] = self.client.create_host_config()
13471348
expected_payload['HostConfig']['CapAdd'] = ['MKNOD']
13481349
self.assertEqual(json.loads(args[1]['data']), expected_payload)
13491350
self.assertEqual(
@@ -1357,14 +1358,14 @@ def test_create_container_with_dropped_capabilities(self):
13571358
try:
13581359
self.client.create_container(
13591360
'busybox', 'true',
1360-
host_config=create_host_config(cap_drop=['MKNOD'])
1361+
host_config=self.client.create_host_config(cap_drop=['MKNOD'])
13611362
)
13621363
except Exception as e:
13631364
self.fail('Command should not raise exception: {0}'.format(e))
13641365
args = fake_request.call_args
13651366
self.assertEqual(args[0][0], url_prefix + 'containers/create')
13661367
expected_payload = self.base_create_payload()
1367-
expected_payload['HostConfig'] = create_host_config()
1368+
expected_payload['HostConfig'] = self.client.create_host_config()
13681369
expected_payload['HostConfig']['CapDrop'] = ['MKNOD']
13691370
self.assertEqual(json.loads(args[1]['data']), expected_payload)
13701371
self.assertEqual(
@@ -1377,7 +1378,7 @@ def test_create_container_with_dropped_capabilities(self):
13771378
def test_create_container_with_devices(self):
13781379
try:
13791380
self.client.create_container(
1380-
'busybox', 'true', host_config=create_host_config(
1381+
'busybox', 'true', host_config=self.client.create_host_config(
13811382
devices=['/dev/sda:/dev/xvda:rwm',
13821383
'/dev/sdb:/dev/xvdb',
13831384
'/dev/sdc']
@@ -1388,7 +1389,7 @@ def test_create_container_with_devices(self):
13881389
args = fake_request.call_args
13891390
self.assertEqual(args[0][0], url_prefix + 'containers/create')
13901391
expected_payload = self.base_create_payload()
1391-
expected_payload['HostConfig'] = create_host_config()
1392+
expected_payload['HostConfig'] = self.client.create_host_config()
13921393
expected_payload['HostConfig']['Devices'] = [
13931394
{'CgroupPermissions': 'rwm',
13941395
'PathInContainer': '/dev/xvda',
@@ -1462,7 +1463,7 @@ def test_create_container_with_named_volume(self):
14621463
volume_name = 'name'
14631464
self.client.create_container(
14641465
'busybox', 'true',
1465-
host_config=create_host_config(
1466+
host_config=self.client.create_host_config(
14661467
binds={volume_name: {
14671468
"bind": mount_dest,
14681469
"ro": False
@@ -1477,7 +1478,7 @@ def test_create_container_with_named_volume(self):
14771478
'containers/create')
14781479
expected_payload = self.base_create_payload()
14791480
expected_payload['VolumeDriver'] = 'foodriver'
1480-
expected_payload['HostConfig'] = create_host_config()
1481+
expected_payload['HostConfig'] = self.client.create_host_config()
14811482
expected_payload['HostConfig']['Binds'] = ["name:/mnt:rw"]
14821483
self.assertEqual(json.loads(args[1]['data']), expected_payload)
14831484
self.assertEqual(args[1]['headers'],
@@ -2536,12 +2537,12 @@ def test_tar_with_directory_symlinks(self):
25362537

25372538
def test_create_host_config_secopt(self):
25382539
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)
25402541
self.assertIn('SecurityOpt', result)
25412542
self.assertEqual(result['SecurityOpt'], security_opt)
25422543

25432544
self.assertRaises(
2544-
docker.errors.DockerException, create_host_config,
2545+
docker.errors.DockerException, self.client.create_host_config,
25452546
security_opt='wrong'
25462547
)
25472548

0 commit comments

Comments
 (0)