Beispiel #1
0
def check(args):
    """
    Checks that the specified device is configured correctly

    Args:
        args (configuration object): Program command line arguments

    Returns:
        Tuple (Bool, String): Test status code and result message string. True
        indicates tests passed succesfully, false indicates that there were
        failures
    """

    if not args.device:
        raise errors.AFTConfigurationError(
            "You must specify the device that will be checked")

    if args.verbose:
        print("Running configuration check on " + args.device)

    if args.checkall:
        logger.init_thread(args.device + "_")

    logger.info("Running configuration check on " + args.device)

    manager = DevicesManager(args)
    device = manager.reserve_specific(args.device)

    if args.verbose:
        print("Device " + args.device + " acquired, running checks")

    try:
        sanity_results = _run_sanity_tests(args, device)
        image_test_results = (True, "Image Test result: Not run")
        # only run image test if sanity test passed
        if sanity_results[0] == True:
            image_test_results = _run_tests_on_know_good_image(args, device)

    finally:
        if args.verbose:
            print("Releasing device " + args.device)

        if not args.nopoweroff:
            device.detach()

        manager.release(device)

    results = (sanity_results[0] and image_test_results[0],
               sanity_results[1] + "\n" + image_test_results[1])

    if not results[0]:
        common.blacklist_device(device.dev_id, args.device,
                                "Failed device health check")
        msg = "Device " + args.device + " failed health test - blacklisting"
        logger.info(msg)
        if args.verbose:
            print msg

    return results
Beispiel #2
0
def check(args):
    """
    Checks that the specified device is configured correctly

    Args:
        args (configuration object): Program command line arguments

    Returns:
        Tuple (Bool, String): Test status code and result message string. True
        indicates tests passed succesfully, false indicates that there were
        failures
    """

    if not args.device:
        raise errors.AFTConfigurationError(
            "You must specify the device that will be checked")

    if args.verbose:
        print "Running configuration check on " + args.device

    logging.info("Running configuration check on " + args.device)
    manager = DevicesManager(args)
    device = manager.reserve_specific(args.device)

    if args.verbose:
        print "Device " + args.device + " acquired, running checks"

    test_results = _run_tests(args, device)


    if args.verbose:
        print "Releasing device " + args.device

    manager.release(device)
    results =  _handle_test_results(args, device, test_results)

    if not results[0]:
        common.blacklist_device(
                device.dev_id,
                args.device,
                "Failed device health check")

        msg = "Device " + args.device + " failed health test - blacklisting"
        logging.info(msg)
        if args.verbose:
            print msg


    return results
Beispiel #3
0
    def blacklist_device(self, device, reason):
        """
        Blacklist a device, preventing any further testing

        Args:
            Device (str): Name of the device
            reason (str): Reason for blacklisting
        """
        dev_id = None

        for config in self.device_configs:
            if config["name"].lower() == device.lower():
                dev_id = config["settings"]["id"]
                break

        common.blacklist_device(dev_id, device, reason)
Beispiel #4
0
    def _flash_image(self, file_name_no_extension):
        """
        Flash the new bootloader and image

        Args:
            file_name_no_extension (str):
                Image name without the extension (eg. edison-image.ext4 ->
                    edison-image)

        Returns:
            True

        Raises:
            errors.aft.AFTDeviceError if flashing fails
        """
        self._power_cycle()

        try:
            self._flash_partitions(file_name_no_extension)
        except errors.AFTPotentiallyBrokenBootloader as err:
            # if the bootloader is broken, the device is bricked until it is
            # recovered through recovery flashing. As only one device can be
            # powered on during recovery flashing, we just blacklist the device
            # and recover it later

            logger.critical(
                "Bootloader might be broken - blacklisting the " +
                "device as a precaution (Note: This could be a false positive)"
            )

            common.blacklist_device(
                self._configuration["id"], self._configuration["name"],
                "Bootloader might be broken - recovery flashing " +
                "will be performed as a precaution (Note: This could be a " +
                "false positive")

            self._recover_edison()

            raise errors.AFTDeviceError(
                "Bootloader might be broken - blacklisting the " +
                "device as a precaution (Note: This could be a false positive)"
            )

        return True
