Merge "Fix checking IP version when using IPv6."
This commit is contained in:
commit
bf38c2c932
@ -23,7 +23,7 @@ from oslo_log import log
|
||||
from oslo_utils import netutils
|
||||
|
||||
import ceilometer
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer.i18n import _, _LW
|
||||
from ceilometer import publisher
|
||||
from ceilometer.publisher import utils
|
||||
|
||||
@ -38,9 +38,22 @@ class UDPPublisher(publisher.PublisherBase):
|
||||
self.host, self.port = netutils.parse_host_port(
|
||||
parsed_url.netloc,
|
||||
default_port=cfg.CONF.collector.udp_port)
|
||||
if netutils.is_valid_ipv6(self.host):
|
||||
addr_family = socket.AF_INET6
|
||||
addrinfo = None
|
||||
try:
|
||||
addrinfo = socket.getaddrinfo(self.host, None, socket.AF_INET6,
|
||||
socket.SOCK_DGRAM)[0]
|
||||
except socket.gaierror:
|
||||
try:
|
||||
addrinfo = socket.getaddrinfo(self.host, None, socket.AF_INET,
|
||||
socket.SOCK_DGRAM)[0]
|
||||
except socket.gaierror:
|
||||
pass
|
||||
if addrinfo:
|
||||
addr_family = addrinfo[0]
|
||||
else:
|
||||
LOG.warning(_LW(
|
||||
"Cannot resolve host %s, creating AF_INET socket..."),
|
||||
self.host)
|
||||
addr_family = socket.AF_INET
|
||||
self.socket = socket.socket(addr_family,
|
||||
socket.SOCK_DGRAM)
|
||||
|
@ -127,6 +127,28 @@ class TestUDPPublisher(base.BaseTestCase):
|
||||
self._check_udp_socket('udp://[::1]:4952',
|
||||
socket.AF_INET6)
|
||||
|
||||
def test_publisher_udp_socket_ipv4_hostname(self):
|
||||
host = "ipv4.google.com"
|
||||
try:
|
||||
socket.getaddrinfo(host, None,
|
||||
socket.AF_INET,
|
||||
socket.SOCK_DGRAM)
|
||||
except socket.gaierror:
|
||||
self.skipTest("cannot resolve not running test")
|
||||
url = "udp://"+host+":4952"
|
||||
self._check_udp_socket(url, socket.AF_INET)
|
||||
|
||||
def test_publisher_udp_socket_ipv6_hostname(self):
|
||||
host = "ipv6.google.com"
|
||||
try:
|
||||
socket.getaddrinfo(host, None,
|
||||
socket.AF_INET6,
|
||||
socket.SOCK_DGRAM)
|
||||
except socket.gaierror:
|
||||
self.skipTest("cannot resolve not running test")
|
||||
url = "udp://"+host+":4952"
|
||||
self._check_udp_socket(url, socket.AF_INET6)
|
||||
|
||||
def test_published(self):
|
||||
self.data_sent = []
|
||||
with mock.patch('socket.socket',
|
||||
|
Loading…
Reference in New Issue
Block a user