Merge pull request #2322 from jzelinskie/acifix

image/appc: fix volume conversion and add tests
This commit is contained in:
Jimmy Zelinskie 2017-04-21 10:15:03 -04:00 committed by GitHub
commit 6bef1d1ff3
3 changed files with 24 additions and 3 deletions

View file

@ -156,8 +156,8 @@ class DockerV1ToACIManifestTranslator(object):
volume_name = DockerV1ToACIManifestTranslator._ac_name(docker_volume_path) volume_name = DockerV1ToACIManifestTranslator._ac_name(docker_volume_path)
return "volume-%s" % volume_name return "volume-%s" % volume_name
volume_list = docker_config['Volumes'] or docker_config['volumes'] or [] volume_list = docker_config['Volumes'] or docker_config['volumes'] or {}
for docker_volume_path in volume_list: for docker_volume_path in volume_list.iterkeys():
if not docker_volume_path: if not docker_volume_path:
continue continue

View file

@ -2,6 +2,7 @@ import pytest
from image.appc import DockerV1ToACIManifestTranslator from image.appc import DockerV1ToACIManifestTranslator
from data.interfaces.verbs import RepositoryReference, ImageWithBlob from data.interfaces.verbs import RepositoryReference, ImageWithBlob
from util.dict_wrappers import JSONPathDict
EXAMPLE_MANIFEST_OBJ = { EXAMPLE_MANIFEST_OBJ = {
@ -96,3 +97,16 @@ def test_legacy_port_conversion(repo_image):
ports.sort() ports.sort()
assert {'name':'port-8080', 'port':8080, 'protocol':'tcp'} == ports[0] assert {'name':'port-8080', 'port':8080, 'protocol':'tcp'} == ports[0]
assert {'name':'port-8081', 'port':8081, 'protocol':'tcp'} == ports[1] assert {'name':'port-8081', 'port':8081, 'protocol':'tcp'} == ports[1]
@pytest.mark.parametrize("vcfg,expected", [
({'Volumes': None}, []),
({'Volumes': {}}, []),
({'Volumes': {'/bin': {}}}, [{'name': 'volume-bin', 'path': '/bin', 'readOnly': False}]),
({'volumes': None}, []),
({'volumes': {}}, []),
({'volumes': {'/bin': {}}}, [{'name': 'volume-bin', 'path': '/bin', 'readOnly': False}]),
])
def test_volume_version_easy(vcfg, expected):
output = DockerV1ToACIManifestTranslator._build_volumes(JSONPathDict(vcfg))
assert output == expected

View file

@ -59,8 +59,16 @@ class JSONPathDict(object):
def __getitem__(self, path): def __getitem__(self, path):
return self.get(path) return self.get(path)
def __iter__(self):
return self._object.itervalues()
def iterkeys(self):
return self._object.iterkeys()
def get(self, path, not_found_handler=None): def get(self, path, not_found_handler=None):
""" Returns the value found at the given path. Path is a json-path expression. """ """ Returns the value found at the given path. Path is a json-path expression. """
if self._object == {} or self._object is None:
return None
jsonpath_expr = parse(path) jsonpath_expr = parse(path)
try: try:
@ -82,4 +90,3 @@ class JSONPathDict(object):
def keys(self): def keys(self):
return self._object.keys() return self._object.keys()