Skip to content

fix: replace broken S3 cleanup with LlamaStack files API#1210

Merged
jgarciao merged 2 commits intoopendatahub-io:mainfrom
Ygnas:s3-file-cleanup
Mar 16, 2026
Merged

fix: replace broken S3 cleanup with LlamaStack files API#1210
jgarciao merged 2 commits intoopendatahub-io:mainfrom
Ygnas:s3-file-cleanup

Conversation

@Ygnas
Copy link
Copy Markdown
Contributor

@Ygnas Ygnas commented Mar 12, 2026

The S3 file cleanup was failing because boto3 is not a project dependency. Replace the direct S3 access with the LlamaStack client's files API (client.files.list/delete), which requires no additional dependencies.

  • Remove _cleanup_s3_files helper and its boto3 dependency
  • Remove S3 credential parameters from distribution fixtures
  • Add _cleanup_files using the LlamaStack files API
  • Snapshot existing file IDs before tests to only delete files created during the current test execution

Pull Request

Summary

Related Issues

  • Fixes:
  • JIRA:

How it has been tested

  • Locally
  • Jenkins

Additional Requirements

  • If this PR introduces a new test image, did you create a PR to mirror it in disconnected environment?
  • If this PR introduces new marker(s)/adds a new component, was relevant ticket created to update relevant Jenkins job?

Summary by CodeRabbit

  • Tests
    • Test cleanup now uses the service API to delete only files created during a test run, reducing collateral deletions.
    • Removed S3-based cleanup and simplified fixtures so S3 bucket parameters and AWS credentials are no longer required.
    • Client lifecycle and teardown have been simplified to centralize cleanup after test execution.

@Ygnas Ygnas requested a review from a team as a code owner March 12, 2026 10:14
@github-actions
Copy link
Copy Markdown

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/wip', '/build-push-pr-image', '/lgtm', '/cherry-pick', '/verified', '/hold'}

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 708e8a85-8387-4888-9b25-cf1549c3136a

📥 Commits

Reviewing files that changed from the base of the PR and between 2b24ed0 and 8a71fa5.

📒 Files selected for processing (1)
  • tests/llama_stack/conftest.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/llama_stack/conftest.py

📝 Walkthrough

Walkthrough

Replaced S3-based test cleanup with client-driven cleanup: snapshot existing file IDs via LlamaStackClient before tests and delete only newly created files afterward. Removed S3-related fixture parameters and updated imports to include APIError and LlamaStackClient.

Changes

Cohort / File(s) Summary
Test Fixture Cleanup Refactor
tests/llama_stack/conftest.py
Removed _cleanup_s3_files and all S3 usage. Added APIError and LlamaStackClient imports. Added _cleanup_files(client: LlamaStackClient, existing_file_ids: set[str]) -> None. _create_llama_stack_client now snapshots existing_file_ids before yielding and invokes _cleanup_files after. Removed S3-related fixture parameters (ci_s3_bucket_name, ci_s3_bucket_endpoint, ci_s3_bucket_region, aws_access_key_id, aws_secret_access_key) from distribution fixtures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Actionable Issues

  1. Ensure _cleanup_files distinguishes transient API failures vs permanent errors and retries idempotently where appropriate; surface persistent failures for test diagnostics (CWE-755: Improper Handling of Exceptional Conditions).
  2. Verify the snapshot of existing_file_ids occurs at a time that cannot be raced by concurrent test setup actions; consider moving snapshot to immediately before test operations or using a transactional marker to avoid misclassifying files (CWE-362: Concurrent Execution Using Shared Resource with Improper Synchronization).
  3. Handle APIError explicitly: avoid logging sensitive file identifiers or auth tokens, and ensure logs redact sensitive details; treat authorization failures separately and fail fast where required (CWE-200: Exposure of Sensitive Information to an Unauthorized Actor).
🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description begins with a clear technical rationale and lists specific changes, but the PR template sections (Related Issues, How it has been tested, Additional Requirements) remain entirely incomplete with placeholder text. Complete the template by filling in Related Issues (github issue/JIRA links if applicable) and mark testing checkboxes; clarify whether local/Jenkins validation was performed.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective: replacing S3 cleanup logic with the LlamaStack files API.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/llama_stack/conftest.py`:
- Around line 569-572: Narrow the broad except handlers in the cleanup function
to catch only llama_stack_client.APIError (or import APIError with from
llama_stack_client import APIError) instead of Exception; replace both "except
Exception as e" blocks that log via LOGGER.warning(f"Failed to delete file
{file.id}: {e}") and LOGGER.warning(f"Failed to clean up files: {e}") so they
only swallow SDK/API errors while letting other exceptions surface.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: f3812329-a938-44f6-8c20-37042d49e047

📥 Commits

Reviewing files that changed from the base of the PR and between 8a8185f and ac96746.

📒 Files selected for processing (1)
  • tests/llama_stack/conftest.py

Comment thread tests/llama_stack/conftest.py Outdated
@Ygnas Ygnas force-pushed the s3-file-cleanup branch from ac96746 to 2b24ed0 Compare March 12, 2026 10:27
Copy link
Copy Markdown
Contributor

@Bobbins228 Bobbins228 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm bar code rabbit nit
were you able to verify the bucket had been cleaned?

Comment thread tests/llama_stack/conftest.py Outdated
@Ygnas
Copy link
Copy Markdown
Contributor Author

Ygnas commented Mar 12, 2026

/lgtm bar code rabbit nit were you able to verify the bucket had been cleaned?

Yes but as per description only cleans itself, so there is still files from the previous runs that is not touched.

Copy link
Copy Markdown
Contributor

@jiripetrlik jiripetrlik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ygnas
It often happens that Llama stack distribution does not start/work properly when we are testing it. If I understand correctly this clean up will not work when Llama stack does not work. Please correct me if I'm wrong. Maybe it would be good to keep clean up logic independent of Llama stack which we are testing.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/llama_stack/conftest.py`:
- Around line 544-548: The current snapshot-and-cleanup in the conftest fixture
(existing_file_ids = {f.id for f in client.files.list().data}; yield client;
_cleanup_files(client=client, existing_file_ids=existing_file_ids)) has a TOCTOU
race that can delete other sessions' files when tests run in parallel; fix it by
scoping cleanup to this test session: modify the fixture and _cleanup_files to
use a unique session/run identifier (e.g., generate a run_id at fixture setup
and require that created files include this run_id in their metadata or
filename), filter client.files.list() by that run_id when building
existing_file_ids and when deleting files so only files created by this session
are removed, and ensure the client/file-creation helpers in tests add the
run_id; alternatively, if preferring documentation, update the conftest fixture
docstring to explicitly state that tests must use isolated LlamaStack instances
when running with pytest-xdist instead of relying on snapshot cleanup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 0ed30bc4-5bf0-4674-9c41-92eb0d359e52

