All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guilherme Campos Camargo <guicc@profusion.mobi>
To: fuego@lists.linuxfoundation.org
Subject: [Fuego] [PATCH 02/16] Mount fuego-rw/ro/core into the fuego-under-test container
Date: Wed, 28 Mar 2018 21:08:18 -0300	[thread overview]
Message-ID: <20180329000832.12268-3-guicc@profusion.mobi> (raw)
In-Reply-To: <20180329000832.12268-1-guicc@profusion.mobi>

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 <guicc@profusion.mobi>
---
 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


  parent reply	other threads:[~2018-03-29  0:08 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29  0:08 [Fuego] [PATCH 00/16] Fuego Release Test Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 01/16] Add fuego-release Functional test Guilherme Campos Camargo
2018-03-30 22:17   ` Tim.Bird
2018-03-30 22:37     ` Tim.Bird
2018-04-03  3:18       ` Guilherme Camargo
2018-04-03 20:03         ` Tim.Bird
2018-04-03  3:17     ` Guilherme Camargo
2018-04-03 20:22       ` Tim.Bird
2018-04-03 22:09         ` Guilherme Camargo
2018-03-29  0:08 ` Guilherme Campos Camargo [this message]
2018-03-30 22:31   ` [Fuego] [PATCH 02/16] Mount fuego-rw/ro/core into the fuego-under-test container Tim.Bird
2018-04-03  3:18     ` Guilherme Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 03/16] Increase wait_for_jenkins timeout from 10 to 60s Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 04/16] Print fuego repo/branch information during test build Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 05/16] Properly check install return code and abort in case of failure Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 06/16] Allow the user to keep the container running after the test Guilherme Campos Camargo
2018-03-30 22:48   ` Tim.Bird
2018-04-03  3:20     ` Guilherme Camargo
2018-04-03 20:08       ` Tim.Bird
2018-03-29  0:08 ` [Fuego] [PATCH 07/16] Add Back() Selenium Command Guilherme Campos Camargo
2018-03-30 22:52   ` Tim.Bird
2018-04-03  3:21     ` Guilherme Camargo
2018-04-03 20:09       ` Tim.Bird
2018-03-29  0:08 ` [Fuego] [PATCH 08/16] Add ClickLink selenium command Guilherme Campos Camargo
2018-03-30 22:53   ` Tim.Bird
2018-04-03  3:21     ` Guilherme Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 09/16] Include add-jobs, add-views and build-jobs tests Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 10/16] Write ok/fail on test report Guilherme Campos Camargo
2018-03-30 22:58   ` Tim.Bird
2018-04-03  3:21     ` Guilherme Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 11/16] Properly quit Selenium driver when SeleniumSession is deleted Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 12/16] Minor style/PEP8 fixes Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 13/16] Move Selenium implicitly_wait() to SeleniumSession start Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 14/16] Use a fixed language for Selenium Chrome-WebDriver Guilherme Campos Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 15/16] Improve Click and Check methods to allow multiple locators Guilherme Campos Camargo
2018-03-30 23:03   ` Tim.Bird
2018-04-03  3:22     ` Guilherme Camargo
2018-03-29  0:08 ` [Fuego] [PATCH 16/16] Add test that starts a job through the UI Guilherme Campos Camargo
2018-03-30 21:34 ` [Fuego] [PATCH 00/16] Fuego Release Test Tim.Bird
2018-04-03  3:16   ` Guilherme Camargo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180329000832.12268-3-guicc@profusion.mobi \
    --to=guicc@profusion.mobi \
    --cc=fuego@lists.linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.