@@ -466,6 +466,22 @@ def test_get_node_uuid_invalid_node(self):
466466 self .assertRaises (errors .UnknownNodeError ,
467467 self .agent .get_node_uuid )
468468
469+ @mock .patch .object (utils , 'execute' , autospec = True )
470+ def test_get_route_source (self , mock_execute ):
471+ mock_execute .return_value = ('XXX src 1.2.3.4 XXX\n cache' , None )
472+
473+ source = self .agent ._get_route_source ('XXX' )
474+ self .assertEqual ('1.2.3.4' , source )
475+
476+ @mock .patch .object (agent , 'LOG' , autospec = True )
477+ @mock .patch .object (utils , 'execute' , autospec = True )
478+ def test_get_route_source_indexerror (self , mock_execute , mock_log ):
479+ mock_execute .return_value = ('XXX src \n cache' , None )
480+
481+ source = self .agent ._get_route_source ('XXX' )
482+ self .assertIsNone (source )
483+ mock_log .warning .assert_called_once ()
484+
469485
470486@mock .patch .object (hardware .GenericHardwareManager , '_wait_for_disks' ,
471487 lambda self : None )
@@ -597,6 +613,22 @@ def test_route_with_ip(self, mock_exec, mock_gethostbyname):
597613 mock_exec .assert_called_once_with ('ip' , 'route' , 'get' , '1.2.1.2' )
598614 mock_gethostbyname .assert_called_once_with ('1.2.1.2' )
599615
616+ def test_route_with_ipv6 (self , mock_exec , mock_gethostbyname ):
617+ self .agent .api_url = 'http://[fc00:1111::1]:8081/v1'
618+ mock_gethostbyname .side_effect = socket .gaierror ()
619+ mock_exec .return_value = (
620+ """fc00:101::1 dev br-ctlplane src fc00:101::4 metric 0
621+ cache """ ,
622+ ""
623+ )
624+
625+ self .agent .set_agent_advertise_addr ()
626+
627+ self .assertEqual (('fc00:101::4' , 9990 ),
628+ self .agent .advertise_address )
629+ mock_exec .assert_called_once_with ('ip' , 'route' , 'get' , 'fc00:1111::1' )
630+ mock_gethostbyname .assert_called_once_with ('fc00:1111::1' )
631+
600632 def test_route_with_host (self , mock_exec , mock_gethostbyname ):
601633 mock_gethostbyname .return_value = '1.2.1.2'
602634 mock_exec .return_value = (
0 commit comments