Skip to content

Commit 4bf9b93

Browse files
Move Docker-Compose files into their own folder
Move the BDD Docker compose files into a new sub folder so they are all in one place and do not clog up the root of the bddtests/ folder. While altering logic to determine the container names I also refactored the Docker-Compose parsing code to make it more clear as to what it was doing (parseComposeOutput in bdd_compose_util.py). I needed to add a dummy compose-defaults.yml file so that CI would successfully pass. When this change makes it into all branches then it can be removed and the CI scripts updated. I also changed the permissions on a couple of the bdd files from 755 to 644. Signed-off-by: Julian Carrivick <[email protected]> Change-Id: Iefd1007e79ee3827d39ed9b0bdec327f30e0c39f
1 parent c891561 commit 4bf9b93

29 files changed

+104
-65
lines changed

bddtests/bdd-docker/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# BDD Docker Compose Files
2+
These files are utilized by the BDD tests to provide standardized environments
3+
for running tests cases against. They also conveniently demonstrate some of the
4+
different configurations that the peers can be run in.
5+
6+
For convenience, all the configurations inherit from `compose-defaults.yml`.
7+
8+
Two important notes:
9+
10+
1. If a shell script is used as the docker comment to run (say, to add
11+
additional logic before starting a peer) then the shell script and the command
12+
should be invoked with an exec statement so that the signals that docker sends
13+
to the container get through to the process. Otherwise there will be a 10
14+
second when stopping a container before docker sends a SIGKILL.
15+
See the command used for the peer in `compose-defaults.yml` for an example
16+
17+
2. The name of peers should adhere to the convention of `vp[0-9]+` as this is
18+
the method as to which peers (as opposed to the membersrvc) are detected during
19+
the BDD runs. Peers are subjected to additional constraints before being
20+
considered 'ready'.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
vp:
2+
image: hyperledger/fabric-peer
3+
environment:
4+
- CORE_PEER_ADDRESSAUTODETECT=true
5+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
6+
# TODO: This is currently required due to BUG in variant logic based upon log level.
7+
- CORE_LOGGING_LEVEL=DEBUG
8+
# Script will wait until membersrvc is up (if it exists) before starting
9+
# $$GOPATH (double dollar) required to prevent docker-compose doing its own
10+
# substitution before the value gets to the container
11+
command: sh -c "exec $$GOPATH/src/github.com/hyperledger/fabric/bddtests/scripts/start-peer.sh"
12+
# Ideally we'd only mount /var/run/docker.sock but v1.5.2 of docker-compose
13+
# does not have to capability to mount individual files. Hence we mount the
14+
# entire folder in specific folder and specify it explicitly above.
15+
# This issue seems to be sorted in docker-compose 1.8.0 however that requires
16+
# Docker 1.10 and CI isn't at that version yet.
17+
volumes:
18+
- /var/run/:/host/var/run/
19+
20+
# Use these options if coverage desired for peers
21+
#image: hyperledger/fabric-peer-coverage
22+
#command: ./peer.test --test.coverprofile=coverage.cov node start
23+
membersrvc:
24+
image: hyperledger/fabric-membersrvc
25+
command: membersrvc
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vp3:
2+
environment:
3+
- CORE_PBFT_GENERAL_BYZANTINE=true
File renamed without changes.
File renamed without changes.
File renamed without changes.

bddtests/compose-defaults.yml

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
vp:
2-
image: hyperledger/fabric-peer
3-
environment:
4-
- CORE_PEER_ADDRESSAUTODETECT=true
5-
- CORE_VM_ENDPOINT=http://172.17.0.1:2375
6-
# TODO: This is currently required due to BUG in variant logic based upon log level.
7-
- CORE_LOGGING_LEVEL=DEBUG
8-
# Script will wait until membersrvc is up (if it exists) before starting
9-
# $$GOPATH (double dollar) required to prevent docker-compose doing its own
10-
# substitution before the value gets to the container
11-
command: sh -c "exec $$GOPATH/src/github.com/hyperledger/fabric/bddtests/scripts/start-peer.sh"
12-
13-
# Use these options if coverage desired for peers
14-
#image: hyperledger/fabric-peer-coverage
15-
#command: ./peer.test --test.coverprofile=coverage.cov node start
16-
membersrvc:
17-
image: hyperledger/fabric-membersrvc
18-
command: membersrvc
1+
- |
2+
This file is a simple dummy to satisfy the CI scripts which make modifications
3+
to this file. This file now lives in bddtests/bdd-docker. When the CI scripts
4+
are modified to remove that logic, this file can be removed.

