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
8 changes: 4 additions & 4 deletions examples/examples/itf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ py_itf_test(
)

py_itf_test(
name = "test_ssh_bridge_network",
name = "test_qemu_ssh_bridge_network",
srcs = [
"test_ssh.py",
"test_qemu.py",
],
args = [
"--target_config=$(location @score_itf//test/resources:target_config)",
Expand All @@ -68,9 +68,9 @@ py_itf_test(
)

py_itf_test(
name = "test_ssh_port_forwarding",
name = "test_qemu_ssh_port_forwarding",
srcs = [
"test_ssh.py",
"test_qemu.py",
],
args = [
"--target_config=$(location @score_itf//test/resources:target_config)",
Expand Down
1 change: 1 addition & 0 deletions examples/examples/itf/test_qemu.py
1 change: 0 additions & 1 deletion examples/examples/itf/test_ssh.py

This file was deleted.

57 changes: 55 additions & 2 deletions score/itf/plugins/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from score.itf.plugins.core import determine_target_scope
from score.itf.plugins.core import Target

from score.itf.core.com.ssh import Ssh


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,16 +50,67 @@ def __init__(self, container, capabilities=DOCKER_CAPABILITIES):
def __getattr__(self, name):
return getattr(self.container, name)

def get_ip(self):
self.container.reload()
return self.container.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"]

def get_gateway(self):
self.container.reload()
return self.container.attrs["NetworkSettings"]["Networks"]["bridge"]["Gateway"]

def ssh(self, username="score", password="score", port=2222):
return Ssh(target_ip=self.get_ip(), port=port, username=username, password=password)


@pytest.fixture(scope=determine_target_scope)
def docker_configuration():
"""
Fixture that provides a customization point for Docker configuration in tests.

This fixture allows tests to override and customize Docker settings by providing
a dictionary of configuration parameters. Tests can use this fixture to inject
custom Docker configuration values as needed for their specific test scenarios.

Returns:
dict: An empty dictionary that can be populated with custom Docker configuration
parameters by tests or through pytest fixtures/parametrization.

Scope:
The fixture scope is determined dynamically based on the target scope.
"""
return {}


@pytest.fixture(scope=determine_target_scope)
def _docker_configuration(docker_configuration):
configuration = {
"environment": {},
"command": "sleep infinity",
"init": True,
}
merged_configuration = {**configuration, **docker_configuration}

return merged_configuration


@pytest.fixture(scope=determine_target_scope)
def target_init(request):
def target_init(request, _docker_configuration):
print(_docker_configuration)

docker_image_bootstrap = request.config.getoption("docker_image_bootstrap")
if docker_image_bootstrap:
logger.info(f"Executing custom image bootstrap command: {docker_image_bootstrap}")
subprocess.run([docker_image_bootstrap], check=True)

docker_image = request.config.getoption("docker_image")
client = pypi_docker.from_env()
container = client.containers.run(docker_image, "sleep infinity", detach=True, auto_remove=True, init=True)
container = client.containers.run(
docker_image,
_docker_configuration["command"],
detach=True,
auto_remove=True,
init=_docker_configuration["init"],
environment=_docker_configuration["environment"],
)
yield DockerTarget(container)
container.stop(timeout=1)
23 changes: 18 additions & 5 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,23 @@ py_itf_test(
)

py_itf_test(
name = "test_ssh_bridge_network",
name = "test_ssh",
srcs = [
"test_ssh.py",
],
args = [
"--docker-image=linuxserver/openssh-server:version-10.2_p1-r0",
],
plugins = [
docker,
],
)

py_itf_test(
name = "test_qemu_bridge_network",
srcs = [
"test_qemu.py",
],
args = [
"--target_config=$(location //test/resources:target_config)",
"--dlt-config=$(location //test/resources:dlt_config)",
Expand All @@ -76,9 +89,9 @@ py_itf_test(
)

py_itf_test(
name = "test_ssh_bridge_network_no_dlt",
name = "test_qemu_bridge_network_no_dlt",
srcs = [
"test_ssh.py",
"test_qemu.py",
],
args = [
"--target_config=$(location //test/resources:target_config)",
Expand All @@ -98,9 +111,9 @@ py_itf_test(
)

py_itf_test(
name = "test_ssh_port_forwarding",
name = "test_qemu_port_forwarding",
srcs = [
"test_ssh.py",
"test_qemu.py",
],
args = [
"--target_config=$(location //test/resources:target_config)",
Expand Down
23 changes: 23 additions & 0 deletions test/test_qemu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
from score.itf.core.com.ssh import execute_command


def test_ssh_with_default_user(target_fixture):
with target_fixture.sut.ssh() as ssh:
execute_command(ssh, "echo 'Username:' $USER && uname -a")


def test_ssh_with_qnx_user(target_fixture):
with target_fixture.sut.ssh(username="qnxuser") as ssh:
execute_command(ssh, "echo 'Username:' $USER && uname -a")
29 changes: 24 additions & 5 deletions test/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
import pytest

from score.itf.core.com.ssh import execute_command


def test_ssh_with_default_user(target_fixture):
with target_fixture.sut.ssh() as ssh:
execute_command(ssh, "echo 'Username:' $USER && uname -a")
@pytest.fixture(scope="session")
def docker_configuration():
return {
"environment": {
"PASSWORD_ACCESS": "true",
"USER_NAME": "score",
"USER_PASSWORD": "score",
},
"command": None,
"init": False,
}


def check_command_exec(target, message):
exit_code, output = target.exec_run(f"echo -n {message}")
return f"{message}" == output.decode()


def test_docker_runs_1(target):
assert check_command_exec(target, "hello, world 1")


def test_ssh_with_qnx_user(target_fixture):
with target_fixture.sut.ssh(username="qnxuser") as ssh:
def test_ssh_with_default_user(target):
with target.ssh() as ssh:
execute_command(ssh, "echo 'Username:' $USER && uname -a")