Ejemplo n.º 1
0
def _assert_class_valid(board_class, board_type):
    """Check expected values on classes."""
    assert board_class.TYPE == board_type
    # Tuple with (class, machine) run 'elftarget.py' on a node firmware
    assert len(board_class.ELF_TARGET) == 2

    for firmware_attr in ('FW_IDLE', 'FW_AUTOTEST'):
        firmware = getattr(board_class, firmware_attr, None)
        assert elftarget.is_compatible_with_node(firmware, board_class), \
            firmware

    required_autotest = {'echo', 'get_time'}  # mandatory
    assert required_autotest.issubset(board_class.AUTOTEST_AVAILABLE)
Ejemplo n.º 2
0
def _assert_class_valid(board_class, board_type):
    """Check expected values on classes."""
    assert board_class.TYPE == board_type
    # Tuple with (class, machine) run 'elftarget.py' on a node firmware
    assert len(board_class.ELF_TARGET) == 2

    for firmware_attr in ('FW_IDLE', 'FW_AUTOTEST'):
        firmware = getattr(board_class, firmware_attr, None)
        assert elftarget.is_compatible_with_node(firmware, board_class), \
            firmware

    required_autotest = {'echo', 'get_time'}  # mandatory
    assert required_autotest.issubset(board_class.AUTOTEST_AVAILABLE)
Ejemplo n.º 3
0
    def node_flash(self, node, firmware_path):
        """
        Flash the given firmware on the given node

        :param node: Node name in {'control', 'open'}
        :param firmware_path: Path to the firmware to be flashed on `node`.
        """
        assert node in ['control', 'open'], "Invalid node name"
        LOGGER.info('Flash firmware on %s node: %s', node, firmware_path)

        target_node = self._nodes[node]

        if not elftarget.is_compatible_with_node(firmware_path, target_node):
            LOGGER.error('Invalid firmware target, not flashing.')
            return 1

        ret = target_node.flash(firmware_path)
        if ret != 0:  # pragma: no cover
            LOGGER.error('Flash firmware failed on %s node: %d', node, ret)
        return ret
Ejemplo n.º 4
0
    def verify(cls):
        """ Verifiy the open node """
        ret_val = 0
        # Tuple with (class, machine) run 'elftarget.py' on a node firmware
        if (getattr(cls, 'ELF_TARGET', None) is None or
                len(cls.ELF_TARGET) != 2):
            ret_val += 1

        for firmware_attr in ('FW_IDLE', 'FW_AUTOTEST'):
            firmware = getattr(cls, firmware_attr, None)
            if (firmware is not None and not
                    elftarget.is_compatible_with_node(firmware, cls)):
                ret_val += 1

        required_autotest = {'echo', 'get_time'}  # mandatory
        if (getattr(cls, 'AUTOTEST_AVAILABLE', None) is None or
                not required_autotest.issubset(cls.AUTOTEST_AVAILABLE)):
            ret_val += 1

        return ret_val
Ejemplo n.º 5
0
    def node_flash(self, node, firmware_path, binary=False, offset=0):
        """
        Flash the given firmware on the given node

        :param node: Node name in {'control', 'open'}
        :param firmware_path: Path to the firmware to be flashed on `node`.
        :param binary: The given file is a binary file
        :param offset: The offset at which to flash the binary file
        """
        assert node in ['control', 'open'], "Invalid node name"
        LOGGER.info('Flash firmware on %s node: %s', node, firmware_path)

        target_node = self._nodes[node]

        if not binary and not \
                elftarget.is_compatible_with_node(firmware_path, target_node):
            LOGGER.error('Invalid firmware target, not flashing.')
            return 1

        ret = target_node.flash(firmware_path, binary, offset)
        if ret != 0:  # pragma: no cover
            LOGGER.error('Flash firmware failed on %s node: %d', node, ret)
        return ret
Ejemplo n.º 6
0
    def exp_start(self, user, exp_id,  # pylint: disable=R0913
                  firmware_path=None, profile_dict=None, timeout=0):
        """
        Start an experiment

        :param exp_id: experiment id
        :param user: user running the experiment
        :param firmware_path: path of the firmware file to use, can be None
        :param profile_dict: monitoring profile
        :param timeout: Experiment expiration timeout. On 0 no timeout.

        Experiment start steps

        1) Prepare Gateway: User experiment files and log:
        2) Prepare Control node: Start communication and power on open node
        3) Prepare Open node: Check OK, setup firmware and serial redirection
        4) Configure Control Node Profile and experiment
        5) Set Experiment expiration timer

        """
        if self.experiment_is_running:
            LOGGER.debug('Experiment running. Stop previous experiment')
            self.exp_stop()

        try:
            profile = self.board_cfg.profile_from_dict(profile_dict)
        except ValueError as err:
            LOGGER.error('%r', err)
            return 1
        if not elftarget.is_compatible_with_node(firmware_path,
                                                 self.open_node):
            LOGGER.error('Invalid firmware target, aborting experiment.')
            return 1

        ret_val = 0

        self.experiment_is_running = True
        self.exp_id = exp_id
        self.user = user

        if (self.board_cfg.robot_type == 'turtlebot2' or
                self.board_cfg.cn_class.TYPE == 'no'):  # pragma: no cover
            LOGGER.info('Create user exp folder')
            self._create_user_exp_folders(user, exp_id)

        self.exp_files = self.create_user_exp_files(self.board_cfg.node_id,
                                                    user, exp_id)

        # Create user log
        self.user_log_handler = gateway_logging.user_logger(
            self.exp_files['log'])
        LOGGER.addHandler(self.user_log_handler)
        LOGGER.info('Start experiment: %s-%i', user, exp_id)

        # Init ControlNode
        ret_val += self.control_node.start(self.exp_id, self.exp_files)
        # Configure Open Node
        ret_val += self.open_node.setup(firmware_path)
        # Configure experiment and monitoring on ControlNode
        ret_val += self.control_node.start_experiment(profile)

        if timeout != 0:
            LOGGER.debug("Setting timeout to: %d", timeout)
            self.timeout_timer = Timer(timeout, self._timeout_exp_stop,
                                       args=(exp_id, user))
            self.timeout_timer.start()
        LOGGER.info("Start experiment succeeded")
        return ret_val