Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed new docker versioning vs semantic_version #267

Merged
merged 2 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crawler/utils/dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import docker
import semantic_version
import itertools
import re

from utils import misc
from crawler_exceptions import (DockerutilsNoJsonLog,
Expand Down Expand Up @@ -237,11 +238,25 @@ def _get_container_rootfs_path_dm(long_id, inspect=None):
return rootfs_path + '/rootfs'


def _fix_version(v):
# removing leading zeroes from docker version
# which are not liked by semantic_version
version_parts = re.match(r'(\d+).(\d+).(\d+)', v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So essentially for docker version "17.04.01-ce", "17.04.01" would be compared against 1.10.0?

if version_parts is not None:
fixed_v = ''
for item in version_parts.groups():
if len(item) > 1 and item.startswith('0'):
item = item[1:]
fixed_v = fixed_v + item + '.'
return fixed_v[:-1]


def _get_container_rootfs_path_btrfs(long_id, inspect=None):

rootfs_path = None

if VERSION_SPEC.match(semantic_version.Version(server_version)):
if VERSION_SPEC.match(semantic_version.Version(_fix_version(
server_version))):
btrfs_path = None
mountid_path = ('/var/lib/docker/image/btrfs/layerdb/mounts/' +
long_id + '/mount-id')
Expand Down Expand Up @@ -274,7 +289,8 @@ def _get_container_rootfs_path_aufs(long_id, inspect=None):

rootfs_path = None

if VERSION_SPEC.match(semantic_version.Version(server_version)):
if VERSION_SPEC.match(semantic_version.Version(_fix_version(
server_version))):
aufs_path = None
mountid_path = ('/var/lib/docker/image/aufs/layerdb/mounts/' +
long_id + '/mount-id')
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/test_functional_dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
exec_docker_history,
exec_dockerinspect,
_get_docker_server_version,
_fix_version,
get_docker_container_rootfs_path
)

Expand Down Expand Up @@ -44,6 +45,14 @@ def tearDown(self):

shutil.rmtree(self.tempd)

def test_fix_version(self):
import semantic_version
ver = u'17.03.01-ce'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a travis test for new docker version ?

fixed_ver = _fix_version(ver)
assert fixed_ver == u'17.3.1'
VERSION_SPEC = semantic_version.Spec('>=1.10.0')
assert VERSION_SPEC.match(semantic_version.Version(fixed_ver)) is True

def test_docker_version(self):
ver = _get_docker_server_version()
import re
Expand Down