[Fuego] [PATCH 02/16] Mount fuego-rw/ro/core into the fuego-under-test container

Guilherme Camargo guicc at profusion.mobi
Tue Apr 3 03:18:34 UTC 2018


On Fri, Mar 30, 2018 at 10:31:42PM +0000, Tim.Bird at sony.com wrote:
> 
> One question inline...
> 
> > -----Original Message-----
> > From Guilherme Campos Camargo
> > 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 at 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'])
> I assume from the usage here that LOGGER.debug does
> string formatting?
> 

Yes, Tim. It does. You can see that we have set the formatting settings
on the first lines of the script.

```
19 LOGGER = logging.getLogger('test_run')
20 STREAM_HANDLER = logging.StreamHandler()
21 STREAM_HANDLER.setFormatter(
22    logging.Formatter("%(name)s:%(levelname)s: %(message)s"))
23 LOGGER.setLevel(logging.DEBUG)
24 LOGGER.addHandler(STREAM_HANDLER)

> > +                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
> 


More information about the Fuego mailing list