def test_git_extension(self): plugins = list_plugins() git_plugin = plugins['git'] self.assertEqual(git_plugin.get_name(), 'git') p = git_plugin() self.assertTrue(plugin_load_parser_correctly(git_plugin)) mock_cliargs = {} self.assertEqual(p.get_snippet(mock_cliargs), '') self.assertEqual(p.get_preamble(mock_cliargs), '') args = p.get_docker_args(mock_cliargs) # self.assertFalse(args) system_gitconfig = '/etc/gitconfig' user_gitconfig = os.path.expanduser('~/.gitconfig') user_gitconfig_target = '/root/.gitconfig' if os.path.exists(system_gitconfig): # TODO(tfoote) This isn't exercised on most systems, it would need to be mocked self.assertIn('-v %s:%s' % (system_gitconfig, system_gitconfig), args) if os.path.exists(user_gitconfig): self.assertIn('-v %s:%s' % (user_gitconfig, user_gitconfig_target), args) # Test with user "enabled" mock_cliargs = {'user': True} user_args = p.get_docker_args(mock_cliargs) if os.path.exists(user_gitconfig): self.assertIn('-v %s:%s' % (user_gitconfig, user_gitconfig), user_args)
def test_nvidia_extension_basic(self): plugins = list_plugins() nvidia_plugin = plugins['nvidia'] self.assertEqual(nvidia_plugin.get_name(), 'nvidia') self.assertTrue(plugin_load_parser_correctly(nvidia_plugin)) p = nvidia_plugin() mock_cliargs = {'base_image': 'ubuntu:xenial'} snippet = p.get_snippet(mock_cliargs) self.assertIn( 'COPY --from=glvnd /usr/local/lib/x86_64-linux-gnu /usr/local/lib/x86_64-linux-gnu', snippet) self.assertIn( 'COPY --from=glvnd /usr/local/lib/i386-linux-gnu /usr/local/lib/i386-linux-gnu', snippet) self.assertIn( 'ENV LD_LIBRARY_PATH /usr/local/lib/x86_64-linux-gnu:/usr/local/lib/i386-linux-gnu', snippet) self.assertIn('NVIDIA_VISIBLE_DEVICES', snippet) self.assertIn('NVIDIA_DRIVER_CAPABILITIES', snippet) mock_cliargs = {'base_image': 'ubuntu:bionic'} snippet = p.get_snippet(mock_cliargs) self.assertIn( 'RUN apt-get update && apt-get install -y --no-install-recommends', snippet) self.assertIn(' libglvnd0 ', snippet) self.assertIn(' libgles2 ', snippet) self.assertIn( 'COPY --from=glvnd /usr/share/glvnd/egl_vendor.d/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json', snippet) self.assertIn('NVIDIA_VISIBLE_DEVICES', snippet) self.assertIn('NVIDIA_DRIVER_CAPABILITIES', snippet) preamble = p.get_preamble(mock_cliargs) self.assertIn('FROM nvidia/opengl:1.0-glvnd-devel-', preamble) docker_args = p.get_docker_args(mock_cliargs) #TODO(tfoote) restore with #37 self.assertIn(' -e DISPLAY -e TERM', docker_args) #TODO(tfoote) restore with #37 self.assertIn(' -e QT_X11_NO_MITSHM=1', docker_args) #TODO(tfoote) restore with #37 self.assertIn(' -e XAUTHORITY=', docker_args) #TODO(tfoote) restore with #37 self.assertIn(' -v /tmp/.X11-unix:/tmp/.X11-unix ', docker_args) #TODO(tfoote) restore with #37 self.assertIn(' -v /etc/localtime:/etc/localtime:ro ', docker_args) if get_docker_version() >= Version("19.03"): self.assertIn(' --gpus all', docker_args) else: self.assertIn(' --runtime=nvidia', docker_args)
def test_x11_extension_basic(self): plugins = list_plugins() x11_plugin = plugins['x11'] self.assertEqual(x11_plugin.get_name(), 'x11') self.assertTrue(plugin_load_parser_correctly(x11_plugin)) p = x11_plugin() mock_cliargs = {'base_image': 'ubuntu:xenial'} docker_args = p.get_docker_args(mock_cliargs) self.assertIn(' -e DISPLAY -e TERM', docker_args) self.assertIn(' -e QT_X11_NO_MITSHM=1', docker_args) self.assertIn(' -e XAUTHORITY=', docker_args) self.assertIn(' -v /tmp/.X11-unix:/tmp/.X11-unix ', docker_args) self.assertIn(' -v /etc/localtime:/etc/localtime:ro ', docker_args)
def test_git_extension(self): plugins = list_plugins() git_plugin = plugins['git'] self.assertEqual(git_plugin.get_name(), 'git') p = git_plugin() self.assertTrue(plugin_load_parser_correctly(git_plugin)) mock_cliargs = {} mock_config_file = tempfile.NamedTemporaryFile() mock_system_config_file = tempfile.NamedTemporaryFile() mock_cliargs['git_config_path'] = mock_config_file.name mock_cliargs['git_config_path_system'] = mock_system_config_file.name args = p.get_docker_args(mock_cliargs) system_gitconfig = mock_system_config_file.name system_gitconfig_target = '/etc/gitconfig' user_gitconfig = mock_config_file.name user_gitconfig_target = '/root/.gitconfig' self.assertIn('-v %s:%s' % (system_gitconfig, system_gitconfig_target), args) self.assertIn('-v %s:%s' % (user_gitconfig, user_gitconfig_target), args) # Test with user "enabled" mock_cliargs = {'user': True} mock_cliargs['git_config_path'] = mock_config_file.name user_args = p.get_docker_args(mock_cliargs) user_gitconfig_target = os.path.expanduser('~/.gitconfig') self.assertIn('-v %s:%s' % (user_gitconfig, user_gitconfig_target), user_args) # Test with overridden user mock_cliargs['user_override_name'] = 'testusername' user_args = p.get_docker_args(mock_cliargs) user_gitconfig_target = '/home/testusername/.gitconfig' self.assertIn('-v %s:%s' % (user_gitconfig, user_gitconfig_target), user_args) # Test non-extant files no generation mock_cliargs['git_config_path'] = '/path-does-not-exist' mock_cliargs['git_config_path_system'] = '/path-does-not-exist-either' user_args = p.get_docker_args(mock_cliargs) self.assertNotIn('-v', user_args)
def test_ssh_extension(self): plugins = list_plugins() ssh_plugin = plugins['ssh'] self.assertEqual(ssh_plugin.get_name(), 'ssh') p = ssh_plugin() self.assertTrue(plugin_load_parser_correctly(ssh_plugin)) mock_cliargs = {} self.assertEqual(p.get_snippet(mock_cliargs), '') self.assertEqual(p.get_preamble(mock_cliargs), '') # with SSH_AUTH_SOCK set os.environ['SSH_AUTH_SOCK'] = 'foo' args = p.get_docker_args(mock_cliargs) self.assertIn( '-e SSH_AUTH_SOCK -v ' + shlex.quote( '{SSH_AUTH_SOCK}:{SSH_AUTH_SOCK}'.format(**os.environ)), args) #without it set del os.environ['SSH_AUTH_SOCK'] args = p.get_docker_args(mock_cliargs) self.assertNotIn('SSH_AUTH_SOCK', args)