def test_guess_host(): """Assert that `guess_host()` does not recognize a random machine as a host. Note: this test may fail on a machine that, by accident, is called like a host file that we provide. """ assert utils.guess_host() is None
def validate_hosts(ctx, param, host=None): """Callback to validate the hostname received as input. If we were not given a hostname, we first try to guess it via `utils.guess_host`. If this fails, we give up and throw an error. Otherwise we compare the provided/guessed host with the list of available templates. If the hostname matches the template name, we continue by returning the hostname. """ if host is None: host = utils.guess_host() if host is None: raise click.BadParameter( "Could not guess host. Please provide a value explicitly.", param_hint='"--host"', ) known_hosts = utils.get_possible_hosts() if host not in known_hosts: console.info("Could not find template for host '{}'.", host) utils.print_possible_hosts() # TODO: Raise some appropriate error here ctx.exit() return return host
def test_monkeypatch_guess_host(monkeypatch): """Assert that `guess_host()` will correctly assign the hostname to a host file. """ host = 'HPC_cluster' monkeypatch.setattr('mdbenchmark.utils.socket.gethostname', lambda: host) monkeypatch.setattr('mdbenchmark.utils.get_possible_hosts', lambda: [host]) assert utils.guess_host() == host