def test_entrypoint_assign_default_repo(self) -> None: """Verify entrypoint can be set if repo is default.""" docker_policy = DockerPolicy(entrypoint='foo', tag='bar') assert docker_policy.entrypoint == 'foo' assert docker_policy.repository == 'osrf/ros' assert docker_policy.tag == 'bar'
def test_repository_defaults_to_osrf_if_tag_is_defined(self) -> None: """Verify DockerPolicy repository defaults to 'osrf/ros' if tag is defined.""" docker_policy = DockerPolicy(tag='crystal-desktop') assert docker_policy.image_name == 'osrf/ros:crystal-desktop' assert docker_policy.repository == 'osrf/ros' assert docker_policy.tag == 'crystal-desktop'
def test_entrypoint_assign_default_repo_default_tag(self) -> None: """Verify entrypoint can be set if repo and tag are defaults.""" docker_policy = DockerPolicy(entrypoint='foo') assert docker_policy.entrypoint == 'foo' assert docker_policy.repository == 'osrf/ros' assert docker_policy.tag == 'dashing-desktop'
def generate_launch_description(): ld = LaunchDescription() ld.add_action( SandboxedNodeContainer( sandbox_name='my_sandbox', policy=DockerPolicy( tag='latest', repository='rosswg/turtlebot3_demo', container_name='sandboxed-cpu-hog', run_args={ # CPU quota, in microseconds per scheduler period. # The default scheduler period is 100ms == 100000us # Therefore the below value of 200000us limits this container to using, # at most, 2 cpu cores' worth of processing 'cpu_period': 100000, 'cpu_quota': 200000, }, entrypoint='/ros_entrypoint.sh', ), node_descriptions=[ SandboxedNode( package='example_nodes', node_executable='cpu_hog', ), ])) return ld
def test_tag_defaults_to_latest_if_repository_is_defined(self) -> None: """Verify DockerPolicy tag defaults to 'latest' when only repository is specified.""" docker_policy = DockerPolicy(repository='ubuntu') assert docker_policy.image_name == 'ubuntu:latest' assert docker_policy.repository == 'ubuntu' assert docker_policy.tag == 'latest'
def generate_launch_description(): """ Create launch description for starting a SandboxedNodeContainer with a local image. A SandboxedNode must be loaded into the container for any work to be done. """ ld = LaunchDescription() ld.add_action( SandboxedNodeContainer( sandbox_name='my_sandbox', policy=DockerPolicy( tag='latest', repository='ros-dashing-dummy', entrypoint='/ros_entrypoint.sh' ), node_descriptions=[ SandboxedNode( package='demo_nodes_cpp', node_executable='talker', ), SandboxedNode( package='demo_nodes_cpp', node_executable='listener' ), ] ) ) return ld
def generate_launch_description() -> LaunchDescription: """ Create launch description for starting SandboxedNodeContainer with DockerPolicy. Talker and Listener are both loaded inside the SandboxedNodeContainer. When the sandboxed node is executed, it runs the ROS 2 node within the Docker container. The container continues to run until stopped externally. The output of the talker and listener nodes should be logged to the host machine's stdout. """ ld = LaunchDescription() ld.add_action( SandboxedNodeContainer(sandbox_name='my_sandbox', policy=DockerPolicy( tag='dashing-desktop', repository='osrf/ros', container_name='sandboxed-listener-node', ), node_descriptions=[ SandboxedNode( package='demo_nodes_cpp', node_executable='talker', ), SandboxedNode(package='demo_nodes_cpp', node_executable='listener') ])) return ld
def generate_launch_description() -> LaunchDescription: """ Create a launch description for starting SandboxedNodeContainer with DockerPolicy. In this example, the C++ demo talker node is loaded inside the SandboxedNodeContainer called 'sandboxed-listener-node'. The Docker policy uses a Docker image of ROS2 Dashing (Desktop) from 'osrf/ros'. When the sandboxed node is executed, it runs the ROS 2 node within the Docker container. The container continues to run until stopped externally. The talker node can be interacted with by launching a listener node. The listener node does not need to be launched from within the Docker container. Only CPU 0 will be available to the nodes. The number of CPUs can be queried by running nproc inside the container. """ ld = LaunchDescription() ld.add_action( SandboxedNodeContainer(sandbox_name='my_sandbox', policy=DockerPolicy( tag='dashing-desktop', repository='osrf/ros', container_name='sandboxed-listener-node', run_args={'cpuset_cpus': '0'}), node_descriptions=[ SandboxedNode( package='demo_nodes_cpp', node_executable='talker', ), ])) return ld
def test_entrypoint_assign_default_tag(self) -> None: """Verify entrypoint can be set if tag is default.""" docker_policy = DockerPolicy(entrypoint='foo', repository='bar') assert docker_policy.entrypoint == 'foo' assert docker_policy.repository == 'bar' assert docker_policy.tag == 'latest'
def generate_launch_description() -> LaunchDescription: """ Create launch description for starting SandboxedNodeContainer with DockerPolicy. Talker is loaded inside the SandboxedNodeContainer. When the sandboxed node is executed, it runs the ROS 2 node within the Docker container. The container continues to run until stopped externally. The talker node can be interacted with by launching a listener node. The listener node does not need to be launched from within the Docker container. """ ld = LaunchDescription() ld.add_action( SandboxedNodeContainer(sandbox_name='my_sandbox', policy=DockerPolicy( tag='dashing-desktop', repository='osrf/ros', container_name='sandboxed-listener-node', ), node_descriptions=[ SandboxedNode( package='demo_nodes_cpp', node_executable='talker', ), ])) return ld
def test_tag_defaults_to_dashing_desktop_if_repository_is_manually_set( self) -> None: """Verify DockerPolicy tag defaults to 'dashing-desktop' if repository is 'osrf/ros'.""" docker_policy = DockerPolicy(repository='osrf/ros', ) assert docker_policy.image_name == 'osrf/ros:dashing-desktop' assert docker_policy.repository == 'osrf/ros' assert docker_policy.tag == 'dashing-desktop'
def test_entrypoint_default_not_osrf_repo(self) -> None: """Verify entrypoint is '/bin/bash -c' if repo is set to not 'osrf/ros'.""" docker_policy = DockerPolicy( repository='foo' ) assert docker_policy.repository == 'foo' assert docker_policy.entrypoint == '/bin/bash -c'
def test_image_name_properly_set_if_tag_and_repository_are_defined( self) -> None: """Verify DockerPolicy image_name is 'repository:tag' if both are defined.""" docker_policy = DockerPolicy(repository='ubuntu', tag='bionic') assert docker_policy.image_name == 'ubuntu:bionic' assert docker_policy.repository == 'ubuntu' assert docker_policy.tag == 'bionic'
def test_entrypoint_default_osrf_repo(self) -> None: """Verify entrypoint is 'ros_entrypoint' if repo is set to 'osrf/ros'.""" docker_policy = DockerPolicy( repository='osrf/ros' ) assert docker_policy.repository == 'osrf/ros' assert docker_policy.entrypoint == '/ros_entrypoint.sh'
def test_repository_and_tag_defaults_to_osrf_ros_dashing_desktop(self) -> None: """ Verify DockerPolicy 'image_name' is properly resolved with default 'tag' and 'repository'. DockerPolicy should resolve 'repository' to 'osrf/ros' and 'tag' to 'desktop-dashing' only when both are set to their default (None). """ docker_policy = DockerPolicy() assert docker_policy.image_name == 'osrf/ros:dashing-desktop' assert docker_policy.repository == 'osrf/ros' assert docker_policy.tag == 'dashing-desktop'
def test_run_args_set_correctly(self) -> None: """Verify the DockerPolicy run arguments match for the Docker Image.""" run_args = {'cpuset_cpus': 0, 'mem_limit': '128m'} docker_policy = DockerPolicy(run_args=run_args) assert docker_policy.run_args == run_args
def test_empty_run_args_set_correctly(self) -> None: """Verify the DockerPolicy has no run args if not set.""" docker_policy = DockerPolicy() assert docker_policy.run_args is None