1
+ import pytest
2
+ import unittest
3
+
1
4
import docker
2
- from docker .constants import DEFAULT_DATA_CHUNK_SIZE
5
+ from docker .constants import DEFAULT_DATA_CHUNK_SIZE , DEFAULT_DOCKER_API_VERSION
3
6
from docker .models .containers import Container , _create_container_args
4
7
from docker .models .images import Image
5
- import unittest
6
-
7
8
from .fake_api import FAKE_CONTAINER_ID , FAKE_IMAGE_ID , FAKE_EXEC_ID
8
9
from .fake_api_client import make_fake_client
9
- import pytest
10
10
11
11
12
12
class ContainerCollectionTest (unittest .TestCase ):
@@ -74,7 +74,7 @@ def test_create_container_args(self):
74
74
name = 'somename' ,
75
75
network_disabled = False ,
76
76
network = 'foo' ,
77
- network_driver_opt = {'key1' : 'a' },
77
+ network_config = {'aliases' : [ 'test' ], 'driver_opt' : { ' key1' : 'a' } },
78
78
oom_kill_disable = True ,
79
79
oom_score_adj = 5 ,
80
80
pid_mode = 'host' ,
@@ -99,7 +99,7 @@ def test_create_container_args(self):
99
99
user = 'bob' ,
100
100
userns_mode = 'host' ,
101
101
uts_mode = 'host' ,
102
- version = '1.23' ,
102
+ version = DEFAULT_DOCKER_API_VERSION ,
103
103
volume_driver = 'some_driver' ,
104
104
volumes = [
105
105
'/home/user1/:/mnt/vol2' ,
@@ -189,7 +189,9 @@ def test_create_container_args(self):
189
189
mac_address = 'abc123' ,
190
190
name = 'somename' ,
191
191
network_disabled = False ,
192
- networking_config = {'foo' : {'driver_opt' : {'key1' : 'a' }}},
192
+ networking_config = {'EndpointsConfig' : {
193
+ 'foo' : {'Aliases' : ['test' ], 'DriverOpts' : {'key1' : 'a' }}}
194
+ },
193
195
platform = 'linux' ,
194
196
ports = [('1111' , 'tcp' ), ('2222' , 'tcp' )],
195
197
stdin_open = True ,
@@ -346,39 +348,44 @@ def test_run_platform(self):
346
348
host_config = {'NetworkMode' : 'default' },
347
349
)
348
350
349
- def test_run_network_driver_opts_without_network (self ):
351
+ def test_run_network_config_without_network (self ):
350
352
client = make_fake_client ()
351
353
352
354
with pytest .raises (RuntimeError ):
353
355
client .containers .run (
354
356
image = 'alpine' ,
355
- network_driver_opt = {'key1' : 'a' }
357
+ network_config = {'aliases' : ['test' ],
358
+ 'driver_opt' : {'key1' : 'a' }}
356
359
)
357
360
358
- def test_run_network_driver_opts_with_network_mode (self ):
361
+ def test_run_network_config_with_network_mode (self ):
359
362
client = make_fake_client ()
360
363
361
364
with pytest .raises (RuntimeError ):
362
365
client .containers .run (
363
366
image = 'alpine' ,
364
367
network_mode = 'none' ,
365
- network_driver_opt = {'key1' : 'a' }
368
+ network_config = {'aliases' : ['test' ],
369
+ 'driver_opt' : {'key1' : 'a' }}
366
370
)
367
371
368
- def test_run_network_driver_opts (self ):
372
+ def test_run_network_config (self ):
369
373
client = make_fake_client ()
370
374
371
375
client .containers .run (
372
376
image = 'alpine' ,
373
377
network = 'foo' ,
374
- network_driver_opt = {'key1' : 'a' }
378
+ network_config = {'aliases' : ['test' ],
379
+ 'driver_opt' : {'key1' : 'a' }}
375
380
)
376
381
377
382
client .api .create_container .assert_called_with (
378
383
detach = False ,
379
384
image = 'alpine' ,
380
385
command = None ,
381
- networking_config = {'foo' : {'driver_opt' : {'key1' : 'a' }}},
386
+ networking_config = {'EndpointsConfig' : {
387
+ 'foo' : {'Aliases' : ['test' ], 'DriverOpts' : {'key1' : 'a' }}}
388
+ },
382
389
host_config = {'NetworkMode' : 'foo' }
383
390
)
384
391
@@ -409,12 +416,13 @@ def test_create_with_image_object(self):
409
416
host_config = {'NetworkMode' : 'default' }
410
417
)
411
418
412
- def test_create_network_driver_opts_without_network (self ):
419
+ def test_create_network_config_without_network (self ):
413
420
client = make_fake_client ()
414
421
415
422
client .containers .create (
416
423
image = 'alpine' ,
417
- network_driver_opt = {'key1' : 'a' }
424
+ network_config = {'aliases' : ['test' ],
425
+ 'driver_opt' : {'key1' : 'a' }}
418
426
)
419
427
420
428
client .api .create_container .assert_called_with (
@@ -423,13 +431,14 @@ def test_create_network_driver_opts_without_network(self):
423
431
host_config = {'NetworkMode' : 'default' }
424
432
)
425
433
426
- def test_create_network_driver_opts_with_network_mode (self ):
434
+ def test_create_network_config_with_network_mode (self ):
427
435
client = make_fake_client ()
428
436
429
437
client .containers .create (
430
438
image = 'alpine' ,
431
439
network_mode = 'none' ,
432
- network_driver_opt = {'key1' : 'a' }
440
+ network_config = {'aliases' : ['test' ],
441
+ 'driver_opt' : {'key1' : 'a' }}
433
442
)
434
443
435
444
client .api .create_container .assert_called_with (
@@ -438,19 +447,22 @@ def test_create_network_driver_opts_with_network_mode(self):
438
447
host_config = {'NetworkMode' : 'none' }
439
448
)
440
449
441
- def test_create_network_driver_opts (self ):
450
+ def test_create_network_config (self ):
442
451
client = make_fake_client ()
443
452
444
453
client .containers .create (
445
454
image = 'alpine' ,
446
455
network = 'foo' ,
447
- network_driver_opt = {'key1' : 'a' }
456
+ network_config = {'aliases' : ['test' ],
457
+ 'driver_opt' : {'key1' : 'a' }}
448
458
)
449
459
450
460
client .api .create_container .assert_called_with (
451
461
image = 'alpine' ,
452
462
command = None ,
453
- networking_config = {'foo' : {'driver_opt' : {'key1' : 'a' }}},
463
+ networking_config = {'EndpointsConfig' : {
464
+ 'foo' : {'Aliases' : ['test' ], 'DriverOpts' : {'key1' : 'a' }}}
465
+ },
454
466
host_config = {'NetworkMode' : 'foo' }
455
467
)
456
468
@@ -479,6 +491,7 @@ def test_list(self):
479
491
def test_list_ignore_removed (self ):
480
492
def side_effect (* args , ** kwargs ):
481
493
raise docker .errors .NotFound ('Container not found' )
494
+
482
495
client = make_fake_client ({
483
496
'inspect_container.side_effect' : side_effect
484
497
})
0 commit comments