Commit 02faac7f authored by Samuel GAIST's avatar Samuel GAIST

[dock] Implement support for changing user

parent dd8b4f39
......@@ -338,6 +338,11 @@ class Host(object):
network = container.network
if network:
cmd.append(network)
user = container.user
if user:
cmd.append(user)
if container.image in Host.images_cache:
image_infos = Host.images_cache[container.image]
if ('capabilities' in image_infos) and ('gpu' in image_infos['capabilities']):
......@@ -592,6 +597,7 @@ class Container:
self.image = image
self.command = command
self.network_name = None
self.uid = None
self.id = None
self._volumes = {}
self._ports = {}
......@@ -685,6 +691,15 @@ class Container:
if self.network_name:
network = '--network=' + self.network_name
return network
@property
def user(self):
user = ''
if self.uid:
user = '--user={0}:{0}'.format(self.uid)
return user
@property
def command_line(self):
"""Returns the complete docker command to start the container and
......@@ -696,6 +711,7 @@ class Container:
cmd = "docker run -ti --rm=true "
cmd += "%s " % self.network
cmd += "%s " % self.user
cmd += ' '.join(self.volumes)
cmd += ' '.join(self.ports)
......
......@@ -110,6 +110,25 @@ class NetworkTest(NoDiscoveryTests):
self.host.start(container)
except RuntimeError as e:
self.assertTrue(str(e).find('network %s not found' % network_name) >= 0)
class UserTest(NoDiscoveryTests):
@slow
def test_user(self):
"""Test that the uid property is correctly used.
"""
container = self.host.create_container('debian:8.4', ["id"])
container.uid = 10000
self.host.start(container)
status = self.host.wait(container)
self.assertEqual(status, 0)
self.assertTrue(self.host.logs(container).startswith('uid={0} gid={0}'.format(container.uid)))
class AsyncTest(NoDiscoveryTests):
@slow
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment