Ejemplo n.º 1
0
def start_docker_instance(proxy_bind_addr, bundle_http_port, proxy_ports,
                          all_feature_ports):
    log = logging.getLogger(__name__)
    log.info(h1('Starting HAProxy'))

    docker_image = terminal.docker_images(HAPROXY_DOCKER_IMAGE)
    if not docker_image:
        log.info('Pulling docker image {}'.format(HAPROXY_DOCKER_IMAGE))
        terminal.docker_pull(HAPROXY_DOCKER_IMAGE)

    all_proxy_ports = [bundle_http_port]
    all_proxy_ports.extend(DEFAULT_PROXY_PORTS)
    all_proxy_ports.extend(all_feature_ports)
    all_proxy_ports.extend(proxy_ports)
    all_proxy_ports = sorted(set(all_proxy_ports))

    port_args = []
    for port in all_proxy_ports:
        port_args.append('-p')
        port_args.append('{}:{}:{}'.format(proxy_bind_addr.exploded, port,
                                           port))

    docker_args = ['-d', '--name', DEFAULT_SANDBOX_PROXY_CONTAINER_NAME] + port_args + \
                  ['-v', '{}:/usr/local/etc/haproxy:ro'.format(HAPROXY_CFG_DIR)]

    log.info('Exposing the following ports {}'.format(all_proxy_ports))
    terminal.docker_run(docker_args, HAPROXY_DOCKER_IMAGE, positional_args=[])
Ejemplo n.º 2
0
    def start(self):
        log = logging.getLogger(__name__)

        if self.enabled and self.image_name is not None:
            if self.docker_present:
                log.info(h1('Starting OCI-in-Docker support'))
                docker_image = terminal.docker_images(self.image_name)

                if not docker_image:
                    log.info('Pulling docker image {}'.format(self.image_name))
                    terminal.docker_pull(self.image_name)

                log.info('OCI-in-Docker provided by image {}'.format(
                    self.image_name))

                return FeatureStartResult(True, [])
            else:
                log.info(h1('OCI-in-Docker support unavailable.'))
                log.info(
                    h1('To provide support ensure Docker is running and restart the sandbox'
                       ))

                return FeatureStartResult(False, [])
        else:
            return FeatureStartResult(False, [])
Ejemplo n.º 3
0
def pull_image(args):
    if args.image == CONDUCTR_DEV_IMAGE and not terminal.docker_images(
            CONDUCTR_DEV_IMAGE):
        log = logging.getLogger(__name__)
        log.info('Pulling down the ConductR development image..')
        terminal.docker_pull('{image_name}:{image_version}'.format(
            image_name=CONDUCTR_DEV_IMAGE, image_version=args.image_version))
Ejemplo n.º 4
0
    def test_docker_pull(self):
        image = 'image:version'
        stdout = MagicMock()
        subprocess_call_mock = MagicMock()

        with patch('subprocess.call', subprocess_call_mock), \
                patch('sys.stdout', stdout):
            terminal.docker_pull(image)

        self.assertEqual('', self.output(stdout))
        subprocess_call_mock.assert_called_with(['docker', 'pull', image])
Ejemplo n.º 5
0
    def test_docker_pull(self):
        image = 'image:version'
        stdout = MagicMock()
        subprocess_call_mock = MagicMock()

        with patch('subprocess.call', subprocess_call_mock), \
                patch('sys.stdout', stdout):
            terminal.docker_pull(image)

        self.assertEqual('', self.output(stdout))
        subprocess_call_mock.assert_called_with(['docker', 'pull', image])
Ejemplo n.º 6
0
def pull_image(args):
    if args.image == CONDUCTR_DEV_IMAGE and not terminal.docker_images(CONDUCTR_DEV_IMAGE):
        log = logging.getLogger(__name__)
        log.info('Pulling down the ConductR development image..')
        terminal.docker_pull('{image_name}:{image_version}'
                             .format(image_name=CONDUCTR_DEV_IMAGE, image_version=args.image_version))