From 1dc56a8ad3d02046999e4f709d4e5e4fc9688ef2 Mon Sep 17 00:00:00 2001 From: Mark McClain Date: Tue, 22 Jan 2013 12:16:09 -0500 Subject: [PATCH] make IPv6 unit test work on systems with eth0 fixes bug 1103074 The link local unit test was failing because it depended on eth0 to exists. This mocks getaddrinfo() to ensure a consistent return value across testing environments. Change-Id: Ie1a4d837efcacac8c8d2217c164ad751922e1a5f --- quantum/tests/unit/test_wsgi.py | 56 +++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/quantum/tests/unit/test_wsgi.py b/quantum/tests/unit/test_wsgi.py index 45dedc1c4a..bacd86e62c 100644 --- a/quantum/tests/unit/test_wsgi.py +++ b/quantum/tests/unit/test_wsgi.py @@ -41,29 +41,39 @@ class TestWSGIServer(unittest.TestCase): server.stop() server.wait() + def test_ipv6_listen_called_with_scope(self): + server = wsgi.Server("test_app") -class TestWSGIServer2(unittest.TestCase): - def setUp(self): - self.eventlet_p = mock.patch.object(wsgi, 'eventlet') - self.eventlet = self.eventlet_p.start() - self.server = wsgi.Server("test_app") + with mock.patch.object(wsgi.eventlet, 'listen') as mock_listen: + with mock.patch.object(socket, 'getaddrinfo') as mock_get_addr: + mock_get_addr.return_value = [ + (socket.AF_INET6, + socket.SOCK_STREAM, + socket.IPPROTO_TCP, + '', + ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2)) + ] + with mock.patch.object(server, 'pool') as mock_pool: + server.start(None, + 1234, + host="fe80::204:acff:fe96:da87%eth0") - def tearDown(self): - self.eventlet_p.stop() + mock_get_addr.assert_called_once_with( + "fe80::204:acff:fe96:da87%eth0", + 1234, + socket.AF_UNSPEC, + socket.SOCK_STREAM + ) - def test_ipv6_with_link_local_start(self): - mock_app = mock.Mock() - with mock.patch.object(self.server, 'pool') as pool: - self.server.start(mock_app, - 0, - host="fe80::204:acff:fe96:da87%eth0") - self.eventlet.assert_has_calls([ - mock.call.listen(('fe80::204:acff:fe96:da87%eth0', 0, 0, 2), - backlog=128, - family=10) - ]) - pool.spawn.assert_has_calls([mock.call( - self.server._run, - mock_app, - self.eventlet.listen.mock_calls[0].return_value) - ]) + mock_listen.assert_called_once_with( + ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2), + family=socket.AF_INET6, + backlog=128 + ) + + mock_pool.spawn.assert_has_calls([ + mock.call( + server._run, + None, + mock_listen.return_value) + ])