Skip to content

Commit

Permalink
[FAB-1296] Enable some BDD tests to run on macOS
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Luis Sanchez committed Jan 14, 2017
1 parent 9e8fb87 commit e739050
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions bddtests/docker-compose-orderer-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
- ./volumes/orderer:/var/hyperledger/bddtests/volumes/orderer
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
ports:
- '7050'

volumes:

Expand Down
4 changes: 3 additions & 1 deletion bddtests/environments/orderer-1-kafka-1/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ services:
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
- ORDERER_KAFKA_BROKERS=[kafka0:9092]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
command: orderer -loglevel debug -verbose true
ports:
- '7050'
depends_on:
- kafka0

Expand Down
4 changes: 3 additions & 1 deletion bddtests/environments/orderer-1-kafka-3/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ services:
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
- ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
command: orderer -loglevel debug -verbose true
ports:
- '7050'
depends_on:
- kafka0
- kafka1
Expand Down
2 changes: 2 additions & 0 deletions bddtests/environments/orderer-n-kafka-n/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
- ORDERER_GENERAL_LISTENPORT=7050
- ORDERER_GENERAL_GENESISMETHOD=provisional
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
ports:
- '7050'
depends_on:
- zookeeper
- kafka
Expand Down
21 changes: 21 additions & 0 deletions bddtests/steps/bdd_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ def ipFromContainerNamePart(namePart, containerDataList):

return containerData.ipAddress

def getPortHostMapping(compose_container_data, compose_service_name, port, protocol='tcp'):
"""returns (host_ip, host_port)
Returns the host IP address port and port that maps to a container's exposed port.
If the port is not mapped, then the actual container IP address is returned.
"""
container = containerDataFromNamePart(compose_service_name, compose_container_data)
if container:
port_protocol = '%s/%s' % (port, protocol)
if port_protocol in container.ports:
port_mapping = container.ports[port_protocol]
host_ip = port_mapping[0]['HostIp']
host_port = int(port_mapping[0]['HostPort'])
return host_ip, host_port
else:
print('WARNING: Could not find port mapping for port {0}'.format(port_protocol))
# TODO so we don't break existing docker-compose tests on Vagrant just yet
print('WARNING: Returning the actual container IP address, which might not be routable from the host.')
return container.ipAddress, port
else:
raise Exception("Could not find container for service '{0}'".format(compose_service_name))

def fullNameFromContainerNamePart(namePart, containerDataList):
containerData = containerDataFromNamePart(namePart, containerDataList)

Expand Down
5 changes: 4 additions & 1 deletion bddtests/steps/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ def rebuildContainerData(self):
# container environment
container_env = container['Config']['Env']

# container exposed ports
container_ports = container['NetworkSettings']['Ports']

# container docker-compose service
container_compose_service = container['Config']['Labels']['com.docker.compose.service']

self.containerDataList.append(peer_basic_impl.ContainerData(container_name, container_ipaddress, container_env, container_compose_service))
self.containerDataList.append(peer_basic_impl.ContainerData(container_name, container_ipaddress, container_env, container_compose_service, container_ports))

def decompose(self):
self.issueCommand(["unpause"])
Expand Down
9 changes: 4 additions & 5 deletions bddtests/steps/orderer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ def getABStubForComposeService(self, context, composeService):
if composeService in self.atomicBroadcastStubsDict:
return self.atomicBroadcastStubsDict[composeService]
# Get the IP address of the server that the user registered on
ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
channel = getGRPCChannel(ipAddress)
channel = getGRPCChannel(*bdd_test_util.getPortHostMapping(context.compose_containers, composeService, 7050))
newABStub = ab_pb2.beta_create_AtomicBroadcast_stub(channel)
self.atomicBroadcastStubsDict[composeService] = newABStub
return newABStub
Expand Down Expand Up @@ -246,7 +245,7 @@ def generateBroadcastMessages(chainID = TEST_CHAIN_ID, numToGenerate = 1, timeTo
time.sleep(timeToHoldOpen)


def getGRPCChannel(ipAddress):
channel = implementations.insecure_channel(ipAddress, 7050)
print("Returning GRPC for address: {0}".format(ipAddress))
def getGRPCChannel(host='localhost', port=7050):
channel = implementations.insecure_channel(host, port)
print("Returning GRPC for address: {0}:{1}".format(host,port))
return channel
3 changes: 2 additions & 1 deletion bddtests/steps/peer_basic_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
JSONRPC_VERSION = "2.0"

class ContainerData:
def __init__(self, containerName, ipAddress, envFromInspect, composeService):
def __init__(self, containerName, ipAddress, envFromInspect, composeService, ports):
self.containerName = containerName
self.ipAddress = ipAddress
self.envFromInspect = envFromInspect
self.composeService = composeService
self.ports = ports

def getEnv(self, key):
envValue = None
Expand Down

0 comments on commit e739050

Please sign in to comment.