Beispiel #1
0
def run_flannel(etcd):
    ''' Render the docker-compose template, and run the flannel daemon '''

    status_set('maintenance', 'Starting flannel network container.')
    context = {}
    if is_state('etcd.tls.available'):
        cert_path = '/etc/ssl/flannel'
    else:
        cert_path = None

    context.update(config())
    context.update({'charm_dir': os.getenv('CHARM_DIR'),
                    'connection_string': etcd.get_connection_string(),
                    'cert_path': cert_path})
    render('flannel-compose.yml', 'files/flannel/docker-compose.yml', context)

    compose = Compose('files/flannel',
                      socket='unix:///var/run/bootstrap-docker.sock')
    compose.up()
    # Give the flannel daemon a moment to actually generate the interface
    # configuration seed. Otherwise we enter a time/wait scenario which
    # may cuase this to be called out of order and break the expectation
    # of the deployment.
    time.sleep(3)
    ingest_network_config()
def start_application():
    compose = Compose('files/voting-app')
    # Launch the workload
    compose.up()
    # Declare ports to Juju - this requires a manual step of juju expose
    # otherwise the public facing ports never actually get exposed for traffic.
    open_port(config('vote_port'))
    open_port(config('result_port'))
Beispiel #3
0
 def test_context_manager(self, cwdmock):
     cwdmock.return_value = '/tmp'
     with patch('os.chdir') as chmock:
         compose = Compose('files/workspace', strict=False)
         with patch('charms.docker.runner.check_output'):
             compose.up('nginx')
             # We can only test the return called with in this manner.
             # So check that we at least reset context
             chmock.assert_called_with('/tmp')
Beispiel #4
0
def start_swarm(cluster_string, cert_path=None):
    """ Render the compose configuration and start the swarm scheduler """
    opts = {}
    opts["addr"] = unit_private_ip()
    opts["port"] = 2376
    opts["leader"] = is_leader()
    opts["connection_string"] = cluster_string
    if cert_path:
        opts["discovery_tls_path"] = cert_path
    render("docker-compose.yml", "files/swarm/docker-compose.yml", opts)
    c = Compose("files/swarm")
    c.up()
    set_state("swarm.available")
Beispiel #5
0
def start_swarm(cluster_string, cert_path=None):
    ''' Render the compose configuration and start the swarm scheduler '''
    opts = {}
    opts['addr'] = unit_private_ip()
    opts['port'] = 2376
    opts['leader'] = is_leader()
    opts['connection_string'] = cluster_string
    if cert_path:
        opts['discovery_tls_path'] = cert_path
    render('docker-compose.yml', 'files/swarm/docker-compose.yml', opts)
    c = Compose('files/swarm')
    c.up()
    set_state('swarm.available')
def run_flannel(etcd):
    ''' Render the docker-compose template, and run the flannel daemon '''

    status_set('maintenance', 'Starting flannel network container.')
    context = {}
    if is_state('etcd.tls.available'):
        cert_path = '/etc/ssl/flannel'
    else:
        cert_path = None
    # Put all the configuration values in the context dictionary.
    context.update(config())
    iface = config('iface')
    # When iface is None or empty string.
    if not iface:
        # Attempt to detect the default interface.
        iface = get_default_interface()
        # When detection not successful, print message and return.
        if not iface:
            status_set('blocked', "Interface detection failed. "
                       "Set charm's iface config option.")
            return
    # Add additional key/values to the context dictionary.
    context.update({'charm_dir': os.getenv('CHARM_DIR'),
                    'connection_string': etcd.get_connection_string(),
                    'cert_path': cert_path})
    # Render the flannel-compose.yml file using the current context.
    render('flannel-compose.yml', 'files/flannel/docker-compose.yml', context)

    compose = Compose('files/flannel',
                      socket='unix:///var/run/bootstrap-docker.sock')
    compose.up()
    # Give the flannel daemon a moment to actually generate the interface
    # configuration seed. Otherwise we enter a time/wait scenario which
    # may cause this to be called out of order and break the expectation
    # of the deployment.
    time.sleep(3)
    ingest_network_config()
def start():
    compose = Compose('files/docker-registry')
    compose.up()
    open_port(config('registry_port'))
    status_set('active', 'Docker registry ready.')
Beispiel #8
0
 def test_run(self, ccmock, chmock):
     compose = Compose('files/workspace', strict=False)
     compose.up('nginx')
     chmock.assert_called_with('files/workspace')
     ccmock.assert_called_with(['docker-compose', 'up', '-d', 'nginx'])
Beispiel #9
0
 def test_socket_run_has_host_output(self, ccmock, chmock):
     compose = Compose('files/workspace', strict=False, socket='test')
     compose.up()
     chmock.assert_called_with('files/workspace')
     ccmock.assert_called_with(['docker-compose', 'up', '-d'])
     assert (os.getenv('DOCKER_HOST') == 'test')