@@ -74,6 +74,7 @@ def test_create_container_args(self):
7474 name = 'somename' ,
7575 network_disabled = False ,
7676 network = 'foo' ,
77+ network_driver_opt = {'key1' : 'a' },
7778 oom_kill_disable = True ,
7879 oom_score_adj = 5 ,
7980 pid_mode = 'host' ,
@@ -188,7 +189,7 @@ def test_create_container_args(self):
188189 mac_address = 'abc123' ,
189190 name = 'somename' ,
190191 network_disabled = False ,
191- networking_config = {'foo' : None },
192+ networking_config = {'foo' : { 'driver_opt' : { 'key1' : 'a' }} },
192193 platform = 'linux' ,
193194 ports = [('1111' , 'tcp' ), ('2222' , 'tcp' )],
194195 stdin_open = True ,
@@ -345,6 +346,42 @@ def test_run_platform(self):
345346 host_config = {'NetworkMode' : 'default' },
346347 )
347348
349+ def test_run_network_driver_opts_without_network (self ):
350+ client = make_fake_client ()
351+
352+ with pytest .raises (RuntimeError ):
353+ client .containers .run (
354+ image = 'alpine' ,
355+ network_driver_opt = {'key1' : 'a' }
356+ )
357+
358+ def test_run_network_driver_opts_with_network_mode (self ):
359+ client = make_fake_client ()
360+
361+ with pytest .raises (RuntimeError ):
362+ client .containers .run (
363+ image = 'alpine' ,
364+ network_mode = 'none' ,
365+ network_driver_opt = {'key1' : 'a' }
366+ )
367+
368+ def test_run_network_driver_opts (self ):
369+ client = make_fake_client ()
370+
371+ client .containers .run (
372+ image = 'alpine' ,
373+ network = 'foo' ,
374+ network_driver_opt = {'key1' : 'a' }
375+ )
376+
377+ client .api .create_container .assert_called_with (
378+ detach = False ,
379+ image = 'alpine' ,
380+ command = None ,
381+ networking_config = {'foo' : {'driver_opt' : {'key1' : 'a' }}},
382+ host_config = {'NetworkMode' : 'foo' }
383+ )
384+
348385 def test_create (self ):
349386 client = make_fake_client ()
350387 container = client .containers .create (
@@ -372,6 +409,51 @@ def test_create_with_image_object(self):
372409 host_config = {'NetworkMode' : 'default' }
373410 )
374411
412+ def test_create_network_driver_opts_without_network (self ):
413+ client = make_fake_client ()
414+
415+ client .containers .create (
416+ image = 'alpine' ,
417+ network_driver_opt = {'key1' : 'a' }
418+ )
419+
420+ client .api .create_container .assert_called_with (
421+ image = 'alpine' ,
422+ command = None ,
423+ host_config = {'NetworkMode' : 'default' }
424+ )
425+
426+ def test_create_network_driver_opts_with_network_mode (self ):
427+ client = make_fake_client ()
428+
429+ client .containers .create (
430+ image = 'alpine' ,
431+ network_mode = 'none' ,
432+ network_driver_opt = {'key1' : 'a' }
433+ )
434+
435+ client .api .create_container .assert_called_with (
436+ image = 'alpine' ,
437+ command = None ,
438+ host_config = {'NetworkMode' : 'none' }
439+ )
440+
441+ def test_create_network_driver_opts (self ):
442+ client = make_fake_client ()
443+
444+ client .containers .create (
445+ image = 'alpine' ,
446+ network = 'foo' ,
447+ network_driver_opt = {'key1' : 'a' }
448+ )
449+
450+ client .api .create_container .assert_called_with (
451+ image = 'alpine' ,
452+ command = None ,
453+ networking_config = {'foo' : {'driver_opt' : {'key1' : 'a' }}},
454+ host_config = {'NetworkMode' : 'foo' }
455+ )
456+
375457 def test_get (self ):
376458 client = make_fake_client ()
377459 container = client .containers .get (FAKE_CONTAINER_ID )
0 commit comments