def start_explorer_impl(context, srcfile, dstfile, peer): try: testConfigs = config_util.makeProjectConfigDir(context) updated_env = config_util.updateEnviron(context) cmd = ['docker cp {0} {1}:{2}'.format(srcfile, peer, dstfile)] subprocess.call(cmd, shell=True, env=updated_env) except: print("Unable to copy {0} on {1}: {2}".format(srcfile, peer, sys.exc_info()[1]))
def get_block_num_impl(context, number, channel): updated_env = config_util.updateEnviron(context) time.sleep(2) chaincode = { "args": '["GetBlockByNumber","{0}","{1}"]'.format(channel, number), "chaincodeId": 'qscc', "name": 'qscc' } context.result = context.interface.query_chaincode( context, chaincode, "peer0.org1.example.com", channel, user="******")
def start_balancetransfer_impl(context): testConfigs = config_util.makeProjectConfigDir(context) curpath = os.path.realpath('.') shutil.copytree( "%s/fabric-samples/balance-transfer/artifacts/channel/crypto-config/ordererOrganizations" % (curpath), "%s/%s/ordererOrganizations" % (curpath, testConfigs)) shutil.copytree( "%s/fabric-samples/balance-transfer/artifacts/channel/crypto-config/peerOrganizations" % (curpath), "%s/%s/peerOrganizations" % (curpath, testConfigs)) os.chdir("{0}/fabric-samples/balance-transfer".format(curpath)) # In this step, composition will not be used, clear it once if hasattr(context, "composition"): del context.composition updated_env = config_util.updateEnviron(context) updated_env["COMPOSE_PROJECT_NAME"] = context.projectName updated_env["CORE_PEER_NETWORKID"] = context.projectName try: command = ["npm install --silent"] subprocess.call(command, shell=True, env=updated_env, stdout=FNULL) except: print("Failed npm install: {0}".format(sys.exc_info()[1])) try: command = ["./runApp.sh"] p = subprocess.Popen(command, shell=True, env=updated_env, stdout=subprocess.PIPE) except: print("Failed to start application: {0}".format(sys.exc_info()[1])) while True: line = p.stdout.readline() if "SERVER STARTED" in line: print(line) break else: time.sleep(1) try: command = ["./testAPIs.sh"] subprocess.call(command, shell=True, env=updated_env, stdout=FNULL) except: print("Failed to exectute REST API: {0}".format(sys.exc_info()[1])) os.chdir(curpath)
def generateCryptoArtifacts(context, channelID): testConfigs = config_util.makeProjectConfigDir(context) updated_env = config_util.updateEnviron(context) try: command = [ "../../fabric-samples/first-network/byfn.sh", "generate", "-c", channelID ] return subprocess.call(command, cwd=testConfigs, env=updated_env, stdout=FNULL, stderr=subprocess.STDOUT) #return subprocess.check_output(command, env=updated_env) except: print("Unable to inspect orderer config data: {0}".format( sys.exc_info()[1]))
def generateCryptoArtifacts(context, channelID, consensus_type): curpath = os.path.realpath('.') testConfigs = config_util.makeProjectConfigDir(context) updated_env = config_util.updateEnviron(context) try: command = [ "../../fabric-samples/first-network/byfn.sh", "generate", "-f", "docker-compose-explorer.yaml", "-c", channelID, "-o", consensus_type ] subprocess.call(command, cwd=testConfigs, env=updated_env, stderr=subprocess.STDOUT) except: print("Unable to generate crypto artifacts: {0}".format( sys.exc_info()[1])) try: shutil.rmtree( "{0}/fabric-samples/first-network/crypto-config".format(curpath), ignore_errors=True) shutil.copytree( "{0}/crypto-config".format(testConfigs), "{0}/fabric-samples/first-network/crypto-config".format(curpath)) shutil.copytree( "{0}/crypto-config/peerOrganizations".format(testConfigs), "{0}/peerOrganizations".format(testConfigs)) shutil.copytree( "{0}/crypto-config/ordererOrganizations".format(testConfigs), "{0}/ordererOrganizations".format(testConfigs)) except: print("Unable to copy crypto artifacts: {0}".format(sys.exc_info()[1])) try: shutil.rmtree( "{0}/fabric-samples/first-network/channel-artifacts".format( curpath), ignore_errors=True) shutil.copytree( "{0}/channel-artifacts".format(testConfigs), "{0}/fabric-samples/first-network/channel-artifacts".format( curpath)) except: print("Unable to copy channel artifacts: {0}".format( sys.exc_info()[1]))
def step_impl(context, peer, org, channel): try: testConfigs = config_util.makeProjectConfigDir(context) updated_env = config_util.updateEnviron(context) cmd = ['mkdir -p {0}/channel-artifacts'.format(testConfigs)] subprocess.call(cmd, shell=True, env=updated_env) cmd = [ 'configtxgen -configPath {1} -profile {0} -outputAnchorPeersUpdate ./{1}/channel-artifacts/{2}_{3}anchor.tx -channelID {2} -asOrg {3}' .format(config_util.CHANNEL_PROFILE, testConfigs, channel, org) ] subprocess.call(cmd, shell=True, env=updated_env) except: print("Unable to create anchor tx file for {0} on {1}: {2}".format( peer, channel, sys.exc_info()[1])) update_anchor(context, peer, channel, tx_filename='channel-artifacts/{0}_{1}anchor.tx'.format( channel, org))
def start_firstnetwork_impl(context, consensus_type="solo"): curpath = os.path.realpath('.') composeFiles = [ "%s/fabric-samples/first-network/docker-compose-explorer.yaml" % (curpath) ] config_util.makeProjectConfigDir(context) shutil.copyfile( "{0}/fabric-samples/first-network/crypto-config.yaml".format(curpath), "{0}/configs/{1}/crypto-config.yaml".format(curpath, context.projectName)) shutil.copyfile( "{0}/fabric-samples/first-network/configtx.yaml".format(curpath), "{0}/configs/{1}/configtx.yaml".format(curpath, context.projectName)) os.mkdir("{0}/configs/{1}/channel-artifacts".format( curpath, context.projectName)) generateCryptoArtifacts(context, "mychannel", consensus_type) # In this step, composition will not be used, clear it once if hasattr(context, "composition"): del context.composition updated_env = config_util.updateEnviron(context) updated_env["COMPOSE_PROJECT_NAME"] = context.projectName updated_env["CORE_PEER_NETWORKID"] = context.projectName os.chdir("{0}/fabric-samples/first-network".format(curpath)) try: command = [ "./byfn.sh up -f docker-compose-explorer.yaml -c {0} -o {1}". format("mychannel", consensus_type) ] subprocess.call(command, shell=True, env=updated_env, stdout=FNULL) except: print("Failed npm install: {0}".format(sys.exc_info()[1])) os.chdir(curpath)
def start_explorer_impl(context): try: testConfigs = config_util.makeProjectConfigDir(context) updated_env = config_util.updateEnviron(context) cmd = [ 'find {0} -iregex \'.*_sk$\' -type f | xargs -I[] dirname [] | xargs -I[] bash -c \'pushd [] && ln -s *_sk sk && popd\'' .format(testConfigs) ] subprocess.call(cmd, shell=True, env=updated_env) except: print("Unable to create symbolic link for secret keys: {0}".format( sys.exc_info()[1])) context.headers = {} context.base_url = "" context.json_responses = json_responses curpath = os.path.realpath('.') composeFiles = [ "%s/docker-compose/docker-compose-explorer.yaml" % (curpath) ] if not hasattr(context, "composition_explorer"): context.composition_explorer = compose_util.Composition( context, composeFiles, projectName=context.projectName, startContainers=False) else: context.composition_explorer.composeFilesYaml = composeFiles if hasattr(context, "composition"): env = context.composition.getEnv() for key, value in env.items(): context.composition_explorer.environ[key] = value context.composition_explorer.up()