Skip to content

Commit

Permalink
Merge branch 'main' into issue_upgrade-configtxgen-HLFv2.5.9
Browse files Browse the repository at this point in the history
Signed-off-by: YoungHypo <92037433+YoungHypo@users.noreply.github.com>
  • Loading branch information
YoungHypo authored Sep 27, 2024
2 parents e749bf8 + 77f7994 commit 0f692e6
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,7 @@ src/dashboard/lambda/mock/index.js
# Local Netlify folder
.netlify
deno.lock

# test postman
tests/postman/env.json
tests/postman/junitResult.xml
2 changes: 2 additions & 0 deletions src/api-engine/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
FABRIC_CA_CFG = "/opt/node/ca.yaml.bak"

FABRIC_CHAINCODE_STORE = "/opt/cello/chaincode"

FABRIC_VERSION = "2.5.9"
4 changes: 2 additions & 2 deletions src/api-engine/api/lib/configtxlator/configtxlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# SPDX-License-Identifier: Apache-2.0
#
from subprocess import call, run
from api.config import FABRIC_TOOL
from api.config import FABRIC_TOOL, FABRIC_VERSION


class ConfigTxLator:
"""
Class represents configtxlator CLI.
"""

def __init__(self, configtxlator=FABRIC_TOOL, version="2.2.0"):
def __init__(self, configtxlator=FABRIC_TOOL, version=FABRIC_VERSION):
self.configtxlator = configtxlator + "/configtxlator"
self.version = version

Expand Down
4 changes: 2 additions & 2 deletions src/api-engine/api/lib/peer/chaincode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import json
import subprocess
from api.lib.peer.command import Command
from api.config import FABRIC_TOOL, FABRIC_CFG
from api.config import FABRIC_TOOL, FABRIC_CFG, FABRIC_VERSION


