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 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)
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 #4
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)