forked from osrf/rocker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Intermodalics/merge/upstream/v0.2.6
Merge upstream v0.2.6
- Loading branch information
Showing
9 changed files
with
177 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[sdist_dsc] | ||
epoch: 1 | ||
debian-version: 4intermodalics | ||
debian-version: 2intermodalics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2019 Open Source Robotics Foundation | ||
|
||
# Licensed 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. | ||
|
||
from argparse import ArgumentTypeError | ||
import os | ||
from rocker.extensions import RockerExtension | ||
|
||
|
||
class Volume(RockerExtension): | ||
|
||
ARG_DOCKER_VOLUME = "-v" | ||
ARG_ROCKER_VOLUME = ["--volume", "--mount"] | ||
name = 'volume' | ||
|
||
@classmethod | ||
def get_name(cls): | ||
return cls.name | ||
|
||
def get_docker_args(self, cli_args): | ||
""" | ||
@param cli_args: {'volume': [[%arg%]]} | ||
- 'volume' is fixed. | ||
- %arg% can be: | ||
- %path_host%: a path on the host. Same path will be populated in | ||
the container. | ||
- %path_host%:%path_cont% | ||
- %path_host%:%path_cont%:%option% | ||
""" | ||
args = [''] | ||
|
||
# flatten cli_args['volume'] | ||
volumes = [ x for sublist in cli_args[self.name] for x in sublist] | ||
|
||
for volume in volumes: | ||
elems = volume.split(':') | ||
host_dir = os.path.abspath(elems[0]) | ||
if len(elems) == 1: | ||
args.append('{0} {1}:{1}'.format(self.ARG_DOCKER_VOLUME, host_dir)) | ||
elif len(elems) == 2: | ||
container_dir = elems[1] | ||
args.append('{0} {1}:{2}'.format(self.ARG_DOCKER_VOLUME, host_dir, container_dir)) | ||
elif len(elems) == 3: | ||
container_dir = elems[1] | ||
options = elems[2] | ||
args.append('{0} {1}:{2}:{3}'.format(self.ARG_DOCKER_VOLUME, host_dir, container_dir, options)) | ||
else: | ||
raise ArgumentTypeError( | ||
'{} expects arguments in format HOST-DIR[:CONTAINER-DIR[:OPTIONS]]'.format(self.ARG_ROCKER_VOLUME)) | ||
|
||
return ' '.join(args) | ||
|
||
@staticmethod | ||
def register_arguments(parser): | ||
parser.add_argument(*Volume.ARG_ROCKER_VOLUME, | ||
metavar='HOST-DIR[:CONTAINER-DIR[:OPTIONS]]', | ||
type=str, | ||
nargs='+', | ||
action='append', | ||
help='volume volumes in container') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# 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 os | ||
import unittest | ||
|
||
from rocker.core import list_plugins | ||
from rocker.volume_extension import Volume | ||
|
||
|
||
class VolumeTest(unittest.TestCase): | ||
def setUp(self): | ||
self._instance = Volume() | ||
self._curr_path = os.path.abspath(os.path.curdir) | ||
self._virtual_path = "/path/in/container" | ||
|
||
def _test_equals_args(self, mock_cliargs, expected): | ||
""" | ||
@type mock_cliargs: { str: [[str]] } | ||
@type expected: [[str]] | ||
""" | ||
print("DEBUG: 'mock_cliargs' {}\n\t'expected': {}".format(mock_cliargs, expected)) | ||
docker_args = self._instance.get_docker_args(mock_cliargs) | ||
print("DEBUG: Resulted docker_args: {}".format(docker_args)) | ||
for arg_expected in expected: | ||
# Whitespace at the beginning is needed. | ||
complete_expected = " {} {}".format(Volume.ARG_DOCKER_VOLUME, arg_expected[0]) | ||
self.assertTrue(complete_expected in docker_args) | ||
|
||
def test_args_single(self): | ||
"""Passing source path""" | ||
arg = [[self._curr_path]] | ||
expected = [['{}:{}'.format(self._curr_path, self._curr_path)]] | ||
mock_cliargs = {Volume.name: arg} | ||
self._test_equals_args(mock_cliargs, expected) | ||
|
||
def test_args_twopaths(self): | ||
"""Passing source path, dest path""" | ||
arg = ["{}:{}".format(self._curr_path, self._virtual_path)] | ||
mock_cliargs = {Volume.name: [arg]} | ||
self._test_equals_args(mock_cliargs, arg) | ||
|
||
def test_args_twopaths_opt(self): | ||
"""Passing source path, dest path, and Docker's volume option""" | ||
arg = ["{}:{}:ro".format(self._curr_path, self._virtual_path)] | ||
mock_cliargs = {Volume.name: [arg]} | ||
self._test_equals_args(mock_cliargs, arg) | ||
|
||
def test_args_two_volumes(self): | ||
"""Multiple volume points""" | ||
arg_first = ["{}:{}:ro".format(self._curr_path, self._virtual_path)] | ||
arg_second = ["/tmp:{}".format(os.path.join(self._virtual_path, "tmp"))] | ||
args = [arg_first, arg_second] | ||
mock_cliargs = {Volume.name: args} | ||
self._test_equals_args(mock_cliargs, args) |