def test_formatted_ports(self): ports = [ '3000', '0.0.0.0:4025-4030:23000-23005', ServicePort(6000, None, None, None, None), ServicePort(8080, 8080, None, None, None), ServicePort('20000', '20000', 'udp', 'ingress', None), ServicePort(30000, '30000', 'tcp', None, '127.0.0.1'), ] formatted = formatted_ports(ports) assert ports[0] in formatted assert ports[1] in formatted assert '6000/tcp' in formatted assert '8080:8080/tcp' in formatted assert '20000:20000/udp' in formatted assert '127.0.0.1:30000:30000/tcp' in formatted
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
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', }
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
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
def test_retrieve_ports_data(self): features.register(DockerFeature()) load_registered_features() action = actions.get( 'docker:display-info') # type:DockerDisplayInfoAction assert [] == action._retrieve_service_ports(Dotty({})) assert [] == action._retrieve_service_ports(Dotty({'toto': 'toto'})) assert [ServicePort(45, 123, None, None, None) ] == action._retrieve_service_ports( Dotty({'ports': [{ 'published': '123', 'target': '45' }]})) assert [ServicePort(45, 123, None, None, None)] == action._retrieve_service_ports( Dotty({'ports': ['123:45']})) assert [ServicePort(45, 123, 'tcp', None, None)] == action._retrieve_service_ports( Dotty({'ports': ['123:45/tcp']}))
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
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
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)
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]
def bootnode(config): name = 'wrkchain_bootnode' return { 'name': name, 'hostname': name, 'container_name': name, 'ports': [ ServicePort(published=config['docker_port'], target=config['docker_port'], protocol='udp', mode=None, external_ip=None), ], 'networks': { 'wrkchainnet': { 'ipv4_address': config['docker_ip'] } }, 'build': { 'context': '..', 'dockerfile': 'Docker/bootnode/Dockerfile', 'args': { 'GO_VERSION': constants.GO_VERSION, 'WRKCHAIN_DATA_DIR': constants.DEFAULT_WRKCHAIN_DATA_DIR }, }, 'environment': [f'BOOTNODE_PORT={config["docker_port"]}'], 'command': f'/root/.go/bin/bootnode -nodekey ' f'/root/{constants.DEFAULT_WRKCHAIN_DATA_DIR}/node_keys/bootnode.key' f' -verbosity 4 --addr :{config["docker_port"]}', 'expose': [config["docker_port"]] }
def generate_nodes(nodes, bootnode_config, wrkchain_id): d = [] n = 0 for validator in nodes: n = n + 1 name_list = ['wrkchain'] if validator['rpc']: name_list.append('rpc') if validator['is_validator']: name_list.append('validator') name_list.append(str(n)) name = '-'.join(name_list) cmd = generate_geth_cmd(validator, bootnode_config, wrkchain_id, validator['docker_listen_port']) build_d = { 'context': '..', 'dockerfile': 'Docker/node/Dockerfile', 'args': { 'WALLET_PASS': '******', 'PRIVATE_KEY': validator['private_key'], 'GO_VERSION': constants.GO_VERSION, 'WRKCHAIN_DATA_DIR': constants.DEFAULT_WRKCHAIN_DATA_DIR }, } ports = [] expose_ports = [] if validator['rpc']: rpc_port = validator['rpc']['docker_port'] ports.append( ServicePort(published=rpc_port, target=rpc_port, protocol=None, mode=None, external_ip=None)) expose_ports.append(rpc_port) if validator['is_validator']: geth_listen_port = validator['docker_listen_port'] ports.append( ServicePort(published=geth_listen_port, target=geth_listen_port, protocol=None, mode=None, external_ip=None)) expose_ports.append(geth_listen_port) d.append({ 'name': name, 'hostname': name, 'container_name': name, 'ports': ports, 'networks': { 'wrkchainnet': { 'ipv4_address': validator['docker_ip'] } }, 'build': build_d, 'command': cmd, 'expose': expose_ports }) return d
def test_parse_invalid_port(self): port_def = '4000p' with pytest.raises(ConfigurationError): ServicePort.parse(port_def)
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'
def test_parse_simple_target_port(self): ports = ServicePort.parse(8000) assert len(ports) == 1 assert ports[0].target == 8000