Skip to content

Commit e739050

Browse files
author
Luis Sanchez
committed
[FAB-1296] Enable some BDD tests to run on macOS
Have the BDD tests comminucate with the docker environments via exposed ports, rather than relying on the existance of bridged networks (which are not exposed on macOS). - Only did enough work to get the orderer.feature tests running. This is one of the only two features enabled in CI. - The other feature enabled in CI, endorser.feature does not currently work. CI currenlty ignores that this feature fails. - All the other pre-fabric 1.0 features are currently disabled. More work will be needed to get those working. Change-Id: I73ea1f3fc3e7b46088f73b6fc55882835459b0ef Signed-off-by: Luis Sanchez <[email protected]>
1 parent 9e8fb87 commit e739050

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

bddtests/docker-compose-orderer-base.yml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ services:
1818
- ./volumes/orderer:/var/hyperledger/bddtests/volumes/orderer
1919
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
2020
command: orderer
21+
ports:
22+
- '7050'
2123

2224
volumes:
2325

bddtests/environments/orderer-1-kafka-1/docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ services:
1919
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
2020
- ORDERER_KAFKA_BROKERS=[kafka0:9092]
2121
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
22-
command: orderer
22+
command: orderer -loglevel debug -verbose true
23+
ports:
24+
- '7050'
2325
depends_on:
2426
- kafka0
2527

bddtests/environments/orderer-1-kafka-3/docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ services:
1919
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
2020
- ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092]
2121
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
22-
command: orderer
22+
command: orderer -loglevel debug -verbose true
23+
ports:
24+
- '7050'
2325
depends_on:
2426
- kafka0
2527
- kafka1

bddtests/environments/orderer-n-kafka-n/docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ services:
1717
- ORDERER_GENERAL_LISTENPORT=7050
1818
- ORDERER_GENERAL_GENESISMETHOD=provisional
1919
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
20+
ports:
21+
- '7050'
2022
depends_on:
2123
- zookeeper
2224
- kafka

bddtests/steps/bdd_test_util.py

+21
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ def ipFromContainerNamePart(namePart, containerDataList):
8484

8585
return containerData.ipAddress
8686

87+
def getPortHostMapping(compose_container_data, compose_service_name, port, protocol='tcp'):
88+
"""returns (host_ip, host_port)
89+
Returns the host IP address port and port that maps to a container's exposed port.
90+
If the port is not mapped, then the actual container IP address is returned.
91+
"""
92+
container = containerDataFromNamePart(compose_service_name, compose_container_data)
93+
if container:
94+
port_protocol = '%s/%s' % (port, protocol)
95+
if port_protocol in container.ports:
96+
port_mapping = container.ports[port_protocol]
97+
host_ip = port_mapping[0]['HostIp']
98+
host_port = int(port_mapping[0]['HostPort'])
99+
return host_ip, host_port
100+
else:
101+
print('WARNING: Could not find port mapping for port {0}'.format(port_protocol))
102+
# TODO so we don't break existing docker-compose tests on Vagrant just yet
103+
print('WARNING: Returning the actual container IP address, which might not be routable from the host.')
104+
return container.ipAddress, port
105+
else:
106+
raise Exception("Could not find container for service '{0}'".format(compose_service_name))
107+
87108
def fullNameFromContainerNamePart(namePart, containerDataList):
88109
containerData = containerDataFromNamePart(namePart, containerDataList)
89110

bddtests/steps/compose.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ def rebuildContainerData(self):
127127
# container environment
128128
container_env = container['Config']['Env']
129129

130+
# container exposed ports
131+
container_ports = container['NetworkSettings']['Ports']
132+
130133
# container docker-compose service
131134
container_compose_service = container['Config']['Labels']['com.docker.compose.service']
132135

133-
self.containerDataList.append(peer_basic_impl.ContainerData(container_name, container_ipaddress, container_env, container_compose_service))
136+
self.containerDataList.append(peer_basic_impl.ContainerData(container_name, container_ipaddress, container_env, container_compose_service, container_ports))
134137

135138
def decompose(self):
136139
self.issueCommand(["unpause"])

bddtests/steps/orderer_util.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ def getABStubForComposeService(self, context, composeService):
170170
if composeService in self.atomicBroadcastStubsDict:
171171
return self.atomicBroadcastStubsDict[composeService]
172172
# Get the IP address of the server that the user registered on
173-
ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
174-
channel = getGRPCChannel(ipAddress)
173+
channel = getGRPCChannel(*bdd_test_util.getPortHostMapping(context.compose_containers, composeService, 7050))
175174
newABStub = ab_pb2.beta_create_AtomicBroadcast_stub(channel)
176175
self.atomicBroadcastStubsDict[composeService] = newABStub
177176
return newABStub
@@ -246,7 +245,7 @@ def generateBroadcastMessages(chainID = TEST_CHAIN_ID, numToGenerate = 1, timeTo
246245
time.sleep(timeToHoldOpen)
247246

248247

249-
def getGRPCChannel(ipAddress):
250-
channel = implementations.insecure_channel(ipAddress, 7050)
251-
print("Returning GRPC for address: {0}".format(ipAddress))
248+
def getGRPCChannel(host='localhost', port=7050):
249+
channel = implementations.insecure_channel(host, port)
250+
print("Returning GRPC for address: {0}:{1}".format(host,port))
252251
return channel

bddtests/steps/peer_basic_impl.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
JSONRPC_VERSION = "2.0"
3434

3535
class ContainerData:
36-
def __init__(self, containerName, ipAddress, envFromInspect, composeService):
36+
def __init__(self, containerName, ipAddress, envFromInspect, composeService, ports):
3737
self.containerName = containerName
3838
self.ipAddress = ipAddress
3939
self.envFromInspect = envFromInspect
4040
self.composeService = composeService
41+
self.ports = ports
4142

4243
def getEnv(self, key):
4344
envValue = None

0 commit comments

Comments
 (0)