Beispiel #5
0
    def _flash_image(self, file_name_no_extension):
        """
        Flash the new bootloader and image

        Args:
            file_name_no_extension (str):
                Image name without the extension (eg. edison-image.ext4 ->
                    edison-image)

        Returns:
            True

        Raises:
            errors.aft.AFTDeviceError if flashing fails
        """
        self._power_cycle()

        try:
            self._flash_partitions(file_name_no_extension)
        except errors.AFTPotentiallyBrokenBootloader as err:
            # if the bootloader is broken, the device is bricked until it is
            # recovered through recovery flashing. As only one device can be
            # powered on during recovery flashing, we just blacklist the device
            # and recover it later

            logger.critical(
                "Bootloader might be broken - blacklisting the " +
                "device as a precaution (Note: This could be a false positive)")

            common.blacklist_device(
                self._configuration["id"],
                self._configuration["name"],
                "Bootloader might be broken - recovery flashing " +
                "will be performed as a precaution (Note: This could be a " +
                "false positive")

            self._recover_edison()

            raise errors.AFTDeviceError(
                "Bootloader might be broken - blacklisting the " +
                "device as a precaution (Note: This could be a false positive)")

        return True
Beispiel #6
0
    def _flash_image(self, file_name_no_extension):
        """
        Flash the new bootloader and image

        Args:
            file_name_no_extension (str):
                Image name without the extension (eg. edison-image.ext4 ->
                    edison-image)

        Returns:
            True

        Raises:
            errors.aft.AFTDeviceError if flashing fails
        """
        self._power_cycle()

        try:
            self._flash_partitions(file_name_no_extension)
        except errors.AFTPotentiallyBrokenBootloader, err:
            # if the bootloader is broken, the device is bricked until it is
            # recovered through recovery flashing. As only one device can be
            # powered on during recovery flashing, we just blacklist the device
            # and recover it later

            logging.critical(
                "Bootloader seems to have been broken - blacklisting the " +
                "device")

            common.blacklist_device(
                self._configuration["id"],
                self._configuration["name"],
                "Bootloader seems to be broken - recovery flashing " +
                "required")

            self._recover_edison()

            raise errors.AFTDeviceError(
                "Bootloader seems to have been broken - blacklisting the " +
                "device")
def check(args):
    """
    Checks that the specified device is configured correctly

    Args:
        args (configuration object): Program command line arguments

    Returns:
        Tuple (Bool, String): Test status code and result message string. True
        indicates tests passed succesfully, false indicates that there were
        failures
    """

    if not args.device:
        raise errors.AFTConfigurationError(
            "You must specify the device that will be checked")

    if args.verbose:
        print("Running configuration check on " + args.device)

    if args.checkall:
        logger.init_thread(args.device + "_")

    logger.info("Running configuration check on " + args.device)

    manager = DevicesManager(args)
    device = manager.reserve_specific(args.device)

    if args.verbose:
        print("Device " + args.device + " acquired, running checks")

    try:
        sanity_results = _run_sanity_tests(args, device)
        image_test_results = (True, "Image Test result: Not run")
        # only run image test if sanity test passed
        if sanity_results[0] == True:
            image_test_results = _run_tests_on_know_good_image(args, device)

    finally:
        if args.verbose:
            print("Releasing device " + args.device)

        if not args.nopoweroff:
            device.detach()

        manager.release(device)

    results = (
        sanity_results[0] and image_test_results[0],
        sanity_results[1] + "\n" + image_test_results[1]
        )

    if not results[0]:
        common.blacklist_device(
                device.dev_id,
                args.device,
                "Failed device health check")
        msg = "Device " + args.device + " failed health test - blacklisting"
        logger.info(msg)
        if args.verbose:
            print msg

    return results
