Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shorthand option for switching to alternate rmws #268

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Then you can run pytest.
Notes:

- Make sure to use the python3 instance of pytest from inside the environment.
- The tests include an nvidia test which assumes you're using a machine with an nvidia gpu.
- The tests include an nvidia test which assumes you're using a machine with an nvidia gpu. To skip them use `-m "not nvidia"`


# Example usage
Expand Down
10 changes: 7 additions & 3 deletions src/rocker/rmw_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

class RMW(RockerExtension):
rmw_map = {
# TODO(tfoote) Remove extra ddscommon working around recent upgrade of dds-common from 2.x to 3.x which is out of date in the image
'cyclonedds': ['ros-${ROS_DISTRO}-rmw-cyclonedds-cpp', 'ros-${ROS_DISTRO}-rmw-dds-common'],
'cyclonedds': ['ros-${ROS_DISTRO}-rmw-cyclonedds-cpp'],
'fastrtps' : ['ros-${ROS_DISTRO}-rmw-fastrtps-cpp'],
# TODO(tfoote) Enable connext with license acceptance method
# 'connextdds': ['ros-${ROS_DISTRO}-rmw-connextdds'],
Expand All @@ -43,7 +42,10 @@ def __init__(self):
self.name = RMW.get_name()

def get_docker_args(self, cli_args):
implementation = cli_args.get('rmw')[0]
rmw_config = cli_args.get('rmw')
if not rmw_config:
return '' # not active
implementation = rmw_config[0]
args = f' -e RMW_IMPLEMENTATION=rmw_{implementation}_cpp'
return args #% self.get_environment_subs()

Expand All @@ -62,6 +64,8 @@ def get_snippet(self, cliargs):
rmw = cliargs.get('rmw', None)
if rmw:
rmw = rmw[0]
else:
return '' # rmw not active
data['rmw'] = rmw
data['packages'] = RMW.get_package_names(rmw)
# data['rosdistro'] = 'rolling'
Expand Down
2 changes: 1 addition & 1 deletion src/rocker/templates/rmw_snippet.Dockerfile.em
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN \
@(' '.join(packages)) \
&& apt-get clean ;\
else \
echo "Found rmw implementation no need to install" ; \
echo "Found rmw packages @(' '.join(packages)) no need to install" ; \
fi
@[ end if ]@

95 changes: 95 additions & 0 deletions test/test_rmw_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import em
import os
import unittest
import pytest


from rocker.core import DockerImageGenerator
from rocker.core import list_plugins

from test_extension import plugin_load_parser_correctly



class rmwExtensionTest(unittest.TestCase):

def setUp(self):
# Work around interference between empy Interpreter
# stdout proxy and test runner. empy installs a proxy on stdout
# to be able to capture the information.
# And the test runner creates a new stdout object for each test.
# This breaks empy as it assumes that the proxy has persistent
# between instances of the Interpreter class
# empy will error with the exception
# "em.Error: interpreter stdout proxy lost"
em.Interpreter._wasProxyInstalled = False

def test_rmw_extension(self):
plugins = list_plugins()
rmw_plugin = plugins['rmw']
self.assertEqual(rmw_plugin.get_name(), 'rmw')

p = rmw_plugin()
self.assertTrue(plugin_load_parser_correctly(rmw_plugin))


mock_cliargs = {'rmw': ['cyclonedds']}
# TODO self.assertEqual(p.get_snippet(mock_cliargs), '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this comment be removed, due to line 55 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks yes, it was implemented in L58/9. I'll remove it.

self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertIn('-e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp', args)
snippet = p.get_snippet(mock_cliargs)
self.assertIn('rmw-cyclonedds-cpp', snippet)


#without it set
mock_cliargs = {'rmw': None}
args = p.get_docker_args(mock_cliargs)
snippet = p.get_snippet(mock_cliargs)
self.assertNotIn('RMW_IMPLEMENTATION', args)
self.assertNotIn('rmw-cyclonedds-cpp', snippet)


@pytest.mark.docker
class rmwRuntimeExtensionTest(unittest.TestCase):

def setUp(self):
# Work around interference between empy Interpreter
# stdout proxy and test runner. empy installs a proxy on stdout
# to be able to capture the information.
# And the test runner creates a new stdout object for each test.
# This breaks empy as it assumes that the proxy has persistent
# between instances of the Interpreter class
# empy will error with the exception
# "em.Error: interpreter stdout proxy lost"
em.Interpreter._wasProxyInstalled = False

def test_rmw_extension(self):
plugins = list_plugins()
rmw_plugin = plugins['rmw']

p = rmw_plugin()
self.assertTrue(plugin_load_parser_correctly(rmw_plugin))

mock_cliargs = {'rmw': ['cyclonedds']}
dig = DockerImageGenerator([rmw_plugin()], mock_cliargs, 'ros:rolling')
self.assertEqual(dig.build(), 0)
self.assertEqual(dig.run(command='dpkg -l ros-rolling-rmw-cyclonedds-cpp'), 0)
self.assertIn('-e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp', dig.generate_docker_cmd('', mode='dry-run'))
Loading