Exemple #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
Exemple #2
0
def main(argv=None):
    """
    Entry point for library-like use.
    """
    try:
        logger.set_process_prefix()

        config.parse()

        if argv != None:
            backup_argv = sys.argv
            sys.argv = argv

        args = parse_args()

        if args.debug:
            logger.level(logging.DEBUG)

        device_manager = DevicesManager(args)

        if args.device:
            device, tester = device_manager.try_flash_specific(args)
        else:
            device, tester = device_manager.try_flash_model(args)

        if not args.notest:
            print("Testing " + str(device.name) + ".")
            tester.execute()

        if not args.nopoweroff:
            device.detach()

        if args.boot:
            device_manager.boot_device_to_mode(device, args)

        device_manager.release(device)

        if "backup_argv" in locals():
            sys.argv = backup_argv
        return 0

    except KeyboardInterrupt:
        print("Keyboard interrupt, stopping aft")
        logger.error("Keyboard interrupt, stopping aft.")
        sys.exit(0)

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

    finally:
        thread_handler.set_flag(thread_handler.RECORDERS_STOP)
        for thread in thread_handler.get_threads():
            thread.join(5)
Exemple #3
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
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
Exemple #5
0
def main(argv=None):
    """
    Entry point for library-like use.
    """
    try:
        logger.set_process_prefix()

        config.parse()

        if argv != None:
            backup_argv = sys.argv
            sys.argv = argv

        args = parse_args()

        if args.debug:
            logger.level(logging.DEBUG)

        device_manager = DevicesManager(args)
        device, tester = device_manager.try_flash_model(args)

        if args.emulateusb:
            device.boot_usb_test_mode()

        if not args.notest:
            if not args.emulateusb:
                device.boot_internal_test_mode()

            print("Testing " + str(device.name) + ".")
            tester.execute()

            if not args.nopoweroff:
                device.detach()
                if args.emulateusb:
                    device_manager.stop_image_usb_emulation(
                                                    device.leases_file_name)

        if not args.emulateusb:
            if args.boot == "test_mode":
                device.boot_internal_test_mode()

            elif args.boot == "service_mode":
                device.boot_usb_service_mode()

        device_manager.release(device)

        if "backup_argv" in locals():
            sys.argv = backup_argv
        return 0

    except KeyboardInterrupt:
        print("Keyboard interrupt, stopping aft")
        logger.error("Keyboard interrupt, stopping aft.")
        sys.exit(0)

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

    finally:
        thread_handler.set_flag(thread_handler.RECORDERS_STOP)
        for thread in thread_handler.get_threads():
            thread.join(5)
Exemple #6
0
def main(argv=None):
    """
    Entry point for library-like use.
    """

    try:
        logger.init_root_logger()
        logger.init_thread()

        config.parse()

        if argv != None:
            backup_argv = sys.argv
            sys.argv = argv

        args = parse_args()

        if args.debug:
            logger.level(logging.DEBUG)

        if args.configure:
            builder = TopologyBuilder(args)
            builder.build_topology()
            return 0

        if args.check:
            results = device_config.check(args)
            logger.info(results[1])
            print(results[1])

            if results[0] == True:
                return 0
            else:
                return 1
        elif args.checkall:
            results = device_config.check_all(args)
            logger.info(results[1])
            print(results[1])

            if results[0] == True:
                logger.info("All tests passed")
                return 0
            else:
                logger.info("There were failures")
                return 1


        device_manager = DevicesManager(args)

        if args.blacklist:
            if not args.device:
                print("Device must be specified for blacklisting")
                return 1

            device_manager.blacklist_device(args.device, args.reason)
            return 0

        if args.unblacklist:
            if not args.device:
                print("Device must be specified for unblacklisting")
                return 1
            device_manager.unblacklist_device(args.device)
            return 0

        if args.blacklist_print:
            device_manager.blacklist_print()
            return 0

        if args.recover_edisons:
            recover_edisons(device_manager, args.verbose)
            return 0

        if not args.machine:
            print("Both machine and image must be specified")
            return 1

        if not args.noflash:
            if not args.file_name:
                print("Both machine and image must be specified")
                return 1

            if not os.path.isfile(args.file_name):
                print("Didn't find image: " + args.file_name)
                logger.error("Didn't find image: " + args.file_name)
                return 1

        if args.device:
            device, tester = try_flash_specific(args, device_manager)
        else:
            device, tester = try_flash_model(args, device_manager)

        if not args.notest:
            print("Testing " + str(device.name) + ".")
            tester.execute()

        if not args.nopoweroff:
            device.detach()

        device_manager.release(device)

        if "backup_argv" in locals():
            sys.argv = backup_argv
        return 0

    except KeyboardInterrupt:
        print("Keyboard interrupt, stopping aft")
        logger.error("Keyboard interrupt, stopping aft.")
        sys.exit(0)

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

    finally:
        thread_handler.set_flag(thread_handler.RECORDERS_STOP)
        for thread in thread_handler.get_threads():
            thread.join(5)
Exemple #7
0
def main(argv=None):
    """
    Entry point for library-like use.
    """

    try:
        logger.init_root_logger()
        logger.init_thread()

        config.parse()

        if argv != None:
            backup_argv = sys.argv
            sys.argv = argv

        args = parse_args()

        if args.debug:
            logger.level(logging.DEBUG)

        if args.configure:
            builder = TopologyBuilder(args)
            builder.build_topology()
            return 0

        if args.check:
            results = device_config.check(args)
            logger.info(results[1])
            print(results[1])

            if results[0] == True:
                return 0
            else:
                return 1
        elif args.checkall:
            results = device_config.check_all(args)
            logger.info(results[1])
            print(results[1])

            if results[0] == True:
                logger.info("All tests passed")
                return 0
            else:
                logger.info("There were failures")
                return 1

        device_manager = DevicesManager(args)

        if args.blacklist:
            if not args.device:
                print("Device must be specified for blacklisting")
                return 1

            device_manager.blacklist_device(args.device, args.reason)
            return 0

        if args.unblacklist:
            if not args.device:
                print("Device must be specified for unblacklisting")
                return 1
            device_manager.unblacklist_device(args.device)
            return 0

        if args.blacklist_print:
            device_manager.blacklist_print()
            return 0

        if args.recover_edisons:
            recover_edisons(device_manager, args.verbose)
            return 0

        if not args.machine:
            print("Both machine and image must be specified")
            return 1

        if not args.noflash:
            if not args.file_name:
                print("Both machine and image must be specified")
                return 1

            if not os.path.isfile(args.file_name):
                print("Didn't find image: " + args.file_name)
                logger.error("Didn't find image: " + args.file_name)
                return 1

        if args.device:
            device, tester = try_flash_specific(args, device_manager)
        else:
            device, tester = try_flash_model(args, device_manager)

        if not args.notest:
            print("Testing " + str(device.name) + ".")
            tester.execute()

        if not args.nopoweroff:
            device.detach()

        device_manager.release(device)

        if "backup_argv" in locals():
            sys.argv = backup_argv
        return 0

    except KeyboardInterrupt:
        print("Keyboard interrupt, stopping aft")
        logger.error("Keyboard interrupt, stopping aft.")
        sys.exit(0)

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

    finally:
        thread_handler.set_flag(thread_handler.RECORDERS_STOP)
        for thread in thread_handler.get_threads():
            thread.join(5)