cfme.utils.net module

cfme.utils.net.find_pingable(mgmt_vm)[source]

Looks for a pingable address from mgmt_vm.all_ips

Assuming mgmt_vm is a wrapanapi VM entity, with all_ips and ip methods

Returns

first pingable address, address ‘selected’ by wrapanapi (possibly None)

Return type

In priority

cfme.utils.net.ip_echo_socket(port=32123)[source]

A simple socket server, for use with my_ip_address()

cfme.utils.net.is_ipv4(ip_addr)[source]

verifies whether address is ipv4.

Parameters

ip_addr – ip_address to verify.

returns: return True if ip_address is ipv4 else returns False.

cfme.utils.net.is_ipv6(ip_addr)[source]

verifies whether address is ipv6.

Parameters

ip_addr – ip_address to verify.

returns: return True if ip_address is ipv6 else returns False.

cfme.utils.net.is_pingable(ip_addr)[source]

verifies the specified ip_address is reachable or not.

Parameters

ip_addr – ip_address to verify the PING.

returns: return True is ip_address is pinging else returns False.

cfme.utils.net.my_ip_address(http=False)[source]

Get the ip address of the host running tests using the service listed in cfme_data[‘ip_echo’]

The ip echo endpoint is expected to write the ip address to the socket and close the connection. See a working example of this in ip_echo_socket().

cfme.utils.net.net_check(port, addr=None, force=False)[source]

Checks the availablility of a port

cfme.utils.net.net_check_remote(port, addr=None, machine_addr=None, ssh_creds=None, force=False)[source]

Checks the availability of a port from outside using another machine (over SSH)

cfme.utils.net.random_port(tcp=True)[source]

Get a random port number for making a socket

Parameters

tcp – Return a TCP port number if True, UDP if False

This may not be reliable at all due to an inherent race condition. This works by creating a socket on an ephemeral port, inspecting it to see what port was used, closing it, and returning that port number. In the time between closing the socket and opening a new one, it’s possible for the OS to reopen that port for another purpose.

In practical testing, this race condition did not result in a failure to (re)open the returned port number, making this solution squarely “good enough for now”.

cfme.utils.net.resolve_hostname(hostname, force=False)[source]

Cached DNS resolver. If the hostname does not resolve to an IP, returns None.

cfme.utils.net.resolve_ips(host_iterable, force_dns=False)[source]

Takes list of hostnames, ips and another things. If the item is not an IP, it will be tried to be converted to an IP. If that succeeds, it is appended to the set together with original hostname. If it can’t be resolved, just the original hostname is appended.

cfme.utils.net.wait_for(func, func_args=[], func_kwargs={}, *, logger=<TraceLogger cfme (INFO)>, **kwargs)

Waits for a certain amount of time for an action to complete Designed to wait for a certain length of time, either linearly in 1 second steps, or exponentially, up to a maximum. Returns the output from the function once it completes successfully, along with the time taken to complete the command.

It tries to use time.monotonic(), if it is not present, falls back to time.time(), but it then is not resistant against system time changes.

Note: If using the expo keyword, the returned elapsed time will be inaccurate

as wait_for does not know the exact time that the function returned correctly, only that it returned correctly at last check.

Parameters
  • func – A function to be run

  • func_args – A list of function arguments to be passed to func

  • func_kwargs – A dict of function keyword arguments to be passed to func

  • num_sec – An int describing the number of seconds to wait before timing out.

  • timeout – Either an int describing the number of seconds to wait before timing out. Or a timedelta object. Or a string formatted like 1h 10m 5s. This then sets the num_sec variable.

  • expo – A boolean flag toggling exponential delay growth.

  • message – A string containing a description of func’s operation. If None, defaults to the function’s name.

  • fail_condition – An object describing the failure condition that should be tested against the output of func. If func() == fail_condition, wait_for continues to wait. Can be a callable which takes the result and returns boolean whether to fail. You can also specify it as a set, that way it checks whether it is present in the iterable.

  • handle_exception – A boolean controlling the handling of excepetions during func() invocation. If set to True, in cases where func() results in an exception, clobber the exception and treat it as a fail_condition.

  • delay – An integer describing the number of seconds to delay before trying func() again.

  • fail_func – A function to be run after every unsuccessful attempt to run func()

  • quiet – Do not write time report to the log (default False)

  • very_quiet – Do not log unless there was an error (default False). Implies quiet.

  • silent_failure – Even if the entire attempt times out, don’t throw a exception.

  • log_on_loop – Fire off a log.info message indicating we’re still waiting at each iteration of the wait loop

Returns

A tuple containing the output from func() and a float detailing the total wait time.

Raises

TimedOutError – If num_sec is exceeded after an unsuccessful func() invocation.

cfme.utils.net.wait_pingable(mgmt_vm, wait=30)[source]

Looks for a pingable address from mgmt_vm.all_ips and waits if it isn’t present

Assuming mgmt_vm is a wrapanapi VM entity, with all_ips and ip methods

Returns

first pingable address or exception