Compatibility with zeroconf 0.129.0
From Zeroconf CHANGELOG.md: v0.129.0 (2023-12-13) Feature * Add decoded_properties method to ServiceInfo https://github.com/python-zeroconf/python-zeroconf/issues/13329b595a1dca
* Ensure ServiceInfo.properties always returns bytes https://github.com/python-zeroconf/python-zeroconf/issues/1333d29553ab7d
Technically breaking change * `ServiceInfo.properties` always returns a dictionary with type `dict[bytes, bytes | None]` instead of a mix `str` and `bytes`. It was only possible to get a mixed dictionary if it was manually passed in when `ServiceInfo` was constructed. Co-Authored-By: Dmitry Tantsur <dtantsur@protonmail.com> Change-Id: I7f1a0c3329e5f29ec3e274558e3681142cc2ef78
This commit is contained in:
parent
54597e9210
commit
e2ced90dc5
@ -103,12 +103,18 @@ class Zeroconf(object):
|
||||
all_params.update(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
|
||||
info = zeroconf.ServiceInfo(_MDNS_DOMAIN,
|
||||
'%s.%s' % (service_type, _MDNS_DOMAIN),
|
||||
addresses=parsed.addresses,
|
||||
port=parsed.port,
|
||||
properties=all_params,
|
||||
properties=properties,
|
||||
server=parsed.hostname)
|
||||
|
||||
LOG.debug('Registering %s via mDNS', info)
|
||||
|
@ -37,22 +37,22 @@ class RegisterServiceTestCase(base.IronicLibTestCase):
|
||||
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.addresses[0]))
|
||||
self.assertEqual({'path': '/baremetal'}, info.properties)
|
||||
self.assertEqual({b'path': b'/baremetal'}, info.properties)
|
||||
|
||||
def test_with_params(self, mock_zc):
|
||||
CONF.set_override('params', {'answer': 'none', 'foo': 'bar'},
|
||||
group='mdns')
|
||||
zc = mdns.Zeroconf()
|
||||
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)
|
||||
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.addresses[0]))
|
||||
self.assertEqual({'path': '/baremetal',
|
||||
'answer': 42,
|
||||
'foo': 'bar'},
|
||||
self.assertEqual({b'path': b'/baremetal',
|
||||
b'answer': b'42',
|
||||
b'foo': b'bar'},
|
||||
info.properties)
|
||||
|
||||
@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('baremetal._openstack._tcp.local.', info.name)
|
||||
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)
|
||||
def test_failure(self, mock_sleep, mock_zc):
|
||||
|
Loading…
Reference in New Issue
Block a user