Пример #1
0
def test_docker_links(fs, monkeypatch):

    env = {
        "HOSTNAME": "test_env",
        "COMPOSE_SERVICE1_1_PORT": "tcp://172.17.0.2:80",
        "COMPOSE_SERVICE1_1_PORT_80_TCP": "tcp://172.17.0.2:80",
        "COMPOSE_SERVICE1_1_PORT_80_TCP_ADDR": "172.17.0.2",
        "COMPOSE_SERVICE1_1_PORT_80_TCP_PORT": "80",
        "COMPOSE_SERVICE1_1_PORT_80_TCP_PROTO": "tcp",
        "COMPOSE_SERVICE1_1_PORT_8000_TCP": "tcp://172.17.0.2:8000",
        "COMPOSE_SERVICE1_1_PORT_8000_TCP_ADDR": "172.17.0.2",
        "COMPOSE_SERVICE1_1_PORT_8000_TCP_PORT": "8000",
        "COMPOSE_SERVICE1_1_PORT_8000_TCP_PROTO": "tcp",
        "COMPOSE_SERVICE1_1_NAME": "/compose_env_1/compose_service1_1",
        "SERVICE1_PORT": "tcp://172.17.0.2:80",
        "SERVICE1_PORT_80_TCP": "tcp://172.17.0.2:80",
        "SERVICE1_PORT_80_TCP_ADDR": "172.17.0.2",
        "SERVICE1_PORT_80_TCP_PORT": "80",
        "SERVICE1_PORT_80_TCP_PROTO": "tcp",
        "SERVICE1_PORT_8000_TCP": "tcp://172.17.0.2:8000",
        "SERVICE1_PORT_8000_TCP_ADDR": "172.17.0.2",
        "SERVICE1_PORT_8000_TCP_PORT": "8000",
        "SERVICE1_PORT_8000_TCP_PROTO": "tcp",
        "SERVICE1_NAME": "/compose_env_1/service1",
        "SERVICE1_1_PORT": "tcp://172.17.0.2:80",
        "SERVICE1_1_PORT_80_TCP": "tcp://172.17.0.2:80",
        "SERVICE1_1_PORT_80_TCP_ADDR": "172.17.0.2",
        "SERVICE1_1_PORT_80_TCP_PORT": "80",
        "SERVICE1_1_PORT_80_TCP_PROTO": "tcp",
        "SERVICE1_1_PORT_8000_TCP": "tcp://172.17.0.2:8000",
        "SERVICE1_1_PORT_8000_TCP_ADDR": "172.17.0.2",
        "SERVICE1_1_PORT_8000_TCP_PORT": "8000",
        "SERVICE1_1_PORT_8000_TCP_PROTO": "tcp",
        "SERVICE1_1_NAME": "/compose_env_1/service1_1",
    }

    etc_host = """
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.2	service1 bf447f22cdba compose_service1_1
172.17.0.2	service1_1 bf447f22cdba compose_service1_1
172.17.0.2	compose_service1_1 bf447f22cdba
    """.strip()

    fs.create_file("/etc/hosts", contents=etc_host)

    monkeypatch.setattr(os, "environ", env)

    onion = Onions()
    onion._get_setup_from_links()

    assert len(onion.services) == 1
    group = onion.services[0]
    assert len(group.services) == 1
    service = group.services[0]
    assert len(service.ports) == 2
    assert set((port.port_from, port.dest)
               for port in service.ports) == set([(80, 80), (8000, 8000)])
def test_docker_links(fs, monkeypatch):

    env = {
        'HOSTNAME': 'test_env',
        'COMPOSE_SERVICE1_1_PORT': 'tcp://172.17.0.2:80',
        'COMPOSE_SERVICE1_1_PORT_80_TCP': 'tcp://172.17.0.2:80',
        'COMPOSE_SERVICE1_1_PORT_80_TCP_ADDR': '172.17.0.2',
        'COMPOSE_SERVICE1_1_PORT_80_TCP_PORT': '80',
        'COMPOSE_SERVICE1_1_PORT_80_TCP_PROTO': 'tcp',
        'COMPOSE_SERVICE1_1_PORT_8000_TCP': 'tcp://172.17.0.2:8000',
        'COMPOSE_SERVICE1_1_PORT_8000_TCP_ADDR': '172.17.0.2',
        'COMPOSE_SERVICE1_1_PORT_8000_TCP_PORT': '8000',
        'COMPOSE_SERVICE1_1_PORT_8000_TCP_PROTO': 'tcp',
        'COMPOSE_SERVICE1_1_NAME': '/compose_env_1/compose_service1_1',
        'SERVICE1_PORT': 'tcp://172.17.0.2:80',
        'SERVICE1_PORT_80_TCP': 'tcp://172.17.0.2:80',
        'SERVICE1_PORT_80_TCP_ADDR': '172.17.0.2',
        'SERVICE1_PORT_80_TCP_PORT': '80',
        'SERVICE1_PORT_80_TCP_PROTO': 'tcp',
        'SERVICE1_PORT_8000_TCP': 'tcp://172.17.0.2:8000',
        'SERVICE1_PORT_8000_TCP_ADDR': '172.17.0.2',
        'SERVICE1_PORT_8000_TCP_PORT': '8000',
        'SERVICE1_PORT_8000_TCP_PROTO': 'tcp',
        'SERVICE1_NAME': '/compose_env_1/service1',
        'SERVICE1_1_PORT': 'tcp://172.17.0.2:80',
        'SERVICE1_1_PORT_80_TCP': 'tcp://172.17.0.2:80',
        'SERVICE1_1_PORT_80_TCP_ADDR': '172.17.0.2',
        'SERVICE1_1_PORT_80_TCP_PORT': '80',
        'SERVICE1_1_PORT_80_TCP_PROTO': 'tcp',
        'SERVICE1_1_PORT_8000_TCP': 'tcp://172.17.0.2:8000',
        'SERVICE1_1_PORT_8000_TCP_ADDR': '172.17.0.2',
        'SERVICE1_1_PORT_8000_TCP_PORT': '8000',
        'SERVICE1_1_PORT_8000_TCP_PROTO': 'tcp',
        'SERVICE1_1_NAME': '/compose_env_1/service1_1',
    }

    etc_host = '''
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.2	service1 bf447f22cdba compose_service1_1
172.17.0.2	service1_1 bf447f22cdba compose_service1_1
172.17.0.2	compose_service1_1 bf447f22cdba
    '''.strip()

    fs.CreateFile('/etc/hosts', contents=etc_host)

    monkeypatch.setattr(os, 'environ', env)

    onion = Onions()
    onion._get_setup_from_links()

    assert len(onion.services) == 1
    group = onion.services[0]
    assert len(group.services) == 1
    service = group.services[0]
    assert len(service.ports) == 2
    assert set((port.port_from, port.dest)
               for port in service.ports) == set([(80, 80), (8000, 8000)])