Skip to content

Commit

Permalink
Merge branch 'osrf:main' into issue_35_rocker
Browse files Browse the repository at this point in the history
  • Loading branch information
BabaYaga1221 authored May 5, 2023
2 parents 8cfe4a1 + 9304066 commit 59b6c2e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/basic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ jobs:
matrix:
python-version: [3.8, '3.10']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies And Self
run: |
python -m pip install --upgrade pip setuptools wheel
# Workaround for https://github.com/docker/docker-py/issues/2807
python -m pip install six
python -m pip install -e .[test] codecov pytest-cov
- name: Run headless tests
uses: GabrielBB/xvfb-action@v1
uses: coactions/setup-xvfb@v1
with:
run: python -m pytest -s -v --cov=rocker -m "not nvidia"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'empy',
'pexpect',
'packaging',
'urllib3<2', # Workaround for https://github.com/docker/docker-py/issues/3113
]

# docker API used to be in a package called `docker-py` before the 2.0 release
Expand Down Expand Up @@ -49,6 +50,7 @@
'git = rocker.git_extension:Git',
'group_add = rocker.extensions:GroupAdd',
'home = rocker.extensions:HomeDir',
'hostname = rocker.extensions:Hostname',
'name = rocker.extensions:Name',
'network = rocker.extensions:Network',
'nvidia = rocker.nvidia_extension:Nvidia',
Expand Down
23 changes: 23 additions & 0 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ def register_arguments(parser, defaults={}):
help="add development tools emacs and byobu to your environment")


class Hostname(RockerExtension):
@staticmethod
def get_name():
return 'hostname'

def __init__(self):
self.name = Hostname.get_name()

def get_preamble(self, cliargs):
return ''

def get_docker_args(self, cliargs):
args = ''
hostname = cliargs.get('hostname', None)
if hostname:
args += ' --hostname %s ' % hostname
return args

@staticmethod
def register_arguments(parser, defaults={}):
parser.add_argument('--hostname', default=defaults.get('hostname', ''),
help='Hostname of the container.')

class Name(RockerExtension):
@staticmethod
def get_name():
Expand Down
31 changes: 31 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,37 @@ def test_name_extension(self):
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--name docker_name' in args)

class HostnameExtensionTest(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_name_extension(self):
plugins = list_plugins()
name_plugin = plugins['hostname']
self.assertEqual(name_plugin.get_name(), 'hostname')

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

mock_cliargs = {'hostname': 'none'}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--hostname none' in args)

mock_cliargs = {'hostname': 'docker-hostname'}
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--hostname docker-hostname' in args)


class PrivilegedExtensionTest(unittest.TestCase):

Expand Down

0 comments on commit 59b6c2e

Please sign in to comment.