@@ -124,11 +124,10 @@ def base_create_payload(self, img='busybox', cmd=None):
124
124
if not cmd :
125
125
cmd = ['true' ]
126
126
return {"Tty" : False , "Image" : img , "Cmd" : cmd ,
127
- "AttachStdin" : False , "Memory" : 0 ,
127
+ "AttachStdin" : False ,
128
128
"AttachStderr" : True , "AttachStdout" : True ,
129
129
"StdinOnce" : False ,
130
130
"OpenStdin" : False , "NetworkDisabled" : False ,
131
- "MemorySwap" : 0
132
131
}
133
132
134
133
def test_ctor (self ):
@@ -337,11 +336,10 @@ def test_create_container(self):
337
336
self .assertEqual (json .loads (args [1 ]['data' ]),
338
337
json .loads ('''
339
338
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
340
- "AttachStdin": false, "Memory": 0,
339
+ "AttachStdin": false,
341
340
"AttachStderr": true, "AttachStdout": true,
342
341
"StdinOnce": false,
343
- "OpenStdin": false, "NetworkDisabled": false,
344
- "MemorySwap": 0}''' ))
342
+ "OpenStdin": false, "NetworkDisabled": false}''' ))
345
343
self .assertEqual (args [1 ]['headers' ],
346
344
{'Content-Type' : 'application/json' })
347
345
@@ -361,12 +359,11 @@ def test_create_container_with_binds(self):
361
359
json .loads ('''
362
360
{"Tty": false, "Image": "busybox",
363
361
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
364
- "Volumes": {"/mnt": {}}, "Memory": 0,
362
+ "Volumes": {"/mnt": {}},
365
363
"AttachStderr": true,
366
364
"AttachStdout": true, "OpenStdin": false,
367
365
"StdinOnce": false,
368
- "NetworkDisabled": false,
369
- "MemorySwap": 0}''' ))
366
+ "NetworkDisabled": false}''' ))
370
367
self .assertEqual (args [1 ]['headers' ],
371
368
{'Content-Type' : 'application/json' })
372
369
@@ -386,12 +383,11 @@ def test_create_container_with_volume_string(self):
386
383
json .loads ('''
387
384
{"Tty": false, "Image": "busybox",
388
385
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
389
- "Volumes": {"/mnt": {}}, "Memory": 0,
386
+ "Volumes": {"/mnt": {}},
390
387
"AttachStderr": true,
391
388
"AttachStdout": true, "OpenStdin": false,
392
389
"StdinOnce": false,
393
- "NetworkDisabled": false,
394
- "MemorySwap": 0}''' ))
390
+ "NetworkDisabled": false}''' ))
395
391
self .assertEqual (args [1 ]['headers' ],
396
392
{'Content-Type' : 'application/json' })
397
393
@@ -409,16 +405,15 @@ def test_create_container_with_ports(self):
409
405
json .loads ('''
410
406
{"Tty": false, "Image": "busybox",
411
407
"Cmd": ["ls"], "AttachStdin": false,
412
- "Memory": 0, " ExposedPorts": {
408
+ "ExposedPorts": {
413
409
"1111/tcp": {},
414
410
"2222/udp": {},
415
411
"3333/tcp": {}
416
412
},
417
413
"AttachStderr": true,
418
414
"AttachStdout": true, "OpenStdin": false,
419
415
"StdinOnce": false,
420
- "NetworkDisabled": false,
421
- "MemorySwap": 0}''' ))
416
+ "NetworkDisabled": false}''' ))
422
417
self .assertEqual (args [1 ]['headers' ],
423
418
{'Content-Type' : 'application/json' })
424
419
@@ -436,13 +431,11 @@ def test_create_container_with_entrypoint(self):
436
431
json .loads ('''
437
432
{"Tty": false, "Image": "busybox",
438
433
"Cmd": ["hello"], "AttachStdin": false,
439
- "Memory": 0,
440
434
"AttachStderr": true,
441
435
"AttachStdout": true, "OpenStdin": false,
442
436
"StdinOnce": false,
443
437
"NetworkDisabled": false,
444
- "Entrypoint": "cowsay",
445
- "MemorySwap": 0}''' ))
438
+ "Entrypoint": "cowsay"}''' ))
446
439
self .assertEqual (args [1 ]['headers' ],
447
440
{'Content-Type' : 'application/json' })
448
441
@@ -460,13 +453,11 @@ def test_create_container_with_cpu_shares(self):
460
453
json .loads ('''
461
454
{"Tty": false, "Image": "busybox",
462
455
"Cmd": ["ls"], "AttachStdin": false,
463
- "Memory": 0,
464
456
"AttachStderr": true,
465
457
"AttachStdout": true, "OpenStdin": false,
466
458
"StdinOnce": false,
467
459
"NetworkDisabled": false,
468
- "CpuShares": 5,
469
- "MemorySwap": 0}''' ))
460
+ "CpuShares": 5}''' ))
470
461
self .assertEqual (args [1 ]['headers' ],
471
462
{'Content-Type' : 'application/json' })
472
463
@@ -484,14 +475,12 @@ def test_create_container_with_cpuset(self):
484
475
json .loads ('''
485
476
{"Tty": false, "Image": "busybox",
486
477
"Cmd": ["ls"], "AttachStdin": false,
487
- "Memory": 0,
488
478
"AttachStderr": true,
489
479
"AttachStdout": true, "OpenStdin": false,
490
480
"StdinOnce": false,
491
481
"NetworkDisabled": false,
492
482
"Cpuset": "0,1",
493
- "CpusetCpus": "0,1",
494
- "MemorySwap": 0}''' ))
483
+ "CpusetCpus": "0,1"}''' ))
495
484
self .assertEqual (args [1 ]['headers' ],
496
485
{'Content-Type' : 'application/json' })
497
486
@@ -509,13 +498,11 @@ def test_create_container_with_working_dir(self):
509
498
json .loads ('''
510
499
{"Tty": false, "Image": "busybox",
511
500
"Cmd": ["ls"], "AttachStdin": false,
512
- "Memory": 0,
513
501
"AttachStderr": true,
514
502
"AttachStdout": true, "OpenStdin": false,
515
503
"StdinOnce": false,
516
504
"NetworkDisabled": false,
517
- "WorkingDir": "/root",
518
- "MemorySwap": 0}''' ))
505
+ "WorkingDir": "/root"}''' ))
519
506
self .assertEqual (args [1 ]['headers' ],
520
507
{'Content-Type' : 'application/json' })
521
508
@@ -531,11 +518,10 @@ def test_create_container_with_stdin_open(self):
531
518
self .assertEqual (json .loads (args [1 ]['data' ]),
532
519
json .loads ('''
533
520
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
534
- "AttachStdin": true, "Memory": 0,
521
+ "AttachStdin": true,
535
522
"AttachStderr": true, "AttachStdout": true,
536
523
"StdinOnce": true,
537
- "OpenStdin": true, "NetworkDisabled": false,
538
- "MemorySwap": 0}''' ))
524
+ "OpenStdin": true, "NetworkDisabled": false}''' ))
539
525
self .assertEqual (args [1 ]['headers' ],
540
526
{'Content-Type' : 'application/json' })
541
527
@@ -581,78 +567,95 @@ def test_create_named_container(self):
581
567
self .assertEqual (json .loads (args [1 ]['data' ]),
582
568
json .loads ('''
583
569
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
584
- "AttachStdin": false, "Memory": 0,
570
+ "AttachStdin": false,
585
571
"AttachStderr": true, "AttachStdout": true,
586
572
"StdinOnce": false,
587
- "OpenStdin": false, "NetworkDisabled": false,
588
- "MemorySwap": 0}''' ))
573
+ "OpenStdin": false, "NetworkDisabled": false}''' ))
589
574
self .assertEqual (args [1 ]['headers' ],
590
575
{'Content-Type' : 'application/json' })
591
576
self .assertEqual (args [1 ]['params' ], {'name' : 'marisa-kirisame' })
592
577
593
578
def test_create_container_with_mem_limit_as_int (self ):
594
579
try :
595
- self .client .create_container ('busybox' , 'true' ,
596
- mem_limit = 128.0 )
580
+ self .client .create_container (
581
+ 'busybox' , 'true' , host_config = create_host_config (
582
+ mem_limit = 128.0
583
+ )
584
+ )
597
585
except Exception as e :
598
586
self .fail ('Command should not raise exception: {0}' .format (e ))
599
587
600
588
args = fake_request .call_args
601
589
data = json .loads (args [1 ]['data' ])
602
- self .assertEqual (data ['Memory' ], 128.0 )
590
+ self .assertEqual (data ['HostConfig' ][ ' Memory' ], 128.0 )
603
591
604
592
def test_create_container_with_mem_limit_as_string (self ):
605
593
try :
606
- self .client .create_container ('busybox' , 'true' ,
607
- mem_limit = '128' )
594
+ self .client .create_container (
595
+ 'busybox' , 'true' , host_config = create_host_config (
596
+ mem_limit = '128'
597
+ )
598
+ )
608
599
except Exception as e :
609
600
self .fail ('Command should not raise exception: {0}' .format (e ))
610
601
611
602
args = fake_request .call_args
612
603
data = json .loads (args [1 ]['data' ])
613
- self .assertEqual (data ['Memory' ], 128.0 )
604
+ self .assertEqual (data ['HostConfig' ][ ' Memory' ], 128.0 )
614
605
615
606
def test_create_container_with_mem_limit_as_string_with_k_unit (self ):
616
607
try :
617
- self .client .create_container ('busybox' , 'true' ,
618
- mem_limit = '128k' )
608
+ self .client .create_container (
609
+ 'busybox' , 'true' , host_config = create_host_config (
610
+ mem_limit = '128k'
611
+ )
612
+ )
619
613
except Exception as e :
620
614
self .fail ('Command should not raise exception: {0}' .format (e ))
621
615
622
616
args = fake_request .call_args
623
617
data = json .loads (args [1 ]['data' ])
624
- self .assertEqual (data ['Memory' ], 128.0 * 1024 )
618
+ self .assertEqual (data ['HostConfig' ][ ' Memory' ], 128.0 * 1024 )
625
619
626
620
def test_create_container_with_mem_limit_as_string_with_m_unit (self ):
627
621
try :
628
- self .client .create_container ('busybox' , 'true' ,
629
- mem_limit = '128m' )
622
+ self .client .create_container (
623
+ 'busybox' , 'true' , host_config = create_host_config (
624
+ mem_limit = '128m'
625
+ )
626
+ )
627
+
630
628
except Exception as e :
631
629
self .fail ('Command should not raise exception: {0}' .format (e ))
632
630
633
631
args = fake_request .call_args
634
632
data = json .loads (args [1 ]['data' ])
635
- self .assertEqual (data ['Memory' ], 128.0 * 1024 * 1024 )
633
+ self .assertEqual (data ['HostConfig' ][ ' Memory' ], 128.0 * 1024 * 1024 )
636
634
637
635
def test_create_container_with_mem_limit_as_string_with_g_unit (self ):
638
636
try :
639
- self .client .create_container ('busybox' , 'true' ,
640
- mem_limit = '128g' )
637
+ self .client .create_container (
638
+ 'busybox' , 'true' , host_config = create_host_config (
639
+ mem_limit = '128g'
640
+ )
641
+ )
641
642
except Exception as e :
642
643
self .fail ('Command should not raise exception: {0}' .format (e ))
643
644
644
645
args = fake_request .call_args
645
646
data = json .loads (args [1 ]['data' ])
646
- self .assertEqual (data ['Memory' ], 128.0 * 1024 * 1024 * 1024 )
647
+ self .assertEqual (
648
+ data ['HostConfig' ]['Memory' ], 128.0 * 1024 * 1024 * 1024
649
+ )
647
650
648
651
def test_create_container_with_mem_limit_as_string_with_wrong_value (self ):
649
- self .assertRaises (docker . errors . DockerException ,
650
- self . client . create_container ,
651
- 'busybox' , 'true' , mem_limit = '128p' )
652
+ self .assertRaises (
653
+ docker . errors . DockerException , create_host_config , mem_limit = '128p'
654
+ )
652
655
653
- self .assertRaises (docker . errors . DockerException ,
654
- self . client . create_container ,
655
- 'busybox' , 'true' , mem_limit = '1f28' )
656
+ self .assertRaises (
657
+ docker . errors . DockerException , create_host_config , mem_limit = '1f28'
658
+ )
656
659
657
660
def test_start_container (self ):
658
661
try :
0 commit comments