Example #1
0
def get_ip_for_pc_device(leases_file_path):
    """
    Return active ip address for PC like device that leases it through dnsmasq.

    Address is considered to be active if ssh connection can be made
    successfully

    Args:
        leases_file_path (str): Path to dnsmasq leases file

    Returns:
        Device ip address as string or None if device does not have active
        ip address
    """
    ip_addresses = get_leased_ip_addresses_for_mac(leases_file_path)

    for ip_address in ip_addresses:
        if ssh.test_ssh_connectivity(ip_address):
            return ip_address

    return None
Example #2
0
def get_ip_for_pc_device(leases_file_path):
    """
    Return active ip address for PC like device that leases it through dnsmasq.

    Address is considered to be active if ssh connection can be made
    successfully

    Args:
        leases_file_path (str): Path to dnsmasq leases file

    Returns:
        Device ip address as string or None if device does not have active
        ip address
    """
    ip_addresses = get_leased_ip_addresses_for_mac(leases_file_path)

    for ip_address in ip_addresses:
        if ssh.test_ssh_connectivity(ip_address):
            return ip_address

    return None
Example #3
0
    def _wait_until_ssh_visible(self, timeout=180):
        """
        Wait until the DUT answers to ssh

        Args:
            timeout (integer): The timeout value in seconds
        Returns:
            None

        Raises:
            aft.errors.AFTConnectionError on timeout
        """
        start = time.time()
        while time.time() - start < timeout:
            if ssh.test_ssh_connectivity(self.get_ip()):
                return
        logger.critical("Failed to establish ssh-connection in " +
                        str(timeout) +
                        " seconds after enabling the network interface.")

        raise errors.AFTConnectionError(
            "Failed to establish ssh-connection in " + str(timeout) +
            " seconds after enabling the network interface.")
Example #4
0
    def _check_connectivity(self, ip, device_type):
        """
        Check ssh connectivity to ip address. Edison is an exception, we
        ping it instead.

        Connectivity check on non-Edison devices rely on the device operating
        systems, and currently we cannot safely assume that the firewall does
        not filter ping requests. SSH on the other hand should be working.

        Edison uses the host computer usb interface, to check connectivity,and
        the host system probably does not have its own public key in the
        authorized_keys list, so SSHing into the edison ip is bound
        to fail. On the other hand, we can configure the host to respond to
        pings, so we use pinging here instead.

        Args:
            ip (string): Target ip
            type (string): Device type
        Returns:
            Operation status code: 0 = success, 1 = failure
        """

        if device_type == "edison":
            if self._verbose:
                print "Pinging " + ip

            logging.info("Pinging ip address " + ip)
            return os.system("ping -c 10 " + ip + " > /dev/null")
        else:
            if self._verbose:
                print "Testing ssh connection for " + ip
            logging.info("Testing ssh connection for " + ip)
            if ssh.test_ssh_connectivity(ip):
                return 0
            else:
                return 1
Example #5
0
    def _wait_until_ssh_visible(self, timeout=180):
        """
        Wait until the DUT answers to ssh

        Args:
            timeout (integer): The timeout value in seconds
        Returns:
            None

        Raises:
            aft.errors.AFTConnectionError on timeout

        """
        start = time.time()
        while time.time() - start < timeout:
            if ssh.test_ssh_connectivity(self.get_ip()):
                return
        logger.critical(
            "Failed to establish ssh-connection in " + str(timeout) +
            " seconds after enabling the network interface.")

        raise errors.AFTConnectionError(
            "Failed to establish ssh-connection in " + str(timeout) +
            " seconds after enabling the network interface.")