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)
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}
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)
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)}
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)}
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}