Merge "Compatibility with zeroconf 0.129.0"

This commit is contained in:
Zuul 2024-01-05 19:54:03 +00:00 committed by Gerrit Code Review
commit 523407eebf
2 changed files with 13 additions and 7 deletions

View File

@ -103,12 +103,18 @@ class Zeroconf(object):
all_params.update(params) all_params.update(params)
all_params.update(parsed.params) all_params.update(parsed.params)
properties = {
(key.encode('utf-8') if isinstance(key, str) else key):
(value.encode('utf-8') if isinstance(value, str) else value)
for key, value in all_params.items()
}
# TODO(dtantsur): allow overriding TTL values via configuration # TODO(dtantsur): allow overriding TTL values via configuration
info = zeroconf.ServiceInfo(_MDNS_DOMAIN, info = zeroconf.ServiceInfo(_MDNS_DOMAIN,
'%s.%s' % (service_type, _MDNS_DOMAIN), '%s.%s' % (service_type, _MDNS_DOMAIN),
addresses=parsed.addresses, addresses=parsed.addresses,
port=parsed.port, port=parsed.port,
properties=all_params, properties=properties,
server=parsed.hostname) server=parsed.hostname)
LOG.debug('Registering %s via mDNS', info) LOG.debug('Registering %s via mDNS', info)

View File

@ -37,22 +37,22 @@ class RegisterServiceTestCase(base.IronicLibTestCase):
self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('_openstack._tcp.local.', info.type)
self.assertEqual('baremetal._openstack._tcp.local.', info.name) self.assertEqual('baremetal._openstack._tcp.local.', info.name)
self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0])) self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0]))
self.assertEqual({'path': '/baremetal'}, info.properties) self.assertEqual({b'path': b'/baremetal'}, info.properties)
def test_with_params(self, mock_zc): def test_with_params(self, mock_zc):
CONF.set_override('params', {'answer': 'none', 'foo': 'bar'}, CONF.set_override('params', {'answer': 'none', 'foo': 'bar'},
group='mdns') group='mdns')
zc = mdns.Zeroconf() zc = mdns.Zeroconf()
zc.register_service('baremetal', 'https://127.0.0.1/baremetal', zc.register_service('baremetal', 'https://127.0.0.1/baremetal',
params={'answer': 42}) params={'answer': b'42'})
mock_zc.return_value.register_service.assert_called_once_with(mock.ANY) mock_zc.return_value.register_service.assert_called_once_with(mock.ANY)
info = mock_zc.return_value.register_service.call_args[0][0] info = mock_zc.return_value.register_service.call_args[0][0]
self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('_openstack._tcp.local.', info.type)
self.assertEqual('baremetal._openstack._tcp.local.', info.name) self.assertEqual('baremetal._openstack._tcp.local.', info.name)
self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0])) self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0]))
self.assertEqual({'path': '/baremetal', self.assertEqual({b'path': b'/baremetal',
'answer': 42, b'answer': b'42',
'foo': 'bar'}, b'foo': b'bar'},
info.properties) info.properties)
@mock.patch.object(mdns.time, 'sleep', autospec=True) @mock.patch.object(mdns.time, 'sleep', autospec=True)
@ -81,7 +81,7 @@ class RegisterServiceTestCase(base.IronicLibTestCase):
self.assertEqual('_openstack._tcp.local.', info.type) self.assertEqual('_openstack._tcp.local.', info.type)
self.assertEqual('baremetal._openstack._tcp.local.', info.name) self.assertEqual('baremetal._openstack._tcp.local.', info.name)
self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0])) self.assertEqual('127.0.0.1', socket.inet_ntoa(info.addresses[0]))
self.assertEqual({'path': '/baremetal'}, info.properties) self.assertEqual({b'path': b'/baremetal'}, info.properties)
@mock.patch.object(mdns.time, 'sleep', autospec=True) @mock.patch.object(mdns.time, 'sleep', autospec=True)
def test_failure(self, mock_sleep, mock_zc): def test_failure(self, mock_sleep, mock_zc):