def test_run_no_options(): """Uses Mock to enforce the Bladerunner.run logic with no configuration.""" runner = Bladerunner() with patch.object(runner, "_run_parallel") as patched_run: runner.run("nothing", "nowhere") patched_run.assert_called_once_with(["nowhere"])
def test_serial_execution(): """If the delay optios is set, we should call _run_serial.""" runner = Bladerunner({"delay": 10}) with patch.object(runner, "_run_serial") as patched_run: runner.run("nothing", "nowhere") patched_run.assert_called_once_with(["nowhere"])
def test_progressbar_setup(): """If the progressbar is used it should be of len servers.""" runner = Bladerunner({"progressbar": True}) with patch.object(base, "ProgressBar") as patched_pbar: with patch.object(runner, "_run_parallel") as patched_run: runner.run("nothing", "nowhere") patched_pbar.assert_called_once_with(1, runner.options) patched_run.assert_called_once_with(["nowhere"])
def test_jumpbox_errors_raise(): """Any error connecting to the jumpbox should bail the job.""" runner = Bladerunner({ "jump_host": "some_fake_host", "username": "******", "jump_pass": "******", "jump_port": 222, }) with patch.object(runner, "connect", return_value=(None, -1)) as p_connect: with pytest.raises(SystemExit) as p_sysexit: runner.run("nothing", "nowhere") err_msg = p_sysexit.exconly() p_connect.assert_called_once_with( "some_fake_host", "someguy", "hunter7", 222, ) assert runner.errors[0] in err_msg and "Jumpbox Error:" in err_msg
def test_jumpbox_user_priority(): """Ensure the jump_user is used over username for the jump host.""" runner = Bladerunner({ "username": "******", "jump_user": "******", "jump_host": "some_fake_host", "jump_pass": "******", "jump_port": 2222, }) with patch.object(runner, "connect", return_value=("ok", 0)) as p_connect: with patch.object(runner, "_run_serial") as p_run: with patch.object(runner, "close") as p_close: runner.run("nothing", "nowhere") p_connect.assert_called_once_with( "some_fake_host", "somedude", "hunter8", 2222, ) p_run.assert_called_once_with(["nowhere"]) p_close.assert_called_once_with("ok", True)