Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#issue-320] lifecycle_query_installed&lifecycle_get_installed_package #321

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/api-engine/api/lib/peer/chaincode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json
from api.lib.peer.basicEnv import BasicEnv
from api.config import FABRIC_TOOL
from api.config import FABRIC_TOOL, FABRIC_CFG


class ChainCode(BasicEnv):
Expand Down Expand Up @@ -39,3 +40,49 @@ def lifecycle_install(self, cc_targz):
err_msg = "install chaincode failed for {}!".format(e)
raise Exception(err_msg)
return res

def lifecycle_query_installed(self, timeout):
"""
get the chaincode info installed in peer.
:param timeout:
:return: res 0 means success
installed_chaincodes: the json format of installed_chaincodes info
"""

try:
res = os.system("{} lifecycle chaincode queryinstalled --output json --connTimeout {}"
" > ./queryInstalled.txt".format(self.peer, timeout))
with open('./queryInstalled.txt', 'r', encoding='utf-8') as f:
content = f.read()
os.system("rm ./queryInstalled.txt")
installed_chaincodes = json.loads(content)
except Exception as e:
err_msg = "query_installed chaincode info failed for {}!".format(e)
raise Exception(err_msg)
return res, installed_chaincodes

def lifecycle_get_installed_package(self, timeout):
"""
lifecycle_query_installed will return a list installed in peer.
then execute cmd to get all chaincode with tar.gz format installed in peer.
:param timeout:
:return: res_return: 0 means success get all chaincode in peers.
"""
try:
res, installed = self.lifecycle_query_installed("3s")
res_return = 0
if res == 0:
for item in installed['installed_chaincodes']:
res_get = os.system("{} lifecycle chaincode getinstalledpackage --package-id {} "
"--output-directory {} --connTimeout {}".format(self.peer,
item['package_id'], FABRIC_CFG, timeout))
res_get = res_get >> 8
res_return = res_return or res_get
else:
print("package_id get failed.")
return 1, {}
except Exception as e:
err_msg = "get_installed_package failed for {}!".format(e)
raise Exception(err_msg)
return res_return