Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/container.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CONTAINER:
- docker
- podman
REGISTRY_HUB: https://mirror.gcr.io
UPSTREAM_NAME: 'library/busybox'
UPSTREAM_NAME: jmalloc/echo-server
ALTERNATIVE_UPSTREAM_NAMES:
- hello-world
- alpine
Expand Down
2 changes: 1 addition & 1 deletion robottelo/config/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
'container.upstream_name',
must_exist=True,
is_type_of=str,
default='library/busybox',
default='jmalloc/echo-server',
),
Validator(
'container.alternative_upstream_names',
Expand Down
17 changes: 10 additions & 7 deletions tests/foreman/cli/test_container_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from datetime import UTC, datetime
import re

from box import Box
from fauxfactory import gen_string
Expand Down Expand Up @@ -95,16 +96,18 @@ def test_positive_pull_image(
)
assert result.status == 0
try:
result = module_container_contenthost.execute(f'docker run {repo["published-at"]}')
result = module_container_contenthost.execute(
f'docker run -d {repo["published-at"]}'
)
assert result.status == 0
match = re.match(r'^[0-9a-f]+$', result.stdout)
if match:
container_id = match.group(0)
finally:
# Stop and remove the container

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

result = module_container_contenthost.execute(
f'docker ps -a | grep {repo["published-at"]}'
)
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
module_container_contenthost.execute(f'docker rmi {repo["published-at"]}')
Expand Down
Loading