From cc50dab51325bdf03fd840f7cb69bea1af2ea99f Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Mon, 8 Jun 2020 10:25:29 +0200 Subject: [PATCH] Fix for latest zeroconf version The zeroconf library removed address in version 0.27.0 [1] This patch should fix potential issues with that change. Changes: ironic_lib/tests/test_mdns.py [1] https://github.com/jstasiak/python-zeroconf/#changelog Change-Id: I694ae5587ac8c3aae43d98902f56738773d31284 (cherry picked from commit 4c185438e6b07b647457068de45a73a42352f886) --- ironic_lib/tests/test_mdns.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ironic_lib/tests/test_mdns.py b/ironic_lib/tests/test_mdns.py index 21c7656a..75020b0e 100644 --- a/ironic_lib/tests/test_mdns.py +++ b/ironic_lib/tests/test_mdns.py @@ -35,7 +35,14 @@ class RegisterServiceTestCase(base.IronicLibTestCase): info = mock_zc.return_value.register_service.call_args[0][0] self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('baremetal._openstack._tcp.local.', info.name) - self.assertEqual('127.0.0.1', socket.inet_ntoa(info.address)) + # NOTE(rpittau) address zeroconf differences + # the addresses attribute is not supported in the version used + # in Python 2.x + try: + result = socket.inet_ntoa(info.addresses[0]) + except AttributeError: + result = socket.inet_ntoa(info.address) + self.assertEqual('127.0.0.1', result) self.assertEqual({'path': '/baremetal'}, info.properties) def test_with_params(self, mock_zc): @@ -48,7 +55,14 @@ class RegisterServiceTestCase(base.IronicLibTestCase): info = mock_zc.return_value.register_service.call_args[0][0] self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('baremetal._openstack._tcp.local.', info.name) - self.assertEqual('127.0.0.1', socket.inet_ntoa(info.address)) + # NOTE(rpittau) address zeroconf differences + # the addresses attribute is not supported in the version used + # in Python 2.x + try: + result = socket.inet_ntoa(info.addresses[0]) + except AttributeError: + result = socket.inet_ntoa(info.address) + self.assertEqual('127.0.0.1', result) self.assertEqual({'path': '/baremetal', 'answer': 42, 'foo': 'bar'}, @@ -78,7 +92,14 @@ class RegisterServiceTestCase(base.IronicLibTestCase): info = mock_zc.return_value.register_service.call_args[0][0] self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('baremetal._openstack._tcp.local.', info.name) - self.assertEqual('127.0.0.1', socket.inet_ntoa(info.address)) + # NOTE(rpittau) address zeroconf differences + # the addresses attribute is not supported in the version used + # in Python 2.x + try: + result = socket.inet_ntoa(info.addresses[0]) + except AttributeError: + result = socket.inet_ntoa(info.address) + self.assertEqual('127.0.0.1', result) self.assertEqual({'path': '/baremetal'}, info.properties) @mock.patch.object(mdns.time, 'sleep', autospec=True)