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 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)
Exemple #3
0
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)
Exemple #4
0
def start_firstnetwork_impl(context):
    curpath = os.path.realpath('.')
    composeFiles = [
        "%s/fabric-samples/first-network/docker-compose-cli.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))
    # config_util.buildCryptoFile(context, 2, 2, numOrderers, 2, ouEnable=ouEnabled)
    generateCryptoArtifacts(context, "mychannel")
    # config_util.generateCrypto(context, "./configs/{0}/crypto.yaml".format(context.projectName))
    # config_util.generateConfig(context, "byfn-sys-channel", "TwoOrgsChannel", "TwoOrgsOrdererGenesis")
    # shutil.copyfile("{0}/configs/{1}/byfn-sys-channel.tx".format(curpath, context.projectName), "{0}/configs/{1}/channel.tx".format(curpath, context.projectName))
    timeout = 120
    with common_util.Timeout(timeout):
        if not hasattr(context, "composition"):
            context.composition = compose_util.Composition(
                context,
                composeFiles,
                projectName=context.projectName,
                startContainers=True)
        else:
            context.composition.composeFilesYaml = composeFiles
            context.composition.up()
        context.compose_containers = context.composition.collectServiceNames()

        common_util.wait_until_in_log(
            ["cli"], "Query successful on peer1.org2 on channel ")
Exemple #5
0
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_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()
Exemple #9
0
def bootstrapped_impl(context, ordererType, database, tlsEnabled=False, timeout=300, ouEnabled=False, fca=False):
    assert ordererType in config_util.ORDERER_TYPES, "Unknown network type '%s'" % ordererType
    curpath = os.path.realpath('.')

    # Get the correct composition file
    context.composeFile = getCompositionFiles(context, curpath, ordererType, database, fca)

    # Should TLS be enabled
    context.tls = tlsEnabled
    projectName = None
    if hasattr(context, "projectName"):
        projectName = context.projectName
    compose_util.enableTls(context, tlsEnabled, projectName=projectName)

    # Perform bootstrap process
    context.ordererProfile = config_util.PROFILE_TYPES.get(ordererType, "SampleInsecureSolo")
    channelID = context.interface.SYS_CHANNEL_ID

    testConfigs, context = config_util.makeProjectConfigDir(context, returnContext=True)

    # Determine number of orderers
    numOrderers = 1
    if ordererType == 'kafka':
        numOrderers = 3

    # Get Configs setup
    if ouEnabled:
        config_util.buildCryptoFile(context, 2, 2, numOrderers, 2, ouEnable=ouEnabled)
        config_util.generateCrypto(context, "./{0}/crypto.yaml".format(testConfigs))
    else:
        config_util.generateCrypto(context)

    config_util.generateConfig(context, channelID, config_util.CHANNEL_PROFILE, context.ordererProfile)

    compose_impl(context, context.composeFile, projectName=context.projectName)
    wait_for_bootstrap_completion(context, timeout)