Exemplo n.º 1
0
def wait_for_responsive_ip_for_pc_device(leases_file_path, timeout,
                                         polling_interval):
    """
    Attempt to acquire active ip address for the device with the given mac
    address up to timeout seconds.

    Args:
        leases_file_path (str): Path to dnsmasq leases file
        timeout (integer): Timeout in seconds
        polling_interval (integer): Time between retries in seconds.

    Returns:
        Ip address as a string, or None if ip address was not responsive.
    """
    logger.info("Waiting for the device to become responsive")
    logger.debug("Timeout: " + str(timeout))
    logger.debug("Polling interval: " + str(polling_interval))

    for _ in range(timeout // polling_interval):
        responsive_ip = get_ip_for_pc_device(leases_file_path)

        if not responsive_ip:
            time.sleep(polling_interval)
            continue

        logger.info("Got a response from " + responsive_ip)
        return responsive_ip

    logger.info("No responsive ip was found")
Exemplo n.º 2
0
def verify_device_mode(ip, mode_name):
    """
    Check that the device with given ip is responsive to ssh and is in the
    specified mode.

    The mode is checked by checking that the mode_name arg is present in the
    /proc/version file

    Args:
        ip (str): The device ip address
        mode_name (str): Word to check for in /proc/version

    Returns:
        True if the device is in the desired mode, False otherwise
    """
    try:
        sshout = ssh.remote_execute(ip, ["cat", "/proc/version"])
        if mode_name in sshout:
            logger.info("Found " + mode_name + " in DUT /proc/version")
            return True
        logger.info("Didn't find " + mode_name + " in DUT /proc/version")
        logger.debug("/cat/proc/version: " + str(sshout))
        return False

    except subprocess32.CalledProcessError as err:
        logger.warning("Failed verifying the device mode with command: '" +
                       str(err.cmd) + "' failed with error code: '" +
                       str(err.returncode) + "' and output: '" +
                       str(err.output) + "'.")

        return False
Exemplo n.º 3
0
def wait_for_responsive_ip_for_pc_device(
    leases_file_path,
    timeout,
    polling_interval):
    """
    Attempt to acquire active ip address for the device with the given mac
    address up to timeout seconds.

    Args:
        leases_file_path (str): Path to dnsmasq leases file
        timeout (integer): Timeout in seconds
        polling_interval (integer): Time between retries in seconds.

    Returns:
        Ip address as a string, or None if ip address was not responsive.
    """
    logger.info("Waiting for the device to become responsive")
    logger.debug("Timeout: " + str(timeout))
    logger.debug("Polling interval: " + str(polling_interval))

    for _ in range(timeout // polling_interval):
        responsive_ip = get_ip_for_pc_device(leases_file_path)

        if not responsive_ip:
            time.sleep(polling_interval)
            continue

        logger.info("Got a response from " + responsive_ip)
        return responsive_ip

    logger.info("No responsive ip was found")
Exemplo n.º 4
0
def verify_device_mode(ip, mode_name):
    """
    Check that the device with given ip is responsive to ssh and is in the
    specified mode.

    The mode is checked by checking that the mode_name arg is present in the
    /proc/version file

    Args:
        ip (str): The device ip address
        mode_name (str): Word to check for in /proc/version

    Returns:
        True if the device is in the desired mode, False otherwise
    """
    try:
        sshout = ssh.remote_execute(ip, ["cat", "/proc/version"])
        if mode_name in sshout:
            logger.info("Found " + mode_name + " in DUT /proc/version")
            return True
        logger.info("Didn't find " + mode_name + " in DUT /proc/version")
        logger.debug("/cat/proc/version: " + str(sshout))
        return False

    except subprocess32.CalledProcessError as err:
        logger.warning(
            "Failed verifying the device mode with command: '" +
            str(err.cmd) + "' failed with error code: '" +
            str(err.returncode) + "' and output: '" +
            str(err.output) + "'.")

        return False
Exemplo n.º 5
0
    def run_local_command(self, timeout=1800):
        """
        Executes a command locally, on the test harness.
        """
        command = "timeout " + str(timeout) + " " + self.parameters
        process = subprocess32.Popen(command.split(),
                                     universal_newlines=True,
                                     stderr=subprocess32.STDOUT,
                                     stdout=subprocess32.PIPE)
        self.output = process.communicate()[0]
        logger.debug("Output return code in basictestcase.run_local_command():" + str(process.returncode))
        logger.debug("And output: " + self.output)


        if process.returncode == 124 or process.returncode == 128 + 9:
            raise errors.AFTTimeoutError("Test cases failed to complete in " + str(timeout) + " seconds")
        return True
Exemplo n.º 6
0
    def run(self, device):
        param = self.parameters
        success = True

        # test manifest contains the list of tests that should be executed.
        with open(self.test_manifest) as manifest:

            for line in manifest:
                line = line.strip()
                logger.debug("Read line: " + line)
                if len(line) == 0:
                    logger.debug("Empty line - skipping")
                    continue
                if line.startswith("#"):
                    logger.debug("Starts with '#', is comment - skipping")
                    continue
                self.parameters = param + " -n " + line
                logger.debug("Running local command with following parameters: " + self.parameters)
                self.run_local_command()
                logger.debug("Success status: " + str(self._success()))
                success = success and self._success()

        return success