class ChainCode(Command):
def __init__(self, version="2.2.0", peer=FABRIC_TOOL, **kwargs):
def __init__(self, version=FABRIC_VERSION, peer=FABRIC_TOOL, **kwargs):
self.peer = peer + "/peer"
super(ChainCode, self).__init__(version, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions src/api-engine/api/lib/peer/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import json
import subprocess
from api.lib.peer.command import Command
from api.config import FABRIC_TOOL
from api.config import FABRIC_TOOL, FABRIC_VERSION


class Channel(Command):
"""Call CMD to perform channel create, join and other related operations"""

def __init__(self, version="2.2.0", peer=FABRIC_TOOL, **kwargs):
def __init__(self, version=FABRIC_VERSION, peer=FABRIC_TOOL, **kwargs):
self.peer = peer + "/peer"
super(Channel, self).__init__(version, **kwargs)

Expand Down
33 changes: 27 additions & 6 deletions src/api-engine/api/lib/pki/cryptogen/cryptogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# SPDX-License-Identifier: Apache-2.0
#
from subprocess import call
from api.config import CELLO_HOME, FABRIC_TOOL
from api.config import CELLO_HOME, FABRIC_TOOL, FABRIC_VERSION

import logging
LOG = logging.getLogger(__name__)


class CryptoGen:
"""Class represents crypto-config tool."""

def __init__(self, name, filepath=CELLO_HOME, cryptogen=FABRIC_TOOL, version="2.2.0"):
def __init__(self, name, filepath=CELLO_HOME, cryptogen=FABRIC_TOOL, version=FABRIC_VERSION):
"""init CryptoGen
param:
name: organization's name
Expand All @@ -30,8 +33,17 @@ def generate(self, output="crypto-config", config="crypto-config.yaml"):
return:
"""
try:
call([self.cryptogen, "generate", "--output={}/{}/{}".format(self.filepath, self.name, output),
"--config={}/{}/{}".format(self.filepath, self.name, config)])
command = [
self.cryptogen,
"generate",
"--output={}/{}/{}".format(self.filepath, self.name, output),
"--config={}/{}/{}".format(self.filepath, self.name, config)
]

LOG.info("Running command: " + " ".join(command))

call(command)

except Exception as e:
err_msg = "cryptogen generate fail for {}!".format(e)
raise Exception(err_msg)
Expand All @@ -44,8 +56,17 @@ def extend(self, input="crypto-config", config="crypto-config.yaml"):
return:
"""
try:
call([self.cryptogen, "extend", "--input={}/{}/{}".format(self.filepath, self.name, input),
"--config={}/{}/{}".format(self.filepath, self.name, config)])
command = [
self.cryptogen,
"extend",
"--input={}/{}/{}".format(self.filepath, self.name, input),
"--config={}/{}/{}".format(self.filepath, self.name, config)
]

LOG.info("Running command: " + " ".join(command))

call(command)

except Exception as e:
err_msg = "cryptogen extend fail for {}!".format(e)
raise Exception(err_msg)
18 changes: 9 additions & 9 deletions src/api-engine/api/routes/chaincode/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def package(self, request):
# )
# peer_node = qs.first()
# envs = init_env_vars(peer_node, org)
# peer_channel_cli = PeerChainCode("v2.2.0", **envs)
# peer_channel_cli = PeerChainCode("v2.5.9", **envs)
# return_code, content = peer_channel_cli.lifecycle_calculatepackageid(temp_cc_path)
# if (return_code != 0):
# return Response(
Expand Down Expand Up @@ -241,7 +241,7 @@ def install(self, request):
peer_node = qs.first()
envs = init_env_vars(peer_node, org)

peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
res = peer_channel_cli.lifecycle_install(cc_targz)
if res != 0:
return Response(err("install chaincode failed."), status=status.HTTP_400_BAD_REQUEST)
Expand Down Expand Up @@ -270,7 +270,7 @@ def query_installed(self, request):
envs = init_env_vars(peer_node, org)

timeout = "5s"
peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
res, installed_chaincodes = peer_channel_cli.lifecycle_query_installed(
timeout)
if res != 0:
Expand Down Expand Up @@ -300,7 +300,7 @@ def get_installed_package(self, request):
envs = init_env_vars(peer_node, org)

timeout = "5s"
peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
res = peer_channel_cli.lifecycle_get_installed_package(timeout)
if res != 0:
return Response(err("get installed package failed."), status=status.HTTP_400_BAD_REQUEST)
Expand Down Expand Up @@ -352,7 +352,7 @@ def approve_for_my_org(self, request):
peer_node = qs.first()
envs = init_env_vars(peer_node, org)

peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
code, content = peer_channel_cli.lifecycle_approve_for_my_org(orderer_url, orderer_tls_root_cert, channel_name,
chaincode_name, chaincode_version, policy, sequence)
if code != 0:
Expand Down Expand Up @@ -384,7 +384,7 @@ def query_approved(self, request):
channel_name = request.data.get("channel_name")
cc_name = request.data.get("chaincode_name")

peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
code, content = peer_channel_cli.lifecycle_query_approved(
channel_name, cc_name)
if code != 0:
Expand Down Expand Up @@ -438,7 +438,7 @@ def check_commit_readiness(self, request):
peer_node = qs.first()
envs = init_env_vars(peer_node, org)

peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
code, content = peer_channel_cli.lifecycle_check_commit_readiness(orderer_url, orderer_tls_root_cert,
channel_name, chaincode_name,
chaincode_version, policy, sequence)
Expand Down Expand Up @@ -507,7 +507,7 @@ def commit(self, request):
peer_address_list.append(peer_address)
peer_root_certs.append(peer_tls_cert)

peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
code = peer_channel_cli.lifecycle_commit(orderer_url, orderer_tls_root_cert, channel_name,
chaincode_name, chaincode_version, policy,
peer_address_list, peer_root_certs, sequence)
Expand Down Expand Up @@ -539,7 +539,7 @@ def query_committed(self, request):
raise ResourceNotFound
peer_node = qs.first()
envs = init_env_vars(peer_node, org)
peer_channel_cli = PeerChainCode("v2.2.0", **envs)
peer_channel_cli = PeerChainCode(**envs)
code, chaincodes_commited = peer_channel_cli.lifecycle_query_committed(
channel_name, chaincode_name)
if code != 0:
Expand Down
7 changes: 3 additions & 4 deletions src/api-engine/api/routes/channel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from rest_framework.response import Response
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
from rest_framework.permissions import IsAuthenticated
#

from drf_yasg.utils import swagger_auto_schema

Expand Down Expand Up @@ -318,7 +317,7 @@ def update(self, request, pk=None):
env = {
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org.name, node.name + "." + org.name),
}
cli = PeerChannel("v2.2.0", **env)
cli = PeerChannel(**env)
cli.signconfigtx(
channel.get_channel_artifacts_path(CFG_DELTA_ENV_PB))
LOG.info("Peers to send the update transaction success")
Expand Down Expand Up @@ -349,7 +348,7 @@ def get_channel_org_config(self, request, pk=None):
env = {
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org.name, node.name + "." + org.name),
}
peer_channel_cli = PeerChannel("v2.2.0", **env)
peer_channel_cli = PeerChannel(**env)
peer_channel_cli.fetch(option="config", channel=channel.name)

# Decode latest config block into json
Expand Down Expand Up @@ -413,7 +412,7 @@ def join_peers(envs, block_path):
:param block_path: Path to file containing genesis block
"""
# Join the peers to the channel.
peer_channel_cli = PeerChannel("v2.2.0", **envs)
peer_channel_cli = PeerChannel(**envs)
peer_channel_cli.join(
block_file=block_path
)
Loading

0 comments on commit 0f692e6

Please sign in to comment.