def create_task(): server_id = pytest.faux.gen_uuid() host = pytest.faux.gen_alphanumeric() username = pytest.faux.gen_alpha() initiator_id = pytest.faux.gen_uuid() tsk = task.ServerDiscoveryTask(server_id, host, username, initiator_id) tsk = tsk.create() return tsk
def new_task(configure_model): username = pytest.faux.gen_alpha() initiator_id = pytest.faux.gen_uuid() server_id = pytest.faux.gen_uuid() tsk = task.ServerDiscoveryTask(server_id, "localhost", username, initiator_id) tsk = tsk.create() tsk = tsk.start() return tsk
def post(self): tsk = task.ServerDiscoveryTask( self.request_json["id"], self.request_json["host"], self.request_json["username"], self.request_id # execution for server discovery is request ) tsk.create() LOG.info( "Created task %s for server discovery of %s@%s (id: %s) by %s", tsk._id, self.request_json["username"], self.request_json["host"], self.request_json["id"], self.initiator_id) return {}
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
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