📥 Commits

Reviewing files that changed from the base of the PR and between ac96746 and 2b24ed0.

📒 Files selected for processing (1)
  • tests/llama_stack/conftest.py

Comment thread tests/llama_stack/conftest.py
@Ygnas
Copy link
Copy Markdown
Contributor Author

Ygnas commented Mar 12, 2026

@Ygnas It often happens that Llama stack distribution does not start/work properly when we are testing it. If I understand correctly this clean up will not work when Llama stack does not work. Please correct me if I'm wrong. Maybe it would be good to keep clean up logic independent of Llama stack which we are testing.

If LlamaStack never starts, it blocks the fixture from yielding, so no tests run and no files are created - nothing to clean up? If I understand correctly.
On the other hand if Llama stack distribution crashed before teardown that would leave the files, not sure if Llama stack distribution ever crash? And for that we would need to add boto3 as dependency and that is what Jira want's to skip. Correct me if I'm wrong

@jiripetrlik
Copy link
Copy Markdown
Contributor

@jgarciao
Is there any reason to not to have boto3 dependency in our project? It will help us to keep test and clean up logic separated. But I have no strong opinion on this. As @Ygnas correctly mentioned if LlamaStack never starts no files are created.

@jgarciao
Copy link
Copy Markdown
Contributor

@jgarciao Is there any reason to not to have boto3 dependency in our project? It will help us to keep test and clean up logic separated. But I have no strong opinion on this. As @Ygnas correctly mentioned if LlamaStack never starts no files are created.

Not having the boto3 dependency was a bug in the automation. The files weren't being deleted because of that. I think this PR is correct. The only doubt I have is if the files should be cleared during the llama-stack-distribution or the client yield block. Let's discuss that in our meeting

Ygnas and others added 2 commits March 16, 2026 11:50
The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
@Ygnas Ygnas force-pushed the s3-file-cleanup branch from 1381698 to 8a71fa5 Compare March 16, 2026 11:50
@jgarciao jgarciao merged commit 2ac4148 into opendatahub-io:main Mar 16, 2026
9 checks passed
@jgarciao
Copy link
Copy Markdown
Contributor

/cherry-pick 3.4ea1

rhods-ci-bot pushed a commit that referenced this pull request Mar 16, 2026
The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

@rhods-ci-bot
Copy link
Copy Markdown
Contributor

Cherry pick action created PR #1223 successfully 🎉!
See: https://github.com/opendatahub-io/opendatahub-tests/actions/runs/23143345856

@jgarciao
Copy link
Copy Markdown
Contributor

/cherry-pick 3.3

@rhods-ci-bot
Copy link
Copy Markdown
Contributor

Error cherry-picking.

Auto-merging tests/llama_stack/conftest.py
CONFLICT (content): Merge conflict in tests/llama_stack/conftest.py
error: could not apply 2ac4148... fix: replace broken S3 cleanup with LlamaStack files API (#1210)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

@rhods-ci-bot
Copy link
Copy Markdown
Contributor

‼️ cherry pick action failed.
See: https://github.com/opendatahub-io/opendatahub-tests/actions/runs/23143370131

jgarciao added a commit that referenced this pull request Mar 16, 2026
The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
Ygnas added a commit to Ygnas/opendatahub-tests that referenced this pull request Mar 16, 2026
…-io#1210)

The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
jgarciao added a commit that referenced this pull request Mar 16, 2026
The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
ssaleem-rh pushed a commit to ssaleem-rh/opendatahub-tests that referenced this pull request Mar 23, 2026
…-io#1210)

The S3 file cleanup was failing because boto3 is not a project
dependency. Replace the direct S3 access with the LlamaStack
client's files API (client.files.list/delete), which requires
no additional dependencies.

- Remove _cleanup_s3_files helper and its boto3 dependency
- Remove S3 credential parameters from distribution fixtures
- Add _cleanup_files using the LlamaStack files API
- Snapshot existing file IDs before tests to only delete files
  created during the current test execution

Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
Signed-off-by: Shehan Saleem <ssaleem@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants