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/1332
9b595a1dca
* Ensure ServiceInfo.properties always returns bytes
https://github.com/python-zeroconf/python-zeroconf/issues/1333
d29553ab7d

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:
Thomas Goirand 2023-12-17 13:55:54 +01:00 committed by Dmitry Tantsur
parent 54597e9210
commit e2ced90dc5
No known key found for this signature in database
GPG Key ID: 315B2AF9FD216C60
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(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)

View File

@ -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):