summaryrefslogtreecommitdiff
path: root/ironic_python_agent/tests/unit/test_agent.py
diff options
context:
space:
mode:
authorDerek Higgins <derekh@redhat.com>2016-12-16 12:59:55 +0000
committerDerek Higgins <derekh@redhat.com>2017-01-11 11:00:56 +0000
commit9f5f6640804e255b05adfa34de9dd4d900fcdcbf (patch)
tree5cb14d0265a214f352893fa669f50051d4b3970d /ironic_python_agent/tests/unit/test_agent.py
parenta6b09f2fa85f397cfda6a43ce19c995c8a3be76d (diff)
downloadironic-python-agent-9f5f6640804e255b05adfa34de9dd4d900fcdcbf.tar.gz
Advertise the correct address when using IPv6
Parse the output of "ip route get $IP" taking IPv6 into consideration. Also wrap the IP address in square brackets if it is IPv6. Change-Id: Ifc44e5aa3c5b814b6ceba04461bb68fe1d75c22b Closes-Bug: #1650533
Diffstat (limited to 'ironic_python_agent/tests/unit/test_agent.py')
-rw-r--r--ironic_python_agent/tests/unit/test_agent.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py
index 62bd509e..71ee80cc 100644
--- a/ironic_python_agent/tests/unit/test_agent.py
+++ b/ironic_python_agent/tests/unit/test_agent.py
@@ -466,6 +466,22 @@ class TestBaseAgent(test_base.BaseTestCase):
self.assertRaises(errors.UnknownNodeError,
self.agent.get_node_uuid)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_route_source(self, mock_execute):
+ mock_execute.return_value = ('XXX src 1.2.3.4 XXX\n cache', None)
+
+ source = self.agent._get_route_source('XXX')
+ self.assertEqual('1.2.3.4', source)
+
+ @mock.patch.object(agent, 'LOG', autospec=True)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_route_source_indexerror(self, mock_execute, mock_log):
+ mock_execute.return_value = ('XXX src \n cache', None)
+
+ source = self.agent._get_route_source('XXX')
+ self.assertIsNone(source)
+ mock_log.warning.assert_called_once()
+
@mock.patch.object(hardware.GenericHardwareManager, '_wait_for_disks',
lambda self: None)
@@ -597,6 +613,22 @@ class TestAdvertiseAddress(test_base.BaseTestCase):
mock_exec.assert_called_once_with('ip', 'route', 'get', '1.2.1.2')
mock_gethostbyname.assert_called_once_with('1.2.1.2')
+ def test_route_with_ipv6(self, mock_exec, mock_gethostbyname):
+ self.agent.api_url = 'http://[fc00:1111::1]:8081/v1'
+ mock_gethostbyname.side_effect = socket.gaierror()
+ mock_exec.return_value = (
+ """fc00:101::1 dev br-ctlplane src fc00:101::4 metric 0
+ cache """,
+ ""
+ )
+
+ self.agent.set_agent_advertise_addr()
+
+ self.assertEqual(('fc00:101::4', 9990),
+ self.agent.advertise_address)
+ mock_exec.assert_called_once_with('ip', 'route', 'get', 'fc00:1111::1')
+ mock_gethostbyname.assert_called_once_with('fc00:1111::1')
+
def test_route_with_host(self, mock_exec, mock_gethostbyname):
mock_gethostbyname.return_value = '1.2.1.2'
mock_exec.return_value = (