github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/test/feature/steps/config_util.py (about) 1 # Copyright IBM Corp. 2017 All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 17 import subprocess 18 import os 19 import sys 20 from shutil import copyfile 21 22 def generateConfig(channelID, profile, projectName, ordererBlock="orderer.block"): 23 # Save all the files to a specific directory for the test 24 testConfigs = "configs/%s" % projectName 25 if not os.path.isdir(testConfigs): 26 os.mkdir(testConfigs) 27 28 configFile = "configtx.yaml" 29 if os.path.isfile("configs/%s.yaml" % channelID): 30 configFile = "%s.yaml" % channelID 31 copyfile("configs/%s" % configFile, "%s/%s" %(testConfigs, configFile)) 32 33 # Default location: /opt/gopath/src/github.com/hyperledger/fabric/common/configtx/tool/configtx.yaml 34 # Workaround until the -path option is added to configtxgen 35 os.environ['ORDERER_CFG_PATH'] = testConfigs 36 37 try: 38 subprocess.check_call(["configtxgen", "-profile", profile, 39 #"-path", configFile, 40 "-outputCreateChannelTx", "%s/%s.tx" % (testConfigs, channelID), 41 "-outputBlock", "%s/%s" % (testConfigs, ordererBlock), 42 "-channelID", channelID]) 43 except: 44 print("Unable to generate channel config data: {0}".format(sys.exc_info()[0])) 45 46 47 def generateCrypto(projectName): 48 # Save all the files to a specific directory for the test 49 testConfigs = "configs/%s" % projectName 50 if not os.path.isdir(testConfigs): 51 os.mkdir(testConfigs) 52 53 try: 54 subprocess.check_call(["cryptogen", "generate", 55 '--output={0}'.format(testConfigs), 56 '--config=./configs/crypto.yaml']) 57 except: 58 print("Unable to generate crypto material: {0}".format(sys.exc_info()[1]))