bddtests/docker-compose-4-consensus-vp3-byzantine.yml

-3
This file was deleted.

bddtests/environment.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
import glob
44

55
from steps.bdd_test_util import cli_call, bdd_log
6+
from steps.bdd_compose_util import getDockerComposeFileArgsFromYamlFile
67

78
from steps.coverage import saveCoverageFiles, createCoverageAggregate
89

910
def coverageEnabled(context):
1011
return context.config.userdata.get("coverage", "false") == "true"
1112

12-
13-
def getDockerComposeFileArgsFromYamlFile(compose_yaml):
14-
parts = compose_yaml.split()
15-
args = []
16-
for part in parts:
17-
args = args + ["-f"] + [part]
18-
return args
19-
2013
def after_scenario(context, scenario):
2114
get_logs = context.config.userdata.get("logs", "N")
2215
if get_logs.lower() == "force" or (scenario.status == "failed" and get_logs.lower() == "y" and "compose_containers" in context):

bddtests/peer_logging.feature

100755100644
File mode changed.

bddtests/steps/bdd_compose_util.py

+45-28
Original file line numberDiff line numberDiff line change
@@ -43,50 +43,29 @@ def __str__(self):
4343
def __repr__(self):
4444
return self.__str__()
4545

46+
DOCKER_COMPOSE_FOLDER = "bdd-docker"
47+
4648
def getDockerComposeFileArgsFromYamlFile(compose_yaml):
4749
parts = compose_yaml.split()
4850
args = []
4951
for part in parts:
52+
part = "{}/{}".format(DOCKER_COMPOSE_FOLDER, part)
5053
args = args + ["-f"] + [part]
5154
return args
5255

5356
def parseComposeOutput(context):
5457
"""Parses the compose output results and set appropriate values into context. Merges existing with newly composed."""
55-
# Use the prefix to get the container name
56-
containerNamePrefix = os.path.basename(os.getcwd()) + "_"
57-
containerNames = []
58-
for l in context.compose_error.splitlines():
59-
tokens = l.split()
60-
bdd_log(tokens)
61-
if 1 < len(tokens):
62-
thisContainer = tokens[1]
63-
if containerNamePrefix not in thisContainer:
64-
thisContainer = containerNamePrefix + thisContainer + "_1"
65-
if thisContainer not in containerNames:
66-
containerNames.append(thisContainer)
58+
containerNames = getContainerNamesFromContext(context)
6759

6860
bdd_log("Containers started: ")
6961
bdd_log(containerNames)
7062
# Now get the Network Address for each name, and set the ContainerData onto the context.
7163
containerDataList = []
7264
for containerName in containerNames:
73-
output, error, returncode = \
74-
cli_call(["docker", "inspect", "--format", "{{ .NetworkSettings.IPAddress }}", containerName], expect_success=True)
75-
bdd_log("container {0} has address = {1}".format(containerName, output.splitlines()[0]))
76-
ipAddress = output.splitlines()[0]
65+
ipAddress = getIpFromContainerName(containerName)
66+
env = getEnvironmentVariablesFromContainerName(containerName)
67+
dockerComposeService = getDockerComposeServiceForContainer(containerName)
7768

