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
18 changes: 11 additions & 7 deletions tests/foreman/cli/test_container_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

"""

import re

from fauxfactory import gen_string
import pytest
from wait_for import wait_for
Expand Down Expand Up @@ -92,16 +94,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)
Comment on lines +101 to +103

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): Potential use of container_id before assignment and missing negative-path handling when the regex does not match

container_id is only set inside the if match: block but is always referenced in finally. If re.match returns None (e.g., due to trailing whitespace or extra output), this will raise UnboundLocalError, and even if pre-initialized, cleanup would be skipped when there’s no match.

Consider initializing container_id = None before the try, and then either normalizing the output (e.g., strip / split to get the ID) or failing the test explicitly when match is None instead of silently skipping cleanup.

finally:
# Stop and remove the container
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