[6.18.z] Replace library/busybox with lighter container repo - #20856
Conversation
(cherry picked from commit 8ac73bc)
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplace the default test container image from library/busybox to jmalloc/echo-server and adapt the CLI container management test logic to work with the new image and output format while ensuring containers and images are still cleaned up properly. Sequence diagram for updated container pull and run CLI testsequenceDiagram
title Container_pull_and_run_test_with_jmalloc_echo_server
actor Tester
participant TestRunner
participant ContainerCLI
participant ContainerEngine
participant Registry
Tester ->> TestRunner: start_container_pull_and_run_test
TestRunner ->> ContainerCLI: pull_image(container.upstream_name = jmalloc/echo-server)
ContainerCLI ->> ContainerEngine: pull_image(jmalloc/echo-server)
ContainerEngine ->> Registry: fetch_image_layers(jmalloc/echo-server)
Registry -->> ContainerEngine: image_layers
ContainerEngine -->> ContainerCLI: pull_result
ContainerCLI -->> TestRunner: pull_output
TestRunner ->> ContainerCLI: run_container_detached(jmalloc/echo-server)
ContainerCLI ->> ContainerEngine: run_detached(jmalloc/echo-server)
ContainerEngine -->> ContainerCLI: container_id_in_output
ContainerCLI -->> TestRunner: run_output_with_container_id
TestRunner ->> TestRunner: extract_container_id_from_output
TestRunner ->> ContainerCLI: stop_container(container_id)
ContainerCLI ->> ContainerEngine: stop(container_id)
ContainerEngine -->> ContainerCLI: stop_result
ContainerCLI -->> TestRunner: stop_output
TestRunner ->> ContainerCLI: remove_container(container_id)
ContainerCLI ->> ContainerEngine: rm(container_id)
ContainerEngine -->> ContainerCLI: rm_result
ContainerCLI -->> TestRunner: rm_output
TestRunner ->> ContainerCLI: remove_image(jmalloc/echo-server)
ContainerCLI ->> ContainerEngine: rmi(jmalloc/echo-server)
ContainerEngine -->> ContainerCLI: rmi_result
ContainerCLI -->> TestRunner: rmi_output
TestRunner -->> Tester: test_result_success
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
test_positive_pull_image,container_idis only defined inside theif matchblock but referenced in thefinallyclause; initializecontainer_id = Nonebefore thetryso thefinallyblock cannot raise anUnboundLocalError. - When parsing the container ID from
result.stdout, consider stripping whitespace or using the first line (e.g.,result.stdout.strip().splitlines()[0]) before applying the regex to avoid failures due to trailing newlines or additional output.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `test_positive_pull_image`, `container_id` is only defined inside the `if match` block but referenced in the `finally` clause; initialize `container_id = None` before the `try` so the `finally` block cannot raise an `UnboundLocalError`.
- When parsing the container ID from `result.stdout`, consider stripping whitespace or using the first line (e.g., `result.stdout.strip().splitlines()[0]`) before applying the regex to avoid failures due to trailing newlines or additional output.
## Individual Comments
### Comment 1
<location path="tests/foreman/cli/test_container_management.py" line_range="108-107" />
<code_context>
- container_id = result.stdout[0].split()[0]
- module_container_contenthost.execute(f'docker stop {container_id}')
- module_container_contenthost.execute(f'docker rm {container_id}')
+ if container_id:
+ module_container_contenthost.execute(f'docker stop {container_id}')
+ module_container_contenthost.execute(f'docker rm {container_id}')
finally:
# Remove docker image
</code_context>
<issue_to_address>
**issue (bug_risk):** Possible `UnboundLocalError` for `container_id` in `finally` block and potential container leak
Because `container_id` is only assigned inside the `try` when the regex matches, any failure before that (or a non‑match) means the `finally` block will reference an undefined variable and hide the real error. It also means a container that was started but not matched will never be cleaned up. Initialize `container_id = None` before the `try`, and consider a fallback cleanup strategy (e.g., `docker ps -a | grep ...`) when the regex doesn’t match to avoid leaking containers and to keep the test robust.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if match: | ||
| container_id = match.group(0) | ||
| finally: | ||
| # Stop and remove the container |
There was a problem hiding this comment.
issue (bug_risk): Possible UnboundLocalError for container_id in finally block and potential container leak
Because container_id is only assigned inside the try when the regex matches, any failure before that (or a non‑match) means the finally block will reference an undefined variable and hide the real error. It also means a container that was started but not matched will never be cleaned up. Initialize container_id = None before the try, and consider a fallback cleanup strategy (e.g., docker ps -a | grep ...) when the regex doesn’t match to avoid leaking containers and to keep the test robust.
|
|
PRT Result |
|
trigger: test-robottelo |
|
PRT Result |
Cherrypick of PR: #20671
Problem Statement
Gradually over time the
library/busyboxrepo is becoming more and more huge.The problem with repo sync arises especially in IPv6 environment where the traffic goes over IPv6-to-4 proxy.
Testing revealed that syncing over IPv4 takes approx. 10 min while syncing over IPv6 takes 25 min and tends to time out quite often.
Solution
Find more suitable replacement for testing container repo target
Related Issues
SAT-41831
Summary by Sourcery
Update container image defaults to use a lighter test repository and adjust container management tests accordingly.
Bug Fixes:
docker run.Enhancements:
library/busyboxtojmalloc/echo-serverto reduce sync size and improve reliability of container-related tests.Tests:
docker runinstead of parsingdocker psoutput.