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:
Comment on lines +97 to +102

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: Potential use of uninitialized container_id and missing assertion on container ID format in the test

container_id is only set inside the if match: block but used in finally, so if re.match returns None you’ll hit an UnboundLocalError there. Initialize container_id = None before the try: and have the cleanup check it safely. Also, instead of silently skipping cleanup when match is falsy, assert that the output is a valid container ID, e.g.:

container_id = None
...
container_id = result.stdout.strip()
assert re.match(r"^[0-9a-f]+$", container_id), f"Unexpected container id: {container_id!r}"

so the test explicitly verifies the expected format and fails if Docker returns something unexpected.

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