Exemple #1
0
def setup_ord(opts, upgrade=False):
    """Setup Orderer on K8S.

    Args:
        opts (dict): Nephos options dict.
        upgrade (bool): Do we upgrade the deployment? False by default.
    """
    # Kafka
    if "kafka" in opts["ordering"]:
        # Kafka upgrade is risky, so we disallow it by default
        version = get_version(opts, "kafka")
        kafka_config = get_kafka_configs(opts=opts)
        ord_namespace = get_namespace(opts, msp=kafka_config["msp"])
        config_yaml = f"{opts['core']['dir_values']}/{kafka_config['msp']}/kafka/{kafka_config['name']}.yaml"
        extra_vars = helm_extra_vars(version=version, config_yaml=config_yaml)
        helm_install(
            "incubator",
            "kafka",
            kafka_config["name"],
            ord_namespace,
            extra_vars=extra_vars,
        )
        helm_check(
            "kafka",
            kafka_config["name"],
            ord_namespace,
            pod_num=kafka_config["pod_num"],
        )

    for msp in get_msps(opts=opts):
        if not is_orderer_msp(opts=opts, msp=msp):
            continue
        ord_namespace = get_namespace(opts, msp=msp)
        version = get_version(opts, "hlf-ord")
        for release in get_orderers(opts=opts, msp=msp):
            # HL-Ord
            config_yaml = f'{opts["core"]["dir_values"]}/{msp}/hlf-ord/{release}.yaml'
            extra_vars = helm_extra_vars(version=version, config_yaml=config_yaml)
            if not upgrade:
                helm_install(
                    opts["core"]["chart_repo"],
                    "hlf-ord",
                    release,
                    ord_namespace,
                    extra_vars=extra_vars,
                )
            else:
                helm_upgrade(
                    opts["core"]["chart_repo"],
                    "hlf-ord",
                    release,
                    extra_vars=extra_vars,
                )
            helm_check("hlf-ord", release, ord_namespace)
            # Check that Orderer is running
            check_ord(ord_namespace, release)
Exemple #2
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")
Exemple #3
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}'"
                        )
                    )
Exemple #4
0
 def test_get_orderers(self):
     assert (["ord0", "ord1"] == get_orderers(opts=self.OPTS))
Exemple #5
0
 def test_get_orderers_from_msp_with_no_orderer(self):
     assert [] == get_orderers(opts=self.OPTS, msp="BetaMSP")
Exemple #6
0
 def test_get_orderers(self):
     assert {"ord2", "ord1"} == get_orderers(opts=self.OPTS, msp="AlphaMSP")