Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to remove OCI Image if removing as Ollama or Huggingface fails #432

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 8, 2024

Summary by Sourcery

Implement a fallback mechanism to remove a model as an OCI Image if removal as Ollama or Huggingface fails, and update the system test accordingly.

Bug Fixes:

  • Fix the issue where removing a model as Ollama or Huggingface fails by attempting to remove it as an OCI Image instead.

Tests:

  • Update system test to correctly remove a model from the registry without the 'oci://' prefix.

Copy link
Contributor

sourcery-ai bot commented Nov 8, 2024

Reviewer's Guide by Sourcery

This PR enhances the model removal functionality by adding a fallback mechanism. If removing a model as an Ollama or Huggingface model fails, the system will attempt to remove it as an OCI container image before raising the original error.

Sequence diagram for model removal process

sequenceDiagram
    participant User
    participant CLI as Ramalama CLI
    participant Model as Model
    participant OCI as OCI Image

    User->>CLI: Request to remove model
    CLI->>Model: Attempt to remove as Ollama/Huggingface
    alt Removal successful
        Model-->>CLI: Model removed
    else Removal fails
        CLI->>OCI: Attempt to remove as OCI Image
        alt OCI removal successful
            OCI-->>CLI: OCI Image removed
        else OCI removal fails
            CLI-->>User: Raise original error
        end
    end
Loading

File-Level Changes

Change Details Files
Added fallback logic for model removal
  • Wrapped model removal in try-except block
  • Added fallback attempt to remove as OCI container image
  • Original error is re-raised if both attempts fail
ramalama/cli.py
Updated system test for model removal
  • Modified model removal test to use simplified registry path format
test/system/050-pull.bats

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @rhatdan - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider improving error handling to preserve the OCI removal error instead of re-raising the original KeyError. This would make debugging easier when the fallback fails.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# attempt to remove as a container image
m=OCI(model, config.get('engine', container_manager()))
m.remove(args)
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider preserving the OCI exception instead of re-raising the KeyError

When the OCI operation fails, re-raising the original KeyError could mask important error information. Consider either letting the OCI exception propagate or wrapping it with additional context.

            except Exception as oci_error:
                raise oci_error from e

@@ -89,7 +89,7 @@ load setup_suite

run_ramalama rm oci://$registry/tiny
run_ramalama rm oci://$registry/tiny-car
run_ramalama rm oci://$registry/mymodel
run_ramalama rm $registry/mymodel
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Test coverage for new error handling path is missing

The PR adds new error handling logic to attempt OCI image removal as a fallback, but there are no tests verifying this behavior. Consider adding test cases that verify: 1) successful fallback to OCI removal, 2) proper error propagation when both attempts fail, and 3) verification that the original error is raised when OCI removal also fails.

@ericcurtin ericcurtin merged commit 0cd1a93 into containers:main Nov 8, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants