Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profusion-mobi.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JHFhSJdpFb6btmaBgZ97XMwqBTcmprBjUE1/dV+Sfwk=; b=09I5kZGsFKmOS3lXFK1yWsfws853w4mBb7lQM79lTAZF4FrM6bIYO9r2JiJ4Vm53jQ iZ+wHL4A+EzohM2iElXbgHfsIvB9dFxbLdD1pfHMozm9z3tTyJLIvkNO4c8VeNFxnU3C C2OrjCsM+Ro3ttiOWaN04w+5RpwowVq8ogLqa7PyIwpu7pXLLimjTFs/4spRKAocSgI5 8yZoNa8fphx13v4GisH+LgRY6s3psTFp3IDrncqr00NyCQoKHwye9C9wHP+XaBQMsaWP JkIwUkwMhW1pPYFnHEl4Mrth+LifFVDs9GqwZg/7sNAgXb7t/+6SjdOzIIJcCyu6LBNY NrRw== From: Guilherme Campos Camargo Date: Wed, 7 Mar 2018 16:54:50 -0300 Message-Id: <20180307195459.16757-3-guicc@profusion.mobi> In-Reply-To: <20180307195459.16757-1-guicc@profusion.mobi> References: <20180307195459.16757-1-guicc@profusion.mobi> Subject: [Fuego] [PATCH 02/11] Mount fuego-rw/ro/core into the fuego-under-test container List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org This patch implements the necessary logic for mounting fuego-rw, fuego-ro and fuego-core into fuego. Given that the dockerd socket is shared between the host and the fuego container, the mountpoints that are passed to the `docker create` call need to be provided as full paths relative to the *host* (and not relative to fuego, as would be expected if the docker daemons were independent) Signed-off-by: Guilherme Campos Camargo --- engine/tests/Functional.fuegotest/test_run.py | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/engine/tests/Functional.fuegotest/test_run.py b/engine/tests/Functional.fuegotest/test_run.py index 96fcfb7..7eae056 100755 --- a/engine/tests/Functional.fuegotest/test_run.py +++ b/engine/tests/Functional.fuegotest/test_run.py @@ -173,12 +173,43 @@ class FuegoContainer: self.container = None def setup_docker(self): + def this_container_id(): + with open('/proc/self/cgroup', 'rt') as f: + f_text = f.read() + + if 'docker' not in f_text: + return None + + for c in self.docker_client.containers(quiet=True): + if c['Id'] in f_text: + return c['Id'] + + return None + + def map_to_host(mounts, container_id): + host_mounts = self.docker_client.\ + inspect_container(container_id)['Mounts'] + + for mount in mounts: + LOGGER.debug(' Trying to find %s mountpoint in the host', mount['source']) + for host_mount in host_mounts: + if mount['source'].startswith(host_mount['Destination']): + mount['source'] = mount['source'].\ + replace(host_mount['Destination'], + host_mount['Source'], 1) + LOGGER.debug(' Found: %s', mount['source']) + break + else: + LOGGER.debug(' Not Found') + mount['source'] = None + cmd = './{} {}'.format(self.install_script, self.image_name) LOGGER.debug('Running \'%s\' to install the docker image. ' 'This may take a while....', cmd) status = subprocess.call(cmd, shell=True) if status != 0: return None + docker_client = docker.from_env() containers = docker_client.containers.list( all=True, filters={'name': self.container_name}) @@ -188,10 +219,42 @@ class FuegoContainer: self.container_name) containers[0].remove(force=True) + mounts = [ + {'source': os.path.abspath('./fuego-rw'), + 'destination': '/fuego-rw', + 'readonly': False, + }, + {'source': os.path.abspath('./fuego-ro'), + 'destination': '/fuego-ro', + 'readonly': True, + }, + {'source': os.path.abspath('../fuego-core'), + 'destination': '/fuego-core', + 'readonly': True, + }, + ] + + our_id = this_container_id() + + if our_id: + LOGGER.debug('Running inside the Docker container %s', our_id) + map_to_host(mounts, our_id) + else: + LOGGER.debug('Not running inside a Docker container') + + LOGGER.debug('Creating container with the following mountpoints:') + LOGGER.debug(' %s', mounts) + container = docker_client.containers.create( self.image_name, stdin_open=True, tty=True, network_mode='bridge', + mounts=[docker.types.Mount(m['destination'], + m['source'], + type='bind', + read_only=m['readonly']) + for m in mounts], name=self.container_name, command='/bin/bash') + LOGGER.debug('Container \'%s\' created', self.container_name) return container -- 2.16.2