예제 #1
0
 def test_parse_port_publish_range(self):
     ports = ServicePort.parse('4440-4450:4000')
     assert len(ports) == 1
     reprs = [p.repr() for p in ports]
     assert {
         'target': 4000,
         'published': '4440-4450'
     } in reprs
예제 #2
0
 def test_parse_port_publish_range(self):
     ports = ServicePort.parse('4440-4450:4000')
     assert len(ports) == 1
     reprs = [p.repr() for p in ports]
     assert {
         'target': 4000,
         'published': '4440-4450'
     } in reprs
예제 #3
0
 def test_parse_ext_ip_no_published_port(self):
     port_def = '1.1.1.1::3000'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].legacy_repr() == port_def + '/tcp'
     assert ports[0].repr() == {
         'target': 3000,
         'external_ip': '1.1.1.1',
     }
예제 #4
0
 def test_parse_ext_ip_no_published_port(self):
     port_def = '1.1.1.1::3000'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].legacy_repr() == port_def + '/tcp'
     assert ports[0].repr() == {
         'target': 3000,
         'external_ip': '1.1.1.1',
     }
예제 #5
0
 def test_parse_dict(self):
     data = {
         'target': 8000,
         'published': 8000,
         'protocol': 'udp',
         'mode': 'global',
     }
     ports = ServicePort.parse(data)
     assert len(ports) == 1
     assert ports[0].repr() == data
예제 #6
0
 def test_parse_dict(self):
     data = {
         'target': 8000,
         'published': 8000,
         'protocol': 'udp',
         'mode': 'global',
     }
     ports = ServicePort.parse(data)
     assert len(ports) == 1
     assert ports[0].repr() == data
예제 #7
0
 def test_parse_complete_port_definition(self):
     port_def = '1.1.1.1:3000:3000/udp'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].repr() == {
         'target': 3000,
         'published': 3000,
         'external_ip': '1.1.1.1',
         'protocol': 'udp',
     }
     assert ports[0].legacy_repr() == port_def
예제 #8
0
 def test_parse_complete_port_definition(self):
     port_def = '1.1.1.1:3000:3000/udp'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].repr() == {
         'target': 3000,
         'published': 3000,
         'external_ip': '1.1.1.1',
         'protocol': 'udp',
     }
     assert ports[0].legacy_repr() == port_def
예제 #9
0
 def test_parse_port_range(self):
     ports = ServicePort.parse('25000-25001:4000-4001')
     assert len(ports) == 2
     reprs = [p.repr() for p in ports]
     assert {
         'target': 4000,
         'published': 25000
     } in reprs
     assert {
         'target': 4001,
         'published': 25001
     } in reprs
예제 #10
0
 def test_parse_port_range(self):
     ports = ServicePort.parse('25000-25001:4000-4001')
     assert len(ports) == 2
     reprs = [p.repr() for p in ports]
     assert {
         'target': '4000',
         'published': '25000'
     } in reprs
     assert {
         'target': '4001',
         'published': '25001'
     } in reprs
예제 #11
0
    def test_parse_invalid_publish_range(self):
        port_def = '-4000:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = 'asdf:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = '1234-12f:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = '1234-1235-1239:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)
예제 #12
0
    def test_parse_invalid_publish_range(self):
        port_def = '-4000:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = 'asdf:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = '1234-12f:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)

        port_def = '1234-1235-1239:4000'
        with pytest.raises(ConfigurationError):
            ServicePort.parse(port_def)
예제 #13
0
파일: proxy.py 프로젝트: iamdork/compose
    def preprocess_config(self, config):

        for service in config.services:
            if 'ports' in service:
                indices = range(len(service['ports']))
                indices.reverse()
                for index in indices:
                    port = service['ports'][index]
                    if port.published:
                        domain = self.service_domain() if port.published == '80' or port.published == '443' else self.service_domain(service['name'])
                        if 'environment' not in service:
                            service['environment'] = {}
                        service['environment']['VIRTUAL_HOST'] = domain
                        service['environment']['LETSENCRYPT_HOST'] = domain
                        service['environment']['LETSENCRYPT_EMAIL'] = self.letsencrypt_email
                        if 'labels' not in service:
                            service['labels'] = {}
                        service['environment']['VIRTUAL_PORT'] = int(port.target)
                        port_dict = {k: v for k, v in port.repr().iteritems() if k != "published"}
                        port_dict['mode'] = 'host'
                        spec = normalize_port_dict(port_dict)
                        service['ports'][index] = ServicePort.parse(spec)[0]
예제 #14
0
 def test_parse_simple_target_port(self):
     ports = ServicePort.parse(8000)
     assert len(ports) == 1
     assert ports[0].target == 8000
예제 #15
0
 def test_repr_published_port_0(self):
     port_def = '0:4000'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].legacy_repr() == port_def + '/tcp'
예제 #16
0
 def test_parse_simple_target_port(self):
     ports = ServicePort.parse(8000)
     assert len(ports) == 1
     assert ports[0].target == 8000
예제 #17
0
 def test_parse_invalid_port(self):
     port_def = '4000p'
     with pytest.raises(ConfigurationError):
         ServicePort.parse(port_def)
예제 #18
0
 def test_parse_invalid_port(self):
     port_def = '4000p'
     with pytest.raises(ConfigurationError):
         ServicePort.parse(port_def)
예제 #19
0
 def test_repr_published_port_0(self):
     port_def = '0:4000'
     ports = ServicePort.parse(port_def)
     assert len(ports) == 1
     assert ports[0].legacy_repr() == port_def + '/tcp'