Beispiel #8
0
def try_flash_model(args, device_manager):
    '''
    Reserve and flash a machine. By default it tries to flash 2 times with 2
    different machines. If flashing fails machine will be blacklisted.

    Args:
        args: AFT arguments
        device_manager: Device manager object

    Returns:
        device, tester: Reserved machine and tester handles.
    '''
    machine_attempt = 0
    machine_retries = args.machine_retries

    while machine_attempt < machine_retries:
        machine_attempt += 1

        device = device_manager.reserve()
        tester = Tester(device)

        if args.record:
            device.record_serial()

        if args.noflash:
            return device, tester

        flash_attempt = 0
        flash_retries = args.flash_retries

        while flash_attempt < flash_retries:
            flash_attempt += 1

            try:
                print("Flashing " + str(device.name) + ", attempt " +
                    str(flash_attempt) + " of " + str(flash_retries) + ".")
                device.write_image(args.file_name)
                print("Flashing successful.")
                return device, tester

            except KeyboardInterrupt:
                raise

            except:
                _err = sys.exc_info()
                _err = str(_err[0]).split("'")[1] + ": " + str(_err[1])
                logger.error(_err)
                print(_err)

                if (flash_retries - flash_attempt) == 0:
                    msg = "Flashing failed " + str(flash_attempt) + " times"
                    print(msg + ", blacklisting " + str(device.name))
                    logger.info(msg + ", blacklisting " + str(device.name))
                    common.blacklist_device(device.dev_id, device.name, msg)
                    device_manager.release(device)

                    if machine_attempt < machine_retries:
                        print("Attempting flashing another machine")

                    else:
                        raise

                elif (flash_retries - flash_attempt) == 1:
                    print("Flashing failed, trying again one more time")

                elif (flash_retries - flash_attempt) > 1:
                    print("Flashing failed, trying again " +
                        str(flash_retries - flash_attempt) + " more times")
Beispiel #9
0
def try_flash_model(args, device_manager):
    '''
    Reserve and flash a machine. By default it tries to flash 2 times with 2
    different machines. If flashing fails machine will be blacklisted.

    Args:
        args: AFT arguments
        device_manager: Device manager object

    Returns:
        device, tester: Reserved machine and tester handles.
    '''
    machine_attempt = 0
    machine_retries = args.machine_retries

    while machine_attempt < machine_retries:
        machine_attempt += 1

        device = device_manager.reserve()
        tester = Tester(device)

        if args.record:
            device.record_serial()

        if args.noflash:
            return device, tester

        flash_attempt = 0
        flash_retries = args.flash_retries

        while flash_attempt < flash_retries:
            flash_attempt += 1

            try:
                print("Flashing " + str(device.name) + ", attempt " +
                      str(flash_attempt) + " of " + str(flash_retries) + ".")
                device.write_image(args.file_name)
                print("Flashing successful.")
                return device, tester

            except KeyboardInterrupt:
                raise

            except:
                _err = sys.exc_info()
                _err = str(_err[0]).split("'")[1] + ": " + str(_err[1])
                logger.error(_err)
                print(_err)

                if (flash_retries - flash_attempt) == 0:
                    msg = "Flashing failed " + str(flash_attempt) + " times"
                    print(msg + ", blacklisting " + str(device.name))
                    logger.info(msg + ", blacklisting " + str(device.name))
                    common.blacklist_device(device.dev_id, device.name, msg)
                    device_manager.release(device)

                    if machine_attempt < machine_retries:
                        print("Attempting flashing another machine")

                    else:
                        raise

                elif (flash_retries - flash_attempt) == 1:
                    print("Flashing failed, trying again one more time")

                elif (flash_retries - flash_attempt) > 1:
                    print("Flashing failed, trying again " +
                          str(flash_retries - flash_attempt) + " more times")