Skip to content

Commit

Permalink
FAB-3264: Config Utility for Behave Func Tests
Browse files Browse the repository at this point in the history
This config utility contains methods that generates
configuration artifacts and used in the setup of the
fabric network when executing behave functional tests.

Change-Id: I372c1bec28a3f7cc5e836fcf928b6bfbe80d9ef5
Signed-off-by: Latitia M Haskins <latitia.haskins@gmail.com>
  • Loading branch information
lhaskins committed Apr 26, 2017
1 parent 62aec85 commit fd477e4
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 0 deletions.
150 changes: 150 additions & 0 deletions test/feature/configs/configtx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
################################################################################
#
# Profile
#
# - Different configuration profiles may be encoded here to be specified
# as parameters to the configtxgen tool.
#
################################################################################
Profiles:

# SampleInsecureSolo defines a configuration which uses the Solo orderer,
# contains no MSP definitions, and allows all transactions and channel
# creation requests.
SampleInsecureSolo:
Orderer:
<<: *OrdererDefaults
Application:
<<: *ApplicationDefaults

# SampleInsecureKafka defines a configuration that differs from the
# SampleInsecureSolo one only in that is uses the Kafka-based orderer.
SampleInsecureKafka:
Orderer:
<<: *OrdererDefaults
OrdererType: kafka
Application:
<<: *ApplicationDefaults

# SampleSingleMSPSolo defines a configuration which uses the Solo orderer,
# and contains a single MSP definition (the MSP sampleconfig).
SampleSingleMSPSolo:
Orderer:
<<: *OrdererDefaults
Organizations:
- *SampleOrg
Application:
<<: *ApplicationDefaults
Organizations:
- *SampleOrg

################################################################################
#
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:

# SampleOrg defines an MSP using the sampleconfig. It should never be used
# in production but may be used as a template for other definitions.
- &SampleOrg
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment.
Name: SampleOrg

# ID to load the MSP definition as.
ID: DEFAULT

# MSPDir is the filesystem path which contains the MSP configuration.
MSPDir: msp/sampleconfig

# BCCSP: Select which crypto implementation or library to use for the
# blockchain crypto service provider.
BCCSP:
Default: SW
SW:
# TODO: The default Hash and Security level needs refactoring to be
# fully configurable. Changing these defaults requires coordination
# SHA2 is hardcoded in several places, not only BCCSP
Hash: SHA2
Security: 256
# Location of key store. If this is unset, a location will
# be chosen using: 'MSPDir'/keystore
FileKeyStore:
KeyStore:

AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context.
- Host: 127.0.0.1
Port: 7051

################################################################################
#
# SECTION: Orderer
#
# - This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters.
#
################################################################################
Orderer: &OrdererDefaults

# Orderer Type: The orderer implementation to start.
# Available types are "solo" and "kafka".
OrdererType: solo

Addresses:
- 127.0.0.1:7050

# Batch Timeout: The amount of time to wait before creating a batch.
BatchTimeout: 2s

# Batch Size: Controls the number of messages batched into a block.
BatchSize:

# Max Message Count: The maximum number of messages to permit in a
# batch.
MaxMessageCount: 10

# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 99 MB

# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the
# preferred max bytes will result in a batch larger than preferred max
# bytes.
PreferredMaxBytes: 512 KB

# Max Channels is the maximum number of channels to allow on the ordering network
# When set to 0, this implies no maximum number of channels
MaxChannels: 0

Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects.
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092

# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network.
Organizations:

################################################################################
#
# SECTION: Application
#
# - This section defines the values to encode into a config transaction or
# genesis block for application related parameters.
#
################################################################################
Application: &ApplicationDefaults

# Organizations is the list of orgs which are defined as participants on
# the application side of the network.
Organizations:
File renamed without changes.
60 changes: 60 additions & 0 deletions test/feature/steps/config_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright IBM Corp. 2016 All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import subprocess
import os
import sys
from shutil import copyfile

def generateConfig(context, channelID, profile, ordererBlock="orderer.block"):
# Save all the files to a specific directory for the test
testConfigs = "configs/%s" % context.composition.projectName
if not os.path.isdir(testConfigs):
os.mkdir(testConfigs)

configFile = "configtx.yaml"
if os.path.isfile("configs/%s.yaml" % channelID):
configFile = "%s.yaml" % channelID
copyfile("configs/%s" % configFile, "%s/%s" %(testConfigs, configFile))

# Default location: /opt/gopath/src/github.com/hyperledger/fabric/common/configtx/tool/configtx.yaml
# Workaround until the -path option is added to configtxgen
os.environ['ORDERER_CFG_PATH'] = testConfigs

try:
subprocess.check_call(["configtxgen", "-profile", profile,
#"-path", configFile,
"-outputCreateChannelTx", "%s/%s.tx" % (testConfigs, channelID),
"-outputBlock", "%s/%s" % (testConfigs, ordererBlock),
"-channelID", channelID])
except:
print("Unable to generate channel config data: {0}".format(sys.exc_info()[0]))


def generateCrypto(context, numOrgs=2, numPeersPerOrg=2, numOrderers=1):
# Save all the files to a specific directory for the test
testConfigs = "configs/%s" % context.composition.projectName
if not os.path.isdir(testConfigs):
os.mkdir(testConfigs)

try:
subprocess.check_call(["cryptogen",
"-peerOrgs", numOrgs,
"-ordererNodes", numOrderers,
"-peersPerOrg", numPeersPerOrg,
"-baseDir", testConfigs])
except:
print("Unable to generate crypto material: {0}".format(sys.exc_info()[0]))

0 comments on commit fd477e4

Please sign in to comment.