Merge "Compatibility with zeroconf 0.129.0"
This commit is contained in:
commit
523407eebf
@ -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)
|
||||||
|
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user