diff --git a/README.md b/README.md index ffc6a8d8..19418186 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/rocker/rmw_extension.py b/src/rocker/rmw_extension.py index 93d440c9..5cef594f 100644 --- a/src/rocker/rmw_extension.py +++ b/src/rocker/rmw_extension.py @@ -42,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() @@ -61,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' diff --git a/src/rocker/templates/rmw_snippet.Dockerfile.em b/src/rocker/templates/rmw_snippet.Dockerfile.em index f5bb97c0..87f50275 100644 --- a/src/rocker/templates/rmw_snippet.Dockerfile.em +++ b/src/rocker/templates/rmw_snippet.Dockerfile.em @@ -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 ]@ diff --git a/test/test_rmw_extension.py b/test/test_rmw_extension.py new file mode 100644 index 00000000..faebe6a1 --- /dev/null +++ b/test/test_rmw_extension.py @@ -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), '') + 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'))