예제 #1
0
def test_run(join, run_command, run_on_frontend):
    # pylint: disable=unused-argument
    """Test running commands on ssh nodes."""
    config_ssh = {
        'user': '******',
        'exp_id': 123,
    }

    test_command = 'test'
    groups = _nodes_grouped(_ROOT_NODES)

    node_ssh = OpenLinuxSsh(config_ssh, groups, verbose=True)

    # Print output of run_command
    if run_on_frontend:
        output = [HostOutput('saclay.iot-lab.info', 'test', 0),
                  HostOutput()]
    else:
        output = [HostOutput(host, 'test', 1) for host in _GRENOBLE_NODES]
        output.extend([HostOutput(host, 'test', 0) for host in _SACLAY_NODES])
    run_command.return_value = output

    ret = node_ssh.run(test_command, with_proxy=not run_on_frontend)
    if run_on_frontend:
        assert ret == {'0': ['saclay.iot-lab.info'],
                       '1': ['grenoble.iot-lab.info']}
    else:
        assert ret == {'0': _SACLAY_NODES,
                       '1': _GRENOBLE_NODES}
    assert run_command.call_count == len(groups)
    run_command.assert_called_with(test_command, stop_on_errors=False)
예제 #2
0
def run_cmd(config_ssh, nodes, cmd, run_on_frontend=False, verbose=False):
    """Run a command on the Linux nodes or SSH frontend servers """

    # Configure ssh.
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    return {"run-cmd": ssh.run(cmd, with_proxy=not run_on_frontend)}
예제 #3
0
def wait_for_boot(config_ssh, nodes, max_wait=120, verbose=False):
    """Wait for the open Linux nodes boot """

    # Configure ssh.
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    # Wait for boot
    return {"wait-for-boot": ssh.wait(max_wait)}
예제 #4
0
def reset(config_ssh, nodes, verbose=False):
    """Reset co-microcontroller """

    # Configure ssh
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    # Run reset command
    return {"reset": ssh.run(_RESET_CMD)}
예제 #5
0
def copy_file(config_ssh, nodes, file_path, verbose=False):
    """Copy a file to SSH frontend servers """

    # Configure ssh.
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    # relative path with native client
    remote_file = os.path.join(_REMOTE_SHARED_DIR, os.path.basename(file_path))
    result = ssh.scp(file_path, remote_file)
    return {"copy-file": result}
예제 #6
0
def run_script(config_ssh, nodes, script, run_on_frontend=False,
               verbose=False):
    """Run a script in background on Linux nodes or SSH frontend servers """

    # Configure ssh.
    failed_hosts = []
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    screen = f'{config_ssh["user"]}-{config_ssh["exp_id"]}'
    remote_script = os.path.join(_REMOTE_SHARED_DIR, os.path.basename(script))
    script_data = {'screen': screen, 'path': remote_script}
    # Copy script on SSH frontend servers
    scp_result = ssh.scp(script, remote_script)
    failed_hosts.append(_get_failed_result(ssh.groups, scp_result,
                                           run_on_frontend))
    # Make script executable
    run_result = ssh.run(_MAKE_EXECUTABLE_CMD.format(remote_script),
                         with_proxy=False)
    failed_hosts.append(_get_failed_result(ssh.groups, run_result,
                                           run_on_frontend))
    # Try cleanup and kill any running script (don't check the result)
    ssh.run(_QUIT_SCRIPT_CMD.format(**script_data),
            with_proxy=not run_on_frontend)
    # Run script
    result = ssh.run(_RUN_SCRIPT_CMD.format(**script_data),
                     with_proxy=not run_on_frontend, use_pty=False)
    for hosts in filter(None, failed_hosts):
        result.setdefault('1', []).extend(hosts)
    return {"run-script": result}
예제 #7
0
def flash(config_ssh, nodes, firmware, verbose=False):
    """Flash the firmware of co-microcontroller """
    failed_hosts = []
    # configure ssh and remote firmware names.
    groups = _nodes_grouped(nodes)
    ssh = OpenLinuxSsh(config_ssh, groups, verbose=verbose)
    remote_fw = os.path.join(_REMOTE_SHARED_DIR, os.path.basename(firmware))
    # copy the firmware to the site SSH servers
    # scp create remote directory if it doesn't exist
    result = ssh.scp(firmware, remote_fw)
    # We delete failed hosts for the next command
    if '1' in result:
        failed_hosts = [ssh.groups.pop(res) for res in result['1']]
    # Run firmware update.
    bin_opt = "--bin" if remote_fw.endswith(".bin") else ""
    result = ssh.run(_FLASH_CMD.format(fw=remote_fw, bin=bin_opt))
    for hosts in failed_hosts:
        result.setdefault('1', []).extend(hosts)
    return {"flash": result}
예제 #8
0
def test_wait_all_boot(join, run_command):
    # pylint: disable=unused-argument
    """Test wait for ssh nodes to be available."""
    config_ssh = {
        'user': '******',
        'exp_id': 123,
    }

    test_command = 'test'
    groups = _nodes_grouped(_ROOT_NODES)

    # normal boot
    node_ssh = OpenLinuxSsh(config_ssh, groups, verbose=True)

    output = [HostOutput(host, 'test', 0) for host in _ROOT_NODES]
    run_command.return_value = output

    node_ssh.wait(120)
    assert run_command.call_count == 2
    run_command.assert_called_with('uptime', stop_on_errors=False)
    run_command.reset_mock()

    node_ssh.run(test_command)
    assert run_command.call_count == 2
    run_command.assert_called_with(test_command, stop_on_errors=False)
예제 #9
0
def test_scp(copy_file, init):
    # pylint: disable=unused-argument
    """Test wait for ssh nodes to be available."""
    config_ssh = {
        'user': '******',
        'exp_id': 123,
    }

    src = 'test_src'
    dst = 'test_dst'

    groups = _nodes_grouped(_ROOT_NODES)

    node_ssh = OpenLinuxSsh(config_ssh, groups, verbose=True)
    ret = node_ssh.scp(src, dst)
    assert copy_file.call_count == 2
    assert ret == {'0': ['saclay.iot-lab.info', 'grenoble.iot-lab.info']}

    copy_file.side_effect = SFTPError()
    ret = node_ssh.scp(src, dst)

    assert ret == {'1': ['saclay.iot-lab.info', 'grenoble.iot-lab.info']}