Merge "Added ipv6 support for udp publisher"
This commit is contained in:
commit
beec41081a
@ -38,7 +38,11 @@ class UDPPublisher(publisher.PublisherBase):
|
||||
self.host, self.port = netutils.parse_host_port(
|
||||
parsed_url.netloc,
|
||||
default_port=cfg.CONF.collector.udp_port)
|
||||
self.socket = socket.socket(socket.AF_INET,
|
||||
if netutils.is_valid_ipv6(self.host):
|
||||
addr_family = socket.AF_INET6
|
||||
else:
|
||||
addr_family = socket.AF_INET
|
||||
self.socket = socket.socket(addr_family,
|
||||
socket.SOCK_DGRAM)
|
||||
|
||||
def publish_samples(self, context, samples):
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import socket
|
||||
|
||||
import mock
|
||||
import msgpack
|
||||
@ -112,6 +113,20 @@ class TestUDPPublisher(base.BaseTestCase):
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
self.CONF.publisher.telemetry_secret = 'not-so-secret'
|
||||
|
||||
def _check_udp_socket(self, url, expected_addr_family):
|
||||
with mock.patch.object(socket, 'socket') as mock_socket:
|
||||
udp.UDPPublisher(netutils.urlsplit(url))
|
||||
mock_socket.assert_called_with(expected_addr_family,
|
||||
socket.SOCK_DGRAM)
|
||||
|
||||
def test_publisher_udp_socket_ipv4(self):
|
||||
self._check_udp_socket('udp://127.0.0.1:4952',
|
||||
socket.AF_INET)
|
||||
|
||||
def test_publisher_udp_socket_ipv6(self):
|
||||
self._check_udp_socket('udp://[::1]:4952',
|
||||
socket.AF_INET6)
|
||||
|
||||
def test_published(self):
|
||||
self.data_sent = []
|
||||
with mock.patch('socket.socket',
|
||||
|
Loading…
x
Reference in New Issue
Block a user