Increase the number of ping packages sent to nameservers
Change-Id: I048b1e2c992e0f7f90995b34c66e44b66a231bcf
This commit is contained in:
parent
1eac0e0b9a
commit
e3df3d13c4
|
@ -16,6 +16,7 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
import typing
|
||||
|
||||
import netaddr
|
||||
from oslo_log import log
|
||||
|
@ -23,6 +24,8 @@ from oslo_log import log
|
|||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
PingAddressType = typing.Union[str, netaddr.IPAddress]
|
||||
|
||||
|
||||
class PingParameters(collections.namedtuple('PingParameters',
|
||||
['host',
|
||||
|
@ -61,9 +64,10 @@ def get_ping_parameters(default=None, **ping_params):
|
|||
|
||||
|
||||
def ping_parameters(default=None, count=None, deadline=None,
|
||||
fragmentation=None, host=None, interval=None,
|
||||
ip_version=None, packet_size=None, source=None,
|
||||
timeout=None, network_namespace=None):
|
||||
fragmentation=None,
|
||||
host: typing.Optional[PingAddressType] = None,
|
||||
interval=None, ip_version=None, packet_size=None,
|
||||
source=None, timeout=None, network_namespace=None):
|
||||
"""Validate parameters and initialize a new PingParameters instance
|
||||
|
||||
:param default: (PingParameters or None) instance from where to take
|
||||
|
@ -193,16 +197,23 @@ def get_boolean(name, value, default=None):
|
|||
return value
|
||||
|
||||
|
||||
def get_address(name, value, default=None):
|
||||
if value is None and default:
|
||||
return get_address(name, getattr(default, name))
|
||||
if value is not None:
|
||||
def get_address(name: str, value: typing.Optional[PingAddressType],
|
||||
default=None) -> typing.Optional[PingAddressType]:
|
||||
if value is None:
|
||||
if default:
|
||||
return get_address(name, getattr(default, name))
|
||||
else:
|
||||
return None
|
||||
if isinstance(value, netaddr.IPAddress):
|
||||
return value
|
||||
elif isinstance(value, str):
|
||||
try:
|
||||
value = netaddr.IPAddress(value)
|
||||
return netaddr.IPAddress(value)
|
||||
except netaddr.core.AddrFormatError:
|
||||
# NOTE: value may be an host name so this is fine
|
||||
value = str(value)
|
||||
return value
|
||||
return value
|
||||
else:
|
||||
raise TypeError(f"Object '{value}' is not a valid address")
|
||||
|
||||
|
||||
def get_string(name, value, default=None):
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import time
|
||||
import typing
|
||||
|
||||
import netaddr
|
||||
from oslo_log import log
|
||||
|
||||
|
||||
import tobiko
|
||||
from tobiko.shell import sh
|
||||
from tobiko.shell.ping import _interface
|
||||
|
@ -38,22 +39,37 @@ RECEIVED = 'received'
|
|||
UNRECEIVED = 'unreceived'
|
||||
|
||||
|
||||
def list_reachable_hosts(hosts, **params):
|
||||
PingHostType = typing.Union['str', netaddr.IPAddress]
|
||||
|
||||
|
||||
def list_reachable_hosts(hosts: typing.Iterable[PingHostType],
|
||||
**params) -> tobiko.Selection[PingHostType]:
|
||||
reachable_host, _ = ping_hosts(hosts, **params)
|
||||
return reachable_host
|
||||
|
||||
|
||||
def list_unreachable_hosts(hosts, **params):
|
||||
def list_unreachable_hosts(hosts: typing.Iterable[PingHostType],
|
||||
**params) -> tobiko.Selection[PingHostType]:
|
||||
_, unreachable_host = ping_hosts(hosts, **params)
|
||||
return unreachable_host
|
||||
|
||||
|
||||
def ping_hosts(hosts, **params):
|
||||
reachable = tobiko.Selection()
|
||||
unreachable = tobiko.Selection()
|
||||
PingHostsResultType = typing.Tuple[tobiko.Selection[PingHostType],
|
||||
tobiko.Selection[PingHostType]]
|
||||
|
||||
|
||||
def ping_hosts(hosts: typing.Iterable[PingHostType],
|
||||
count: typing.Optional[int] = None,
|
||||
**params) -> PingHostsResultType:
|
||||
if count is None:
|
||||
count = 1
|
||||
else:
|
||||
count = int(count)
|
||||
reachable = tobiko.Selection[PingHostType]()
|
||||
unreachable = tobiko.Selection[PingHostType]()
|
||||
for host in hosts:
|
||||
try:
|
||||
result = ping(host, count=1, **params)
|
||||
result = ping(host, count=count, **params)
|
||||
except _exception.PingError:
|
||||
LOG.exception('Error pinging host: %r', host)
|
||||
unreachable.append(host)
|
||||
|
@ -65,7 +81,8 @@ def ping_hosts(hosts, **params):
|
|||
return reachable, unreachable
|
||||
|
||||
|
||||
def ping(host, until=TRANSMITTED, check=True, **ping_params):
|
||||
def ping(host: PingHostType, until=TRANSMITTED, check: bool = True,
|
||||
**ping_params) -> _statistics.PingStatistics:
|
||||
"""Send ICMP messages to host address until timeout
|
||||
|
||||
:param host: destination host address
|
||||
|
@ -151,7 +168,7 @@ def ping_until_unreceived(host, **ping_params):
|
|||
|
||||
|
||||
def get_statistics(parameters=None, ssh_client=None, until=None, check=True,
|
||||
**ping_params):
|
||||
**ping_params) -> _statistics.PingStatistics:
|
||||
parameters = _parameters.get_ping_parameters(default=parameters,
|
||||
**ping_params)
|
||||
statistics = _statistics.PingStatistics()
|
||||
|
|
|
@ -95,7 +95,8 @@ class CirrosServerStackTest(testtools.TestCase):
|
|||
self.skipTest(f"Target server has no IPv{ip_version} "
|
||||
"nameservers configured")
|
||||
ping.assert_reachable_hosts(nameservers,
|
||||
ssh_client=self.stack.ssh_client)
|
||||
ssh_client=self.stack.ssh_client,
|
||||
count=5)
|
||||
|
||||
|
||||
class EvacuablesServerStackTest(CirrosServerStackTest):
|
||||
|
|
Loading…
Reference in New Issue