github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/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 CHANNEL_PROFILE = "SysTestChannel" 23 24 def generateConfig(channelID, profile, ordererProfile, projectName, block="orderer.block"): 25 # Save all the files to a specific directory for the test 26 testConfigs = "configs/%s" % projectName 27 if not os.path.isdir(testConfigs): 28 os.mkdir(testConfigs) 29 30 configFile = "configtx.yaml" 31 if os.path.isfile("configs/%s.yaml" % channelID): 32 configFile = "%s.yaml" % channelID 33 34 copyfile("configs/%s" % configFile, "%s/configtx.yaml" % testConfigs) 35 36 # Copy config to orderer org structures 37 for orgDir in os.listdir("./{0}/ordererOrganizations".format(testConfigs)): 38 copyfile("{0}/configtx.yaml".format(testConfigs), 39 "{0}/ordererOrganizations/{1}/msp/config.yaml".format(testConfigs, 40 orgDir)) 41 # Copy config to peer org structures 42 for orgDir in os.listdir("./{0}/peerOrganizations".format(testConfigs)): 43 copyfile("{0}/configtx.yaml".format(testConfigs), 44 "{0}/peerOrganizations/{1}/msp/config.yaml".format(testConfigs, 45 orgDir)) 46 copyfile("{0}/configtx.yaml".format(testConfigs), 47 "{0}/peerOrganizations/{1}/users/Admin@{1}/msp/config.yaml".format(testConfigs, 48 orgDir)) 49 try: 50 command = ["configtxgen", "-profile", ordererProfile, 51 "-outputBlock", block, 52 "-channelID", channelID] 53 subprocess.check_call(command, cwd=testConfigs) 54 55 generateChannelConfig(channelID, profile, projectName) 56 generateChannelAnchorConfig(channelID, profile, projectName) 57 except: 58 print("Unable to generate channel config data: {0}".format(sys.exc_info()[1])) 59 60 def generateChannelConfig(channelID, profile, projectName): 61 testConfigs = "configs/%s" % projectName 62 try: 63 command = ["configtxgen", "-profile", profile, 64 "-outputCreateChannelTx", "%s.tx" % channelID, 65 "-channelID", channelID] 66 subprocess.check_call(command, cwd=testConfigs) 67 except: 68 print("Unable to generate channel config data: {0}".format(sys.exc_info()[1])) 69 70 def generateChannelAnchorConfig(channelID, profile, projectName): 71 testConfigs = "configs/%s" % projectName 72 for org in os.listdir("./{0}/peerOrganizations".format(testConfigs)): 73 try: 74 command = ["configtxgen", "-profile", profile, 75 "-outputAnchorPeersUpdate", "{0}{1}Anchor.tx".format(org, channelID), 76 "-channelID", channelID, 77 "-asOrg", org.title().replace('.', '')] 78 subprocess.check_call(command, cwd=testConfigs) 79 except: 80 print("Unable to generate channel anchor config data: {0}".format(sys.exc_info()[1])) 81 82 def generateCrypto(projectName): 83 # Save all the files to a specific directory for the test 84 testConfigs = "configs/%s" % projectName 85 if not os.path.isdir(testConfigs): 86 os.mkdir(testConfigs) 87 try: 88 subprocess.check_call(["cryptogen", "generate", 89 '--output={0}'.format(testConfigs), 90 '--config=./configs/crypto.yaml'], 91 env=os.environ) 92 except: 93 print("Unable to generate crypto material: {0}".format(sys.exc_info()[1]))