def test_Board_console_setter_should_set_current_console():
    board = Board(name='board')

    console2 = MagicMock(ConsoleBase)
    board.console = console2

    assert board.console is console2
def test_Board_console_should_return_the_first_console_by_default():
    console1 = MagicMock(ConsoleBase)
    console2 = MagicMock(ConsoleBase)
    board = Board(name='board', console={'def': console1, 'abc': console2})

    assert board.console is console1
    assert board.get_console() is console1
def test_Board_console_setter_should_reset_consoles_if_not_in_the_list():
    console1 = MagicMock(ConsoleBase)
    console1_name = 'abc'
    board = Board(name='board', console={console1_name: console1})

    console2 = MagicMock(ConsoleBase)
    board.console = console2

    assert board.get_console(console1_name) is None
Beispiel #4
0
def test_Board_get_console_should_return_the_proper_console_by_name():
    console1 = MagicMock(ConsoleBase)
    console1_name = 'abc'
    console2 = MagicMock(ConsoleBase)
    console2_name = 'def'
    board = Board(name='board', console={
                  console1_name: console1, console2_name: console2})

    assert board.get_console(console1_name) is console1
    assert board.get_console(console2_name) is console2
def test_Board_console_setter_should_keep_consoles_if_in_the_list():
    console1 = MagicMock(ConsoleBase)
    console1_name = 'abc'
    console2 = MagicMock(ConsoleBase)
    console2_name = 'def'
    consoles = {console1_name: console1, console2_name: console2}
    board = Board(name='board', console=consoles)

    assert board.console is console1
    board.console = console2

    assert board.console is console2
    assert board.consoles == consoles
def test_Board_consoles_should_return_all_consoles():
    console1 = MagicMock(ConsoleBase)
    console1_name = 'abc'
    console2 = MagicMock(ConsoleBase)
    console2_name = 'def'
    consoles = {console1_name: console1, console2_name: console2}
    board = Board(name='board', console=consoles)

    assert board.consoles == consoles
Beispiel #7
0
    def __init__(self, board: Board, target: str = None):
        super().__init__(board, script='')

        if not target:
            ssh_console = board.get_console('ssh')
            if not ssh_console:
                raise ValueError(
                    f'{self}: You need to provide a "target" parameter, '
                    'or an SSH console to get the target host from.')
            target = ssh_console.target

        self.target = target
def test_WaitForPatternAction_should_succeed_when_matched_proxy_console(
        mock_board, serial_console_proxy):
    mock_board = Board("board", console=serial_console_proxy.console)
    expected_pattern = 'abc'
    action = WaitForPatternAction(mock_board, pattern=expected_pattern)

    async_action = nonblocking(action.execute)

    # Wait to make sure what we write isn't discarded
    time.sleep(0.1)
    serial_console_proxy.proxy.write('some content')
    serial_console_proxy.proxy.write('abc\n')

    async_action.get()
def test_WaitForPatternAction_should_fail_when_no_matched_proxy_console(
        mock_board, serial_console_proxy):
    mock_board = Board("board", console=serial_console_proxy.console)
    expected_pattern = 'abc'
    action = WaitForPatternAction(mock_board,
                                  pattern=expected_pattern,
                                  timeout=1)

    async_action = nonblocking(action.execute)

    # Wait to make sure what we write isn't discarded
    time.sleep(0.1)
    serial_console_proxy.proxy.write('some content')
    serial_console_proxy.proxy.write('and more\n')

    with pytest.raises(TaskFailed):
        async_action.get()
def test_SetAction_should_set_console():
    ssh_console = MagicMock(ConsoleBase)
    serial_console = MagicMock(ConsoleBase)
    board = Board("board",
                  console={
                      'ssh': ssh_console,
                      'serial': serial_console
                  })

    action = SetAction(board, device_console='ssh')
    action.execute()

    assert board.console is ssh_console

    action = SetAction(board, device_console='serial')
    action.execute()
    assert board.console is serial_console
Beispiel #11
0
    def __init__(self, board: Board, target: str = None):
        super().__init__(board, script='')

        if not target:
            ssh_console = board.get_console('ssh')
            if not ssh_console:
                raise ValueError(
                    f'{self}: You need to provide a "target" parameter, '
                    'or an SSH console to get the target host from.')

            if not isinstance(ssh_console, SSHConsole):
                raise ValueError(
                    f'{self}: The "target" argument must be specified '
                    'for networking tests, if an SSH console is not used')

            target = ssh_console.target

        self.target = target
Beispiel #12
0
    def __init__(self, board: Board, target: str = None):
        super().__init__(board, script='')

        if self.__class__ == NetworkingTestBase:
            raise NotImplementedError(f'{self.__class__.__name__} is a base class and '
                                      'should not be instantiated by itself')

        if not target:
            ssh_console = board.get_console('ssh')
            if not ssh_console:
                raise ValueError(f'{self}: You need to provide a "target" parameter, '
                                 'or an SSH console to get the target host from.')

            if not isinstance(ssh_console, SSHConsole):
                raise ValueError(f'{self}: The "target" argument must be specified '
                                 'for networking tests, if an SSH console is not used')

            target = ssh_console.target

        self.target = target
    def _create_context(config: Configuration) -> PlumaContext:
        variables = TargetFactory.parse_variables(config.pop('variables'))
        system = TargetFactory.parse_system_context(config.pop('system'))
        serial, ssh = TargetFactory.create_consoles(config.pop('console'), system)

        if not serial and not ssh:
            log.warning("No console defined in the device configuration file")

        power = TargetFactory.create_power_control(
            config.pop('power'), ssh)

        config.ensure_consumed()

        consoles = {}
        if serial:
            consoles['serial'] = serial
        if ssh:
            consoles['ssh'] = ssh

        board = Board('Test board', console=consoles, power=power,
                      system=system)
        return PlumaContext(board, variables=variables)
Beispiel #14
0
    def _create_context(config: Configuration) -> PlumaContext:
        variables = TargetFactory.parse_variables(
            config.pop_optional(Configuration, 'variables'))
        system = TargetFactory.parse_system_context(
            config.pop_optional(Configuration, 'system'))
        consoles = TargetFactory.create_consoles(
            config.pop_optional(Configuration, 'console'), system)

        serial = consoles.get('serial')
        ssh = consoles.get('ssh')
        if not serial and not ssh:
            log.warning("No console defined in the device configuration file")

        power = TargetFactory.create_power_control(
            config.pop_optional(Configuration, 'power'), ssh or serial)

        config.ensure_consumed()

        board = Board('Test board',
                      console=consoles,
                      power=power,
                      system=system)
        return PlumaContext(board, variables=variables)
Beispiel #15
0
def test_Board_should_support_empty_console_dict():
    Board(name='board', console={})
Beispiel #16
0
def test_Board_should_support_no_console():
    Board(name='board')
Beispiel #17
0
def test_Board_should_error_on_invalid_console_type(consoles):
    with pytest.raises(ValueError):
        Board(name='board', console=consoles)
Beispiel #18
0
def test_Board_consoles_setter_should_error_on_invalid_type(consoles):
    board = Board(name='board')
    with pytest.raises(ValueError):
        board.consoles = consoles
Beispiel #19
0
def test_Board_console_should_return_single_console_set():
    console1 = MagicMock(ConsoleBase)
    board = Board(name='board', console=console1)

    assert board.console is console1
    assert board.get_console() is console1