78-
# Get the environment array
79-
output, error, returncode = \
80-
cli_call(["docker", "inspect", "--format", "{{ .Config.Env }}", containerName], expect_success=True)
81-
env = output.splitlines()[0][1:-1].split()
82-
83-
# Get the Labels to access the com.docker.compose.service value
84-
output, error, returncode = \
85-
cli_call(["docker", "inspect", "--format", "{{ .Config.Labels }}", containerName], expect_success=True)
86-
labels = output.splitlines()[0][4:-1].split()
87-
dockerComposeService = [composeService[27:] for composeService in labels if composeService.startswith("com.docker.compose.service:")][0]
88-
bdd_log("dockerComposeService = {0}".format(dockerComposeService))
89-
bdd_log("container {0} has env = {1}".format(containerName, env))
9069
containerDataList.append(Container(containerName, ipAddress, env, dockerComposeService))
9170
# Now merge the new containerData info with existing
9271
newContainerDataList = []
@@ -98,6 +77,44 @@ def parseComposeOutput(context):
9877
setattr(context, "compose_containers", newContainerDataList)
9978
bdd_log("")
10079

80+
def getContainerNamesFromContext(context):
81+
containerNames = []
82+
for l in context.compose_error.splitlines():
83+
tokens = l.split()
84+
85+
if len(tokens) > 1:
86+
thisContainer = tokens[1]
87+
88+
if thisContainer not in containerNames:
89+
containerNames.append(thisContainer)
90+
91+
return containerNames
92+
93+
def getIpFromContainerName(containerName):
94+
output, error, returncode = \
95+
cli_call(["docker", "inspect", "--format", "{{ .NetworkSettings.IPAddress }}", containerName], expect_success=True)
96+
bdd_log("container {0} has address = {1}".format(containerName, output.splitlines()[0]))
97+
98+
return output.splitlines()[0]
99+
100+
def getEnvironmentVariablesFromContainerName(containerName):
101+
output, error, returncode = \
102+
cli_call(["docker", "inspect", "--format", "{{ .Config.Env }}", containerName], expect_success=True)
103+
env = output.splitlines()[0][1:-1].split()
104+
bdd_log("container {0} has env = {1}".format(containerName, env))
105+
106+
return env
107+
108+
def getDockerComposeServiceForContainer(containerName):
109+
# Get the Labels to access the com.docker.compose.service value
110+
output, error, returncode = \
111+
cli_call(["docker", "inspect", "--format", "{{ .Config.Labels }}", containerName], expect_success=True)
112+
labels = output.splitlines()[0][4:-1].split()
113+
dockerComposeService = [composeService[27:] for composeService in labels if composeService.startswith("com.docker.compose.service:")][0]
114+
bdd_log("dockerComposeService = {0}".format(dockerComposeService))
115+
116+
return dockerComposeService
117+
101118
def allContainersAreReadyWithinTimeout(context, timeout):
102119
timeoutTimestamp = time.time() + timeout
103120
formattedTime = time.strftime("%X", time.localtime(timeoutTimestamp))

bddtests/steps/bdd_test_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ def bdd_log(msg):
8383
print("{} - {}".format(currentTime(), msg))
8484

8585
def currentTime():
86-
return time.strftime("%H:%M:%S")
86+
return time.strftime("%H:%M:%S")

bddtests/steps/peer_basic_impl.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def transactionCommittedToContainersWithinTimeout(context, containers, timeout):
393393
.format(container.name)
394394

395395
def responseIsOk(response):
396-
isResponseOk = False;
396+
isResponseOk = False
397397

398398
status_code = response.status_code
399399
assert status_code == 200 or status_code == 404, \
@@ -578,12 +578,6 @@ def step_impl(context):
578578

579579
context.peerToSecretMessage = peerToSecretMessage
580580

581-
582-
@given(u'I stop peers')
583-
def step_impl(context):
584-
compose_op(context, "stop")
585-
586-
587581
@given(u'I start a listener')
588582
def step_impl(context):
589583
gopath = os.environ.get('GOPATH')
@@ -597,6 +591,10 @@ def step_impl(context):
597591
def step_impl(context):
598592
compose_op(context, "start")
599593

594+
@given(u'I stop peers')
595+
def step_impl(context):
596+
compose_op(context, "stop")
597+
600598
@given(u'I pause peers')
601599
def step_impl(context):
602600
compose_op(context, "pause")

0 commit comments

Comments
 (0)