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 @@ -94,16 +95,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:
Comment on lines +102 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 assertion that it was parsed correctly

container_id is only set when the regex matches, but it’s always referenced in the finally block. If docker run -d exits 0 but stdout is empty or doesn’t match, container_id will be undefined and cleanup will be skipped. Initialize container_id = None before the inner try, and when result.status == 0 assert that container_id is not None (e.g., assert container_id, 'Expected docker run to return a container ID') so failures are explicit and cleanup logic always has a defined value.

container_id = match.group(0)
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
Loading