@@ -146,6 +146,7 @@ def setUp(self):
146146 'eth0' ,
147147 300 ,
148148 1 ,
149+ None ,
149150 False )
150151 self .agent .ext_mgr = extension .ExtensionManager .\
151152 make_test_instance ([extension .Extension ('fake' , None ,
@@ -239,7 +240,8 @@ def test_url_from_mdns_by_default(self, mock_get_managers, mock_wsgi,
239240 'eth0' ,
240241 300 ,
241242 1 ,
242- False )
243+ False ,
244+ None )
243245
244246 def set_serve_api ():
245247 self .agent .serve_api = False
@@ -296,7 +298,8 @@ def test_url_from_mdns_explicitly(self, mock_get_managers, mock_wsgi,
296298 'eth0' ,
297299 300 ,
298300 1 ,
299- False )
301+ False ,
302+ None )
300303
301304 def set_serve_api ():
302305 self .agent .serve_api = False
@@ -327,6 +330,51 @@ def set_serve_api():
327330 # changed via mdns
328331 self .assertEqual (42 , CONF .disk_wait_attempts )
329332
333+ @mock .patch (
334+ 'ironic_python_agent.hardware_managers.cna._detect_cna_card' ,
335+ mock .Mock ())
336+ @mock .patch .object (hardware , 'dispatch_to_managers' , autospec = True )
337+ @mock .patch .object (agent .IronicPythonAgent ,
338+ '_wait_for_interface' , autospec = True )
339+ @mock .patch ('oslo_service.wsgi.Server' , autospec = True )
340+ @mock .patch .object (hardware , 'get_managers' , autospec = True )
341+ def test_run_agent_token (self , mock_get_managers , mock_wsgi ,
342+ mock_wait , mock_dispatch ):
343+ CONF .set_override ('inspection_callback_url' , '' )
344+
345+ wsgi_server = mock_wsgi .return_value
346+
347+ def set_serve_api ():
348+ self .agent .serve_api = False
349+
350+ wsgi_server .start .side_effect = set_serve_api
351+ self .agent .heartbeater = mock .Mock ()
352+ self .agent .api_client .lookup_node = mock .Mock ()
353+ self .agent .api_client .lookup_node .return_value = {
354+ 'node' : {
355+ 'uuid' : 'deadbeef-dabb-ad00-b105-f00d00bab10c'
356+ },
357+ 'config' : {
358+ 'heartbeat_timeout' : 300 ,
359+ 'agent_token' : '1' * 128 ,
360+ 'agent_token_required' : True
361+ }
362+ }
363+
364+ self .agent .run ()
365+
366+ mock_wsgi .assert_called_once_with (CONF , 'ironic-python-agent' ,
367+ app = self .agent .api ,
368+ host = mock .ANY , port = 9999 )
369+ wsgi_server .start .assert_called_once_with ()
370+ mock_wait .assert_called_once_with (mock .ANY )
371+ self .assertEqual ([mock .call ('list_hardware_info' ),
372+ mock .call ('wait_for_disks' )],
373+ mock_dispatch .call_args_list )
374+ self .agent .heartbeater .start .assert_called_once_with ()
375+ self .assertEqual ('1' * 128 , self .agent .agent_token )
376+ self .assertEqual ('1' * 128 , self .agent .api_client .agent_token )
377+
330378 @mock .patch ('eventlet.sleep' , autospec = True )
331379 @mock .patch (
332380 'ironic_python_agent.hardware_managers.cna._detect_cna_card' ,
@@ -449,7 +497,8 @@ def test_run_with_inspection_without_apiurl(self,
449497 'eth0' ,
450498 300 ,
451499 1 ,
452- False )
500+ False ,
501+ None )
453502 self .assertFalse (hasattr (self .agent , 'api_client' ))
454503 self .assertFalse (hasattr (self .agent , 'heartbeater' ))
455504
@@ -504,7 +553,8 @@ def test_run_without_inspection_and_apiurl(self,
504553 'eth0' ,
505554 300 ,
506555 1 ,
507- False )
556+ False ,
557+ None )
508558 self .assertFalse (hasattr (self .agent , 'api_client' ))
509559 self .assertFalse (hasattr (self .agent , 'heartbeater' ))
510560
@@ -704,6 +754,7 @@ def setUp(self):
704754 300 ,
705755 1 ,
706756 'agent_ipmitool' ,
757+ None ,
707758 True )
708759
709760 @mock .patch (
@@ -756,6 +807,7 @@ def setUp(self):
756807 network_interface = None ,
757808 lookup_timeout = 300 ,
758809 lookup_interval = 1 ,
810+ agent_token = None ,
759811 standalone = False )
760812
761813 def test_advertise_address_provided (self , mock_exec , mock_gethostbyname ):
0 commit comments