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

[FLOC-4480, FLOC-4483] Fix docker systemd dropin configuration files and add docker plugin ID for Docker 1.12 #2880

Merged
merged 6 commits into from
Aug 4, 2016
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
10 changes: 8 additions & 2 deletions flocker/dockerplugin/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ def volumedriver_remove(self, Name):

@app.route("/VolumeDriver.Unmount", methods=["POST"])
@_endpoint(u"Unmount")
def volumedriver_unmount(self, Name):
def volumedriver_unmount(self, Name, ID=None):
"""
The Docker container is no longer using the given volume.

:param unicode Name: The name of the volume.
:param string ID: A unique ID for caller that requested the mount

For now this does nothing. In FLOC-2755 this will release the
lease acquired for the dataset by the ``VolumeDriver.Mount``
Expand Down Expand Up @@ -313,14 +314,19 @@ def got_state(datasets):

@app.route("/VolumeDriver.Mount", methods=["POST"])
@_endpoint(u"Mount")
def volumedriver_mount(self, Name):
def volumedriver_mount(self, Name, ID=None):
"""
Move a volume with the given name to the current node and mount it.

Since we need to return the filesystem path we wait until the
dataset is mounted locally.

:param unicode Name: The name of the volume.
:param string ID: A unique ID for caller that requested the mount

Right now we do nothing with ID, but it can be used to track
the mount calls when multiple containers are trying to mount
the same volume.

:return: Result that includes the mountpoint.
"""
Expand Down
75 changes: 71 additions & 4 deletions flocker/dockerplugin/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests for the Volumes Plugin API provided by the plugin.
"""

import random
from uuid import uuid4

from bitmath import TiB, GiB, MiB, KiB, Byte
Expand Down Expand Up @@ -115,8 +116,22 @@ def test_unmount(self):
"""
``/VolumeDriver.Unmount`` returns a successful result.
"""
unmount_id = ''.join(random.choice(
'0123456789abcdef') for n in xrange(64))
return self.assertResult(b"POST", b"/VolumeDriver.Unmount",
{u"Name": u"vol"}, OK, {u"Err": u""})
{u"Name": u"vol",
u"ID": unicode(unmount_id)},
OK, {u"Err": u""})

def test_unmount_no_id(self):
"""
``/VolumeDriver.Unmount`` returns a successful result.

No ID for backward compatability with Docker < 1.12
"""
return self.assertResult(b"POST", b"/VolumeDriver.Unmount",
{u"Name": u"vol"},
OK, {u"Err": u""})

def test_create_with_profile(self):
"""
Expand Down Expand Up @@ -320,6 +335,52 @@ def test_mount(self):
"""
name = u"myvol"
dataset_id = uuid4()
mount_id = ''.join(random.choice(
'0123456789abcdef') for n in xrange(64))

# Create dataset on a different node:
d = self.flocker_client.create_dataset(
self.NODE_B, int(DEFAULT_SIZE.to_Byte()),
metadata={NAME_FIELD: name},
dataset_id=dataset_id)

self._flush_volume_plugin_reactor_on_endpoint_render()

# Pretend that it takes 5 seconds for the dataset to get established on
# Node A.
self.volume_plugin_reactor.callLater(
5.0, self.flocker_client.synchronize_state)

d.addCallback(lambda _:
self.assertResult(
b"POST", b"/VolumeDriver.Mount",
{u"Name": name, u"ID": unicode(mount_id)}, OK,
{u"Err": u"",
u"Mountpoint": u"/flocker/{}".format(dataset_id)}))
d.addCallback(lambda _: self.flocker_client.list_datasets_state())

def final_assertions(datasets):
self.assertEqual([self.NODE_A],
[d.primary for d in datasets
if d.dataset_id == dataset_id])
# There should be less than 20 calls to list_datasets_state over
# the course of 5 seconds.
self.assertLess(
self.flocker_client.num_calls('list_datasets_state'), 20)
d.addCallback(final_assertions)

return d

def test_mount_no_id(self):
"""
``/VolumeDriver.Mount`` sets the primary of the dataset with matching
name to the current node and then waits for the dataset to
actually arrive.

No ID for backward compatability with Docker < 1.12
"""
name = u"myvol"
dataset_id = uuid4()

# Create dataset on a different node:
d = self.flocker_client.create_dataset(
Expand Down Expand Up @@ -363,6 +424,8 @@ def test_mount_timeout(self):
"""
name = u"myvol"
dataset_id = uuid4()
mount_id = ''.join(random.choice(
'0123456789abcdef') for n in xrange(64))
# Create dataset on a different node:
d = self.flocker_client.create_dataset(
self.NODE_B, int(DEFAULT_SIZE.to_Byte()),
Expand All @@ -379,7 +442,7 @@ def test_mount_timeout(self):
d.addCallback(lambda _:
self.assertResult(
b"POST", b"/VolumeDriver.Mount",
{u"Name": name}, OK,
{u"Name": name, u"ID": unicode(mount_id)}, OK,
{u"Err": u"Timed out waiting for dataset to mount.",
u"Mountpoint": u""}))
return d
Expand All @@ -392,6 +455,8 @@ def test_mount_already_exists(self):
don't have a special dataset ID.
"""
name = u"myvol"
mount_id = ''.join(random.choice(
'0123456789abcdef') for n in xrange(64))

d = self.flocker_client.create_dataset(
self.NODE_A, int(DEFAULT_SIZE.to_Byte()),
Expand All @@ -401,7 +466,7 @@ def created(dataset):
self.flocker_client.synchronize_state()
result = self.assertResult(
b"POST", b"/VolumeDriver.Mount",
{u"Name": name}, OK,
{u"Name": name, u"ID": unicode(mount_id)}, OK,
{u"Err": u"",
u"Mountpoint": u"/flocker/{}".format(
dataset.dataset_id)})
Expand All @@ -420,9 +485,11 @@ def test_unknown_mount(self):
non-existent volume.
"""
name = u"myvol"
mount_id = ''.join(random.choice(
'0123456789abcdef') for n in xrange(64))
return self.assertResult(
b"POST", b"/VolumeDriver.Mount",
{u"Name": name}, OK,
{u"Name": name, u"ID": unicode(mount_id)}, OK,
{u"Err": u"Could not find volume with given name."})

def test_path(self):
Expand Down
11 changes: 7 additions & 4 deletions flocker/provision/_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ def task_enable_docker(distribution):
' --tlscert=/etc/flocker/node.crt --tlskey=/etc/flocker/node.key'
' -H=0.0.0.0:2376')

# Used in multiple config options
unixsock_opt = "-H unix:///var/run/docker.sock"

if is_systemd_distribution(distribution):
conf_path = (
"/etc/systemd/system/docker.service.d/01-TimeoutStartSec.conf"
Expand All @@ -862,16 +865,16 @@ def task_enable_docker(distribution):
"""\
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// {}
""".format(docker_tls_options))),
ExecStart=/usr/bin/dockerd {} {}
""".format(unixsock_opt, docker_tls_options))),
run_from_args(["systemctl", "enable", "docker.service"]),
])
elif is_ubuntu(distribution):
return sequence([
put(path="/etc/default/docker",
content=(
'DOCKER_OPTS="-H unix:///var/run/docker.sock {}"'.format(
docker_tls_options))),
'DOCKER_OPTS="{} {}"'.format(
unixsock_opt, docker_tls_options))),
])
else:
raise DistributionNotSupported(distribution=distribution)
Expand Down