From e10480a373f688c1ca60e46b11fcb5b4d1561f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Fri, 11 Sep 2026 11:25:31 -0300 Subject: [PATCH 1/4] PULP-2219: Fix agent client generation Assisted-by: OpenAI GPT-5.6 --- base/local_scripts/generate_client.sh | 41 +++++++++++++- client/oci_env/agent.py | 82 ++++++++++++++++----------- client/oci_env/main.py | 2 + 3 files changed, 91 insertions(+), 34 deletions(-) diff --git a/base/local_scripts/generate_client.sh b/base/local_scripts/generate_client.sh index 0571a6f..9514b4b 100755 --- a/base/local_scripts/generate_client.sh +++ b/base/local_scripts/generate_client.sh @@ -24,4 +24,43 @@ export PULP_URL="${API_PROTOCOL}://${API_HOST}:${API_PORT}" CONTAINER_LABEL=$("${COMPOSE_BINARY}" container inspect "${CONTAINER_NAME}" | jq -r ".[0].ProcessLabel") export PULP_MCS_LABEL="${CONTAINER_LABEL#'system_u:system_r:container_t:'}" -./generate.sh "${PROJECT}" "${LANGUAGE}" "${API_VERSION}" +if [ -x ./gen-client.sh ] +then + if [ "${PROJECT}" = "pulpcore" ] + then + COMPONENT="core" + else + COMPONENT="${PROJECT#pulp_}" + fi + + API_SPEC="$(mktemp "${PWD}/api-spec.XXXXXX.json")" + cleanup() { + rm -f "${API_SPEC}" + } + trap cleanup EXIT + + API_ROOT="${PULP_API_ROOT:-/pulp/}" + API_ROOT="/${API_ROOT#/}" + API_ROOT="${API_ROOT%/}/" + API_URL="${API_PROTOCOL}://${API_HOST}:${API_PORT}${API_ROOT}api/${API_VERSION}/" + echo "retrieving api.json for version ${API_VERSION}" + RETRY_COUNT=0 + until curl --fail-with-body -k -o "${API_SPEC}" \ + "${API_URL}docs/api.json?bindings&component=${COMPONENT}" + do + if [ "${RETRY_COUNT}" -eq 10 ] + then + exit 1 + fi + sleep 2 + RETRY_COUNT=$((RETRY_COUNT + 1)) + done + + ./gen-client.sh "${API_SPEC}" "${COMPONENT}" "${LANGUAGE}" "${PROJECT}" +elif [ -x ./generate.sh ] +then + ./generate.sh "${PROJECT}" "${LANGUAGE}" "${API_VERSION}" +else + echo "pulp-openapi-generator must provide gen-client.sh or generate.sh" >&2 + exit 1 +fi diff --git a/client/oci_env/agent.py b/client/oci_env/agent.py index 1c0fd04..ae98b6e 100644 --- a/client/oci_env/agent.py +++ b/client/oci_env/agent.py @@ -385,41 +385,45 @@ def agent_create(args): project_name = agent_project_name(args.agent_id) compose_profile = env_overrides.get("COMPOSE_PROFILE") or "lean" - os.makedirs(compiled_dir, exist_ok=True) - overlay = write_plugin_volume_overlay( - agent_volume_overlay_path(oci_env_path, args.agent_id), - plugin_paths, - ) - generator = copy_generator_checkout(host_src_dir, compiled_dir) - if not generator: - logger.warning( - f"No {GENERATOR_REPO} checkout at " - f"{os.path.join(host_src_dir, GENERATOR_REPO)}. " - "oci-env agent generate-client will fail until you clone it and " - "destroy/recreate this agent." + compiled_root = os.path.dirname(compiled_dir) + temp_dir = tempfile.mkdtemp(prefix=f".{project_name}.", dir=compiled_root) + os.chmod(temp_dir, 0o755) + try: + overlay = write_plugin_volume_overlay( + os.path.join(temp_dir, AGENT_OVERLAY_FILENAME), plugin_paths ) + generator = copy_generator_checkout(host_src_dir, temp_dir) + if not generator: + logger.warning( + f"No {GENERATOR_REPO} checkout at " + f"{os.path.join(host_src_dir, GENERATOR_REPO)}. " + "oci-env agent generate-client will fail until you clone it and " + "destroy/recreate this agent." + ) - values = { - "OCI_AGENT_ID": args.agent_id, - "COMPOSE_PROFILE": compose_profile, - "DEV_SOURCE_PATH": ":".join(plugins), - "COMPOSE_PROJECT_NAME": project_name, - "API_PORT": str(api_port), - "SRC_DIR": compiled_dir, - "COMPOSE_BINARY": AGENT_COMPOSE_BINARY, - "API_HOST": "localhost", - "API_PROTOCOL": "http", - # Pulp refuses to start without this; --env can override. - "PULP_SECRET_KEY": "dummy", - "OCI_AGENT_HOST_SRC_DIR": host_src_dir, - "OCI_AGENT_PLUGIN_PATHS": encode_plugin_paths(plugin_paths), - "OCI_AGENT_VOLUME_OVERLAY": overlay, - } - - # Apply user --env overrides (locked keys already rejected). - values.update(env_overrides) - - write_env_file(env_path, values) + values = { + "OCI_AGENT_ID": args.agent_id, + "COMPOSE_PROFILE": compose_profile, + "DEV_SOURCE_PATH": ":".join(plugins), + "COMPOSE_PROJECT_NAME": project_name, + "API_PORT": str(api_port), + "SRC_DIR": compiled_dir, + "COMPOSE_BINARY": AGENT_COMPOSE_BINARY, + "API_HOST": "localhost", + "API_PROTOCOL": "http", + "PULP_SECRET_KEY": "dummy", + "OCI_AGENT_HOST_SRC_DIR": host_src_dir, + "OCI_AGENT_PLUGIN_PATHS": encode_plugin_paths(plugin_paths), + "OCI_AGENT_VOLUME_OVERLAY": agent_volume_overlay_path( + oci_env_path, args.agent_id + ), + } + values.update(env_overrides) + write_env_file(os.path.join(temp_dir, AGENT_ENV_FILENAME), values) + os.replace(temp_dir, compiled_dir) + except BaseException: + shutil.rmtree(temp_dir, ignore_errors=True) + raise print(f"Created agent {args.agent_id}") print(f" env: {env_path}") print(f" project: {project_name}") @@ -590,6 +594,7 @@ def agent_generate_client(args): ) client = compose_for_agent(args.is_verbose, env_path) + client.poll(args.attempts, args.wait) from oci_env.commands import generate_client @@ -602,6 +607,17 @@ class _Args: gargs.install_client = args.install_client gargs.is_verbose = args.is_verbose gargs.api_version = getattr(args, "api_version", "v3") + + requested_plugins = ( + [args.plugin] + if args.plugin + else [p for p in env_data.get("DEV_SOURCE_PATH", "").split(":") if p] + ) + if args.language == "python" and "pulpcore" not in requested_plugins: + gargs.plugin = "pulpcore" + generate_client(gargs, client) + + gargs.plugin = args.plugin generate_client(gargs, client) diff --git a/client/oci_env/main.py b/client/oci_env/main.py index 75c9a9b..8b14d61 100644 --- a/client/oci_env/main.py +++ b/client/oci_env/main.py @@ -281,6 +281,8 @@ def parse_agent_command(subparsers): dest="api_version", help="API version to generate the clients for (default: v3).", ) + gen.add_argument("--attempts", type=int, default=30, help="API readiness poll attempts.") + gen.add_argument("--wait", type=int, default=10, help="Seconds between readiness polls.") gen.set_defaults(func=agent_dispatch, agent_action="generate-client") From c9b2040a15db96a87671e45b2c9f916a6e477cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Fri, 11 Sep 2026 14:46:37 -0300 Subject: [PATCH 2/4] PULP-2219: Require gen-client.sh Assisted-by: OpenAI GPT-5.6 --- base/local_scripts/generate_client.sh | 67 +++++++++++++-------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/base/local_scripts/generate_client.sh b/base/local_scripts/generate_client.sh index 9514b4b..7aa29c8 100755 --- a/base/local_scripts/generate_client.sh +++ b/base/local_scripts/generate_client.sh @@ -24,43 +24,40 @@ export PULP_URL="${API_PROTOCOL}://${API_HOST}:${API_PORT}" CONTAINER_LABEL=$("${COMPOSE_BINARY}" container inspect "${CONTAINER_NAME}" | jq -r ".[0].ProcessLabel") export PULP_MCS_LABEL="${CONTAINER_LABEL#'system_u:system_r:container_t:'}" -if [ -x ./gen-client.sh ] +if [ ! -x ./gen-client.sh ] then - if [ "${PROJECT}" = "pulpcore" ] - then - COMPONENT="core" - else - COMPONENT="${PROJECT#pulp_}" - fi - - API_SPEC="$(mktemp "${PWD}/api-spec.XXXXXX.json")" - cleanup() { - rm -f "${API_SPEC}" - } - trap cleanup EXIT - - API_ROOT="${PULP_API_ROOT:-/pulp/}" - API_ROOT="/${API_ROOT#/}" - API_ROOT="${API_ROOT%/}/" - API_URL="${API_PROTOCOL}://${API_HOST}:${API_PORT}${API_ROOT}api/${API_VERSION}/" - echo "retrieving api.json for version ${API_VERSION}" - RETRY_COUNT=0 - until curl --fail-with-body -k -o "${API_SPEC}" \ - "${API_URL}docs/api.json?bindings&component=${COMPONENT}" - do - if [ "${RETRY_COUNT}" -eq 10 ] - then - exit 1 - fi - sleep 2 - RETRY_COUNT=$((RETRY_COUNT + 1)) - done + echo "The legacy generate.sh interface is deprecated; update pulp-openapi-generator to a checkout providing gen-client.sh." >&2 + exit 1 +fi - ./gen-client.sh "${API_SPEC}" "${COMPONENT}" "${LANGUAGE}" "${PROJECT}" -elif [ -x ./generate.sh ] +if [ "${PROJECT}" = "pulpcore" ] then - ./generate.sh "${PROJECT}" "${LANGUAGE}" "${API_VERSION}" + COMPONENT="core" else - echo "pulp-openapi-generator must provide gen-client.sh or generate.sh" >&2 - exit 1 + COMPONENT="${PROJECT#pulp_}" fi + +API_SPEC="$(mktemp "${PWD}/api-spec.XXXXXX.json")" +cleanup() { + rm -f "${API_SPEC}" +} +trap cleanup EXIT + +API_ROOT="${PULP_API_ROOT:-/pulp/}" +API_ROOT="/${API_ROOT#/}" +API_ROOT="${API_ROOT%/}/" +API_URL="${API_PROTOCOL}://${API_HOST}:${API_PORT}${API_ROOT}api/${API_VERSION}/" +echo "retrieving api.json for version ${API_VERSION}" +RETRY_COUNT=0 +until curl --fail-with-body -k -o "${API_SPEC}" \ + "${API_URL}docs/api.json?bindings&component=${COMPONENT}" +do + if [ "${RETRY_COUNT}" -eq 10 ] + then + exit 1 + fi + sleep 2 + RETRY_COUNT=$((RETRY_COUNT + 1)) +done + +./gen-client.sh "${API_SPEC}" "${COMPONENT}" "${LANGUAGE}" "${PROJECT}" From c31eaecb6a540672cc6ccd942e63e0b19cffae13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Mon, 14 Sep 2026 12:49:01 -0300 Subject: [PATCH 3/4] PULP-2219: Require current generator entrypoint Assisted-by: OpenAI GPT-5.6 --- client/oci_env/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/oci_env/agent.py b/client/oci_env/agent.py index ae98b6e..d0b6d8b 100644 --- a/client/oci_env/agent.py +++ b/client/oci_env/agent.py @@ -281,7 +281,7 @@ def agent_generator_dir(src_dir): def agent_has_generator_copy(src_dir): """True if create copied pulp-openapi-generator into the agent SRC_DIR.""" - return os.path.isfile(os.path.join(agent_generator_dir(src_dir), "generate.sh")) + return os.path.isfile(os.path.join(agent_generator_dir(src_dir), "gen-client.sh")) def copy_generator_checkout(host_src_dir, compiled_dir): From 41e242a93d7ec433921bec1b404d4f0db10856b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Mon, 14 Sep 2026 12:50:07 -0300 Subject: [PATCH 4/4] PULP-2219: Import tempfile for transactional agents Assisted-by: OpenAI GPT-5.6 --- client/oci_env/agent.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/oci_env/agent.py b/client/oci_env/agent.py index d0b6d8b..6e79a7a 100644 --- a/client/oci_env/agent.py +++ b/client/oci_env/agent.py @@ -5,6 +5,7 @@ import shutil import socket import subprocess +import tempfile from oci_env.logger import logger from oci_env.utils import (