From f4361cfa5a16e4b78c67f2fdacae8342fd2f5da1 Mon Sep 17 00:00:00 2001 From: Dmitry Monakhov Date: Sun, 2 Oct 2016 09:39:58 +0300 Subject: [PATCH] docker: Give container selfdescriptive name This works great to hosts wich many containers Example: avocado run --docker debian-avocado-test /bin/true DOCKER : Container id '0f9ebae391183937fb6e98c50cc10f4927963140caf6e63fd108876a6ac7270f' DOCKER : Container name 'job-2016-10-02T07.14-a404c72.avocado' .. --- avocado/plugins/docker.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/avocado/plugins/docker.py b/avocado/plugins/docker.py index 8f9902ac..6108e25a 100644 --- a/avocado/plugins/docker.py +++ b/avocado/plugins/docker.py @@ -14,6 +14,8 @@ """Run the job inside a docker container.""" import logging +import os +import socket import time import aexpect @@ -33,7 +35,7 @@ class DockerRemoter(object): of the commands on docker container. """ - def __init__(self, dkrcmd, image, options): + def __init__(self, dkrcmd, image, options, name=None): """ Executes docker container and attaches it. @@ -42,6 +44,11 @@ class DockerRemoter(object): """ self._dkrcmd = dkrcmd self._docker = None + + if name is not None: + options += " --name %s --hostname %s" % \ + (name, name + '.' + socket.gethostname()) + run_cmd = "%s run -t -i -d %s '%s' bash" % (self._dkrcmd, options, image) self._docker_id = (process.system_output(run_cmd, None).splitlines()[-1] .strip()) @@ -134,11 +141,13 @@ class DockerTestRunner(RemoteTestRunner): def setup(self): dkrcmd = self.job.args.docker_cmd dkr_opt = self.job.args.docker_options - self.remote = DockerRemoter(dkrcmd, self.job.args.docker, dkr_opt) + dkr_name = os.path.basename(self.job.logdir) + '.' + 'avocado' + self.remote = DockerRemoter(dkrcmd, self.job.args.docker, dkr_opt, dkr_name) # We need to create the base dir, otherwise docker creates it as root self.remote.makedir(self.remote_test_dir) self.job.log.info("DOCKER : Container id '%s'" % self.remote.get_cid()) + self.job.log.debug("DOCKER : Container name '%s'" % dkr_name) self.job.args.remote_no_copy = self.job.args.docker_no_copy def tear_down(self): -- GitLab