def test_end_interactive(): """Ensure we can remove interactive sessions from teh object pool.""" runner = Bladerunner() mock_host = Mock() runner.interactive_hosts = {"fake": mock_host} runner.end_interactive("fake") mock_host.end.assert_called_once_with() assert "fake" not in runner.interactive_hosts # running this multiple times shouldn't matter/do anything runner.end_interactive("fake")
def test_end_interactive_file(): """The end_interactive method can also be passed a file of hostnames.""" runner = Bladerunner() runner.setup_interactive( ["one", "two", "three", "four", "five", "six"], connect=False, ) hostfp = tempfile.mktemp() with open(hostfp, "w") as hostsfile: hostsfile.write("one\nfour\nsix\n") runner.end_interactive(hostfp) for host in runner.interactive_hosts.keys(): assert host in ["two", "three", "five"] assert len(runner.interactive_hosts) == 3 os.remove(hostfp)