Example #1
0
def setup_nodes(opts):
    """Setup identities for nodes.

    Args:
        opts (dict): Nephos options dict.
    """
    for msp in get_msps(opts=opts):
        for peer in get_peers(opts=opts, msp=msp):
            setup_id(opts, msp, peer, "peer")

    for msp in get_msps(opts=opts):
        for orderer in get_orderers(opts=opts, msp=msp):
            setup_id(opts, msp, orderer, "orderer")
Example #2
0
def create_channel(opts):
    """Create Channel for Peer.

    Args:
        opts (dict): Nephos options dict.
        
    """
    ord_msp = get_an_orderer_msp(opts=opts)
    ord_namespace = get_namespace(opts, msp=ord_msp)
    ord_name = random.choice(list(get_orderers(opts=opts, msp=ord_msp)))
    cmd_suffix = peer_channel_suffix(opts, ord_msp, ord_name)

    for msp in get_msps(opts=opts):
        peer_namespace = get_namespace(opts, msp=msp)

        for channel in get_channels(opts=opts):
            channel_name = opts["channels"][channel]["channel_name"]
            secret_channel = opts["channels"][channel]["secret_channel"]
            if msp not in opts["channels"][channel]["msps"]:
                continue
            for index, release in enumerate(get_peers(opts=opts, msp=msp)):
                # Get peer pod
                pod_ex = get_helm_pod(peer_namespace, release, "hlf-peer")

                # Check if the file exists
                has_channel = False
                while not has_channel:
                    has_channel = get_channel_block(
                        pod_ex, ord_name, ord_namespace, channel_name, cmd_suffix
                    )
                    if not has_channel:
                        pod_ex.execute(
                            (
                                "bash -c 'peer channel create "
                                + f"-o {ord_name}-hlf-ord.{ord_namespace}.svc.cluster.local:7050 "
                                + f"-c {channel_name} -f /hl_config/channel/{secret_channel}/{channel_name}.tx {cmd_suffix}'"
                            )
                        )
                res, _ = pod_ex.execute("peer channel list")
                channels = (res.split("Channels peers has joined: ")[1]).split()
                if channel_name not in channels:
                    pod_ex.execute(
                        (
                            "bash -c "
                            + "'CORE_PEER_MSPCONFIGPATH=$ADMIN_MSP_PATH "
                            + f"peer channel join -b /var/hyperledger/{channel_name}.block {cmd_suffix}'"
                        )
                    )
Example #3
0
def create_channel(opts):
    """Create Channel for Peer.

    Args:
        opts (dict): Nephos options dict.
        
    """
    peer_namespace = get_namespace(opts, opts["peers"]["msp"])
    ord_namespace = get_namespace(opts, opts["orderers"]["msp"])
    channel = opts["peers"]["channel_name"]
    # Get orderer TLS status
    ord_name = random.choice(opts["orderers"]["names"])
    # TODO: This should be a function
    cmd_suffix = peer_channel_suffix(opts, ord_name)

    for index, release in enumerate(get_peers(opts=opts)):
        # Get peer pod
        pod_ex = get_helm_pod(peer_namespace, release, "hlf-peer")

        # Check if the file exists
        has_channel = False
        while not has_channel:
            has_channel = get_channel_block(pod_ex, ord_name, ord_namespace,
                                            channel, cmd_suffix)
            if not has_channel:
                pod_ex.execute((
                    "bash -c 'peer channel create " +
                    f"-o {ord_name}-hlf-ord.{ord_namespace}.svc.cluster.local:7050 "
                    +
                    f"-c {opts['peers']['channel_name']} -f /hl_config/channel/{channel}.tx {cmd_suffix}'"
                ))
        res, _ = pod_ex.execute("peer channel list")
        channels = (res.split("Channels peers has joined: ")[1]).split()
        if opts["peers"]["channel_name"] not in channels:
            pod_ex.execute((
                "bash -c " + "'CORE_PEER_MSPCONFIGPATH=$ADMIN_MSP_PATH " +
                f"peer channel join -b /var/hyperledger/{opts['peers']['channel_name']}.block {cmd_suffix}'"
            ))
Example #4
0
 def test_get_peers(self):
     assert (["peer0", "peer1"] == get_peers(opts=self.OPTS))
Example #5
0
 def test_get_peers(self):
     assert {"peer0", "peer1"} == get_peers(opts=self.OPTS, msp="BetaMSP")
Example #6
0
def setup_peer(opts, upgrade=False):
    """Setup Peer on K8S.

    Args:
        opts (dict): Nephos options dict.
        upgrade (bool): Do we upgrade the deployment? False by default.
        
    """
    for msp in get_msps(opts=opts):
        peer_namespace = get_namespace(opts, msp=msp)
        for release in get_peers(opts=opts, msp=msp):
            # Deploy the CouchDB instances
            version = get_version(opts, "hlf-couchdb")
            config_yaml = (
                f'{opts["core"]["dir_values"]}/{msp}/hlf-couchdb/cdb-{release}.yaml'
            )
            if not upgrade:
                extra_vars = helm_extra_vars(version=version,
                                             config_yaml=config_yaml)
                helm_install(
                    opts["core"]["chart_repo"],
                    "hlf-couchdb",
                    f"cdb-{release}",
                    peer_namespace,
                    extra_vars=extra_vars,
                )
            else:
                preserve = (
                    HelmPreserve(
                        peer_namespace,
                        f"cdb-{release}-hlf-couchdb",
                        "COUCHDB_USERNAME",
                        "couchdbUsername",
                    ),
                    HelmPreserve(
                        peer_namespace,
                        f"cdb-{release}-hlf-couchdb",
                        "COUCHDB_PASSWORD",
                        "couchdbPassword",
                    ),
                )
                extra_vars = helm_extra_vars(version=version,
                                             config_yaml=config_yaml,
                                             preserve=preserve)
                helm_upgrade(
                    opts["core"]["chart_repo"],
                    "hlf-couchdb",
                    f"cdb-{release}",
                    extra_vars=extra_vars,
                )
            helm_check("hlf-couchdb", f"cdb-{release}", peer_namespace)

            # Deploy the HL-Peer charts
            version = get_version(opts, "hlf-peer")
            config_yaml = f"{opts['core']['dir_values']}/{msp}/hlf-peer/{release}.yaml"
            extra_vars = helm_extra_vars(version=version,
                                         config_yaml=config_yaml)
            if not upgrade:
                helm_install(
                    opts["core"]["chart_repo"],
                    "hlf-peer",
                    release,
                    peer_namespace,
                    extra_vars=extra_vars,
                )
            else:
                helm_upgrade(
                    opts["core"]["chart_repo"],
                    "hlf-peer",
                    release,
                    extra_vars=extra_vars,
                )
            helm_check("hlf-peer", release, peer_namespace)
            # Check that peer is running
            check_peer(peer_namespace, release)