Example #1
0
def test_run_single_success():
    """Ensure the calls to send commands on a single host."""

    runner = Bladerunner({
        "username": "******",
        "password": "******",
        "progressbar": True,
        "port": 2012,
    })

    runner.progress = ProgressBar(1, runner.options)

    with patch.object(runner, "connect", return_value=("ok", 0)) as p_connect:
        with patch.object(runner, "send_commands", return_value=[]) as p_send:
            with patch.object(runner, "close") as p_close:
                with patch.object(runner.progress, "update") as p_update:
                    runner._run_single("nowhere")

    p_connect.assert_called_once_with(
        "nowhere",
        "dudeguybro",
        "hunter40",
        2012,
    )
    p_send.assert_called_once_with("ok", "nowhere")
    p_close.assert_called_once_with("ok", True)
    # if the progressbar is used we should tick it once for the check run
    assert p_update.called
Example #2
0
def test_run_single_error():
    """Ensure an error is passed back during run_single on connect errors."""

    runner = Bladerunner({
        "username": "******",
        "password": "******",
        "progressbar": True,
        "port": 2212,
    })

    runner.progress = ProgressBar(1, runner.options)

    with patch.object(runner, "connect", return_value=(None, -3)) as p_connect:
        with patch.object(runner.progress, "update") as p_update:
            ret = runner._run_single("nowhere")

    p_connect.assert_called_once_with(
        "nowhere",
        "dudeguy",
        "hunter111",
        2212,
    )

    # if the progressbar should tick regardless of success
    assert p_update.called
    assert ret == {"name": "nowhere", "results": [("login", runner.errors[2])]}
Example #3
0
def test_run_safely_to_parralel():
    """Ensure after the first success the rest are run in parallel."""

    runner = Bladerunner({
        "username": "******",
        "password": "******",
        "progressbar": True,
        "port": 2244,
    })

    # we have to set up the progressbar ourselves here, normally it'd happen in
    # run once we know the len of servers to run on.
    runner.progress = ProgressBar(3, runner.options)

    with patch.object(runner, "connect", return_value=("ok", 0)) as p_connect:
        with patch.object(runner, "send_commands", return_value=[]) as p_send:
            with patch.object(runner, "close") as p_close:
                with patch.object(runner, "_run_parallel_no_check") as p_run:
                    with patch.object(runner.progress, "update") as p_update:
                        runner._run_parallel_safely(["1st", "2nd", "3rd"])

    p_connect.assert_called_once_with(
        "1st",
        "broguy",
        "hunter14",
        2244,
    )
    p_send.assert_called_once_with("ok", "1st")
    p_close.assert_called_once_with("ok", True)
    # if the progressbar is used we should update it once for the check run
    assert p_update.called
    p_run.assert_called_once_with(["2nd", "3rd"])
Example #4
0
def test_run_single_success():
    """Ensure the calls to send commands on a single host."""

    runner = Bladerunner({
        "username": "******",
        "password": "******",
        "progressbar": True,
        "port": 2012,
    })

    runner.progress = ProgressBar(1, runner.options)

    with patch.object(runner, "connect", return_value=("ok", 0)) as p_connect:
        with patch.object(runner, "send_commands", return_value=[]) as p_send:
            with patch.object(runner, "close") as p_close:
                with patch.object(runner.progress, "update") as p_update:
                    runner._run_single("nowhere")

    p_connect.assert_called_once_with(
        "nowhere",
        "dudeguybro",
        "hunter40",
        2012,
    )
    p_send.assert_called_once_with("ok", "nowhere")
    p_close.assert_called_once_with("ok", True)
    # if the progressbar is used we should tick it once for the check run
    assert p_update.called
Example #5
0
def test_run_single_error():
    """Ensure an error is passed back during run_single on connect errors."""

    runner = Bladerunner(
        username="******",
        password="******",
        progressbar=True,
        port=2212,
    )

    runner.progress = ProgressBar(1, runner.options)

    with patch.object(runner, "connect", return_value=(None, -3)) as p_connect:
        with patch.object(runner.progress, "update") as p_update:
            ret = runner._run_single("nowhere")

    p_connect.assert_called_once_with(
        "nowhere",
        "dudeguy",
        "hunter111",
        2212,
    )

    # if the progressbar should tick regardless of success
    assert p_update.called
    assert ret == {"name": "nowhere", "results": [("login", runner.errors[2])]}
Example #6
0
def test_run_safely_to_parralel():
    """Ensure after the first success the rest are run in parallel."""

    runner = Bladerunner({
        "username": "******",
        "password": "******",
        "progressbar": True,
        "port": 2244,
    })

    # we have to set up the progressbar ourselves here, normally it'd happen in
    # run once we know the len of servers to run on.
    runner.progress = ProgressBar(3, runner.options)

    with patch.object(runner, "connect", return_value=("ok", 0)) as p_connect:
        with patch.object(runner, "send_commands", return_value=[]) as p_send:
            with patch.object(runner, "close") as p_close:
                with patch.object(runner, "_run_parallel_no_check") as p_run:
                    with patch.object(runner.progress, "update") as p_update:
                        runner._run_parallel_safely(["1st", "2nd", "3rd"])

    p_connect.assert_called_once_with(
        "1st",
        "broguy",
        "hunter14",
        2244,
    )
    p_send.assert_called_once_with("ok", "1st")
    p_close.assert_called_once_with("ok", True)
    # if the progressbar is used we should update it once for the check run
    assert p_update.called
    p_run.assert_called_once_with(["2nd", "3rd"])