CLI: Add container prune command#40547
Draft
ptrivedi wants to merge 1 commit into
Draft
Conversation
Implement the 'wslc container prune' command to remove all stopped containers. The backend IWSLCSession::PruneContainers API already exists; this adds the CLI frontend. Changes: - ContainerPruneCommand: new command class with --session arg - ContainerService::Prune(): service layer using RAII PruneResult - PruneContainers task: prints pruned container IDs and reclaimed space - PruneContainersResult model struct - 3 localization strings (desc, long desc, space reclaimed) - CLI parsing unit tests in CommandLineTestCases.h - E2E tests: help, no-stopped, stopped, running-preserved, multi-stopped - Updated container help output test to include prune subcommand Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+47
to
+51
| // Prune when no stopped containers exist should succeed with zero reclaimed space | ||
| const auto result = RunWslc(L"container prune"); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| VerifyStdoutContains(result, L"Total reclaimed space:"); |
Contributor
There was a problem hiding this comment.
Since it's zero reclaimed, can we use the .Verify({.Stdout = "...: 0", ...}); instead?
| const auto result = RunWslc(L"container prune"); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| VerifyStdoutContains(result, L"Total reclaimed space:"); |
Contributor
There was a problem hiding this comment.
Is there a chance we can hardcode the values here based on manual test, or they are unpredictable?
Comment on lines
+70
to
+77
| auto listResult = RunWslc(L"container list --all"); | ||
| listResult.Verify({.Stderr = L"", .ExitCode = 0}); | ||
| for (const auto& line : listResult.GetStdoutLines()) | ||
| { | ||
| VERIFY_IS_FALSE( | ||
| line.find(L"prune-test-container") != std::wstring::npos, | ||
| L"Container 'prune-test-container' should have been pruned"); | ||
| } |
Contributor
There was a problem hiding this comment.
We have a method for this VerifyContainerIsNotListed 😊
Contributor
There was a problem hiding this comment.
Same for the other methods
| private: | ||
| const TestImage& DebianImage = DebianTestImage(); | ||
|
|
||
| static void VerifyStdoutContains(const WSLCExecutionResult& result, const std::wstring& substring) |
Contributor
There was a problem hiding this comment.
Unless my comment suggestion above does not help eliminate the need for this method, I would suggest moving this method to the WSLCExecutor where another method called StdoutContainsLine method exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement the
wslc container prunecommand to remove all stopped containers. The backendIWSLCSession::PruneContainersAPI already exists; this adds the CLI frontend.Changes
--sessionargPruneResultfor exception-safe CoTaskMem cleanupprunesubcommand