@@ -428,3 +428,87 @@ def __init__(self, name):
428
428
agent ._destroy_router_namespaces (self .conf .router_id )
429
429
430
430
self .assertEqual (agent ._destroy_router_namespace .call_count , 1 )
431
+
432
+
433
+ class TestL3AgentEventHandler (base .BaseTestCase ):
434
+
435
+ def setUp (self ):
436
+ super (TestL3AgentEventHandler , self ).setUp ()
437
+ cfg .CONF .register_opts (l3_agent .L3NATAgent .OPTS )
438
+ cfg .CONF .set_override (
439
+ 'interface_driver' , 'quantum.agent.linux.interface.NullDriver'
440
+ )
441
+ cfg .CONF .set_override ('use_namespaces' , True )
442
+ agent_config .register_root_helper (cfg .CONF )
443
+
444
+ self .device_exists_p = mock .patch (
445
+ 'quantum.agent.linux.ip_lib.device_exists' )
446
+ self .device_exists = self .device_exists_p .start ()
447
+
448
+ self .utils_exec_p = mock .patch (
449
+ 'quantum.agent.linux.utils.execute' )
450
+ self .utils_exec = self .utils_exec_p .start ()
451
+
452
+ self .drv_cls_p = mock .patch ('quantum.agent.linux.interface.NullDriver' )
453
+ driver_cls = self .drv_cls_p .start ()
454
+ self .mock_driver = mock .MagicMock ()
455
+ self .mock_driver .DEV_NAME_LEN = (
456
+ interface .LinuxInterfaceDriver .DEV_NAME_LEN )
457
+ driver_cls .return_value = self .mock_driver
458
+
459
+ self .l3_plugin_p = mock .patch (
460
+ 'quantum.agent.l3_agent.L3PluginApi' )
461
+ l3_plugin_cls = self .l3_plugin_p .start ()
462
+ self .plugin_api = mock .Mock ()
463
+ l3_plugin_cls .return_value = self .plugin_api
464
+
465
+ self .external_process_p = mock .patch (
466
+ 'quantum.agent.linux.external_process.ProcessManager'
467
+ )
468
+ self .external_process = self .external_process_p .start ()
469
+
470
+ self .agent = l3_agent .L3NATAgent (HOSTNAME )
471
+
472
+ def tearDown (self ):
473
+ self .device_exists_p .stop ()
474
+ self .utils_exec_p .stop ()
475
+ self .drv_cls_p .stop ()
476
+ self .l3_plugin_p .stop ()
477
+ self .external_process_p .stop ()
478
+ super (TestL3AgentEventHandler , self ).tearDown ()
479
+
480
+ def test_spawn_metadata_proxy (self ):
481
+ router_id = _uuid ()
482
+ metadata_port = 8080
483
+ ip_class_path = 'quantum.agent.linux.ip_lib.IPWrapper'
484
+
485
+ cfg .CONF .set_override ('metadata_port' , metadata_port )
486
+ cfg .CONF .set_override ('log_file' , 'test.log' )
487
+ cfg .CONF .set_override ('debug' , True )
488
+
489
+ router_info = l3_agent .RouterInfo (
490
+ router_id , cfg .CONF .root_helper , cfg .CONF .use_namespaces , None
491
+ )
492
+
493
+ self .external_process_p .stop ()
494
+ try :
495
+ with mock .patch (ip_class_path ) as ip_mock :
496
+ self .agent ._spawn_metadata_proxy (router_info )
497
+ ip_mock .assert_has_calls ([
498
+ mock .call (
499
+ 'sudo' ,
500
+ 'qrouter-' + router_id
501
+ ),
502
+ mock .call ().netns .execute ([
503
+ 'quantum-ns-metadata-proxy' ,
504
+ mock .ANY ,
505
+ '--router_id=%s' % router_id ,
506
+ mock .ANY ,
507
+ '--metadata_port=%s' % metadata_port ,
508
+ '--debug' ,
509
+ '--log-file=quantum-ns-metadata-proxy%s.log' %
510
+ router_id
511
+ ])
512
+ ])
513
+ finally :
514
+ self .external_process_p .start ()
0 commit comments