Exemplo n.º 1
0
def test_main_host_failed(monkeypatch, capsys, mocked_sysexit,
                          mocked_configure):
    server_id = pytest.faux.gen_uuid()
    host = pytest.faux.gen_alphanumeric()
    unknown_host = pytest.faux.gen_alphanumeric()
    username = pytest.faux.gen_alphanumeric()
    initiator_id = pytest.faux.gen_uuid()

    tsk = task.ServerDiscoveryTask(server_id, host, username, initiator_id)
    tsk = tsk.create()

    monkeypatch.setenv(playbook_plugin.ENV_ENTRY_POINT, "server_discovery")
    monkeypatch.setenv(playbook_plugin.ENV_TASK_ID, str(tsk._id))
    monkeypatch.setattr("sys.argv", ["progname", "--host", unknown_host])

    inventory.main()

    mocked_sysexit.assert_called_once_with(
        "Cannot find required host {0}".format(unknown_host))
    out, _ = capsys.readouterr()
    assert not out
Exemplo n.º 2
0
def test_main_host_ok(monkeypatch, capsys, mocked_sysexit, mocked_configure):
    server_id = pytest.faux.gen_uuid()
    host = pytest.faux.gen_alphanumeric()
    username = pytest.faux.gen_alphanumeric()
    initiator_id = pytest.faux.gen_uuid()

    tsk = task.ServerDiscoveryTask(server_id, host, username, initiator_id)
    tsk = tsk.create()

    monkeypatch.setenv(playbook_plugin.ENV_ENTRY_POINT, "server_discovery")
    monkeypatch.setenv(playbook_plugin.ENV_TASK_ID, str(tsk._id))
    monkeypatch.setattr("sys.argv", ["progname", "--host", host])

    assert inventory.main() == os.EX_OK

    mocked_sysexit.assert_not_called()

    out, _ = capsys.readouterr()
    arg = json.loads(out)
    assert arg["ansible_user"] == username