コード例 #1
0
ファイル: mockdevice.py プロジェクト: marosmars/cli-testtool
def spawn_server(port_low, port_high, interface, protocol_type, data):
    #p = psutil.Process(os.getpid())
    try:
        os.nice(-1)
    except Exception as e:
        print "Unable to lower niceness(priority), RUN AS SUDO, running with normal priority"

    for i in range(port_low, port_high):
        try:
            print "Spawning "
            show_commands, prompt_change_commands, usr, passwd, cmd_delay, default_prompt = parse_commands(
                data)

            users = {usr: passwd}

            local_commands = []

            for cmd in show_commands:
                command = getShowCommand(cmd, data, show_commands[cmd],
                                         cmd_delay)
                local_commands.append(command)

            for cmd in prompt_change_commands:
                if ("password" in prompt_change_commands[cmd]):
                    command = getPasswordPromptCommand(
                        cmd, prompt_change_commands[cmd], cmd_delay)
                else:
                    command = getPromptChangingCommand(
                        cmd, prompt_change_commands[cmd], cmd_delay)
                local_commands.append(command)

            factory = None
            if (protocol_type == "ssh"):
                factory = MockSSH.getSSHFactory(local_commands, default_prompt,
                                                ".", **users)
            elif (protocol_type == "telnet"):
                factory = MockSSHExtensions.getTelnetFactory(
                    local_commands, default_prompt, **users)

            reactor.listenTCP(i, factory, interface=interface)

        except Exception as e:
            print >> sys.stderr, traceback.format_exc()
            print "Unable to open port at %s, due to: %s" % (i, e)

    reactor.run()
コード例 #2
0
ファイル: mockdevice.py プロジェクト: marosmars/cli-testtool
def getShowCommand(cmd, data, arguments, cmd_delay):
    return MockSSHExtensions.ShowCommand(cmd, data, cmd_delay, *arguments)
コード例 #3
0
ファイル: mockdevice.py プロジェクト: marosmars/cli-testtool
def getPromptChangingCommand(cmd, values, cmd_delay):
    return MockSSHExtensions.PromptChangingCommand(cmd, values["newprompt"],
                                                   cmd_delay)
コード例 #4
0
ファイル: mockdevice.py プロジェクト: marosmars/cli-testtool
def getPasswordPromptCommand(cmd, values, cmd_delay):
    return MockSSHExtensions.SimplePromptingCommand(
        values["name"], values["password"], values["prompt"],
        values["newprompt"], values["error_message"], cmd_delay)